Sign in to follow this  
bengaltgrs

Pixel Shader?

Recommended Posts

Basically I am wondering what the best solution would be to light and show the specular highlights of a large surface with very few polys, such as a wall or ground. Assuming you wanted to have a point light or spot light correctly lighting up a small portion of a very large ground mesh made up of 1 quad, how would that be done? I assumed it would be done by pixel shader, but spotlights can put off many different shapes depending on how they are angled. Also, is it possible to place a point light right in the center of a large quad and have the bump map correctly shadow the quad in all directions instead of the entire quad being shadowed in one direction? I am sure that there are sites dedicated to this topic, I just cannot seem to find them. If anyone can give me any links or help, it would be much appreciated. -Chris

Share this post


Link to post
Share on other sites
To do this nicely you will need a card with pixel shader 2.0 support (GeForceFX or similar Radeon). You can approach this a couple ways:

In a vertex shader, output the vector from the light to the vertex as a texture coordinate. In a pixel shader, re-normalize the interpolated direction, and use that to do a dot product with a normal map. You will likely want to have the vertex shader move the vector into tangent space. You can get this working on pixel shader 1.1, though you'll need to scale and bias the light vector in the vertex shader, and convert it back in the pixel shader. This is because 1.1 shaders can only have inputs of 0 to 1, and a direction vector may range from -1 to 1. This is a single extra vertex shader instruction (vector = vector*0.5+0.5) and an instruction modifier in the pixel shader (_bx2).

In a vertex shader, output the vertex position as a texture coordinate. In a pixel shader, calculate the direction to the light, normalize it, and follow the bump map steps above. This will require pixel shader 2.0 to handle pixel shader inputs above 1, as positions likely will be.

If the light is close to the surface, the first method will produce somewhat incorrect values. This is because it will linearly interpolate between the two extreme direction vectors. When the light is close to the surface, most of the directions will actually be off to one side or another, and very few vectors will point more directly towards the face. Since the second method is interpolating positions, which do change in more linear fashion across the face, it will produce a more correct result. The second method does more work per-pixel, and will be slower, and require a higher-end card.

Grab something like nVidia's FX composer. It may have an appropriate sample shader that does this (I don't remember if their sample is point light or directional light based). Even if you have to find the sample elsewhere, FX Composer is a decent tool for testing and developing shaders.

Share this post


Link to post
Share on other sites
I see, so then it is a matter of applying an extra map with a pixel shader. What happens if there are two lights shining on one quad though, would blending two lighting textures need to be done?

-Chris

Share this post


Link to post
Share on other sites
Quote:
What happens if there are two lights shining on one quad though, would blending two lighting textures need to be done?


There are 2 ways to accomplish this:
1. You can let your pixel shader process more than 1 light at once but you may run out of instructions with too much lights.

2.Let you pixel shader only process 1 light and do 1 pass for each light. This can be slow with many lights because the geometry has to be rerendered for every light.

regards,
m4gnus

Share this post


Link to post
Share on other sites

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