From 54cf2749759045b646282c5e28139510d3e7783e Mon Sep 17 00:00:00 2001 From: yum Date: Fri, 4 Oct 2024 16:38:29 -0700 Subject: Add audiolink chroma gimmick Enable displaying chroma as a solid color on the base/forward pass and/or the outline pass. Also: * add optional mask for mochie reflection strength * update README with dev instructions --- Editor/tooner.cs | 73 ++++++++++++++++++++++++++++++++++++++++++++++- MochieStandardBRDF.cginc | 4 +-- README.md | 4 ++- feature_macros.cginc | 3 ++ globals.cginc | 14 +++++++++ oklab.cginc | 2 +- pbr.cginc | 7 ++++- tooner.shader | 10 +++++++ tooner_lighting.cginc | 12 ++++++++ tooner_outline_pass.cginc | 19 ++++++++++-- 10 files changed, 139 insertions(+), 9 deletions(-) diff --git a/Editor/tooner.cs b/Editor/tooner.cs index 8cc1f62..d2588b2 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -1933,6 +1933,72 @@ public class ToonerGUI : ShaderGUI { EditorGUI.indentLevel -= 1; } + EditorGUI.indentLevel -= 1; + } + + void DoGimmickAudiolinkChroma00() { + MaterialProperty bc; + bc = FindProperty("_Gimmick_AL_Chroma_00_Enable_Static"); + bool enabled = (bc.floatValue != 0.0); + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Audiolink chroma 00", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + SetKeyword("_GIMMICK_AL_CHROMA_00", enabled); + + if (!enabled) { + return; + } + + EditorGUI.indentLevel += 1; + + bc = FindProperty("_Gimmick_AL_Chroma_00_Forward_Pass"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Forward pass", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + + if (enabled) { + bc = FindProperty("_Gimmick_AL_Chroma_00_Forward_Blend"); + RangeProperty(bc, "Blend factor"); + } + + bc = FindProperty("_Gimmick_AL_Chroma_00_Outline_Pass"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Outline pass", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + + if (enabled) { + EditorGUI.indentLevel += 1; + + bc = FindProperty("_Gimmick_AL_Chroma_00_Outline_Blend"); + RangeProperty(bc, "Blend factor"); + + bc = FindProperty("_Gimmick_AL_Chroma_00_Outline_Emission"); + RangeProperty(bc, "Emission strength"); + EditorGUI.indentLevel -= 1; + } + + bc = FindProperty("_Gimmick_AL_Chroma_00_Hue_Shift_Enable_Static"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Hue shift", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + SetKeyword("_GIMMICK_AL_CHROMA_00_HUE_SHIFT", enabled); + + if (enabled) { + EditorGUI.indentLevel += 1; + + bc = FindProperty("_Gimmick_AL_Chroma_00_Hue_Shift_Theta"); + RangeProperty(bc, "Theta"); + + EditorGUI.indentLevel -= 1; + } + EditorGUI.indentLevel -= 1; } @@ -1954,6 +2020,7 @@ public class ToonerGUI : ShaderGUI { DoGimmickRorschach(); DoGimmickMirrorUVFlip(); DoGimmickLetterGrid(); + DoGimmickAudiolinkChroma00(); DoClones(); DoExplosion(); DoGeoScroll(); @@ -1982,8 +2049,12 @@ public class ToonerGUI : ShaderGUI { EditorGUI.EndChangeCheck(); bc.floatValue = enabled ? 1.0f : 0.0f; + MaterialProperty bct = FindProperty("_ReflectionStrengthTex"); bc = FindProperty("_ReflectionStrength"); - RangeProperty(bc, "Reflection strength"); + TexturePropertySingleLine( + MakeLabel(bct, "Ambient occlusion"), + bct, bc); + SetKeyword("_REFLECTION_STRENGTH_TEX", bct.textureValue); EditorGUI.indentLevel -= 1; show_ui.RemoveAt(show_ui.Count - 1); diff --git a/MochieStandardBRDF.cginc b/MochieStandardBRDF.cginc index 2dd5c94..1bf85c6 100644 --- a/MochieStandardBRDF.cginc +++ b/MochieStandardBRDF.cginc @@ -86,7 +86,7 @@ half4 BRDF1_Mochie_PBS ( half3 diffColor, half3 specColor, half oneMinusReflectivity, half smoothness, half3 normal, half3 viewDir, half3 worldPos, half2 screenUVs, half4 screenPos, half metallic, half thickness, half3 ssColor, half atten, float2 lightmapUV, float3 vertexColor, - UnityLight light, UnityIndirect gi) + UnityLight light, UnityIndirect gi, float reflection_strength) { half perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness); @@ -138,7 +138,7 @@ half4 BRDF1_Mochie_PBS ( diffCol = diffColor * (gi.diffuse + light.color * lerp(diffuseTerm, wrappedDiffuse, thickness)); half3 specCol = specularTerm * light.color * FresnelTerm (specColor, lh) * _SpecularStrength; - half3 reflCol = surfaceReduction * gi.specular * FresnelLerp (specColor, grazingTerm, lerp(1, nv, _FresnelStrength*_UseFresnel)) * _ReflectionStrength; + half3 reflCol = surfaceReduction * gi.specular * FresnelLerp (specColor, grazingTerm, lerp(1, nv, _FresnelStrength*_UseFresnel)) * reflection_strength; #if SSR_ENABLED half4 ssrCol = GetSSR(worldPos, viewDir, reflect(-viewDir, normal), normal, smoothness, diffColor, metallic, screenUVs, screenPos); ssrCol.rgb *= _SSRStrength; diff --git a/README.md b/README.md index 30c371c..9ff8d0f 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,9 @@ Disclaimers: conjunction with one of my commercially available products. To use it, import the git repo into your project's Assets folder then select -the shader `yum_food/Tooner`. +the shader `yum_food/tooner_inlined`. To generate a new inlined shader from +sources, select `Tools/yum_food/Shader Inliner` and point it at your +Tooner.shader. ### Strawman FAQ diff --git a/feature_macros.cginc b/feature_macros.cginc index f53e904..daa9b4a 100644 --- a/feature_macros.cginc +++ b/feature_macros.cginc @@ -159,6 +159,9 @@ #pragma shader_feature_local _ _GIMMICK_LETTER_GRID #pragma shader_feature_local _ _GIMMICK_LETTER_GRID_COLOR_WAVE #pragma shader_feature_local _ _GIMMICK_LETTER_GRID_RIM_LIGHTING +#pragma shader_feature_local _ _REFLECTION_STRENGTH_TEX +#pragma shader_feature_local _ _GIMMICK_AL_CHROMA_00 +#pragma shader_feature_local _ _GIMMICK_AL_CHROMA_00_HUE_SHIFT #endif // __FEATURE_MACROS_INC diff --git a/globals.cginc b/globals.cginc index fd7c029..1601ad2 100644 --- a/globals.cginc +++ b/globals.cginc @@ -44,6 +44,9 @@ float _SpecularStrength; float _FresnelStrength; float _UseFresnel; float _ReflectionStrength; +#if defined(_REFLECTION_STRENGTH_TEX) +texture2D _ReflectionStrengthTex; +#endif float3 shadowedReflections; int _ReflShadows; float _ReflShadowStrength; @@ -686,5 +689,16 @@ float _Gimmick_Letter_Grid_Rim_Lighting_Mask_UV_Select; float _Gimmick_Letter_Grid_Rim_Lighting_Mask_Invert; #endif +#if defined(_GIMMICK_AL_CHROMA_00) +float _Gimmick_AL_Chroma_00_Forward_Pass; +float _Gimmick_AL_Chroma_00_Forward_Blend; +float _Gimmick_AL_Chroma_00_Outline_Pass; +float _Gimmick_AL_Chroma_00_Outline_Blend; +float _Gimmick_AL_Chroma_00_Outline_Emission; +#if defined(_GIMMICK_AL_CHROMA_00_HUE_SHIFT) +float _Gimmick_AL_Chroma_00_Hue_Shift_Theta; +#endif +#endif + #endif diff --git a/oklab.cginc b/oklab.cginc index 1b453af..f35d634 100644 --- a/oklab.cginc +++ b/oklab.cginc @@ -29,7 +29,7 @@ #ifndef __OKLAB_INC #define __OKLAB_INC -#if defined(_OKLAB) || defined(_GIMMICK_LETTER_GRID_COLOR_WAVE) +#if defined(_OKLAB) || defined(_GIMMICK_LETTER_GRID_COLOR_WAVE) || defined(_GIMMICK_AL_CHROMA_00_HUE_SHIFT) // Utilities relating to the OKLAB color space, as defined here: // https://bottosson.github.io/posts/oklab/ diff --git a/pbr.cginc b/pbr.cginc index 44c0db6..9955d0d 100644 --- a/pbr.cginc +++ b/pbr.cginc @@ -337,6 +337,10 @@ float4 getLitColor( float2 screenUVs = 0; float4 screenPos = 0; #if 1 + float reflection_strength = _ReflectionStrength; +#if defined(_REFLECTION_STRENGTH_TEX) + reflection_strength *= _ReflectionStrengthTex.SampleLevel(linear_repeat_s, i.uv0, 0); +#endif float4 pbr = BRDF1_Mochie_PBS( albedo, specular_tint, @@ -354,7 +358,8 @@ float4 getLitColor( i.uv2, vertexLightColor, direct_light, - indirect_light); + indirect_light, + reflection_strength); #else float3 pbr = UNITY_BRDF_PBS( albedo, diff --git a/tooner.shader b/tooner.shader index eb42cdf..e6bb8ad 100644 --- a/tooner.shader +++ b/tooner.shader @@ -518,6 +518,15 @@ Shader "yum_food/tooner" _Gimmick_Pixellate_Resolution_V("Resolution (V)", Float) = 64 _Gimmick_Pixellate_Effect_Mask("Effect mask", 2D) = "white" {} + _Gimmick_AL_Chroma_00_Enable_Static("Enable AL chroma effect 00", Float) = 0.0 + _Gimmick_AL_Chroma_00_Forward_Pass("Enable in forward pass", Float) = 0.0 + _Gimmick_AL_Chroma_00_Forward_Blend("Forward pass blend", Range(0, 1)) = 1.0 + _Gimmick_AL_Chroma_00_Outline_Pass("Enable in outline pass", Float) = 1.0 + _Gimmick_AL_Chroma_00_Outline_Emission("Outline emission", Range(0, 1)) = 0 + _Gimmick_AL_Chroma_00_Outline_Blend("Outline pass blend", Range(0 ,1)) = 1.0 + _Gimmick_AL_Chroma_00_Hue_Shift_Enable_Static("Enable hue shift", Float) = 0.0 + _Gimmick_AL_Chroma_00_Hue_Shift_Theta("Hue shift", Range(0, 1)) = 0.0 + _Trochoid_Enable_Static("Enable trochoid", Float) = 0.0 _Trochoid_R("R", Float) = 5.0 _Trochoid_r("r", Float) = 3.0 @@ -565,6 +574,7 @@ Shader "yum_food/tooner" _FresnelStrength("_FresnelStrength", Range(0,1)) = 1 _UseFresnel("_UseFresnel", Float) = 1 _ReflectionStrength("_ReflectionStrength", Range(0,1)) = 1 + _ReflectionStrengthTex("Reflection strength", 2D) = "white" {} shadowedReflections("shadowedReflections", Vector) = (0, 0, 0, 0) _ReflShadows("_ReflShadows", Vector) = (0, 0, 0, 0) _ReflShadowStrength("_ReflShadowStrength", Vector) = (0, 0, 0, 0) diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 23804a4..d503d8f 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -1668,6 +1668,18 @@ float4 effect(inout v2f i) applyDecal(albedo, roughness, metallic, decal_emission, i); #endif +#if defined(_GIMMICK_AL_CHROMA_00) + if (_Gimmick_AL_Chroma_00_Forward_Pass && AudioLinkIsAvailable()) { + float3 c = AudioLinkData(ALPASS_CCSTRIP + uint2(0, 0)).rgb; +#if defined(_GIMMICK_AL_CHROMA_00_HUE_SHIFT) + c = LRGBtoOKLCH(c); + c[2] += _Gimmick_AL_Chroma_00_Hue_Shift_Theta * 2.0 * 3.14159265; + c = OKLCHtoLRGB(c); +#endif + albedo.rgb = lerp(albedo.rgb, c, _Gimmick_AL_Chroma_00_Forward_Blend); + } +#endif + #if defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) || defined(_RIM_LIGHTING2) || defined(_RIM_LIGHTING3) { #define PI 3.14159265 diff --git a/tooner_outline_pass.cginc b/tooner_outline_pass.cginc index 9444c84..15a266e 100644 --- a/tooner_outline_pass.cginc +++ b/tooner_outline_pass.cginc @@ -275,10 +275,20 @@ fixed4 frag (v2f i) : SV_Target clip(albedo.a - _Alpha_Cutoff); #endif - // TODO FIXME the normals are fucked in pbr pass, causing flickering - //return _Outline_Color; - albedo = _Outline_Color; + +#if defined(_GIMMICK_AL_CHROMA_00) + if (_Gimmick_AL_Chroma_00_Outline_Pass && AudioLinkIsAvailable()) { + float3 c = AudioLinkData(ALPASS_CCSTRIP + uint2(0, 0)).rgb; +#if defined(_GIMMICK_AL_CHROMA_00_HUE_SHIFT) + c = LRGBtoOKLCH(c); + c[2] += _Gimmick_AL_Chroma_00_Hue_Shift_Theta * 2.0 * 3.14159265; + c = OKLCHtoLRGB(c); +#endif + albedo.rgb = lerp(albedo.rgb, c, _Gimmick_AL_Chroma_00_Outline_Blend); + } +#endif + #if defined(_OKLAB) // Do hue shift in perceptually uniform color space so it doesn't look like // shit. @@ -306,6 +316,9 @@ fixed4 frag (v2f i) : SV_Target i.uv0, ao, /*enable_direct=*/false, i); result += albedo * _Outline_Emission_Strength; +#if defined(_GIMMICK_AL_CHROMA_00) + result += albedo * _Gimmick_AL_Chroma_00_Outline_Emission; +#endif #if defined(_EXPLODE) && defined(_AUDIOLINK) if (AudioLinkIsAvailable() && _Explode_Phase > 1E-6) { -- cgit v1.2.3