Jump to content
  • Advertisement
Sign in to follow this  
xsirxx

*UPDATE* PointLight: Problem in my HLSL shader(again) Warning-Picture Heavy

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

Ok sorry for so many posts about this stupid point light, just been working on this shader for so long I think I forgot how to program in C++. That said, here goes a lengthy post. I have imported all of my models from 3dsmax in my own format. Diffuse looks just fine but that doesnt use the normals or tangents. So Problem comes when I shine a point light on the scene. This is deferred lighting so I will post all my surfaces(output to jpg.) Here is the shader during render:
VS_OUTPUT0 SimpleVS( VS_INPUT0 In )
{
	VS_OUTPUT0 Out;

    //Out.Normal		= normalize(mul(In.Normal, (float3x3)World));
    Out.Normal		= normalize(In.Normal);
	Out.Color		= In.Color;
	
    float4 Position	= mul(In.Position, Object);
	Out.Position	= mul(Position, WorldViewProj);//mul(In.Position,World);
    Out.Position2	= Position;//mul(tempPos, WorldViewProj);//mul(In.Position, WorldViewProj);
    //Out.Position2	= mul(Position, World);
    Out.TexCoord	= In.TexCoord;
    Out.Tangent		= In.Tangent;

	return Out;
}
vertexfragment DiffuseVertexFragment	= compile_fragment vs_1_1 SimpleVS();

PS_MRT_OUTPUT DiffusePS(VS_OUTPUT0 In)
{
	PS_MRT_OUTPUT Out;
	
	half4 diffuseTex = tex2D( DiffuseTexture, In.TexCoord);
	
	diffuseTex.w = diffuseTex.w - 0.01;
	clip(diffuseTex.www);

	//Out.Color0 = In.Color * float4(diffuseTex.xyz, 1.0f);
	Out.Color0 = float4(0.5,0,0,0.0);//
	Out.Color1 = float4(normalize(In.Normal), 0.0);
	Out.Color2 = In.Position2;
	Out.Color3 = float4(In.Tangent, 0.0);

	return Out;
}
pixelfragment DiffusePixelFragment	= compile_fragment ps_3_0 DiffusePS();



Here is the Lighting shaders( Post shader):
VS_OUTPUT1 main(VS_INPUT1 IN)
{
    VS_OUTPUT1 Out;
	
    Out.Position = mul(IN.Position, WorldViewProj);
    //Out.Position2 = mul(IN.Position, World);
   
    // pass texture coordinates for fetching the diffuse map
    Out.TexCoord = IN.TexCoord;//.xy;

	return Out;
}
vertexfragment MRTVS	= compile_fragment vs_1_1 main();

float4 OmniLightingPS(VS_OUTPUT1 In) : COLOR
{	
	float4 Color			= tex2D(MRT0, In.TexCoord);
	float4 Normal			= tex2D(MRT1, In.TexCoord);
	float4 Position			= tex2D(MRT2, In.TexCoord);
	float4 Tangent			= tex2D(MRT3, In.TexCoord);

	float3x3 worldToTangentSpace;
	worldToTangentSpace[0]	= mul( Tangent, World );
	worldToTangentSpace[1]	= mul( cross(Tangent, Normal), World );
	worldToTangentSpace[2]	= mul( Normal, World );
	
	float3 PosWorld	= normalize( mul(Position, World) );
	float3 Light	= mul(LightVector, World) ;
	Light			= LightVector - PosWorld;
	float4 Light2;
	Light2.xyz		= normalize( mul(worldToTangentSpace, Light) );
	Light2.w		= saturate( 1 - dot(Light * LightRange, Light * LightRange) );
	
	float3 LightDir = normalize(Light2.xyz);
	float Diffuse	= saturate( dot(Normal, LightDir) );
	
	float Shadow	= saturate(4 * LightDir.z);
	
	return ( ( Shadow * (Color * Diffuse) * Light2.w) );
}
pixelfragment OmniPixelFragment	= compile_fragment ps_3_0 OmniLightingPS();



Now here goes all the surfaces: The Final Light Out Surface: The Diffuse Surface: The Normal Surface: The Tangent Surface: The Position Surface: Phew alot, Question is there is one light on top of one of the boxes and yet nothing looks right and im getting weird artifacts like that weird S pattern on the large underneath cube. Can any1 point me in the right direction to why something like this is occuring? Could it be the normals or tangents messed up? Could it be something wrong in my shader? Im so lost I thought Ive gone through everything. Thanks alot all, Brad EDIT: I have noticed that If I replace LightRange with anythign at all besides 0.0 the screen is black. So in other words I only get light when LightRange = 0. why? [Edited by - xsirxx on August 5, 2005 12:12:36 AM]

Share this post


Link to post
Share on other sites
Advertisement
*UPDATE*

All the teapots have the light hitting them at the same side, unfortunatly the lights are in the exact middle of the world. So what might cause them to react like that instead of all of them showing the light on the insides?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!