• Advertisement
Sign in to follow this  

Transformed by ViewProjection or not?

This topic is 1949 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

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(Pos.xyz, 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
Sign in to follow this  

  • Advertisement