Merge pull request #1138 from Azaezel/alha41/luxTargTricks

lighting corrections:
This commit is contained in:
Brian Roberts 2023-11-20 12:03:23 -06:00 committed by GitHub
commit 52e7156436
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 117 additions and 78 deletions

View file

@ -73,4 +73,14 @@ float D_GGX(float NdotH, float alphaRoughnessSq)
return alphaRoughnessSq / (M_PI_F * f * f);
}
float3 Fr_DisneyDiffuse(float3 F0, float NdotV, float NdotL, float LdotH, float linearRoughness)
{
float energyBias = lerp (0 , 0.5 , linearRoughness );
float energyFactor = lerp (1.0 , 1.0 / 1.51 , linearRoughness );
float fd90 = energyBias + 2.0 * LdotH * LdotH * linearRoughness ;
float3 lightScatter = F_Schlick( F0 , fd90 , NdotL );
float3 viewScatter = F_Schlick(F0 , fd90 , NdotV );
return lightScatter * viewScatter * energyFactor ;
}
#endif

View file

@ -67,4 +67,15 @@ float D_GGX(float NdotH, float alphaRoughnessSq)
return alphaRoughnessSq / (M_PI_F * f * f);
}
vec3 Fr_DisneyDiffuse(vec3 F0, float NdotV, float NdotL, float LdotH, float linearRoughness)
{
float energyBias = lerp(0 , 0.5 , linearRoughness );
float energyFactor = lerp(1.0 , 1.0 / 1.51 , linearRoughness );
float fd90 = energyBias + 2.0 * LdotH * LdotH * linearRoughness ;
vec3 lightScatter = F_Schlick( F0 , fd90 , NdotL );
vec3 viewScatter = F_Schlick(F0 , fd90 , NdotV );
return lightScatter * viewScatter * energyFactor ;
}
#endif

View file

@ -216,8 +216,8 @@ float getDistanceAtt( vec3 unormalizedLightVector , float invSqrAttRadius )
float getSpotAngleAtt( vec3 normalizedLightVector , vec3 lightDir , vec2 lightSpotParams )
{
float cd = dot ( lightDir , normalizedLightVector );
float attenuation = saturate ( ( cd - lightSpotParams.x ) / lightSpotParams.y );
float cd = max(dot( lightDir , normalizedLightVector ),0.0);
float attenuation = saturate ( ( cd - lightSpotParams.x/(cd*1.001) ) / lightSpotParams.y );
// smooth the transition
return sqr(attenuation);
}
@ -225,7 +225,7 @@ float getDistanceAtt( vec3 unormalizedLightVector , float invSqrAttRadius )
vec3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
{
//lambert diffuse
vec3 Fd = surface.albedo.rgb * M_1OVER_PI_F;
vec3 Fd = Fr_DisneyDiffuse(surface.f0, surface.NdotV, surfaceToLight.NdotL, surfaceToLight.NdotH, surface.linearRoughness);
//GGX specular
vec3 F = F_Schlick(surface.f0, surface.f90, surfaceToLight.HdotV);
@ -236,7 +236,7 @@ vec3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
#if CAPTURING == 1
return saturate(mix(Fd + Fr,surface.f0,surface.metalness));
#else
return saturate(Fd + Fr);
return Fd + Fr;
#endif
}
@ -254,6 +254,15 @@ vec3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, vec3 light
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
}
vec3 getSpotlight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float radius, vec3 lightDir, vec2 lightSpotParams, float shadow)
{
float attenuation = 1.0f;
attenuation *= getDistanceAtt(surfaceToLight.Lu, radius);
attenuation *= getSpotAngleAtt(-surfaceToLight.L, lightDir, lightSpotParams.xy);
vec3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, 0.0f) ;
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
}
float computeSpecOcclusion( float NdotV , float AO , float roughness )
{
return saturate (pow( abs(NdotV + AO) , exp2 ( -16.0f * roughness - 1.0f )) - 1.0f + AO );
@ -270,7 +279,7 @@ vec4 compute4Lights( Surface surface,
vec4 inLightConfigData[4],
vec4 inLightColor[4],
vec4 inLightSpotDir[4],
vec2 lightSpotParams[4],
vec2 inlightSpotParams[4],
int hasVectorLight,
vec4 vectorLightDirection,
vec4 vectorLightingColor,
@ -305,13 +314,10 @@ vec4 compute4Lights( Surface surface,
//get punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
}
else //spot
else if(inLightConfigData[i].x == 1) //spot
{
//get Punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
//get spot angle attenuation
lighting *= getSpotAngleAtt(-surfaceToLight.L, inLightSpotDir[i].xyz, lightSpotParams[i].xy );
//get spot light contribution
lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, inLightSpotDir[i].xyz, inlightSpotParams[i], shadowed);
}
}
finalLighting += lighting;

