Phong Shading: Which Space to transform into?

Started by
1 comment, last by directNoob 16 years, 10 months ago
Hi folks. Currently I try to implement Phong shading. But I am totally confused!!! In which space do I have to transform all vectors? In the fragment shader I use gl_FragCoord to calculate per pixel lighting. But in which space do I have to transform the eye pos or the normals or the light pos? gl_FragCoord is still in projection space. So, do I need to transform into proj space? Need help please !!! Grateful Alex
Advertisement
You can perform lighting in almost any 3d space. So the choice depends on which would be the most efficent.
As your lights are already in world space this is your first option. but if your using a reflection model which uses the view vector (e.g phong) then its probably more efficient to do the calculations in eye space.

Not used the fragment shader with opengl, but if you glFragcoord uses proj space then you'd have to transform your light and view vectors to proj space.
Hi.

The problem is, that proj space is 2D, so you would loose the 3rd dim.
So, if I transform everything into proj space, I couldn't do any calculation which are 3d dependant. And also, as I said, grabbing data from gl_FragCoord is also not correct in this case.
But how I figured out now, the point is the rasterizer.
Because the rasterizer is linear interpolating every vector/data I pass through.
This means, I have to pass light dir, normal and eye vector form the vertex shader and from a per vertex basis through the rasterizer, so I can grap data per pixel.

And in GLSL, this seems to be a simple task, because you have the varying qualifier. And in terms of ATIs RenderMonkey examples, specified varying variables gets linear interpolated by the rasterizer.

But thanks anyway
Alex

This topic is closed to new replies.

Advertisement