diff options
| author | yum <yum.food.vr@gmail.com> | 2024-07-15 14:23:47 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-07-15 14:23:47 -0700 |
| commit | bfc062d1f056f13dcc43d50c995124288fef5967 (patch) | |
| tree | 928520fba54204ee68aac55fa07bf72f64f89cf4 | |
| parent | 65960b924a861f273b72157456aabaa694831976 (diff) | |
Add clearcoat mask
| -rw-r--r-- | Editor/tooner.cs | 2 | ||||
| -rw-r--r-- | MochieStandardBRDF.cginc | 14 | ||||
| -rw-r--r-- | globals.cginc | 1 | ||||
| -rw-r--r-- | pbr.cginc | 19 | ||||
| -rw-r--r-- | tooner.shader | 1 |
5 files changed, 21 insertions, 16 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index 2c02896..fb870ca 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -113,6 +113,8 @@ public class ToonerGUI : ShaderGUI { editor.RangeProperty(bc, "Strength"); bc = FindProperty("_Clearcoat_Roughness"); editor.RangeProperty(bc, "Roughness"); + bc = FindProperty("_Clearcoat_Mask"); + editor.TexturePropertySingleLine(MakeLabel(bc, "Mask"), bc); } } diff --git a/MochieStandardBRDF.cginc b/MochieStandardBRDF.cginc index 90f5df5..515798e 100644 --- a/MochieStandardBRDF.cginc +++ b/MochieStandardBRDF.cginc @@ -1,9 +1,6 @@ #ifndef MOCHIE_STANDARD_BRDF_INCLUDED #define MOCHIE_STANDARD_BRDF_INCLUDED -#include "filament_math.cginc" -#include "globals.cginc" - /* * MIT License * @@ -173,17 +170,6 @@ half4 BRDF1_Mochie_PBS ( // reflCol *= lerp(1, vertexColor, _ReflVertexColor*_ReflVertexColorStrength); // #endif -#if defined(_CLEARCOAT) - half cc_nh = saturate(dot(mesh_normal, halfDir)); - float clearcoat = FilamentClearcoat( - _Clearcoat_Roughness, - _Clearcoat_Strength, - cc_nh, - lh, - halfDir); - specCol += clearcoat * saturate(dot(mesh_normal, light.dir)) * 10; -#endif - return half4(diffCol + specCol + reflCol + subsurfaceCol, 1); } diff --git a/globals.cginc b/globals.cginc index 128972b..19e82d4 100644 --- a/globals.cginc +++ b/globals.cginc @@ -42,6 +42,7 @@ float3 _ReflShadowStrength; float _Clearcoat_Enabled; float _Clearcoat_Strength; float _Clearcoat_Roughness; +texture2D _Clearcoat_Mask; #endif #if defined(SSR_ENABLED) @@ -4,10 +4,11 @@ #include "UnityPBSLighting.cginc" #include "AutoLight.cginc" -#include "MochieStandardBRDF.cginc" - +#include "globals.cginc" +#include "filament_math.cginc" #include "globals.cginc" #include "interpolators.cginc" +#include "MochieStandardBRDF.cginc" #include "poi.cginc" #if defined(_LTCGI) @@ -262,6 +263,20 @@ float4 getLitColor( indirect_light).xyz; #endif +#if defined(_CLEARCOAT) + half3 half_dir = Unity_SafeNormalize(half3(direct_light.dir) + view_dir); + half lh = saturate(dot(direct_light.dir, half_dir)); + half cc_nh = saturate(dot(i.normal, half_dir)); + float clearcoat = FilamentClearcoat( + _Clearcoat_Roughness, + _Clearcoat_Strength, + cc_nh, + lh, + half_dir); + float cc_mask = _Clearcoat_Mask.SampleGrad(linear_repeat_s, i.uv, ddx(i.uv.x), ddy(i.uv.y)); + pbr.rgb += clearcoat * saturate(dot(i.normal, direct_light.dir)) * cc_mask * 10; +#endif + return float4(pbr.rgb, albedo.a); } diff --git a/tooner.shader b/tooner.shader index 45fa9e2..f2df686 100644 --- a/tooner.shader +++ b/tooner.shader @@ -9,6 +9,7 @@ Shader "yum_food/tooner" _Clearcoat_Enabled("Clearcoat enabled", Float) = 0 _Clearcoat_Strength("Clearcoat strength", Range(0, 1)) = 0 _Clearcoat_Roughness("Clearcoat strength", Range(0, 1)) = 0 + _Clearcoat_Mask("Clearcoat mask", 2D) = "white" {} [NoScaleOffset] _MainTex("Base color", 2D) = "white" {} [NoScaleOffset] _NormalTex("Normal", 2D) = "bump" {} |
