[HLSL] Weird dark areas w/ simple diffuse light (screenshots included)

Started by
12 comments, last by JohnnyCode 14 years ago
Quote:
I also tried just casting the matWorld to (float3x3) for the multiplication with the normal but that doesn't pass my compiler

normalize ( mul ( In.Normal.xyz, (float3x3)matWorldIT ) );
should work

Also you're doing a bunch of operations with float4 ... like this:
// get the normalized vector from this pixel to lightfloat3 LightVector = normalize ( lightPos - In.Position );

lightPos and In.Position are both float4, not sure if the normalize returns what you expect or if it's your problem tho :)

Try to use your original pixel shader (first post) but change the following:
// normalize normal and bring it into world spaceIn.Normal = normalize ( mul ( In.Normal, matWorld ) );// bring position into world spaceIn.Position = mul ( In.Position, matWorld );...// get the normalized vector from this pixel to lightfloat3 LightVector = normalize ( lightPosition - In.Position );

for
// normalize normal and bring it into world spaceIn.Normal = normalize ( mul ( In.Normal.xyz, (float3x3)matWorld ) );// bring position into world spaceIn.Position = mul ( float4(In.Position.xyz,1), matWorld );...// get the normalized vector from this pixel to lightfloat3 LightVector = normalize ( lightPosition.xyz - In.Position );


[Edited by - c3Dp on March 17, 2010 11:37:40 PM]
Advertisement
Thanks for the help, guys. Really appreciated so far!

This is the current shader, produces exactly the same problem I described in the OP though:

float4x4	matWorldViewProj;float4x4	matWorld;float4		lightPosition;float4		lightAmbientColor;float4		lightDiffuseColor;struct VS_Input{	float4 Position	: POSITION;	float2 UV	: TEXCOORD0;	float3 Normal	: NORMAL;};struct VS_Output{	float4 Position		: POSITION;	float2 UV		: TEXCOORD0;	float3 Normal		: TEXCOORD1;	float3 PositionWorld	: TEXCOORD2;};VS_Output MyVertexShader ( VS_Input In ){	VS_Output Out;    	// transform vertex intro projection space for rendering	Out.Position = mul ( In.Position, matWorldViewProj );    	// simply pass UV coordinates on	Out.UV = In.UV;    	// pass the normal on	Out.Normal = In.Normal;    	// get position in world space	Out.PositionWorld = In.Position;		return Out;}struct PS_Input{	float2 UV	: TEXCOORD0;	float3 Normal	: TEXCOORD1;	float3 Position	: TEXCOORD2;};struct PS_Output{	float4 Color	: COLOR;};PS_Output MyPixelShader ( PS_Input In, sampler2D tex0 ){	PS_Output Out;		// normalize normal and bring it into world space	In.Normal = normalize ( mul ( In.Normal.xyz, (float3x3)matWorld ) );	// bring position into world space	In.Position = mul ( float4(In.Position.xyz,1), matWorld );		// look up the diffuse color from the texture	float4 texture_color = tex2D ( tex0, In.UV );		// get the normalized vector from this pixel to light	float3 LightVector = normalize ( lightPosition.xyz - In.Position );		// calculate lighting	float3 light = max ( dot ( LightVector, In.Normal ), 0.0f );    	// calculate the pixel color (ambient and diffuse)	Out.Color.rgb = ( texture_color.rgb * lightAmbientColor.rgb ) + ( texture_color.rgb * lightDiffuseColor.rgb * light );		// support transparency	Out.Color.a = texture_color.a;    	return Out;}technique EntryPoint{	pass SinglePass	{		VertexShader = compile vs_2_0 MyVertexShader ( );		PixelShader = compile ps_2_0 MyPixelShader ( );	}}


Any more ideas?
Quote:Original post by d h k
Thanks for the help, guys. Really appreciated so far!



Your shader is correct, renders fine, but you should take a careful look at your
normals in the mesh. You should for example run a smooth modifier in max on it, that will smooth large angels and not smooth sharp angels, the result is perfect.

You seem to have normals input(explicit art) data not correct.
dont forget that dx utility apps likes to compute tangents,normals and adjencies implicitly,
so explicit art look all ok but not on your side.

This topic is closed to new replies.

Advertisement