Help with Per Pixel Lighting

Started by
3 comments, last by benjamin bunny 19 years, 7 months ago
I am trying to implement per pixel lighting using a vertex/fragment program. I have my heightmap DOT3 bumpmapped and loaded as a texture. Now I am lost on what I need to do next. I have a idea on how to but can't get it to work. Do I want to do the Dot product in the vertex program or fragment program? Here is my vertex program. I am taking the lighting position from glLight for now.

!!ARBvp1.0

#per-pixel lighitng of heightmap with DOT3 RGB bumpmap

TEMP temp;
TEMP tempDOT;

ATTRIB inPosition = vertex.position;
ATTRIB inTexCoord0 = vertex.texcoord[0]; #heightmap
ATTRIB inTexCoord1 = vertex.texcoord[1]; #DOT3 bumpmap of heightmap

PARAM mvp[4] = {state.matrix.mvp};
PARAM lightDirection = state.light[0].position;

OUTPUT outPosition = result.position;
OUTPUT outTexCoord0 = result.texcoord[0];
OUTPUT outTexCoord1 = result.texcoord[1];

DP4 temp.x, mvp[0], inPosition;
DP4 temp.y, mvp[1], inPosition;
DP4 temp.z, mvp[2], inPosition;
DP4 temp.w, mvp[3], inPosition;

MOV outPosition, temp;

#do dot product here between normal and light position
DP3 tempDOT, inTexCoord1, lightDirection;

MOV outTexCoord0, inTexCoord0;
MOV outTexCoord1, inTexCoord1;

END


What I am after is per pixel lighting on my terrain. So if I have a heightmap of 257x257 and a DOT3 bumpmap of that heightmap, how will this give me per pixel lighting when the DOT3 bumpmap maps directly 1to1 for each vertex? How is that method going to light each pixel of my textures I have on the terrain? Any help would be appreciated. Thanks [Edited by - MARS_999 on September 2, 2004 8:40:07 PM]
Advertisement
Quote:
What I am after is per pixel lighting on my terrain. So if I have a heightmap of 257x257 and a DOT3 bumpmap of that heightmap, how will this give me per pixel lighting when the DOT3 bumpmap maps directly 1to1 for each vertex? How is that method going to light each pixel of my textures I have on the terrain?

It's per-pixel because you're calculating the lighting on a per pixel basis.

There's no need to use a bump map if you're just using the terrain heightmap as a normal map, unless perhaps you're using some kind of LOD scheme. You should just use phong shading to interpolate the normals between vertices.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

Quote:Original post by benjamin bunny
Quote:
What I am after is per pixel lighting on my terrain. So if I have a heightmap of 257x257 and a DOT3 bumpmap of that heightmap, how will this give me per pixel lighting when the DOT3 bumpmap maps directly 1to1 for each vertex? How is that method going to light each pixel of my textures I have on the terrain?

It's per-pixel because you're calculating the lighting on a per pixel basis.

There's no need to use a bump map if you're just using the terrain heightmap as a normal map, unless perhaps you're using some kind of LOD scheme. You should just use phong shading to interpolate the normals between vertices.


Thanks for the repy BB. I am not using any kind of LOD scheme. I am using brute force. So I can discard my bumpmap of the heighmap and use the verticies from the heightmap to find my normals and use phong shading. BTW I am using a vertex program and fragment program. Do you have any good examples on how to do phong shading with the vertex program and fragment program without the bumpmap?

Thanks
What I did for terrain lighting was to calculate the normal of each point on the heightmap, and then use a shader which takes the dot product of the light direction, and the vertex normal. It produced very nice results, and gave very smooth terrain.

But, if you want to do per-pixel lighting on the terrain, I suggest you tile a bumpmap over the terrain, and do ordinary bumpmapping. You probably don't need a very high resolution bumpmap.
Quote:Original post by MARS_999
Quote:Original post by benjamin bunny
Quote:
What I am after is per pixel lighting on my terrain. So if I have a heightmap of 257x257 and a DOT3 bumpmap of that heightmap, how will this give me per pixel lighting when the DOT3 bumpmap maps directly 1to1 for each vertex? How is that method going to light each pixel of my textures I have on the terrain?

It's per-pixel because you're calculating the lighting on a per pixel basis.

There's no need to use a bump map if you're just using the terrain heightmap as a normal map, unless perhaps you're using some kind of LOD scheme. You should just use phong shading to interpolate the normals between vertices.


Thanks for the repy BB. I am not using any kind of LOD scheme. I am using brute force. So I can discard my bumpmap of the heighmap and use the verticies from the heightmap to find my normals and use phong shading. BTW I am using a vertex program and fragment program. Do you have any good examples on how to do phong shading with the vertex program and fragment program without the bumpmap?

Thanks


I don't know of any tutorials, but it's a pretty standard technique so I'm sure there are lots out there. Basically you just output the normal from the vertex program. You then read the interpolated value in the fragment program, normalise it (because the interpolation may affect the length), and use

L dot N to get the diffuse lighting amount, where N is the interpolated normal and L is the normalised light vector.

Definitely no need to use a bump map anyway, unless possibly you want a detail texture (which I think is what James is suggesting). But for now I'd just stick with phong shading if I were you.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

This topic is closed to new replies.

Advertisement