Hello all,
I was trying to develop a basic Ray Tracer in GLSL on my PC. Then i came to know about GLSL SandBox.I started my shader development in that as it appeared awesome.
I have a plane and two spheres in my scene. Now my problem is that one of the sphere won’t show up when i run same shader in my own C++ OpenGL code or in Render Monkey on my PC. Basically that sphere become a ghost while its reflections and shadows are visible. Is it any bug or what ?
please find both outputs in attached image files with post.
also link to my shader is RayTrace
My graphic card is ATI Radeon 5470 Mobility. it supports Shader Model 3.0.
That worked like charm for smoothing out Reflections…thank you very much for that… but it did not helped in different output problem i.e. i am still getting different outputs (same as before) on sandbox and OpenGL Code/C++ .
But in your function you did not calculate second root of quadratic equation… why is that ?? and why that work more accurately ??
but it did not helped in different output problem i.e. i am still getting different outputs (same as before) on sandbox and OpenGL Code/C++ .
Well there must be something wrong in your c++ side. Could u show us how u r doing it.
But in your function you did not calculate second root of quadratic equation… why is that ?? and why that work more accurately ??
The solution of this quadratic eq. gives two roots, one t where the ray enters the sphere and the other t where it leaves it. My code takes the nearest t value only since that is the value we need. Since you were taking both of these values and because u initialized the local t value with 0 and not a big value, some values were taken from the back side of the sphere thus u got those grains in the reflection. Usually I see people calculating both t values when infact only the nearest t value is needed.
void reshape(int w, int h)
{
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
// ratio = 1.0f * w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the clipping volume
gluPerspective(100,1.0f * w / h,1,2000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
Why do u use perspective projection? You only need to draw a full screen quad that makes sure that the raytrace fragment shader runs for the whole screen. The projection code is controlled by the raytrace fragment shader.
I dont know if this helps in solving your problem but I would instead use an orthographic projection like this
glOrtho(0,1,0,1,0,1);
Then in my render function, I would specify the quad as follows.
When i started with ray tracer i didn’t know that i will be needing a full screen quad. I thought that i ll be applying ray tracer on OpenGL primitives.
I changed my projection type and quad code as per your suggestion but still it is producing same results…