cty41

[questions]pixel Lighting has errors

Discussion created by cty41 on May 17, 2010
Latest reply on Jun 15, 2010 by plohrmann

Hi, all guys.I'm a newbies on RM and shaders. These days I am reading a book called <Shaders for Game Programming and Artists>.But When I tried to remade his examples in chapter10 which is related with pixel lighting, I could not get the right result from his code.(I mean I create a new project and copy his code,but failed ,I will post the pictures url later)

here is  error picture's url:

http://i965.photobucket.com/albums/ae134/cty41/error.jpg

this is the right one.....

http://i965.photobucket.com/albums/ae134/cty41/right.jpg

And I have edit stream mapping, added NORMAL and TEXCOORD.And there is one clue, the writer used RenderMonkey 1.71 and I use Rm 1.82(current version).

 I am appericated if anyone can help me a hand~~

 

 

float4x4 matViewProjection; float4x4 matViewInverse; float4x4 matView; float4 Light_Ambient; float4 Light1_Position; float4 Light1_Attenuation; float4 view_position; struct VS_OUTPUT { float4 Pos: POSITION; float2 TexCoord: TEXCOORD0; float3 Normal: TEXCOORD1; float4 LightDir: TEXCOORD2; float3 HalfVect: TEXCOORD3; }; VS_OUTPUT vs_main(float4 inPos: POSITION, float3 inNormal: NORMAL,float2 inTxr: TEXCOORD0) { VS_OUTPUT Out; // Compute the projected position and send out the texture coordinates Out.Pos = mul(matViewProjection, inPos); Out.TexCoord = inTxr; // Determine the distance from the light to the vertex and the direction float4 LightDir; LightDir.xyz = Light1_Position - inPos; float Dist = length(LightDir.xyz); LightDir.xyz = LightDir.xyz / Dist; // Compute the per-vertex distance based attenuation LightDir.w = clamp(0,1, 1 / ( Light1_Attenuation.x + Light1_Attenuation.y * Dist + Light1_Attenuation.z * Dist * Dist )); // Determine the eye vector and the half vector float3 EyeVector = -normalize(mul(matViewInverse,float4(0,0,10,1))+inPos); Out.HalfVect = normalize(LightDir-EyeVector); // Output normal and light direction Out.Normal = inNormal; Out.LightDir = LightDir; return Out; } float4 Light1_Color; float4 Light_Point(float3 Normal, float3 HalfVect, float4 LightDir, float4 LightColor) { // Compute both specular and diffuse factors float SpecularAttn = pow( clamp(0, 1,dot(Normal, HalfVect)),32); float DiffuseAttn = clamp(0, 1,dot(Normal, LightDir)); // Compute final lighting return LightColor * LightDir.w * (SpecularAttn+DiffuseAttn); } float4 ps_main(float3 inNormal:TEXCOORD1, float4 LightDir:TEXCOORD2, float3 HalfVect:TEXCOORD3) : COLOR { // Output the lighting color return Light_Point(inNormal,HalfVect,LightDir,Light1_Color); }

Outcomes