From 47eb460bf49d4512f52eecffa5696eb761a08f83 Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 27 May 2024 21:42:06 -0700 Subject: Use _MainTex and _Color Also remove multipliers from gradient-based mipmap sampling. --- Editor/tooner.cs | 5 ++--- globals.cginc | 6 +++--- tooner.shader | 13 ++++++------- tooner_lighting.cginc | 41 ++++++++++++++--------------------------- tooner_outline_pass.cginc | 6 +++--- 5 files changed, 28 insertions(+), 43 deletions(-) diff --git a/Editor/tooner.cs b/Editor/tooner.cs index f984f6a..d60e543 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -48,8 +48,8 @@ public class ToonerGUI : ShaderGUI { } void DoBaseColor() { - MaterialProperty bc = FindProperty("_BaseColor"); - MaterialProperty bct = FindProperty("_BaseColorTex"); + MaterialProperty bc = FindProperty("_Color"); + MaterialProperty bct = FindProperty("_MainTex"); editor.TexturePropertySingleLine( MakeLabel(bct, "Base color (RGBA)"), bct, @@ -917,4 +917,3 @@ public class ToonerGUI : ShaderGUI { } } - diff --git a/globals.cginc b/globals.cginc index 6e56eac..5156284 100644 --- a/globals.cginc +++ b/globals.cginc @@ -5,7 +5,7 @@ SamplerState linear_repeat_s; -float4 _BaseColor; +float4 _Color; float _Metallic; float _Roughness; float _Tex_NormalStr; @@ -20,8 +20,8 @@ float _Confabulate_Normals; #if defined(_BASECOLOR_MAP) -texture2D _BaseColorTex; -float4 _BaseColorTex_ST; +texture2D _MainTex; +float4 _MainTex_ST; #endif texture2D _NormalTex; float4 _NormalTex_ST; diff --git a/tooner.shader b/tooner.shader index 8542e62..fafd215 100644 --- a/tooner.shader +++ b/tooner.shader @@ -2,11 +2,11 @@ Shader "yum_food/tooner" { Properties { - _BaseColor("Base color", Color) = (0.8, 0.8, 0.8, 1) + _Color("Base color", Color) = (0.8, 0.8, 0.8, 1) _Metallic("Metallic", Range(0, 1)) = 0 _Roughness("Roughness", Range(0, 1)) = 1 - [NoScaleOffset] _BaseColorTex("Base color", 2D) = "white" {} + [NoScaleOffset] _MainTex("Base color", 2D) = "white" {} [NoScaleOffset] _NormalTex("Normal", 2D) = "bump" {} [NoScaleOffset] _MetallicTex("Metallic", 2D) = "white" {} [NoScaleOffset] _RoughnessTex("Roughness", 2D) = "black" {} @@ -180,12 +180,14 @@ Shader "yum_food/tooner" } SubShader { + Tags { + "VRCFallback"="ToonCutout" + } Pass { Tags { "RenderType"="Opaque" "Queue"="Geometry" - "LightMode" = "ForwardBase" - "VRCFallback"="Hidden" + "LightMode"="ForwardBase" } Blend [_SrcBlend] [_DstBlend] ZWrite [_ZWrite] @@ -293,7 +295,6 @@ Shader "yum_food/tooner" "RenderType" = "Opaque" "Queue"="Geometry" "LightMode" = "ForwardAdd" - "VRCFallback"="Hidden" } Blend [_SrcBlend] One ZWrite Off @@ -439,14 +440,12 @@ Shader "yum_food/tooner" Pass { Tags { "LightMode" = "ShadowCaster" - "VRCFallback"="Hidden" } CGPROGRAM #include "mochie_shadow_caster.cginc" ENDCG } } - Fallback "Transparent" CustomEditor "ToonerGUI" } diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 2c66964..40e67bc 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -543,41 +543,28 @@ void applyOverlayNormal(inout float3 raw_normal, PbrOverlay ov, v2f i, float idd // Use UVs to smoothly blend between fully detailed normals when close up and // flat normals when far away. If we don't do this, then we see moire effects // on e.g. striped normal maps. - //float3 raw_normal = UnpackScaleNormal(_PBR_Overlay0_NormalTex.SampleGrad(linear_repeat_s, i.uv, iddx/2, iddy/2), _PBR_Overlay0_Tex_NormalStr); - raw_normal_2 = UnpackScaleNormal(_PBR_Overlay0_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay0_NormalTex_ST), iddx/2, iddy/2), _PBR_Overlay0_Tex_NormalStr * ov.ov0_mask); + raw_normal_2 = UnpackScaleNormal(_PBR_Overlay0_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay0_NormalTex_ST), iddx, iddy), _PBR_Overlay0_Tex_NormalStr * ov.ov0_mask); raw_normal = BlendNormals( raw_normal, raw_normal_2); #endif // _PBR_OVERLAY0 && _PBR_OVERLAY0_NORMAL_MAP #if defined(_PBR_OVERLAY1) && defined(_PBR_OVERLAY1_NORMAL_MAP) - // Use UVs to smoothly blend between fully detailed normals when close up and - // flat normals when far away. If we don't do this, then we see moire effects - // on e.g. striped normal maps. - //float3 raw_normal = UnpackScaleNormal(_PBR_Overlay1_NormalTex.SampleGrad(linear_repeat_s, i.uv, iddx/2, iddy/2), _PBR_Overlay1_Tex_NormalStr); - raw_normal_2 = UnpackScaleNormal(_PBR_Overlay1_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay1_NormalTex_ST), iddx/2, iddy/2), _PBR_Overlay1_Tex_NormalStr * ov.ov1_mask); + raw_normal_2 = UnpackScaleNormal(_PBR_Overlay1_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay1_NormalTex_ST), iddx, iddy), _PBR_Overlay1_Tex_NormalStr * ov.ov1_mask); raw_normal = BlendNormals( raw_normal, raw_normal_2); #endif // _PBR_OVERLAY1 && _PBR_OVERLAY1_NORMAL_MAP #if defined(_PBR_OVERLAY2) && defined(_PBR_OVERLAY2_NORMAL_MAP) - // Use UVs to smoothly blend between fully detailed normals when close up and - // flat normals when far away. If we don't do this, then we see moire effects - // on e.g. striped normal maps. - //float3 raw_normal = UnpackScaleNormal(_PBR_Overlay2_NormalTex.SampleGrad(linear_repeat_s, i.uv, iddx/2, iddy/2), _PBR_Overlay2_Tex_NormalStr); - raw_normal_2 = UnpackScaleNormal(_PBR_Overlay2_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay2_NormalTex_ST), iddx/2, iddy/2), _PBR_Overlay2_Tex_NormalStr * ov.ov2_mask); + raw_normal_2 = UnpackScaleNormal(_PBR_Overlay2_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay2_NormalTex_ST), iddx, iddy), _PBR_Overlay2_Tex_NormalStr * ov.ov2_mask); raw_normal = BlendNormals( raw_normal, raw_normal_2); #endif // _PBR_OVERLAY2 && _PBR_OVERLAY2_NORMAL_MAP #if defined(_PBR_OVERLAY3) && defined(_PBR_OVERLAY3_NORMAL_MAP) - // Use UVs to smoothly blend between fully detailed normals when close up and - // flat normals when far away. If we don't do this, then we see moire effects - // on e.g. striped normal maps. - //float3 raw_normal = UnpackScaleNormal(_PBR_Overlay3_NormalTex.SampleGrad(linear_repeat_s, i.uv, iddx/2, iddy/2), _PBR_Overlay3_Tex_NormalStr); - raw_normal_2 = UnpackScaleNormal(_PBR_Overlay3_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay3_NormalTex_ST), iddx/2, iddy/2), _PBR_Overlay3_Tex_NormalStr * ov.ov3_mask); + raw_normal_2 = UnpackScaleNormal(_PBR_Overlay3_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay3_NormalTex_ST), iddx, iddy), _PBR_Overlay3_Tex_NormalStr * ov.ov3_mask); raw_normal = BlendNormals( raw_normal, @@ -587,8 +574,8 @@ void applyOverlayNormal(inout float3 raw_normal, PbrOverlay ov, v2f i, float idd float4 effect(inout v2f i) { - float iddx = ddx(i.uv.x) / 4; - float iddy = ddx(i.uv.y) / 4; + float iddx = ddx(i.uv.x); + float iddy = ddx(i.uv.y); const float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); #if defined(_UVSCROLL) @@ -598,10 +585,10 @@ float4 effect(inout v2f i) #endif #if defined(_BASECOLOR_MAP) - float4 albedo = _BaseColorTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _BaseColorTex_ST), iddx, iddy); - albedo *= _BaseColor; + float4 albedo = _MainTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _MainTex_ST), iddx, iddy); + albedo *= _Color; #else - float4 albedo = _BaseColor; + float4 albedo = _Color; #endif // _BASECOLOR_MAP #if defined(_UVSCROLL) @@ -629,7 +616,7 @@ float4 effect(inout v2f i) // flat normals when far away. If we don't do this, then we see moire effects // on e.g. striped normal maps. float fw = clamp(fwidth(i.uv), .001, 1) * 1200; - float3 raw_normal = UnpackScaleNormal(_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _NormalTex_ST), iddx/2, iddy/2), _Tex_NormalStr); + float3 raw_normal = UnpackScaleNormal(_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _NormalTex_ST), iddx, iddy), _Tex_NormalStr); raw_normal = BlendNormals( (1/fw) * raw_normal, @@ -681,8 +668,8 @@ float4 effect(inout v2f i) float2 matcap_uv = refl.xy / m + 0.5; float iddx = ddx(i.uv.x); float iddy = ddy(i.uv.y); - { #if defined(_MATCAP0) + { #if defined(_MATCAP0_DISTORTION0) float2 distort_uv = matcap_distortion0(matcap_uv); float2 matcap_uv = distort_uv; @@ -727,10 +714,10 @@ float4 effect(inout v2f i) default: break; } -#endif } - { +#endif // _MATCAP0 #if defined(_MATCAP1) + { #if defined(_MATCAP1_DISTORTION0) float2 distort_uv = matcap_distortion0(matcap_uv); float2 matcap_uv = distort_uv; @@ -775,8 +762,8 @@ float4 effect(inout v2f i) default: break; } -#endif // _MATCAP1 } +#endif // _MATCAP1 } #endif // _MATCAP0 || _MATCAP1 #if defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) diff --git a/tooner_outline_pass.cginc b/tooner_outline_pass.cginc index 82b6be8..69de32c 100644 --- a/tooner_outline_pass.cginc +++ b/tooner_outline_pass.cginc @@ -325,10 +325,10 @@ fixed4 frag (v2f i) : SV_Target float iddx = ddx(i.uv.x) / 4; float iddy = ddx(i.uv.y) / 4; #if defined(_BASECOLOR_MAP) - float4 albedo = _BaseColorTex.SampleGrad(linear_repeat_s, i.uv, iddx, iddy); - albedo *= _BaseColor; + float4 albedo = _MainTex.SampleGrad(linear_repeat_s, i.uv, iddx, iddy); + albedo *= _Color; #else - float4 albedo = _BaseColor; + float4 albedo = _Color; #endif // _BASECOLOR_MAP #if defined(_RENDERING_CUTOUT) -- cgit v1.2.3