From c9342de5bd708d309cd0df1e65fe668ecbb9a16a Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 20 Jan 2026 23:30:08 -0800 Subject: Fur: add depth-based ao --- 2ner.cginc | 4 ++-- 2ner.shader | 1 + globals.cginc | 1 + yum_pbr.cginc | 23 +++++++++++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/2ner.cginc b/2ner.cginc index 736210f..0b5ee9f 100644 --- a/2ner.cginc +++ b/2ner.cginc @@ -225,7 +225,7 @@ v2f vert(appdata v) { } //ifex _Fur_Enabled==0 -[maxvertexcount(3 * 9)] +[maxvertexcount(3 * 10)] void geom(triangle v2f input[3], inout TriangleStream stream) { #if defined(_FUR) #if defined(_FUR_MASK) @@ -431,7 +431,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace float4x4 tangentToWorld = float4x4( float4(i.tangent, 0), - float4(cross(i.tangent, i.normal), 0), + float4(f.binormal, 0), float4(i.normal, 0), float4(0, 0, 0, 1) ); diff --git a/2ner.shader b/2ner.shader index 987a990..357f372 100644 --- a/2ner.shader +++ b/2ner.shader @@ -114,6 +114,7 @@ Shader "yum_food/2ner" [IntRange] _Fur_Layers("Layers", Range(1, 12)) = 1 _Fur_Heightmap("Heightmap", 2D) = "black" {} _Fur_Heightmap_Mip_Bias("Heightmap mip bias", Range(-4, 4)) = 0 + _Fur_AO_Strength("Ambient occlusion strength", Range(0, 1)) = 1 [HideInInspector] m_start_Fur_Mask("Mask", Float) = 0 [ThryToggle(_FUR_MASK)]_Fur_Mask_Enabled("Enable", Float) = 0 diff --git a/globals.cginc b/globals.cginc index cfb7f07..4bc39b4 100644 --- a/globals.cginc +++ b/globals.cginc @@ -149,6 +149,7 @@ int _Fur_Layers; texture2D _Fur_Heightmap; float4 _Fur_Heightmap_ST; float _Fur_Heightmap_Mip_Bias; +float _Fur_AO_Strength; #endif #if defined(_FUR_MASK) diff --git a/yum_pbr.cginc b/yum_pbr.cginc index ef07553..a9e65d6 100644 --- a/yum_pbr.cginc +++ b/yum_pbr.cginc @@ -137,14 +137,25 @@ void applySeaFoam(v2f i, inout YumPbr pbr) { } #endif -YumPbr GetYumPbr(v2f i, f2f f, float3x3 tangentToWorld) { - YumPbr result = (YumPbr)0; - +// Returns fur thickness on [0, 1], 0 = no fur, 1 = max fur. +float FurClip(v2f i, f2f f, inout YumPbr result) { #if defined(_FUR) float fur_layer = i.vertexLight.w; - float fur_thickness = _Fur_Heightmap.SampleBias(trilinear_aniso4_repeat_s, i.uv01.xy * _Fur_Heightmap_ST.xy, _Fur_Heightmap_Mip_Bias).r; + float2 fur_uv = i.uv01.xy * _Fur_Heightmap_ST.xy; + float fur_thickness = _Fur_Heightmap.SampleBias( + trilinear_aniso4_repeat_s, fur_uv, + _Fur_Heightmap_Mip_Bias).r; clip(fur_thickness - fur_layer / _Fur_Layers); + return fur_thickness; +#else + return 0; #endif +} + +YumPbr GetYumPbr(v2f i, f2f f, float3x3 tangentToWorld) { + YumPbr result = (YumPbr)0; + + float fur_thickness = FurClip(i, f, result); float2 raw_uv = i.uv01.xy; #if defined(_UV_DOMAIN_WARPING) @@ -246,6 +257,10 @@ YumPbr GetYumPbr(v2f i, f2f f, float3x3 tangentToWorld) { result.ao = 1; #endif +#if defined(_FUR) + result.ao = lerp(result.ao, 0, fur_thickness * _Fur_AO_Strength); +#endif + applyDecals(i, result.albedo, normal_tangent, result.metallic, result.smoothness, result.emission); const float min_roughness_perceptual = 0.045f; result.smoothness = min(1.0f - min_roughness_perceptual, result.smoothness); -- cgit v1.2.3