Sign in to follow this  
q2guy

Specular Bumpmapping

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
nitpick: its not a binormal, its a bitangent. why does everyone call it a binormal, that for circles and stuff!?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
circles and stuff??
http://mathworld.wolfram.com/BinormalVector.html

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