Sign in to follow this  

Normal Mapping Problems

This topic is 3598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, My apologies if this has already been answered, I looked but couldn't find anything which helped me solve it. Anyhow.. I am working on a simple normal mapping shader in HLSL to try and get my head around how it all works. Everything is looking good so far except: when moving the position of the light, the lighting does not seem to be affected. I have the same mesh and light position in a simple shader with no bump mapping at all, and the light moves just fine. Also, the bump mapped shader works perfectly when rotating the object just not when moving the light. I'm sure its something simple that i'm missing because I don't fully understand it all yet. Any help would be greatly appreciated :) Here's my code:
//Vertex Shader
float4x4 preShadeWorld = mul(xRotate, xTranslateScale);
    float4x4 preAll = mul(preShadeWorld, xViewProjection);
    VertexToPixel Output = (VertexToPixel)0;
    Output.Position = mul(inPos, preAll);
    
    //3x3 Matrix to Transform World -> Texture Space
    
    float3x3 wToTex;
    wToTex[0] = normalize(mul(inTang, preShadeWorld));
    wToTex[1] = normalize(mul(inBiNorm, preShadeWorld));
    wToTex[2] = normalize(mul(inNorm, preShadeWorld));
    
    //Construct Output
    Output.TexCoord = inTex.xy;
    float3 posWorld = mul(inPos, preShadeWorld);

    Output.Light = mul(normalize(xLightVec - posWorld), wToTex);
    Output.Viewer = mul(xViewerPos.xyz - posWorld, wToTex);
    return Output;

//Pixel Shader
//Get Textures
	float4 texVal = tex2D(ColTexSam, PIn.TexCoord);
	float3 bumpNorm = (tex2D(BumpTexSam, PIn.TexCoord).rgb * 2.0f - 1.0f);
	
	float3 LightVec = normalize(PIn.Light);
	float3 ViewVec = normalize(PIn.Viewer);
	//Light Calcs 
	float dLight = max(dot(LightVec, bumpNorm), 0.0);
	float3 hVec = HalfVec(LightVec, ViewVec);
	float sLight = dot(hVec, bumpNorm);
    
    PixelToFrame Output = (PixelToFrame)0;
    Output.Color.xyz = (texVal * xTexDec) + (mul(xLightColor, xAmbientLevel) * mul(xLightColor, dLight) * xDiffLightPower);// + texVal ;
    Output.Color += pow(sLight, xSpecularSharp);
    return Output;

Thanks again :)

Share this post


Link to post
Share on other sites

Hi,

a small observation:


Output.Light = mul(normalize(xLightVec - posWorld), wToTex);



Is xLightVec the direction of the light? Ie. is your light directional or a positional ?



Share this post


Link to post
Share on other sites
Hi,

Thanks for the reply :)

xLightVec is holding a position of the light. It's called xLightVec from when i was messing with passing a direction instead of a position.

Moving a directional light wouldn't have any effect on the lighting as I understand it, correct? Maybe that's where i'm going wrong? Would I need to put some distance factor in to make it a positional light?

Thanks again :)

Charlie

Share this post


Link to post
Share on other sites
What you're doing should be enough to get a change when moving the light's position. Distance attenuation will have an additional effect, but the change in light direction because of its position should be enough to affect the result significantly.

I'd suggest that you check what light vector you're getting, either by writing it directly to a render target or using PIX.

Share this post


Link to post
Share on other sites

This topic is 3598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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