Mary Chang
Mary Chang

Reputation: 955

Is it possible to raytrace with GLSL while using OpenGL in a normal way

Is is possible to write a shader in GLSL so that I can turn OpenGL into a ray tracer? Something like the following.

glUseProgram(rayTracer);
//than do anything you do in OpenGL normally
glEnable(GL_LIGHT0);
gl....//Set light parameters
...
//Draw The theme
glDrawArray(.......);

Than the result result will rendered by raytracing. eg: physically correct illumination

I have tried this. But I failed that I can't get all the triangles vertex and color/texture in vertex/fragment shader in order to do raytracing.

Is it possible to create this kind of shader? If it's possible, how and where should I start?

Upvotes: 0

Views: 1038

Answers (2)

derhass
derhass

Reputation: 45322

No, this is not possible. Raytracing is a golbal illumination model. This means that access to the whole scene with all objects and light sources is required, for obvious reasons. The rendering pipleine OpenGL implements never sees more than a single primitive at a time. While one can do raytricing on the GPU, this is completely different from just writing some shader that can work as a drop-in replacement while keeping the rest of the rendering algorithm the same. You need to completely reogranize the data, and the GL drawing functions are of no good use at all anymore.

Upvotes: 1

quantumfoam
quantumfoam

Reputation: 55

Check this examples from OpenGl superbible. http://www.openglsuperbible.com/example-code/

There is an example called "raytracer".

On Windows/Visual studio express, to make it run correctly, you might want to change paths to absolute, with "\\" directory separators instead of "/" in "load_shaders()" function.

Then, +/- keys change recursion depth, other control keys you find in source code.

Maybe the example is not so straightforward as you'd expect, but ... here's where you can start.

Upvotes: 0

Related Questions