View file

@ -217,16 +217,16 @@ float getDistanceAtt( float3 unormalizedLightVector , float invSqrAttRadius )
float getSpotAngleAtt( float3 normalizedLightVector , float3 lightDir , float2 lightSpotParams )
{
float cd = dot ( lightDir , normalizedLightVector );
float attenuation = saturate ( ( cd - lightSpotParams.x ) / lightSpotParams.y );
float cd = max(dot ( lightDir , normalizedLightVector ),0.0);
float attenuation = saturate(((cd - lightSpotParams.x/(cd*1.001))/lightSpotParams.y));
// smooth the transition
return sqr(attenuation);
}
float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
{
//lambert diffuse
float3 Fd = surface.albedo.rgb * M_1OVER_PI_F;
//disney diffuse
float3 Fd = Fr_DisneyDiffuse(surface.f0, surface.NdotV, surfaceToLight.NdotL, surfaceToLight.NdotH, surface.linearRoughness);
//GGX specular
float3 F = F_Schlick(surface.f0, surface.f90, surfaceToLight.HdotV);
@ -237,7 +237,7 @@ float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
#if CAPTURING == 1
return saturate(lerp(Fd + Fr,surface.f0,surface.metalness));
#else
return saturate(Fd + Fr);
return Fd + Fr;
#endif
}
@ -255,6 +255,14 @@ float3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, float3 l
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
}
float3 getSpotlight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float radius, float3 lightDir, float2 lightSpotParams, float shadow)
{
float attenuation = 1.0f;
attenuation *= getDistanceAtt(surfaceToLight.Lu, radius);
attenuation *= getSpotAngleAtt(-surfaceToLight.L, lightDir, lightSpotParams.xy);
float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, 0.0f) ;
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
}
float computeSpecOcclusion( float NdotV , float AO , float roughness )
{
return saturate (pow( abs(NdotV + AO) , exp2 ( -16.0f * roughness - 1.0f )) - 1.0f + AO );
@ -271,7 +279,7 @@ float4 compute4Lights( Surface surface,
float4 inLightConfigData[4],
float4 inLightColor[4],
float4 inLightSpotDir[4],
float2 lightSpotParams[4],
float2 inlightSpotParams[4],
int hasVectorLight,
float4 vectorLightDirection,
float4 vectorLightingColor,
@ -296,7 +304,7 @@ float4 compute4Lights( Surface surface,
float lightBrightness = inLightConfigData[i].y;
float lightInvSqrRange= inLightConfigData[i].a;
float3 lighting = 0.0.xxx;
float3 lighting = float3(0.0,0.0,0.0);
[branch]
if(dist < lightRange)
@ -307,13 +315,10 @@ float4 compute4Lights( Surface surface,
//get punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
}
else //spot
else if(inLightConfigData[i].x == 1) //spot
{
//get Punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
//get spot angle attenuation
lighting *= getSpotAngleAtt(-surfaceToLight.L, inLightSpotDir[i].xyz, lightSpotParams[i].xy );
//get spot light contribution
lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, inLightSpotDir[i].xyz, inlightSpotParams[i], shadowed);
}
}
finalLighting += lighting;
@ -321,7 +326,7 @@ float4 compute4Lights( Surface surface,
//Vector light
[branch]
if(hasVectorLight)
if(hasVectorLight == 1)
{
SurfaceToLight surfaceToVecLight = createSurfaceToLight(surface, -vectorLightDirection.xyz);

View file

@ -154,10 +154,8 @@ void main()
return;
#endif
//get Punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow);
//get spot angle attenuation
lighting *= getSpotAngleAtt(-surfaceToLight.L, lightDirection, lightSpotParams );
//get spot light contribution
lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow);
}
OUT_col = vec4(lighting, 0);

View file

@ -151,10 +151,8 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
return final;
#endif
//get Punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow);
//get spot angle attenuation
lighting *= getSpotAngleAtt(-surfaceToLight.L, lightDirection, lightSpotParams );
//get spot light contribution
lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow);
}
return float4(lighting, 0);