float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 { //Get Screen position input.ScreenPosition.xy /= input.ScreenPosition.w; float2 texCoord = 0.5 * (float2(input.ScreenPosition.x, -input.ScreenPosition.y) + 1); texCoord -= halfPixel; float4 normalData = tex2D(normalSampler, texCoord); float3 normal = 2.0f * normalData.xyz - 1.0f; float specularPower = normalData.a * 255; float specularIntensity = tex2D(diffuseSampler, texCoord).a; float depthData = tex2D(depthSampler, texCoord).r; float4 position; position.xy = input.ScreenPosition.xy; position.z = depthData; position.w = 1.0f; position = mul(position, inverseViewProj); position /= position.w; float3 lightVector = lightPosition - position; //Compute Attenuation (how much the light drops over distance) this is a linear calculation float attenuation = saturate(1.0f - length(lightVector)/radius); lightVector = normalize(lightVector); float normalDotLight = max(0, dot(normal, lightVector)); float3 diffuseLight = normalDotLight * lightColor.rgb; float3 reflectionVector = normalize(reflect(-lightVector, normal)); float3 vectorToCamera = normalize(cameraPosition - position); float specularLight = pow(saturate(dot(reflectionVector, vectorToCamera)), specularPower); specularLight *= specularIntensity; return attenuation * intensity *float4(diffuseLight.rgb,specularLight); }