Skip to main content
GameDev.net gamedev.net
🔒 Locked

Per Pixel Lighting??

Started by Xtreme11 Apr 26, 2004 at 11:16 PM 10 replies 2.3k views
Original Post
Xtreme11
Xtreme11
This is something thats been bothering me. The standard lighting used in DX and openGL is vertex based right? but if I create a shader (say using phong''s equation) how can I calculate the lighting per pixel as opposed to vertex or is it already done per pixel? Hope that makes sense Thanks
ngill
ngill
basically, you pass the normals through the vertex shader.

Now, every fragment[pixel] has a normal, so just do your calculation in the fragment program.

That''s it! You''re done!
Nik02
Nik02
And, you may need to pass the position also, if you need local lights (since prior to PS3.0, pixel shader can''t automatically fetch the interpolated position).
By "local" I mean point and spot lights.

-Nik
Niko Suni
Xtreme11
Xtreme11
Thnx a lot for the quick response.
I still dont understand though, how can you determine the normals for each pixel then if you only have vertex normals?
Xtreme11
Xtreme11
Sorry for all the questions
I understand you will be able to interpolate the vertex normals but how would you create a normal map like this?

Does anyone have any good tutorials or articles on this stuff?

Appreciate the help

[edited by - Xtreme11 on April 27, 2004 2:59:39 AM]
weasalmongler
weasalmongler
You might want to have a look on NVIDIAs site in the developer section. NVIDIA. They have a plug in for photoshop that allows you to generate a normal map from a greyscale "heightmap".

- James
Xtreme11
Xtreme11
Thanks weasalmongler thats a big help!
Sorry Im a noob to all this shader stuff.
Im not quite sure I understand the workings of normal maps.
Do you have any sites that helps to explain uses and creation of them?

I understand you would read in the normal map and use it to pick out a normal for each pixel but what do you create it from?
Do you take the texture youre using and do what with it to generate normals???

[edited by - Xtreme11 on April 27, 2004 6:38:39 AM]
weasalmongler
weasalmongler
Are you after bump mapping?

If this is the case then I got most of my information on the subject from NVIDIAs developer site, there are numerous examples and papers on the subject.

Basic technique I use is:

1 - For a model, generate normal, tangent and binormal Vectors for each vertex.

2 - Using a vertex program, calculate the light direction in object space and transform it into texture space using the transformation:

|Tangent.x Tangent.y Tangent.z | |lightvec.x|
|Binormal.x Binormal.y Binormal.z| |lightvec.y|
|Normal.x Normal.y Normal.z | |lightvec.z|

3 - Output this to Texture unit 1

4 - Use this vector as a lookup in a normalization cube map

5 - Using some form of pixel shader / register combiner work out Cubemap DOT3 Normalmap.

6 - Blend your base texture/colour on top.


Have a look at this paper, it explains things much better than I do: Bump map paper

Need any more help, just ask.

- James
Xtreme11
Xtreme11
Thanks a lot thats a big help
Gotta learn the formulas for the normals and vectors.
Ill be sure to look through the paper when I get time.

Im first trying to do per pixel lighting but I see it is very much related to bump mapping so either way it helps.
If possible could you please give me a simplified set of steps just for the lighting using normal maps so I can get a sense of direction to head for?

I found this site on the subject of creating these shaders using HLSL, seems good:
Clicky

[edited by - Xtreme11 on April 27, 2004 10:14:14 AM]
weasalmongler
weasalmongler
I implemented per pixel lighting quite a long time ago but it had nothing to do with normal maps, normal maps are used for bump mapping in my experience. The technique I used was for per pixel point lights was essentially dynamic light mapping using a 2D and a 1D texture to create what is essentially a 3D texture. The lighting on a suface can therefore be calculated relative to the distance from the point light. I cant remember everything to do with it, so heres some examples I googled for:

Per Pixel Lighting 1

Per Pixel Lighting 2


-James
Xtreme11
Xtreme11
Ok, time for me to start reading and trying to put somethign together .
Thanks again for the help

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.