diff options
| -rw-r--r-- | Editor/tooner.cs | 332 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | globals.cginc | 3 | ||||
| -rw-r--r-- | tooner.shader | 45 | ||||
| -rw-r--r-- | tooner_lighting.cginc | 16 |
5 files changed, 253 insertions, 148 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index a5f4757..8cfbecb 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -106,12 +106,28 @@ public class ToonerGUI : ShaderGUI { SetKeyword("_ROUGHNESS_MAP", bct.textureValue); } + bool AddCollapsibleMenu(string name, string matprop) { + MaterialProperty bc = FindProperty(matprop + "_UI_Show"); + bool enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + var fs_orig = EditorStyles.label.fontStyle; + EditorStyles.label.fontStyle = FontStyle.Bold; + enabled = EditorGUILayout.Toggle(name, enabled); + EditorStyles.label.fontStyle = fs_orig; + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + + return enabled; + } + enum SamplerMode { Repeat, Clamp, }; void DoPBR() { - GUILayout.Label("PBR", EditorStyles.boldLabel); + if (!AddCollapsibleMenu("PBR", "_PBR")) { + return; + } EditorGUI.indentLevel += 1; { DoBaseColor(); @@ -133,6 +149,11 @@ public class ToonerGUI : ShaderGUI { } void DoClearcoat() { + if (!AddCollapsibleMenu($"Clearcoat", $"_Clearcoat")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; bc = FindProperty("_Clearcoat_Enabled"); bool enabled = bc.floatValue > 1E-6; @@ -177,6 +198,7 @@ public class ToonerGUI : ShaderGUI { EditorGUI.indentLevel -= 1; } } + EditorGUI.indentLevel -= 1; } enum PbrAlbedoMixMode { @@ -187,8 +209,14 @@ public class ToonerGUI : ShaderGUI { }; void DoPBROverlay() { + if (!AddCollapsibleMenu($"PBR overlays", $"_PBR_Overlay")) { + return; + } + EditorGUI.indentLevel += 1; for (int i = 0; i < 4; i++) { - GUILayout.Label($"PBR overlay {i}", EditorStyles.boldLabel); + if (!AddCollapsibleMenu($"PBR overlay {i}", $"_PBR_Overlay{i}")) { + continue; + } EditorGUI.indentLevel += 1; MaterialProperty bc = FindProperty($"_PBR_Overlay{i}_Enable"); @@ -357,11 +385,18 @@ public class ToonerGUI : ShaderGUI { } EditorGUI.indentLevel -= 1; } + EditorGUI.indentLevel -= 1; } void DoDecal() { + if (!AddCollapsibleMenu("Decals", "_Decal")) { + return; + } + EditorGUI.indentLevel += 1; for (int i = 0; i < 4; i++) { - GUILayout.Label($"Decal {i}", EditorStyles.boldLabel); + if (!AddCollapsibleMenu($"Decal {i}", $"_Decal{i}")) { + continue; + } EditorGUI.indentLevel += 1; MaterialProperty bc = FindProperty($"_Decal{i}_Enable"); @@ -418,6 +453,11 @@ public class ToonerGUI : ShaderGUI { } void DoEmission() { + if (!AddCollapsibleMenu("Emission", "_Emission")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; MaterialProperty bct; for (int i = 0; i < 2; i++) { @@ -447,6 +487,8 @@ public class ToonerGUI : ShaderGUI { bc = FindProperty("_Global_Emission_Factor"); editor.FloatProperty(bc, "Global emissions multiplier"); + + EditorGUI.indentLevel -= 1; } enum MatcapMode { @@ -460,7 +502,9 @@ public class ToonerGUI : ShaderGUI { void DoMatcap() { for (int i = 0; i < 2; i++) { - GUILayout.Label($"Matcap {i}", EditorStyles.boldLabel); + if (!AddCollapsibleMenu($"Matcap {i}", $"_Matcap{i}")) { + continue; + } EditorGUI.indentLevel += 1; MaterialProperty bc; @@ -607,7 +651,9 @@ public class ToonerGUI : ShaderGUI { void DoRimLighting() { for (int i = 0; i < 4; i++) { - GUILayout.Label($"Rim lighting {i}", EditorStyles.boldLabel); + if (!AddCollapsibleMenu($"Rim lighting {i}", $"_Rim_Lighting{i}")) { + continue; + } EditorGUI.indentLevel += 1; MaterialProperty bc; @@ -762,6 +808,25 @@ public class ToonerGUI : ShaderGUI { } } + void DoMatcapRL() { + if (!AddCollapsibleMenu("Matcaps", "_Matcaps")) { + return; + } + EditorGUI.indentLevel += 1; + + MaterialProperty bc = FindProperty($"_MatcapRL_Center_Eye_Correction"); + bool enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = EditorGUILayout.Toggle("Apply center eye correction", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + + DoMatcap(); + DoRimLighting(); + + EditorGUI.indentLevel -= 1; + } + enum NormalsMode { Flat, Spherical, @@ -770,6 +835,11 @@ public class ToonerGUI : ShaderGUI { }; void DoShadingMode() { + if (!AddCollapsibleMenu("Shading", "_Shading")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; bc = FindProperty($"_Mesh_Normals_Mode"); @@ -788,9 +858,15 @@ public class ToonerGUI : ShaderGUI { bc, "Flattening strength"); } + EditorGUI.indentLevel -= 1; } void DoOKLAB() { + if (!AddCollapsibleMenu("OKLAB", "_Hue_Shift_OKLAB")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; bc = FindProperty("_OKLAB_Enabled"); @@ -830,9 +906,15 @@ public class ToonerGUI : ShaderGUI { bc, "Hue shift"); } + EditorGUI.indentLevel -= 1; } void DoHSV() { + if (!AddCollapsibleMenu("HSV", "_Hue_Shift_HSV")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; for (int i = 0; i < 2; i++) { @@ -874,9 +956,27 @@ public class ToonerGUI : ShaderGUI { "Value shift"); } } + EditorGUI.indentLevel -= 1; + } + + void DoHueShift() { + if (!AddCollapsibleMenu("Hue shift", "_Hue_Shift")) { + return; + } + EditorGUI.indentLevel += 1; + + DoOKLAB(); + DoHSV(); + + EditorGUI.indentLevel -= 1; } void DoClones() { + if (!AddCollapsibleMenu("Clones", "_Clones")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; bc = FindProperty("_Clones_Enabled"); @@ -898,48 +998,59 @@ public class ToonerGUI : ShaderGUI { bc, "x offset"); } + EditorGUI.indentLevel -= 1; } void DoOutlines() { - MaterialProperty bc; + if (!AddCollapsibleMenu("Outlines", "_Outlines")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; - bc = FindProperty("_Outline_Width"); - editor.RangeProperty( - bc, - "Outline width"); - SetKeyword("_OUTLINES", bc.floatValue > 1E-6); + bc = FindProperty("_Outline_Width"); + editor.RangeProperty( + bc, + "Outline width"); + SetKeyword("_OUTLINES", bc.floatValue > 1E-6); - if (bc.floatValue > 1E-6) { - bc = FindProperty("_Outline_Color"); - editor.ColorProperty( - bc, - "Outline color (RGBA)"); + if (bc.floatValue > 1E-6) { + bc = FindProperty("_Outline_Color"); + editor.ColorProperty( + bc, + "Outline color (RGBA)"); - bc = FindProperty("_Outline_Emission_Strength"); - editor.RangeProperty( - bc, - "Outline emission strength"); + bc = FindProperty("_Outline_Emission_Strength"); + editor.RangeProperty( + bc, + "Outline emission strength"); - bc = FindProperty("_Outline_Mask"); - editor.TexturePropertySingleLine( - MakeLabel(bc, "Outline mask"), - bc); + bc = FindProperty("_Outline_Mask"); + editor.TexturePropertySingleLine( + MakeLabel(bc, "Outline mask"), + bc); - bc = FindProperty("_Outline_Mask_Invert"); - bool inverted = bc.floatValue > 1E-6; - EditorGUI.BeginChangeCheck(); - inverted = EditorGUILayout.Toggle("Invert mask", inverted); - EditorGUI.EndChangeCheck(); - bc.floatValue = inverted ? 1.0f : 0.0f; + bc = FindProperty("_Outline_Mask_Invert"); + bool inverted = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + inverted = EditorGUILayout.Toggle("Invert mask", inverted); + EditorGUI.EndChangeCheck(); + bc.floatValue = inverted ? 1.0f : 0.0f; - bc = FindProperty("_Outline_Width_Multiplier"); - editor.FloatProperty( - bc, - "Outline width multiplier"); - } + bc = FindProperty("_Outline_Width_Multiplier"); + editor.FloatProperty( + bc, + "Outline width multiplier"); + } + EditorGUI.indentLevel -= 1; } void DoGlitter() { + if (!AddCollapsibleMenu("Glitter", "_Glitter")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc = FindProperty("_Glitter_Enabled"); bool enabled = bc.floatValue > 1E-6; @@ -998,9 +1109,15 @@ public class ToonerGUI : ShaderGUI { bc, "UV select"); } + EditorGUI.indentLevel -= 1; } void DoExplosion() { + if (!AddCollapsibleMenu("Explosion", "_Explosion")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc = FindProperty("_Explode_Toggle"); bool enabled = bc.floatValue > 1E-6; @@ -1041,9 +1158,15 @@ public class ToonerGUI : ShaderGUI { bc.floatValue = (float) UnityEngine.Rendering.CullMode.Front; } */ + EditorGUI.indentLevel -= 1; } void DoGeoScroll() { + if (!AddCollapsibleMenu("Geometry scroll", "_Geometry_Scroll")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc = FindProperty("_Scroll_Toggle"); bool enabled = bc.floatValue > 1E-6; @@ -1079,9 +1202,15 @@ public class ToonerGUI : ShaderGUI { bc, "Scroll speed"); } + EditorGUI.indentLevel -= 1; } void DoUVScroll() { + if (!AddCollapsibleMenu("UV Scroll", "_UV_Scroll")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc = FindProperty("_UVScroll_Enabled"); bool enabled = bc.floatValue > 1E-6; @@ -1112,29 +1241,7 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bc, "Alpha"), bc); } - } - - void DoTessellation() { - MaterialProperty bc = FindProperty("_Enable_Tessellation"); - bool enabled = bc.floatValue > 1E-6; - - EditorGUI.BeginChangeCheck(); - enabled = EditorGUILayout.Toggle("Enable", enabled); - EditorGUI.EndChangeCheck(); - SetKeyword("_TESSELLATION", enabled); - bc.floatValue = enabled ? 1.0f : 0.0f; - - if (enabled) { - bc = FindProperty("_Tess_Factor"); - editor.RangeProperty( - bc, - "Tessellation factor"); - - bc = FindProperty("_Tess_Dist_Cutoff"); - editor.FloatProperty( - bc, - "Activation distance (negative=always on)"); - } + EditorGUI.indentLevel -= 1; } void DoGimmickFlatColor() @@ -1549,6 +1656,11 @@ public class ToonerGUI : ShaderGUI { } void DoGimmicks() { + if (!AddCollapsibleMenu("Gimmicks", "_Gimmicks")) { + return; + } + EditorGUI.indentLevel += 1; + DoGimmickFlatColor(); DoGimmickQuantizeLocation(); DoGimmickShearLocation(); @@ -1561,9 +1673,19 @@ public class ToonerGUI : ShaderGUI { DoGimmickFaceMeWorldY(); DoGimmickRorschach(); DoGimmickMirrorUVFlip(); + DoClones(); + DoExplosion(); + DoGeoScroll(); + + EditorGUI.indentLevel -= 1; } void DoMochieParams() { + if (!AddCollapsibleMenu("Mochie", "_Mochie")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; bc = FindProperty("_WrappingFactor"); @@ -1576,6 +1698,8 @@ public class ToonerGUI : ShaderGUI { editor.FloatProperty(bc, "Use fresnel"); bc = FindProperty("_ReflectionStrength"); editor.FloatProperty(bc, "Reflection strength"); + + EditorGUI.indentLevel -= 1; } enum RenderingMode { @@ -1592,6 +1716,11 @@ public class ToonerGUI : ShaderGUI { } void DoRendering() { + if (!AddCollapsibleMenu("Rendering", "_Rendering")) { + return; + } + EditorGUI.indentLevel += 1; + RenderingMode mode = RenderingMode.Opaque; if (target.IsKeywordEnabled("_RENDERING_CUTOUT")) { mode = RenderingMode.Cutout; @@ -1772,9 +1901,15 @@ public class ToonerGUI : ShaderGUI { } EditorGUI.indentLevel -= 1; } + EditorGUI.indentLevel -= 1; } void DoLighting() { + if (!AddCollapsibleMenu("Lighting", "_Lighting")) { + return; + } + EditorGUI.indentLevel += 1; + MaterialProperty bc; bc = FindProperty("_Min_Brightness"); editor.RangeProperty( @@ -1904,99 +2039,26 @@ public class ToonerGUI : ShaderGUI { EditorGUI.indentLevel -= 1; } #endif - } - void DoLTCGI() { + EditorGUI.indentLevel -= 1; } void DoMain() { DoPBR(); DoPBROverlay(); - - GUILayout.Label("Clearcoat", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; DoClearcoat(); - EditorGUI.indentLevel -= 1; - DoDecal(); - - GUILayout.Label("Lighting", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; - DoLighting(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Emission", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; DoEmission(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Shading", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; DoShadingMode(); - EditorGUI.indentLevel -= 1; - - DoMatcap(); - DoRimLighting(); - - GUILayout.Label("Outlines", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; + DoMatcapRL(); DoOutlines(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Glitter", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; DoGlitter(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Explosion", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; - DoExplosion(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Geometry scroll", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; - DoGeoScroll(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("UV scroll", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; DoUVScroll(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Tessellation", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; - DoTessellation(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Hue shift (OKLAB)", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; - DoOKLAB(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Hue shift (HSV)", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; - DoHSV(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Clones", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; - DoClones(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Gimmicks", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; + DoHueShift(); DoGimmicks(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Mochie", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; DoMochieParams(); - EditorGUI.indentLevel -= 1; - - GUILayout.Label("Rendering", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; + DoLighting(); DoRendering(); - EditorGUI.indentLevel -= 1; } } @@ -3,7 +3,7 @@ My toon shader for VRChat. I use this on my personal and commercial models. It's semi optimized and a little scuffed. -Features: +Features (maybe out of date): * PBR * Emissions * Outlines @@ -42,6 +42,9 @@ Disclaimers: 3. Stability is a non-goal. Keywords are likely to change in the interest of performance and simplicity. +To use it, import the git repo into your project's Assets folder then select +the shader `yum_food/Tooner`. + ### Strawman FAQ 1. Why create another toon shader? diff --git a/globals.cginc b/globals.cginc index 99db1e7..4c71a85 100644 --- a/globals.cginc +++ b/globals.cginc @@ -374,6 +374,9 @@ float _Matcap1_Overwrite_Rim_Lighting_2; float _Matcap1_Overwrite_Rim_Lighting_3; #endif + +float _MatcapRL_Center_Eye_Correction; + #if defined(_RIM_LIGHTING0) float _Rim_Lighting0_Enabled; float _Rim_Lighting0_Mode; diff --git a/tooner.shader b/tooner.shader index ba153c3..5326f20 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: 23 + // Build nonce: 24 Properties { _Color("Base color", Color) = (0.8, 0.8, 0.8, 1) @@ -239,6 +239,8 @@ Shader "yum_food/tooner" [HideInInspector] _DstBlend ("_SrcBlend", Float) = 0 [HideInInspector] _ZWrite ("_ZWrite", Float) = 1 + _MatcapRL_Center_Eye_Correction("Apply center eye correction to matcaps and rim lighting", Float) = 0 + _Matcap0("Matcap", 2D) = "black" {} _Matcap0_Mask("Matcap mask", 2D) = "white" {} _Matcap0_Mask_Invert("Invert mask", Float) = 0.0 @@ -409,10 +411,6 @@ Shader "yum_food/tooner" _LTCGI_SpecularColor("LTCGI specular color", Color) = (1, 1, 1, 1) _LTCGI_DiffuseColor("LTCGI diffuse color", Color) = (1, 1, 1, 1) - _Enable_Tessellation("Enable tessellation", Float) = 0.0 - _Tess_Factor("Tessellation factor", Range(1, 64)) = 1.0 - _Tess_Dist_Cutoff("Tessellation distance cutoff", Float) = -1.0 - _Cutout_Mode("Cutout rendering mode", Float) = 0.0 _Render_Queue_Offset("Render queue offset", Integer) = 0 @@ -517,6 +515,41 @@ Shader "yum_food/tooner" _Discard_Enable_Static("Enable discard feature (static)", Float) = 0 _Discard_Enable_Dynamic("Enable discard feature (dynamic)", Float) = 0 + + _PBR_UI_Show("UI hide", Float) = 1 + _PBR_Overlay_UI_Show("UI hide", Float) = 0 + _PBR_Overlay0_UI_Show("UI hide", Float) = 0 + _PBR_Overlay1_UI_Show("UI hide", Float) = 0 + _PBR_Overlay2_UI_Show("UI hide", Float) = 0 + _PBR_Overlay3_UI_Show("UI hide", Float) = 0 + _Clearcoat_UI_Show("UI hide", Float) = 0 + _Decal_UI_Show("UI hide", Float) = 0 + _Decal0_UI_Show("UI hide", Float) = 0 + _Decal1_UI_Show("UI hide", Float) = 0 + _Decal2_UI_Show("UI hide", Float) = 0 + _Decal3_UI_Show("UI hide", Float) = 0 + _Lighting_UI_Show("UI hide", Float) = 1 + _Emission_UI_Show("UI hide", Float) = 0 + _Shading_UI_Show("UI hide", Float) = 0 + _Matcaps_UI_Show("UI hide", Float) = 0 + _Matcap0_UI_Show("UI hide", Float) = 0 + _Matcap1_UI_Show("UI hide", Float) = 0 + _Rim_Lighting0_UI_Show("UI hide", Float) = 0 + _Rim_Lighting1_UI_Show("UI hide", Float) = 0 + _Rim_Lighting2_UI_Show("UI hide", Float) = 0 + _Rim_Lighting3_UI_Show("UI hide", Float) = 0 + _Outlines_UI_Show("UI hide", Float) = 0 + _Glitter_UI_Show("UI hide", Float) = 0 + _Gimmicks_UI_Show("UI hide", Float) = 0 + _Rendering_UI_Show("UI hide", Float) = 1 + _Explosion_UI_Show("UI hide", Float) = 0 + _Geometry_Scroll_UI_Show("UI hide", Float) = 0 + _UV_Scroll_UI_Show("UI hide", Float) = 0 + _Hue_Shift_UI_Show("UI hide", Float) = 0 + _Hue_Shift_OKLAB_UI_Show("UI hide", Float) = 0 + _Hue_Shift_HSV_UI_Show("UI hide", Float) = 0 + _Clones_UI_Show("UI hide", Float) = 0 + _Mochie_UI_Show("UI hide", Float) = 0 } SubShader { @@ -559,6 +592,7 @@ Shader "yum_food/tooner" #include "tooner_lighting.cginc" ENDCG } + /* Pass { Tags { "RenderType"="Opaque" @@ -638,6 +672,7 @@ Shader "yum_food/tooner" #include "mochie_shadow_caster.cginc" ENDCG } + */ } CustomEditor "ToonerGUI" } diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 581cae7..fad3e5e 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -30,7 +30,7 @@ void getVertexLightColor(inout v2f i) { #if defined(VERTEXLIGHT_ON) - float3 view_dir = normalize(i.centerCamPos - i.worldPos); + float3 view_dir = normalize(_WorldSPaceCameraPos.xyz - i.worldPos); uint normals_mode = round(_Mesh_Normals_Mode); bool flat = (normals_mode == 0); float3 flat_normal = normalize( @@ -1244,7 +1244,10 @@ float4 pixellate_color(int2 px_res, float2 uv, float4 c) float4 effect(inout v2f i) { - const float3 view_dir = normalize(i.centerCamPos - i.worldPos); + const float3 view_dir = normalize(_WorldSpaceCameraPos.xyz - i.worldPos); + const float3 view_dir_c = normalize(i.centerCamPos - i.worldPos); +#define MATCAP_VIEW_DIR() (_MatcapRL_Center_Eye_Correction == 1 ? view_dir_c : view_dir) + // Not necessarily normalized after interpolation. i.normal = normalize(i.normal); i.tangent.xyz = normalize(i.tangent.xyz); @@ -1410,7 +1413,7 @@ float4 effect(inout v2f i) float matcap_radius; { const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 0))); - const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(view_dir, 0))); + const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(MATCAP_VIEW_DIR(), 0))); const float3 cam_refl = -reflect(cam_view_dir, cam_normal); float m = 2.0 * sqrt( cam_refl.x * cam_refl.x + @@ -1459,7 +1462,7 @@ float4 effect(inout v2f i) ); { const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 0))); - const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(view_dir, 0))); + const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(MATCAP_VIEW_DIR(), 0))); const float3 cam_refl = -reflect(cam_view_dir, cam_normal); float m = 2.0 * sqrt( cam_refl.x * cam_refl.x + @@ -1549,7 +1552,7 @@ float4 effect(inout v2f i) ); { const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 0))); - const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(view_dir, 0))); + const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(MATCAP_VIEW_DIR(), 0))); const float3 cam_refl = -reflect(cam_view_dir, cam_normal); float m = 2.0 * sqrt( cam_refl.x * cam_refl.x + @@ -1620,8 +1623,7 @@ float4 effect(inout v2f i) #if defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) || defined(_RIM_LIGHTING2) || defined(_RIM_LIGHTING3) { - // identity: (a, b, c) and (c, c, -(a +b)) are perpendicular to each other - float theta = atan2(length(cross(view_dir, normal)), dot(view_dir, normal)); + float theta = atan2(length(cross(MATCAP_VIEW_DIR(), normal)), dot(MATCAP_VIEW_DIR(), normal)); #define PI 3.14159265 #if defined(_RIM_LIGHTING0) |
