Where do I start rendering worlds in 2 triangles? :D

category: general [glöplog]
Do you know/have any sample code with a simple raytracer done on a shader, maybe with a couple of spheres? I have no idea where to start... well I have an idea, but... my doubt comes to the whole structure of the code, not the math... at the moment. Do you do one pass per object? How does it work?
added on the 2009-10-04 22:57:32 by xernobyl xernobyl
You very simply set up a program that renders a quad using a single pixel shader. In this shader, you handle it all. Complete traversal of the scene for each pixel. For smaller or test stuff you can very well even hardcode these scenes in the pixelshader itself. Otherwise you use shader constants and possibly texture data to feed your tracer.

Again, this is a simple approach. But most of those 4Ks don't do much else than this. And some of them have source available, so have a look..

added on the 2009-10-04 23:06:31 by superplek superplek
(and obviously, you can use the interpolated position fed by your vertex shader, typically -1 to 1 on an both axii as your screen position)

Then again, I haven't done too much tracing in shaders yet, the more seasoned people can probably give some nice pointers as well. Also, there are a few more topics that have (psuedo) code in them - that should more or less give you an idea.
added on the 2009-10-04 23:10:19 by superplek superplek
you could do this:
aint the sphere_tracing every1 does right now tho, but theres a thread about sphere_tracing @pouet somewhere already !
And some of them have source available

Obfuscated code is not what I call source :D

cocoon: that should help. I'll take a deeeper look.
added on the 2009-10-04 23:18:03 by xernobyl xernobyl
Yeah I'm with you on that obfuscated thing - but not all have supplied it like that right?

That blog has some good 'start here' stuff on it too.
added on the 2009-10-04 23:19:15 by superplek superplek
There are a zillion raymarching topics on pouet. Also check out the iq presentation(s) which you most likely already know about...
yeh, and try start solving quartic equations. *bang*
added on the 2009-10-05 00:19:51 by rudi rudi
xernobyl: opengl or directx? I have both for this, but only the old (and obfuscated shader source) ogl version in the released archieve (I'm using the effect as a "benchmark" for 1k framework experiments).
added on the 2009-10-05 00:42:03 by Psycho Psycho
On the other hand, the ogl version is rendering a quad and the dx a single triangle so that's not what you are asking for ;)
added on the 2009-10-05 00:43:13 by Psycho Psycho
xernobyl: http://iquilezles.org/www/material/isystem1k4k/isystem1k4k.htm

Just pick Lumos, Accio or Reducto. These are exactly what you are asking for.
added on the 2009-10-05 01:21:05 by iq iq
Ok, I get it for a few simple shapes, anything else that requires some sort of geometry sorting and a few optimizations is out of the question, like feeding a few triangles to a shader?
added on the 2009-10-05 03:48:26 by xernobyl xernobyl
BB Image

A new gfx card to play with on such a busy week...
added on the 2009-10-05 04:10:46 by xernobyl xernobyl

Really cool samples. I'm just trying it (VC 2008), and I get these results:

It works, but flickers a lot. I'm not sure if it is an error or how it should work anyway... and maybe because of my drivers maybe? Whatever

Works perfect.

1>.\src\intro.cpp(9) : fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory

Shows a static image for few seconds, then some weird flickering for less than a second, then again the same static image.

1>.\src\intro.cpp(9) : fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory

I'm not sure if this is working correctly or not. There is a rotating cube that looks fine and a continuous beep in the same tone as "music"

The raytracing works fine, there is the same beep as in the thing above.

Looks to be working correctly, but very slow (maybe 10-15 fps) and no sound support.

My specs: Windows Vista SP2 32 bits, Intel Core 2 4400, Raden X1650, DirectX 10

What I have to do to be able to compile the d3dx9.h samples? I suppose I should download any SDK or whatever? Wich one? And should I install it doing anything special?

And, should I learn for the first time with the HLSL or the GLSL? Is there any difference in speed or something? I just want to code for Windows right now, so I don't need portability if that is a difference.

added on the 2009-10-05 05:06:02 by texel texel
texel, you could download and install the directx sdk :D
added on the 2009-10-05 07:05:38 by leb00ster leb00ster
And those who want sources for "big shader 4ks" that are not obfuscated, just take a look at valleyball
added on the 2009-10-05 09:39:57 by xTr1m xTr1m
Update: after installing DirectX SDK, and doing nothing more, d3dx9.h samples works flawlessly :D
added on the 2009-10-06 00:34:01 by texel texel
A note on IQs HLSL sample:

If you want to make a shader model 3 program, you have to make a shader model 3 vertex shader and pixel shader with shader model 3 too.

If you just change in the pixel shader the 2 by a 3 in the compile function, it doesn't work unless you add a vertex shader 3 too.

This took me a lot of hours to understand yesterday, so I think it could be worth to add a sample for sm3 (and sm4 maybe) in the Iqs code collection... I will tell him to do it.
added on the 2009-10-06 20:59:31 by texel texel
I have recently tried the IQ samples frameworks... thanks to IQ for it! At least it gives a simple overview about the think "2 triangles, 1 world"
(by the way.. IQ past some of source code of a procedural GFX in another poet thread)

what about make some "nehe" tutorials for intros? .. someone try get in examples like IQ ones and make some good explanation will be cool