Sign in to follow this  

Transformed by ViewProjection or not?

Recommended Posts

Extract of vertex Shader
// Transform normal to world space.
o.normalW = mul(Normal,gWorldInvTrans).xyz;

// Transform and calculate eye pos
float3 posW = mul(Pos,gWorld).xyz;
o.toEyeW = gEyePosW - posW;

// transform position from world space into view and then projection space
o.Pos = mul(float4(, 1.0f), mViewProj);

Pixel Shader
float4 VBlend2PS(float3 normalW : TEXCOORD0, float3 toEyeW : TEXCOORD1, float2 tex0 : TEXCOORD2) : COLOR
// Interpolated normals can become unnormal--so normalize.
normalW = normalize(normalW);
toEyeW = normalize(toEyeW);

// Light vector is opposite the direction of the light.
float3 lightVecW = lhtDir;

// Compute the reflection vector.
float3 r = reflect(-lightVecW, normalW);

// Determine how much (if any) specular light makes it into the eye.
float t = pow(max(dot(r, toEyeW), 0.0f), SpecPower);

// Determine the diffuse light intensity that strikes the vertex.
float s = max(dot(lightVecW, normalW), 0.0f);

// Compute the ambient, diffuse and specular terms separatly.
float3 spec = t*(MaterialSpec*lightSpec).rgb;
float3 diffuse = s*(MaterialDiffuse*lightDiffuse).rgb;
float3 ambient = MaterialAmbient*lightAmbient;

// Get the texture color.
float4 texColor = tex2D(TexS, tex0);

// Combine the color from lighting with the texture color.
//float3 color = (ambient + diffuse)*texColor.rgb + spec;
float3 color = (ambient + diffuse).rgb + spec;

// Sum all the terms together and copy over the diffuse alpha.
//return float4(color, gMtrl.diffuse.a*texColor.a);
return float4(color, MaterialDiffuse.a);

See that o.toEyeW, do I also transform it by the ViewProj transformation?

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