Based upon where my how far back from the camera is there will be a artifact of my point light.
Here is what I mean before going into details
I have a flat rectangle and a standing rectangle of 20x20 dimensions with a point light of 22 radius. My camera currently sits at -76 but if I were to move the camera to -75 then even in the most extreme example of point light z = 3.0 from above will no longer have the artifact.
I am not sure what could be causing it but I have tried several idea to avail. The one with the biggest benefit seemed to be scaling my world matrix for rendering the point lights sphere by a small modifier like 1.1 in addition to the radius.That seemed to only mask the issue for a little bit.
When looking at the render targets in RenderDoc going into the lighting pass the render targets seem correct so my guess is that it is my shading code.
I am not sure what other details would be beneficial to detailing the problem but if there is something mentioned I will post it.
Shader Code
Texture2D NormalMap : register( t0 );
Texture2D DiffuseAlbedoMap : register( t1 );
Texture2D SpecularAlbedoMap : register( t2 );
Texture2D PositionMap : register(t3);
cbuffer WorldViewProjCB : register( b0 )
{
matrix WorldViewProjMatrix;
matrix WorldViewMatrix;
}
cbuffer CameraPosition : register ( b2 )
{
float3 CameraPosition;
}
cbuffer LightInfo : register ( b3 )
{
float3 LightPosition;
float3 LightColor;
float3 LightDirection;
float2 SpotLightAngles;
float4 LightRange;
};
struct VertexShaderInput
{
float4 Position : POSITION;
};
struct VertexShaderOutput
{
float4 PositionCS : SV_Position;
float3 ViewRay : VIEWRAY;
};
VertexShaderOutput VertexShaderFunction(in VertexShaderInput input)
{
VertexShaderOutput output;
output.PositionCS = mul( input.Position, WorldViewProjMatrix );
float3 positionVS = mul( input.Position, WorldViewMatrix ).xyz;
output.ViewRay = positionVS;
return output;
}
void GetGBufferAttributes(in float2 screenPos, out float3 normal,
out float3 position,
out float3 diffuseAlbedo,
out float3 specularAlbedo,
out float specularPower)
{
int3 sampleIndices = int3(screenPos.xy, 0);
normal = NormalMap.Load(sampleIndices).xyz;
position = PositionMap.Load(sampleIndices).xyz;
diffuseAlbedo = DiffuseAlbedoMap.Load(sampleIndices).xyz;
float4 spec = SpecularAlbedoMap.Load(sampleIndices);
specularAlbedo = spec.xyz;
specularPower = spec.w;
}
float3 CalcLighting(in float3 normal,
in float3 position,
in float3 diffuseAlbedo,
in float3 specularAlbedo,
in float specularPower)
{
float3 L = 0;
float attenuation = 1.0f;
L = LightPosition - position;
float dist = length(L);
attenuation = max(0, 1.0f - (dist / LightRange.x));
L /= dist;
float nDotL = saturate(dot(normal, L));
float3 diffuse = nDotL * LightColor * diffuseAlbedo;
float3 V = CameraPosition - position;
float3 H = normalize( L + V);
float3 specular = pow(saturate(dot(normal, H)), specularPower) * LightColor * specularAlbedo.xyz * nDotL;
return (diffuse + specular) * attenuation;
}
float4 PixelShaderFunction( in float4 screenPos : SV_Position ) : SV_Target0
{
float3 normal;
float3 position;
float3 diffuseAlbedo;
float3 specularAlbedo;
float specularPower;
GetGBufferAttributes(screenPos.xy, normal, position, diffuseAlbedo, specularAlbedo, specularPower);
float3 lighting = CalcLighting(normal, position, diffuseAlbedo, specularAlbedo, specularPower);
return float4(lighting, 1.0f);
}