summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Editor/tooner.cs21
-rw-r--r--globals.cginc9
-rw-r--r--tooner.shader10
-rw-r--r--tooner_lighting.cginc81
4 files changed, 78 insertions, 43 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index fb0cc7c..d224aa1 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -605,6 +605,13 @@ public class ToonerGUI : ShaderGUI {
EditorGUI.indentLevel -= 1;
}
+ bc = FindProperty($"_Matcap{i}_Center_Eye_Fix");
+ enabled = bc.floatValue > 1E-6;
+ EditorGUI.BeginChangeCheck();
+ enabled = EditorGUILayout.Toggle("Center eye fix", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+
EditorGUI.BeginChangeCheck();
bc = FindProperty($"_Matcap{i}Mode");
MatcapMode mode = (MatcapMode) Math.Round(bc.floatValue);
@@ -734,6 +741,13 @@ public class ToonerGUI : ShaderGUI {
bc,
"UV channel");
+ bc = FindProperty($"_Rim_Lighting{i}_Center_Eye_Fix");
+ enabled = bc.floatValue > 1E-6;
+ EditorGUI.BeginChangeCheck();
+ enabled = EditorGUILayout.Toggle("Center eye fix", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+
bc = FindProperty($"_Rim_Lighting{i}_Mask_Sampler_Mode");
SamplerMode sampler_mode = (SamplerMode) Math.Round(bc.floatValue);
sampler_mode = (SamplerMode) EditorGUILayout.EnumPopup(
@@ -854,13 +868,6 @@ public class ToonerGUI : ShaderGUI {
}
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();
diff --git a/globals.cginc b/globals.cginc
index 63cf7fd..630d950 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -340,6 +340,7 @@ texture2D _Matcap0;
texture2D _Matcap0_Mask;
float _Matcap0_Mask_Invert;
float _Matcap0_Mask_UV_Select;
+float _Matcap0_Center_Eye_Fix;
texture2D _Matcap0_Mask2;
float _Matcap0_Mask2_Invert;
float _Matcap0_Mask2_UV_Select;
@@ -367,6 +368,7 @@ texture2D _Matcap1;
texture2D _Matcap1_Mask;
float _Matcap1_Mask_Invert;
float _Matcap1_Mask_UV_Select;
+float _Matcap1_Center_Eye_Fix;
texture2D _Matcap1_Mask2;
float _Matcap1_Mask2_Invert;
float _Matcap1_Mask2_UV_Select;
@@ -388,9 +390,6 @@ 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;
@@ -398,6 +397,7 @@ float3 _Rim_Lighting0_Color;
texture2D _Rim_Lighting0_Mask;
float _Rim_Lighting0_Mask_Invert;
float _Rim_Lighting0_Mask_UV_Select;
+float _Rim_Lighting0_Center_Eye_Fix;
float _Rim_Lighting0_Mask_Sampler_Mode;
float _Rim_Lighting0_Center;
float _Rim_Lighting0_Power;
@@ -426,6 +426,7 @@ float3 _Rim_Lighting1_Color;
texture2D _Rim_Lighting1_Mask;
float _Rim_Lighting1_Mask_Invert;
float _Rim_Lighting1_Mask_UV_Select;
+float _Rim_Lighting1_Center_Eye_Fix;
float _Rim_Lighting1_Mask_Sampler_Mode;
float _Rim_Lighting1_Center;
float _Rim_Lighting1_Power;
@@ -454,6 +455,7 @@ float3 _Rim_Lighting2_Color;
texture2D _Rim_Lighting2_Mask;
float _Rim_Lighting2_Mask_Invert;
float _Rim_Lighting2_Mask_UV_Select;
+float _Rim_Lighting2_Center_Eye_Fix;
float _Rim_Lighting2_Mask_Sampler_Mode;
float _Rim_Lighting2_Center;
float _Rim_Lighting2_Power;
@@ -482,6 +484,7 @@ float3 _Rim_Lighting3_Color;
texture2D _Rim_Lighting3_Mask;
float _Rim_Lighting3_Mask_Invert;
float _Rim_Lighting3_Mask_UV_Select;
+float _Rim_Lighting3_Center_Eye_Fix;
float _Rim_Lighting3_Mask_Sampler_Mode;
float _Rim_Lighting3_Center;
float _Rim_Lighting3_Power;
diff --git a/tooner.shader b/tooner.shader
index 2f1b87e..ddfc5b1 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -270,8 +270,6 @@ 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
@@ -294,6 +292,7 @@ Shader "yum_food/tooner"
_Matcap0_Overwrite_Rim_Lighting_1("Overwrite RL", Float) = 0
_Matcap0_Overwrite_Rim_Lighting_2("Overwrite RL", Float) = 0
_Matcap0_Overwrite_Rim_Lighting_3("Overwrite RL", Float) = 0
+ _Matcap0_Center_Eye_Fix("Enable center eye fix", Float) = 0
_Matcap1("Matcap", 2D) = "black" {}
_Matcap1_Mask("Matcap mask", 2D) = "white" {}
@@ -317,6 +316,7 @@ Shader "yum_food/tooner"
_Matcap1_Overwrite_Rim_Lighting_1("Overwrite RL", Float) = 0
_Matcap1_Overwrite_Rim_Lighting_2("Overwrite RL", Float) = 0
_Matcap1_Overwrite_Rim_Lighting_3("Overwrite RL", Float) = 0
+ _Matcap1_Center_Eye_Fix("Enable center eye fix", Float) = 0
_Rim_Lighting0_Enabled("Enable rim lighting", Float) = 0
_Rim_Lighting0_Mode("Rim lighting mode", Float) = 0
@@ -339,6 +339,7 @@ Shader "yum_food/tooner"
_Rim_Lighting0_PolarMask_Enabled("Rim lighting polar mask enabled", Float) = 0
_Rim_Lighting0_PolarMask_Theta("Rim lighting polar mask - theta", Float) = 0
_Rim_Lighting0_PolarMask_Power("Rim lighting polar mask - power", Float) = 3
+ _Rim_Lighting0_Center_Eye_Fix("Enable center eye fix", Float) = 0
_Rim_Lighting1_Enabled("Enable rim lighting", Float) = 0
_Rim_Lighting1_Mode("Rim lighting mode", Float) = 0
@@ -361,6 +362,7 @@ Shader "yum_food/tooner"
_Rim_Lighting1_PolarMask_Enabled("Rim lighting polar mask enabled", Float) = 0
_Rim_Lighting1_PolarMask_Theta("Rim lighting polar mask - theta", Float) = 0
_Rim_Lighting1_PolarMask_Power("Rim lighting polar mask - power", Float) = 3
+ _Rim_Lighting1_Center_Eye_Fix("Enable center eye fix", Float) = 0
_Rim_Lighting2_Enabled("Enable rim lighting", Float) = 0
_Rim_Lighting2_Mode("Rim lighting mode", Float) = 0
@@ -383,6 +385,7 @@ Shader "yum_food/tooner"
_Rim_Lighting2_PolarMask_Enabled("Rim lighting polar mask enabled", Float) = 0
_Rim_Lighting2_PolarMask_Theta("Rim lighting polar mask - theta", Float) = 0
_Rim_Lighting2_PolarMask_Power("Rim lighting polar mask - power", Float) = 3
+ _Rim_Lighting2_Center_Eye_Fix("Enable center eye fix", Float) = 0
_Rim_Lighting3_Enabled("Enable rim lighting", Float) = 0
_Rim_Lighting3_Mode("Rim lighting mode", Float) = 0
@@ -405,6 +408,7 @@ Shader "yum_food/tooner"
_Rim_Lighting3_PolarMask_Enabled("Rim lighting polar mask enabled", Float) = 0
_Rim_Lighting3_PolarMask_Theta("Rim lighting polar mask - theta", Float) = 0
_Rim_Lighting3_PolarMask_Power("Rim lighting polar mask - power", Float) = 3
+ _Rim_Lighting3_Center_Eye_Fix("Enable center eye fix", Float) = 0
_OKLAB_Enabled("Enable OKLAB", Float) = 0.0
_OKLAB_Mask("Mask", 2D) = "white" {}
@@ -640,7 +644,6 @@ Shader "yum_food/tooner"
#include "tooner_lighting.cginc"
ENDCG
}
- /*
Pass {
Tags {
"RenderType"="Opaque"
@@ -720,7 +723,6 @@ Shader "yum_food/tooner"
#include "mochie_shadow_caster.cginc"
ENDCG
}
- */
}
CustomEditor "ToonerGUI"
}
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index c91598d..08b4557 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -1267,7 +1267,7 @@ float4 effect(inout v2f i)
{
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)
+#define VIEW_DIR(center_eye_fix) (center_eye_fix == 1 ? view_dir_c : view_dir)
// Not necessarily normalized after interpolation.
i.normal = normalize(i.normal);
@@ -1449,7 +1449,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(MATCAP_VIEW_DIR(), 0)));
+ const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(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 +1459,23 @@ float4 effect(inout v2f i)
matcap_radius = length(matcap_uv - 0.5);
matcap_theta = atan2(matcap_uv.y - 0.5, matcap_uv.x - 0.5);
}
+ float2 matcap_uv_center;
+ float matcap_theta_center;
+ float matcap_radius_center;
+ {
+ 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_c, 0)));
+ const float3 cam_refl = -reflect(cam_view_dir, cam_normal);
+ float m = 2.0 * sqrt(
+ cam_refl.x * cam_refl.x +
+ cam_refl.y * cam_refl.y +
+ (cam_refl.z + 1) * (cam_refl.z + 1));
+ matcap_uv_center = cam_refl.xy / m + 0.5;
+ matcap_radius_center = length(matcap_uv_center - 0.5);
+ matcap_theta_center = atan2(matcap_uv_center.y - 0.5, matcap_uv.x - 0.5);
+ }
#endif
+
float4 matcap_overwrite_mask = 0;
#if defined(_MATCAP0) || defined(_MATCAP1)
{
@@ -1496,18 +1512,18 @@ float4 effect(inout v2f i)
raw_normal.y * binormal +
raw_normal.z * i.normal
);
- {
- const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 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 +
- cam_refl.y * cam_refl.y +
- (cam_refl.z + 1) * (cam_refl.z + 1));
- matcap_uv = cam_refl.xy / m + 0.5;
- matcap_radius = length(matcap_uv - 0.5);
- matcap_theta = atan2(matcap_uv.y - 0.5, matcap_uv.x - 0.5);
- }
+ {
+ 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(_Matcap0_Center_Eye_Fix), 0)));
+ const float3 cam_refl = -reflect(cam_view_dir, cam_normal);
+ float m = 2.0 * sqrt(
+ cam_refl.x * cam_refl.x +
+ cam_refl.y * cam_refl.y +
+ (cam_refl.z + 1) * (cam_refl.z + 1));
+ matcap_uv = cam_refl.xy / m + 0.5;
+ matcap_radius = length(matcap_uv - 0.5);
+ matcap_theta = atan2(matcap_uv.y - 0.5, matcap_uv.x - 0.5);
+ }
#endif
#if defined(_MATCAP0_DISTORTION0)
@@ -1518,7 +1534,7 @@ float4 effect(inout v2f i)
float q = _Matcap0Quantization;
if (q > 0) {
- matcap = ceil(matcap * q) / q;
+ matcap = floor(matcap * q) / q;
}
int mode = round(_Matcap0Mode);
@@ -1586,18 +1602,18 @@ float4 effect(inout v2f i)
raw_normal.y * binormal +
raw_normal.z * i.normal
);
- {
- const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 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 +
- cam_refl.y * cam_refl.y +
- (cam_refl.z + 1) * (cam_refl.z + 1));
- matcap_uv = cam_refl.xy / m + 0.5;
- matcap_radius = length(matcap_uv - 0.5);
- matcap_theta = atan2(matcap_uv.y - 0.5, matcap_uv.x - 0.5);
- }
+ {
+ 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(_Matcap1_Center_Eye_Fix), 0)));
+ const float3 cam_refl = -reflect(cam_view_dir, cam_normal);
+ float m = 2.0 * sqrt(
+ cam_refl.x * cam_refl.x +
+ cam_refl.y * cam_refl.y +
+ (cam_refl.z + 1) * (cam_refl.z + 1));
+ matcap_uv = cam_refl.xy / m + 0.5;
+ matcap_radius = length(matcap_uv - 0.5);
+ matcap_theta = atan2(matcap_uv.y - 0.5, matcap_uv.x - 0.5);
+ }
#endif
#if defined(_MATCAP1_DISTORTION0)
float2 distort_uv = matcap_distortion0(matcap_uv);
@@ -1607,7 +1623,7 @@ float4 effect(inout v2f i)
float q = _Matcap1Quantization;
if (q > 0) {
- matcap = ceil(matcap * q) / q;
+ matcap = floor(matcap * q) / q;
}
matcap_mask *= _Matcap1MixFactor;
@@ -1659,11 +1675,12 @@ float4 effect(inout v2f i)
#if defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) || defined(_RIM_LIGHTING2) || defined(_RIM_LIGHTING3)
{
- float theta = atan2(length(cross(MATCAP_VIEW_DIR(), normal)), dot(MATCAP_VIEW_DIR(), normal));
#define PI 3.14159265
#if defined(_RIM_LIGHTING0)
{
+ float rl_view_dir = VIEW_DIR(_Rim_Lighting0_Center_Eye_Fix);
+ float theta = atan2(length(cross(rl_view_dir, normal)), dot(rl_view_dir, normal));
float rl = abs(theta) / PI; // on [0, 1]
rl = pow(2, -_Rim_Lighting0_Power * abs(rl - _Rim_Lighting0_Center));
float q = _Rim_Lighting0_Quantization;
@@ -1741,6 +1758,8 @@ float4 effect(inout v2f i)
#endif // _RIM_LIGHTING0
#if defined(_RIM_LIGHTING1)
{
+ float rl_view_dir = VIEW_DIR(_Rim_Lighting1_Center_Eye_Fix);
+ float theta = atan2(length(cross(rl_view_dir, normal)), dot(rl_view_dir, normal));
float rl = abs(theta) / PI; // on [0, 1]
rl = pow(2, -_Rim_Lighting1_Power * abs(rl - _Rim_Lighting1_Center));
float q = _Rim_Lighting1_Quantization;
@@ -1821,6 +1840,8 @@ float4 effect(inout v2f i)
#endif // _RIM_LIGHTING1
#if defined(_RIM_LIGHTING2)
{
+ float rl_view_dir = VIEW_DIR(_Rim_Lighting2_Center_Eye_Fix);
+ float theta = atan2(length(cross(rl_view_dir, normal)), dot(rl_view_dir, normal));
float rl = abs(theta) / PI; // on [0, 1]
rl = pow(2, -_Rim_Lighting2_Power * abs(rl - _Rim_Lighting2_Center));
float q = _Rim_Lighting2_Quantization;
@@ -1901,6 +1922,8 @@ float4 effect(inout v2f i)
#endif // _RIM_LIGHTING2
#if defined(_RIM_LIGHTING3)
{
+ float rl_view_dir = VIEW_DIR(_Rim_Lighting3_Center_Eye_Fix);
+ float theta = atan2(length(cross(rl_view_dir, normal)), dot(rl_view_dir, normal));
float rl = abs(theta) / PI; // on [0, 1]
rl = pow(2, -_Rim_Lighting3_Power * abs(rl - _Rim_Lighting3_Center));
float q = _Rim_Lighting3_Quantization;