Man ohh man! I hate lighting! I have all the lights working but my spot lights which dont work anymore.... where is my shader code, and my code to run it. Basically I get weird results, either no light spot(most of time), or I cant control the falloff. Please help me out guys, Im kinda at wits end.
Shaders (the SpotPS is the one that is not working)
float4 TSpotLightingPS(VS_OUTPUT1 In) : COLOR
{
half4 Color = tex2D(MRT0, In.TexCoord);
half3 Normal = normalize(2 * (tex2D(MRT1, In.TexCoord) - 0.5));
half2 PositionXY = tex2D(MRT2, In.TexCoord);
half2 PositionZW = tex2D(MRT3, In.TexCoord);
half4 Position = float4(PositionXY.xy, PositionZW.xy);
half4 Light = LightVector - Position;
Light.w = saturate(1 - dot(Light.xyz * tester[2], Light.xyz * tester[2])); // tester[2] == LightRange
half3 LightDirec = normalize(Light.xyz);
half diff = saturate(dot(Normal, LightDirec));
half cosAngle = dot( LightDir, LightDirec );
half spotFactor = smoothstep( tester[1], tester[0], cosAngle );
//return ( (0.1f * Color) + ( spotFactor * LightColor * (Color * diff) ) * Light.w);
return ( ( spotFactor * LightColor * (Color * diff) ) * Light.w);
}
pixelfragment TSpotPixelFragment = compile_fragment ps_2_0 TSpotLightingPS();
pixelfragment FSpotPixelFragment = compile_fragment ps_2_0 TSpotLightingPS();
float4 OmniLightingPS(VS_OUTPUT1 In) : COLOR
{
half4 Color = tex2D(MRT0, In.TexCoord);
half3 Normal = normalize(2 * (tex2D(MRT1, In.TexCoord) - 0.5));
half2 PositionXY = tex2D(MRT2, In.TexCoord);
half2 PositionZW = tex2D(MRT3, In.TexCoord);
half4 Position = float4(PositionXY.xy, PositionZW.xy);
half3 toLight = normalize(LightVector - Position.xyz); // no normalize()?
half Dist = length(toLight);
toLight /= Dist;
half atten = 1.0 - saturate( Dist * LightRange );
half D = saturate( dot(Normal.xyz,toLight) );
//return (0.1f * Color) + ((D * Color) * atten );
return ((D * Color) * atten );
}
pixelfragment OmniPixelFragment = compile_fragment ps_2_0 OmniLightingPS();
Here is the code to set the values:
else if((itLightIT->second).iType == ID_FSPOT)
{
//pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
for(int i = 0; i < 4; i++)
{
pd3dDevice->SetSamplerState( i, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
pd3dDevice->SetSamplerState( i, D3DSAMP_MINFILTER, D3DTEXF_POINT );
pd3dDevice->SetSamplerState( i, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
pd3dDevice->SetSamplerState( i, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
pd3dDevice->SetSamplerState( i, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
pd3dDevice->SetSamplerState( i, D3DSAMP_SRGBTEXTURE, 0 );
}
SetTexture( "MRT0", mrt0 );
SetTexture( "MRT1", mrt1 );
SetTexture( "MRT2", mrt2 );
SetTexture( "MRT3", mrt3 );
SetMatrixVS("WorldViewProj", matWorldViewProj );
float ftester = 0.0f;//0.0004f;//0.04f;
float fHotSpot = 0.51f;
float fFalloff = 0.49f;
D3DXVECTOR3 HotFallRange = D3DXVECTOR3( fHotSpot, fFalloff, ftester );
SetVector4PS( "LightColor", &(itLightIT->second).vecColor );
SetVector4PS( "LightVector", &(itLightIT->second).vecPosition );
SetVector3( "tester", &HotFallRange );
SetVector3( "LightDir", &(itLightIT->second).vecRotation );//
Any help would be greatly appreciated, thanks much!
--Brad