Sign in to follow this  

Basic Per Pixel Lighting/Specular Question

This topic is 3483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a tessellated plane (128x128 vertices), which I've applied a texture and a normal map to. In the pixel shader I use the sampled normal along with the vertex-to-eye vector and the vertex-to-light vector to work out the lighting and specular highlight at that point on the plane. All pretty standard stuff... nothing out of the ordinary. Since the plane is entirely flat, I thought that it is silly to render a 128x128 vertex plane when I could just render a 2x2 plane (i.e. a quad) and it would look that same. So I changed this, but now my lighting has stopped working. I know why, I just don't know how to get around the problem. The previously highly tessellated plane allowed for the vertex-to-eye and vertex-to-light vectors to interpolate across the plane. With a quad however, you only have four vertices. So your vertex-to-whatever vector can only be one of four absolute values. You lose the interpolation across the plane. This results in large very blocky and very sudden lighting as the vectors change across the plane from one sides extreme to the other. I'm just wondering how I go about tackling this problem. How do I do per-pixel lighting on a simple quad surface with no tessellation? How do I determine the to-eye and to-light vectors from any point on the plane? I'll just point out that the plane is on the xz axis and everything is done in world space, which is also object space in this case, so therefore I have no need for tangent space.

Share this post


Link to post
Share on other sites
It would be good if you posted your shaders. I'm not sure I understand how your lighting can be blocky, since vertex output data is still interpolated for the pixel shader. However, you can always compute the vectors in the pixel shader. You can get the coordinate of a pixel by simply passing the vertex coordinate from the vertex shader to the pixel shader.

Share this post


Link to post
Share on other sites
In cases like these, do not use vertex-eye or vertex-light, but rather fragment-eye and fragment-light. The basic idea is to pass your vertex position down to the pixel shader using a texture coordinate slot (so it gets linearly interpolated). This gives you the exact fragment position. Now, you'll want to calculate the eye/light directions at the fragment level - this way the calculations are independent of vertices.

Share this post


Link to post
Share on other sites
I don't know if this helps much, but your loss in precision might be due the data format you choose. The interpolation, is it done with floating numbers, or half/fixed data types? Try to choose for the most precise data type you got in this case.

Greetings,
Rick

Share this post


Link to post
Share on other sites

This topic is 3483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this