diff options
| author | yum <yum.food.vr@gmail.com> | 2024-09-07 13:52:12 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-09-07 13:52:12 -0700 |
| commit | 50bfca1c68773dd8c663577fcef23ac7cfbca0f7 (patch) | |
| tree | e5d6550c1c0b45d8de7ad0a0535b0f3bd84710fb | |
| parent | 489fadcbd2cff45e0f6e38eefb0d9d6766b701bb (diff) | |
Add quantization and alpha blending to rorschach effect
| -rw-r--r-- | Editor/tooner.cs | 6 | ||||
| -rw-r--r-- | globals.cginc | 3 | ||||
| -rw-r--r-- | rorschach.cginc | 15 | ||||
| -rw-r--r-- | tooner.shader | 11 | ||||
| -rw-r--r-- | tooner_lighting.cginc | 3 |
5 files changed, 33 insertions, 5 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index 910098d..17347a7 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -1444,6 +1444,8 @@ public class ToonerGUI : ShaderGUI { EditorGUI.EndChangeCheck(); bc.floatValue = enabled ? 1.0f : 0.0f; + bc = FindProperty("_Rorschach_Color"); + editor.ColorProperty(bc, "Color"); bc = FindProperty("_Rorschach_Count_X"); editor.FloatProperty(bc, "Count (x)"); bc = FindProperty("_Rorschach_Count_Y"); @@ -1456,6 +1458,10 @@ public class ToonerGUI : ShaderGUI { editor.FloatProperty(bc, "Emission strength"); bc = FindProperty("_Rorschach_Speed"); editor.FloatProperty(bc, "Speed"); + bc = FindProperty("_Rorschach_Quantization"); + editor.FloatProperty(bc, "Quantization"); + bc = FindProperty("_Rorschach_Alpha_Cutoff"); + editor.FloatProperty(bc, "Alpha cutoff"); bc = FindProperty("_Rorschach_Mask"); editor.TexturePropertySingleLine( MakeLabel(bc, "Mask"), diff --git a/globals.cginc b/globals.cginc index 7e7c8f7..c13900a 100644 --- a/globals.cginc +++ b/globals.cginc @@ -597,12 +597,15 @@ float _FaceMeWorldY_Enable_Z; #if defined(_RORSCHACH) float _Rorschach_Enable_Dynamic; +float4 _Rorschach_Color; +float _Rorschach_Alpha_Cutoff; float _Rorschach_Count_X; float _Rorschach_Count_Y; float _Rorschach_Center_Randomization; float _Rorschach_Radius; float _Rorschach_Emission_Strength; float _Rorschach_Speed; +float _Rorschach_Quantization; texture2D _Rorschach_Mask; float _Rorschach_Mask_Invert; #endif diff --git a/rorschach.cginc b/rorschach.cginc index 3c27494..d5f8ff1 100644 --- a/rorschach.cginc +++ b/rorschach.cginc @@ -69,6 +69,10 @@ RorschachPBR get_rorschach(v2f i) float3 period = float3(1 / (_Rorschach_Count_X+1), 1 / (_Rorschach_Count_Y+1), 1); float3 count = float3(_Rorschach_Count_X, _Rorschach_Count_Y, 1); float d = map_dr(ro, period, count, which); + + d *= max(_Rorschach_Count_X + 1, _Rorschach_Count_Y + 1); + + #if 0 d -= map_dr(1 - ro, period, count, which) * 4; d = 1 - d; @@ -78,6 +82,9 @@ RorschachPBR get_rorschach(v2f i) d = 1 - d; d *= 3; + #endif + + d = 1 - d; d = saturate(d); #if defined(_RORSCHACH_MASK) @@ -93,7 +100,13 @@ RorschachPBR get_rorschach(v2f i) d *= mask; #endif - result.albedo.rgb = d; + // This also quantizes alpha. It isn't exactly intended, but it looks nice. + if (_Rorschach_Quantization > 0) { + d = round(d * _Rorschach_Quantization) / _Rorschach_Quantization; + } + + float4 col = _Rorschach_Color * d; + result.albedo = lerp(0, col, d > _Rorschach_Alpha_Cutoff); return result; } diff --git a/tooner.shader b/tooner.shader index 23151e1..3f20cfb 100644 --- a/tooner.shader +++ b/tooner.shader @@ -3,7 +3,7 @@ Shader "yum_food/tooner" // Unity fucking sucks ass and sometimes incorrectly uses an old cached // version of the shader. Bump the nonce below to encourage it to use the // current version. - // Build nonce: 8 + // Build nonce: 9 Properties { _Color("Base color", Color) = (0.8, 0.8, 0.8, 1) @@ -452,12 +452,12 @@ Shader "yum_food/tooner" _Gimmick_Vertex_Normal_Slide_Distance("Vertex normal slide distance", Float) = 0.01 _Gimmick_Eyes00_Enable_Static("Enable eyes 00", Float) = 0.0 - _Gimmick_Eyes00_Effect_Mask("Effect mask", 2D) = "white" + _Gimmick_Eyes00_Effect_Mask("Effect mask", 2D) = "white" {} _Gimmick_Pixellate_Enable_Static("Enable pixellation", Float) = 0.0 _Gimmick_Pixellate_Resolution_U("Resolution (U)", Float) = 64 _Gimmick_Pixellate_Resolution_V("Resolution (V)", Float) = 64 - _Gimmick_Pixellate_Effect_Mask("Effect mask", 2D) = "white" + _Gimmick_Pixellate_Effect_Mask("Effect mask", 2D) = "white" {} _Trochoid_Enable_Static("Enable trochoid", Float) = 0.0 _Trochoid_R("R", Float) = 5.0 @@ -472,12 +472,15 @@ Shader "yum_food/tooner" _Rorschach_Enable_Static("Enable rorschach gimmick", Float) = 0.0 _Rorschach_Enable_Dynamic("Enable rorschach gimmick", Float) = 0.0 + _Rorschach_Color("Col", Color) = (1, 1, 1, 1) + _Rorschach_Alpha_Cutoff("Alpha cutoff", Float) = 0.0 _Rorschach_Count_X("Enable rorschach gimmick", Float) = 2 _Rorschach_Count_Y("Enable rorschach gimmick", Float) = 2 _Rorschach_Center_Randomization("Center randomization", Float) = 0 _Rorschach_Radius("Radius", Float) = 1 _Rorschach_Emission_Strength("Emission", Float) = 0 _Rorschach_Speed("Speed", Float) = 1 + _Rorschach_Quantization("Quantization", Float) = -1 _Rorschach_Mask("Mask", 2D) = "white" {} _Rorschach_Mask_Invert("Mask invert", Float) = 0 @@ -548,6 +551,7 @@ Shader "yum_food/tooner" #include "tooner_lighting.cginc" ENDCG } + /* Pass { Tags { "RenderType"="Opaque" @@ -627,6 +631,7 @@ Shader "yum_food/tooner" #include "mochie_shadow_caster.cginc" ENDCG } + */ } CustomEditor "ToonerGUI" } diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 5d73b47..8923122 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -1165,7 +1165,8 @@ float4 effect(inout v2f i) float4 rorschach_albedo = 0; if (_Rorschach_Enable_Dynamic) { rorschach_albedo = get_rorschach(i).albedo; - albedo = rorschach_albedo; + albedo.rgb = rorschach_albedo.rgb * rorschach_albedo.a + albedo.rgb * (1 - rorschach_albedo.a); + albedo.a = saturate(rorschach_albedo.a + albedo.a * (1 - rorschach_albedo.a)); } #endif |
