diff options
| author | yum <yum.food.vr@gmail.com> | 2024-12-16 10:18:59 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-12-16 10:18:59 -0800 |
| commit | 07a94ee97d02aa31b428cbc1f67dc7f8ae58a403 (patch) | |
| tree | 6da50596814c971f954f94f4401d545e276eb766 | |
| parent | f27c89c6ba69ad7abbe60b03e0cc4ccc75f24369 (diff) | |
Fix clearcoat
| -rw-r--r-- | Editor/shader_inliner.cs | 2 | ||||
| -rw-r--r-- | filament_math.cginc | 5 | ||||
| -rw-r--r-- | pbr.cginc | 65 |
3 files changed, 19 insertions, 53 deletions
diff --git a/Editor/shader_inliner.cs b/Editor/shader_inliner.cs index cecf9b8..679dd92 100644 --- a/Editor/shader_inliner.cs +++ b/Editor/shader_inliner.cs @@ -55,7 +55,7 @@ public class ShaderInliner : EditorWindow File.WriteAllText(outputShaderPath, inlinedShader); AssetDatabase.Refresh(); - EditorUtility.DisplayDialog("Success", $"Inlined shader saved to:\n{outputShaderPath}", "OK"); + //EditorUtility.DisplayDialog("Success", $"Inlined shader saved to:\n{outputShaderPath}", "OK"); } private string ProcessShader(string content, string basePath) diff --git a/filament_math.cginc b/filament_math.cginc index e9dcb70..66a1170 100644 --- a/filament_math.cginc +++ b/filament_math.cginc @@ -255,10 +255,11 @@ float FilamentClearcoat( float strength, float NoH, float LoH, - float3 h) { + float3 h, + out float Fc) { float Dc = D_GGX(roughness, NoH, h); float Vc = V_Kelemen(LoH); - float Fc = F_Schlick(0.04, LoH) * strength; + Fc = F_Schlick(0.04, LoH) * strength; return (Dc * Vc) * Fc; } @@ -403,59 +403,24 @@ float4 getLitColor( cc_mask *= cc_mask2_tmp; #endif { - float3 cc_L = direct_light.dir; - half3 cc_H = Unity_SafeNormalize(cc_L + view_dir); - half cc_LoH = saturate(dot(direct_light.dir, cc_H)); - float3 cc_N = normalize(i.normal); - half cc_NoH = saturate(dot(i.normal, cc_H)); - float clearcoat = FilamentClearcoat( + // TODO fold this into the full BRDF and apply the brightness corrections + // described in the filament whitepaper: + // https://google.github.io/filament/Filament.html + metallic = 0; + smoothness = 1.0 - _Clearcoat_Roughness; + indirect_light.specular = getIndirectSpecular(i, view_dir, normal, smoothness, + metallic, worldPos, uv); + + float Fc; + float cc_term = FilamentClearcoat( _Clearcoat_Roughness, _Clearcoat_Strength, - cc_NoH, - cc_LoH, - cc_H); - pbr.rgb += clearcoat * saturate(dot(i.normal, cc_L)) * - cc_mask * direct_color * _Direct_Lighting_Factor; + 1, + dot(view_dir, normal), + normal, + Fc); + pbr.rgb += cc_term * indirect_light.specular; } - // Indirect specular lighting -#if 1 - { - float3 in_L = normalize(reflect(-view_dir, i.normal)); - half3 in_H = i.normal; - half in_LoH = saturate(dot(in_L, in_H)); - half in_NoH = 1; - float clearcoat = FilamentClearcoat( - _Clearcoat_Roughness, - _Clearcoat_Strength, - in_NoH, - in_LoH, - in_H); - pbr.rgb += clearcoat * saturate(dot(i.normal, in_L)) * - cc_mask * indirect_light.specular * _Indirect_Specular_Lighting_Factor; - } -#endif -#if defined(VERTEXLIGHT_ON) - // Vertex lights - for (uint ii = 0; ii < 4; ii++) { - float3 vpos = float3(unity_4LightPosX0[ii], unity_4LightPosY0[ii], - unity_4LightPosZ0[ii]); - float3 vl = normalize(vpos - i.worldPos); - float3 c = unity_LightColor[0].rgb; - - half3 vhalf = Unity_SafeNormalize(half3(vl) + view_dir); - half vlh = saturate(dot(vl, vhalf)); - half cc_vnh = saturate(dot(i.normal, vhalf)); - - float clearcoat = FilamentClearcoat( - _Clearcoat_Roughness, - _Clearcoat_Strength, - cc_vnh, - vlh, - vhalf); - pbr.rgb += clearcoat * saturate(dot(i.normal, vl)) * - cc_mask * c * _Vertex_Lighting_Factor; - } -#endif #endif #if defined(_UNITY_FOG) |
