Specular Bumpmapping

Started by
8 comments, last by GameDev.net 19 years, 4 months ago
I have made a simple diffuse bumpmapping with shaders, using normal map, now I am trying to add specular component to it, but if I do traditional specular component it looks ugly, How can I do specular bump, shining the cracks and bumps of the texture, and not only a specular white shining circle ? Thanks Edit: Which is the minimum version of PS and VS in which is possible to do Specular bumpmapping ? (i know that diffuse bumpmapping can be done in VS 1.1 and PS 1.1) [Edited by - q2guy on December 2, 2004 1:32:42 PM]
Advertisement
Specular bump mapping is done the same way as diffuse: taking the normal from the normal map instead of the vertex normal. Instead of (N dot L) for diffuse lighting, the dotproduct between the normal map normal and the half angle vector H is taken, and exponentiated: (N dot H) ^ specularExponent. H is evalutaed in a vertex shader, and just as L, it must be in tangent space.

Other than the L vs. H issue and the exponent, there's really no difference between diffuse and specular bump mapping.
I have code it like you told and it look good, thanks very much
Good. There's a neat trick you might want to add the specular bump mapping, as it tends to make it look much nicer: gloss maps. Basically a greyscale map (you can put it into the alpha component of your rgb texture) that modulates the strength of the perpixel specularity at each pixel. That way, some parts of the model can be more shiny than others. With old style specularity this wasn't very important, but with specular bump mapping it can really add a lot to the realism.
I have a problem doing it in rendermonkey, my card is gf4 (vs1.1,ps1.3), if I use HAL mode, i get only a plain diffuse texture, if I use REF device, the specular bumpmapping looks good (but not realtime, of course), why ?
Quote:Original post by q2guy
I have a problem doing it in rendermonkey, my card is gf4 (vs1.1,ps1.3), if I use HAL mode, i get only a plain diffuse texture, if I use REF device, the specular bumpmapping looks good (but not realtime, of course), why ?

Probably because your shader exceeds the hardware resources of your gf4. Impossible to say anything more with the limited information you provide. Post your shader source code.

On a guess, it might be the exponentiation, the geforce4 can't do that in a pixel shader. It must be emulated by consecutive multiplications. But post your code.
Before post the code, I have some questions about diffuse bumpmapping correctness, I get slightly different result with simple ambiguous things:

1. Is the same:

   float3 N = mul(world,IN.Normal);   float3 T = mul(world,IN.Tangent);   float3 B = mul(world,cross(T,N));      float3 L;   L.x = dot(T,LightPos);   L.y = dot(B,LightPos);   L.z = dot(N,LightPos);   L = (L * 0.5) + 0.5;     OUT.TexCoord0.xy = IN.TexCoord.xy;   OUT.TexCoord1.xy = IN.TexCoord.xy;      OUT.Color.xyz = normalize(L.xyz);

and
   float3 N = mul(world,IN.Normal);   float3 T = mul(world,IN.Tangent);   float3 B = mul(world,cross(N,T));   // <=   float3 L;   L.x = dot(T,-LightPos);  // <=   L.y = dot(B,-LightPos);  // <=   L.z = dot(N,-LightPos);  // <=   L = (L * 0.5) + 0.5;     OUT.TexCoord0.xy = IN.TexCoord.xy;   OUT.TexCoord1.xy = IN.TexCoord.xy;      OUT.Color.xyz = -normalize(L.xyz); // <=
?

2. Must be L be normalized before encoded into [0,1] range, or after ? Must be N,T,B and LightPos be normalized ?


P.D.:
How can I post images directly here (no links) ?

Pixel Shader:
   float3 N = 2.0f * (tex2D(Texture1,IN.TexCoord1.xy) - 0.5f);   float3 C = 2.0f * (IN.Diffuse - 0.5f);      float  NdotL = dot(N,C);   float4 tcol  = tex2D(Texture0,IN.TexCoord0.xy);   OUT.Color = NdotL * tcol;
I believe that normal pointing out of object vertex position is (Binormal x Tangent) cross product, so Binormal = Tangent x Normal. Also I think you have to use light vector and not light direction, this is:

- Light vector: Light position - vertex position
- Light direction: normalized( vertex position - light position)

the same with view vector for the specular component.
nitpick: its not a binormal, its a bitangent. why does everyone call it a binormal, that for circles and stuff!?
circles and stuff??
http://mathworld.wolfram.com/BinormalVector.html

This topic is closed to new replies.

Advertisement