|
@@ -217,16 +217,16 @@ float getDistanceAtt( float3 unormalizedLightVector , float invSqrAttRadius )
|
|
|
|
|
|
float getSpotAngleAtt( float3 normalizedLightVector , float3 lightDir , float2 lightSpotParams )
|
|
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
|
|
// smooth the transition
|
|
return sqr(attenuation);
|
|
return sqr(attenuation);
|
|
}
|
|
}
|
|
|
|
|
|
float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
|
|
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
|
|
//GGX specular
|
|
float3 F = F_Schlick(surface.f0, surface.f90, surfaceToLight.HdotV);
|
|
float3 F = F_Schlick(surface.f0, surface.f90, surfaceToLight.HdotV);
|
|
@@ -237,7 +237,7 @@ float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
|
|
#if CAPTURING == 1
|
|
#if CAPTURING == 1
|
|
return saturate(lerp(Fd + Fr,surface.f0,surface.metalness));
|
|
return saturate(lerp(Fd + Fr,surface.f0,surface.metalness));
|
|
#else
|
|
#else
|
|
- return saturate(Fd + Fr);
|
|
|
|
|
|
+ return Fd + Fr;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
}
|
|
}
|
|
@@ -255,6 +255,14 @@ float3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, float3 l
|
|
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
|
|
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 )
|
|
float computeSpecOcclusion( float NdotV , float AO , float roughness )
|
|
{
|
|
{
|
|
return saturate (pow( abs(NdotV + AO) , exp2 ( -16.0f * roughness - 1.0f )) - 1.0f + AO );
|
|
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 inLightConfigData[4],
|
|
float4 inLightColor[4],
|
|
float4 inLightColor[4],
|
|
float4 inLightSpotDir[4],
|
|
float4 inLightSpotDir[4],
|
|
- float2 lightSpotParams[4],
|
|
|
|
|
|
+ float2 inlightSpotParams[4],
|
|
int hasVectorLight,
|
|
int hasVectorLight,
|
|
float4 vectorLightDirection,
|
|
float4 vectorLightDirection,
|
|
float4 vectorLightingColor,
|
|
float4 vectorLightingColor,
|
|
@@ -296,7 +304,7 @@ float4 compute4Lights( Surface surface,
|
|
float lightBrightness = inLightConfigData[i].y;
|
|
float lightBrightness = inLightConfigData[i].y;
|
|
float lightInvSqrRange= inLightConfigData[i].a;
|
|
float lightInvSqrRange= inLightConfigData[i].a;
|
|
|
|
|
|
- float3 lighting = 0.0.xxx;
|
|
|
|
|
|
+ float3 lighting = float3(0.0,0.0,0.0);
|
|
|
|
|
|
[branch]
|
|
[branch]
|
|
if(dist < lightRange)
|
|
if(dist < lightRange)
|
|
@@ -307,13 +315,10 @@ float4 compute4Lights( Surface surface,
|
|
//get punctual light contribution
|
|
//get punctual light contribution
|
|
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
|
|
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;
|
|
finalLighting += lighting;
|
|
@@ -321,7 +326,7 @@ float4 compute4Lights( Surface surface,
|
|
|
|
|
|
//Vector light
|
|
//Vector light
|
|
[branch]
|
|
[branch]
|
|
- if(hasVectorLight)
|
|
|
|
|
|
+ if(hasVectorLight == 1)
|
|
{
|
|
{
|
|
SurfaceToLight surfaceToVecLight = createSurfaceToLight(surface, -vectorLightDirection.xyz);
|
|
SurfaceToLight surfaceToVecLight = createSurfaceToLight(surface, -vectorLightDirection.xyz);
|
|
|
|
|