Hi Guys
Ive been working on the shader portion of my project in which Ive been using per pixel lighting. in my project I have the light position attached to a bullet which lights up the terrain as it flies by but the problem Ive been having is that the terrain only lights up when its untextured illustration given below:
code and pic before comment lines removed , in which each bullet lights up the terrain
//------- Technique: PerPixelShading --------
VertexToPixel PPSVertexShader(float4 inPos: POSITION0, float3 inNormal: NORMAL0, float2 inTexCoords: TEXCOORD0)
{
VertexToPixel Output = (VertexToPixel)0;
float4x4 preViewProjection = mul(xView, xProjection);
float4x4 preWorldViewProjection = mul(xWorld, preViewProjection);
Output.Position = mul(inPos, preWorldViewProjection);
//Output.TextureCoords = inTexCoords;
//float3 Normal = normalize(mul(normalize(inNormal), xWorld));
//Output.LightingFactor = 1;
//if (xEnableLighting)
//Output.LightingFactor = dot(Normal, -xLightDirection);
float3 final3DPos = mul(inPos, xWorld);
Output.LightDirection = final3DPos - xLightPosition;
float3x3 rotMatrix = (float3x3)xWorld;
float3 rotNormal = mul(inNormal, rotMatrix);
Output.Normal = rotNormal;
return Output;
}
PixelToFrame PPSPixelShader(VertexToPixel PSIn) : COLOR0
{
PixelToFrame Output = (PixelToFrame)0;
float4 baseColor = float4(20,4,10,1);
float3 normal = normalize(PSIn.Normal);
float3 lightDirection = normalize(PSIn.LightDirection);
float lightFactor = dot(normal, -lightDirection);
//PSIn.TextureCoords.y--;
//float4 baseColor = tex2D(TextureSampler, PSIn.TextureCoords);
Output.Color = baseColor *(lightFactor+xAmbient);
//Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
//Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
return Output;
}
technique PerPixelShading
{
pass Pass0
{
VertexShader = compile vs_2_0 PPSVertexShader();
PixelShader = compile ps_2_0 PPSPixelShader();
}
}
[attachment=18396:10 16 2013 6 10 30 AM.jpeg]
code and pic after comments removed which activates the texture for the terrain but does
not light up as the bullets pass by
//------- Technique: PerPixelShading --------
VertexToPixel PPSVertexShader(float4 inPos: POSITION0, float3 inNormal: NORMAL0, float2 inTexCoords: TEXCOORD0)
{
VertexToPixel Output = (VertexToPixel)0;
float4x4 preViewProjection = mul(xView, xProjection);
float4x4 preWorldViewProjection = mul(xWorld, preViewProjection);
Output.Position = mul(inPos, preWorldViewProjection);
Output.TextureCoords = inTexCoords;
float3 Normal = normalize(mul(normalize(inNormal), xWorld));
Output.LightingFactor = 1;
if (xEnableLighting)
Output.LightingFactor = dot(Normal, -xLightDirection);
float3 final3DPos = mul(inPos, xWorld);
Output.LightDirection = final3DPos - xLightPosition;
float3x3 rotMatrix = (float3x3)xWorld;
float3 rotNormal = mul(inNormal, rotMatrix);
Output.Normal = rotNormal;
return Output;
}
PixelToFrame PPSPixelShader(VertexToPixel PSIn) : COLOR0
{
PixelToFrame Output = (PixelToFrame)0;
float4 baseColor = float4(20,4,10,1);
float3 normal = normalize(PSIn.Normal);
float3 lightDirection = normalize(PSIn.LightDirection);
float lightFactor = dot(normal, -lightDirection);
PSIn.TextureCoords.y--;
//float4 baseColor = tex2D(TextureSampler, PSIn.TextureCoords);
Output.Color = baseColor *(lightFactor+xAmbient);
Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
return Output;
}
technique PerPixelShading
{
pass Pass0
{
VertexShader = compile vs_2_0 PPSVertexShader();
PixelShader = compile ps_2_0 PPSPixelShader();
}
}
[attachment=18397:10 16 2013 6 12 43 AM.jpeg]
if anyone can tell me what Im doing wrong it would be much appreciated
Thankyou