Shader code cleanup;
Added punctual light evaluation in light loop;
This commit is contained in:
@@ -28,11 +28,6 @@
|
||||
|
||||
struct UTSData
|
||||
{
|
||||
float3 viewDirection;
|
||||
float3 normalDirection;
|
||||
fixed cameraDir;
|
||||
float cameraRoll;
|
||||
fixed signMirror;
|
||||
};
|
||||
|
||||
struct UTSSurfaceData
|
||||
@@ -54,8 +49,7 @@ struct UTSSurfaceData
|
||||
float3 geomNormalWS;
|
||||
float3 tangentWS;
|
||||
|
||||
real3 subsurfaceColor;
|
||||
real subsurfaceMask;
|
||||
real4 subsurfaceColor;
|
||||
|
||||
real anisotropy;
|
||||
};
|
||||
@@ -75,7 +69,7 @@ struct UtsBSDFData
|
||||
real ambientOcclusion;
|
||||
real specularOcclusion;
|
||||
real perceptualRoughness;
|
||||
|
||||
|
||||
real3 subsurfaceColor;
|
||||
|
||||
float3 geomNormalWS;
|
||||
@@ -104,8 +98,8 @@ UTSSurfaceData ConvertSurfaceDataToUTSSurfaceData(SurfaceData surfaceData)
|
||||
output.specularColor = surfaceData.specularColor;
|
||||
output.geomNormalWS = surfaceData.geomNormalWS;
|
||||
output.tangentWS = surfaceData.tangentWS;
|
||||
output.subsurfaceColor = surfaceData.transmittanceColor;
|
||||
output.subsurfaceMask = surfaceData.subsurfaceMask;
|
||||
output.subsurfaceColor.rgb = surfaceData.transmittanceColor;
|
||||
output.subsurfaceColor.a = surfaceData.subsurfaceMask;
|
||||
output.anisotropy = surfaceData.anisotropy;
|
||||
|
||||
return output;
|
||||
@@ -124,8 +118,8 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V, float2 UV)
|
||||
|
||||
float4 firstShadingTexture = SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_BaseColorMap, TRANSFORM_TEX(UV, _BaseColorMap));
|
||||
float4 secondShadingTexture = SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_BaseColorMap, TRANSFORM_TEX(UV, _BaseColorMap));
|
||||
output.firstShadingColor = lerp(firstShadingTexture.rgb, mainTexture.rgb, _Use_BaseAs1st) * _1st_ShadeColor;
|
||||
output.secondShadingColor = lerp(secondShadingTexture.rgb, output.firstShadingColor, _Use_1stAs2nd) * _2nd_ShadeColor;
|
||||
output.firstShadingColor = lerp(firstShadingTexture.rgb, mainTexture.rgb, _Use_BaseAs1st) * _1st_ShadeColor.rgb;
|
||||
output.secondShadingColor = lerp(secondShadingTexture.rgb, output.firstShadingColor, _Use_1stAs2nd) * _2nd_ShadeColor.rgb;
|
||||
|
||||
float4 normalLocal = 0;
|
||||
if (_Use_SSSLut)
|
||||
@@ -138,8 +132,13 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V, float2 UV)
|
||||
}
|
||||
normalLocal.rgb = UnpackNormalScale(normalLocal, _NormalScale);
|
||||
float3 normalWS = normalize(mul(normalLocal.rgb, input.tangentToWorld));
|
||||
#if _PBR_MODE_OFF
|
||||
float smoothness = 0.0;
|
||||
float metallic = 0.0;
|
||||
#else
|
||||
float smoothness = _Smoothness;
|
||||
float metallic = _Metallic;
|
||||
#endif
|
||||
float ao = 1.0;
|
||||
float3 specularColor = 1;
|
||||
float anisotropy = 0;
|
||||
@@ -189,7 +188,6 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V, float2 UV)
|
||||
output.tangentWS = Orthonormalize(input.tangentToWorld[0].rgb, normalWS);
|
||||
|
||||
output.subsurfaceColor = SAMPLE_TEXTURE2D(_SSSLutMap, sampler_MainTex, TRANSFORM_TEX(UV, _BaseColorMap)) * _SSSIntensity;
|
||||
output.subsurfaceMask = 1.0;
|
||||
|
||||
output.anisotropy = anisotropy;
|
||||
|
||||
@@ -216,13 +214,9 @@ UtsBSDFData ConvertUTSSurfaceDataToUTSBSDFData(UTSSurfaceData surfaceData)
|
||||
|
||||
output.ambientOcclusion = surfaceData.ambientOcclusion;
|
||||
output.specularOcclusion = surfaceData.specularOcclusion;
|
||||
#if _PBR_MODE_OFF
|
||||
output.perceptualRoughness = 0.0;
|
||||
#else
|
||||
output.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness);
|
||||
#endif
|
||||
|
||||
output.subsurfaceColor = surfaceData.subsurfaceColor * surfaceData.subsurfaceMask;
|
||||
output.subsurfaceColor = surfaceData.subsurfaceColor.rgb * surfaceData.subsurfaceColor.a;
|
||||
|
||||
output.normalWS = surfaceData.normalWS;
|
||||
output.geomNormalWS = surfaceData.geomNormalWS;
|
||||
@@ -230,8 +224,7 @@ UtsBSDFData ConvertUTSSurfaceDataToUTSBSDFData(UTSSurfaceData surfaceData)
|
||||
output.bitangentWS = normalize(cross(surfaceData.normalWS, surfaceData.tangentWS));
|
||||
|
||||
output.anisotropy = surfaceData.anisotropy;
|
||||
output.roughnessT = output.perceptualRoughness * 0.5;
|
||||
output.roughnessB = output.perceptualRoughness * 2.0;
|
||||
ConvertAnisotropyToRoughness(output.perceptualRoughness, surfaceData.anisotropy, output.roughnessT, output.roughnessB);
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -312,6 +305,12 @@ PreLightData GetPreLightData_UTS(float3 V, PositionInputs posInput, inout UtsBSD
|
||||
return preLightData;
|
||||
}
|
||||
|
||||
void UtsClampRoughness(inout PreLightData preLightData, inout UtsBSDFData bsdfData, float minRoughness)
|
||||
{
|
||||
bsdfData.roughnessT = max(minRoughness, bsdfData.roughnessT);
|
||||
bsdfData.roughnessB = max(minRoughness, bsdfData.roughnessB);
|
||||
}
|
||||
|
||||
// Legacy for compatibility with existing shaders
|
||||
inline bool IsGammaSpace()
|
||||
{
|
||||
@@ -534,10 +533,6 @@ float3 ShadeSH9 (float4 normal)
|
||||
return res;
|
||||
}
|
||||
|
||||
float rateR = 0.299;
|
||||
float rateG = 0.587;
|
||||
float rateB = 0.114;
|
||||
|
||||
float3 SampleBakedGI_UTS(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap, bool needToIncludeAPV = false)
|
||||
{
|
||||
float3 bakeDiffuseLighting = float3(0, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user