summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-07-13 01:49:03 -0700
committeryum <yum.food.vr@gmail.com>2024-07-13 01:49:21 -0700
commitbf4457b96cd46ed2d3d61bde2eb4d58d3114730b (patch)
tree00c2e9c18f15dc2decd54666e96254e9176102dd
parentd0032ecf7d258ac52ef572e26f64e18190bf9215 (diff)
Integrate metallic eye shader
-rw-r--r--Editor/tooner.cs59
-rw-r--r--eyes.cginc104
-rw-r--r--feature_macros.cginc2
-rw-r--r--globals.cginc11
-rw-r--r--pbr.cginc6
-rw-r--r--tooner.shader9
-rw-r--r--tooner_lighting.cginc25
-rw-r--r--tooner_outline_pass.cginc11
8 files changed, 223 insertions, 4 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index 9dc90c6..23a93ef 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -475,7 +475,8 @@ public class ToonerGUI : ShaderGUI {
enum NormalsMode {
Flat,
- Spherical
+ Spherical,
+ Realistic
};
void DoShadingMode() {
@@ -889,9 +890,65 @@ public class ToonerGUI : ShaderGUI {
EditorGUI.indentLevel -= 1;
}
+ void DoGimmickShearLocation() {
+ MaterialProperty bc;
+ bc = FindProperty("_Gimmick_Shear_Location_Enable_Static");
+ bool enabled = (bc.floatValue != 0.0);
+ EditorGUI.BeginChangeCheck();
+ enabled = EditorGUILayout.Toggle("Shear location", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+ SetKeyword("_GIMMICK_SHEAR_LOCATION", enabled);
+
+ if (!enabled) {
+ return;
+ }
+
+ EditorGUI.indentLevel += 1;
+
+ bc = FindProperty("_Gimmick_Shear_Location_Enable_Dynamic");
+ enabled = (bc.floatValue != 0.0);
+ EditorGUI.BeginChangeCheck();
+ enabled = EditorGUILayout.Toggle("Enable (runtime switch)", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+
+ bc = FindProperty("_Gimmick_Shear_Location_Strength");
+ editor.VectorProperty(bc, "Strength");
+
+ EditorGUI.indentLevel -= 1;
+ }
+
+ void DoGimmickEyes00() {
+ MaterialProperty bc;
+ bc = FindProperty("_Gimmick_Eyes00_Enable_Static");
+ bool enabled = (bc.floatValue != 0.0);
+ EditorGUI.BeginChangeCheck();
+ enabled = EditorGUILayout.Toggle("Eyes 00", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+ SetKeyword("_GIMMICK_EYES_00", enabled);
+
+ if (!enabled) {
+ return;
+ }
+
+ EditorGUI.indentLevel += 1;
+
+ bc = FindProperty("_Gimmick_Eyes00_Effect_Mask");
+ editor.TexturePropertySingleLine(
+ MakeLabel(bc, "Effect mask"),
+ bc);
+
+ EditorGUI.indentLevel -= 1;
+ }
+
+
void DoGimmicks() {
DoGimmickFlatColor();
DoGimmickQuantizeLocation();
+ DoGimmickShearLocation();
+ DoGimmickEyes00();
}
enum RenderingMode {
diff --git a/eyes.cginc b/eyes.cginc
new file mode 100644
index 0000000..c5fbc1b
--- /dev/null
+++ b/eyes.cginc
@@ -0,0 +1,104 @@
+#ifndef __EYES_INC
+#define __EYES_INC
+
+#if defined(_GIMMICK_EYES_00)
+
+float eyes00_distance_from_sphere(float3 p, float3 c, float r)
+{
+ return length(p - c) - r;
+}
+
+float eyes00_map(float3 p)
+{
+ float t = _Time.y;
+ float theta = sin(_Time[0]) / 2;
+ float2x2 rot = float2x2(
+ cos(theta), -sin(theta),
+ sin(theta), cos(theta));
+
+ float dist = 1000 * 1000 * 1000;
+ #define Y_STEPS 5
+ for (int y = 0; y < Y_STEPS; y++)
+ {
+ const int yy = y - Y_STEPS/2;
+ #define X_STEPS 5
+ for (int x = 0; x < X_STEPS; x++)
+ {
+ const int xx = x - X_STEPS/2;
+ float2 pp = float2(xx * 2, yy * 2);
+ pp = mul(rot, pp);
+ float radius = cos((x + y + _Time[0]) * 3.14159) * 0.5 + 1;
+ float sphere = eyes00_distance_from_sphere(p, float3(pp.x, pp.y, 0.0), radius);
+ dist = min(dist, sphere);
+ dist += sin(5.0 * pp.x) * sin(5.0 * pp.y) * 0.5;
+ }
+ }
+
+ return dist;
+}
+
+float3 eyes00_calc_normal(in float3 p)
+{
+ const float3 small_step = float3(0.0001, 0.0, 0.0);
+
+ float gradient_x = eyes00_map(p + small_step.xyy) - eyes00_map(p - small_step.xyy);
+ float gradient_y = eyes00_map(p + small_step.yxy) - eyes00_map(p - small_step.yxy);
+ float gradient_z = eyes00_map(p + small_step.yyx) - eyes00_map(p - small_step.yyx);
+
+ float3 normal = float3(gradient_x, gradient_y, gradient_z);
+
+ return normalize(normal);
+}
+
+float3 __eyes00_march(float3 ro, float3 rd, inout float3 normal)
+{
+ float total_distance_traveled = 0.0;
+ const float MINIMUM_HIT_DISTANCE = 0.001;
+ const float MAXIMUM_TRACE_DISTANCE = 1000.0;
+
+ #define EYES00_MARCH_STEPS 10
+ float distance_to_closest;
+ float3 current_position;
+ for (int i = 0; i < EYES00_MARCH_STEPS; i++)
+ {
+ current_position = ro + total_distance_traveled * rd;
+
+ distance_to_closest = eyes00_map(current_position);
+
+ if (distance_to_closest < MINIMUM_HIT_DISTANCE)
+ {
+ break;
+ }
+
+ if (total_distance_traveled > MAXIMUM_TRACE_DISTANCE)
+ {
+ break;
+ }
+ total_distance_traveled += distance_to_closest;
+ }
+
+ if (distance_to_closest < MINIMUM_HIT_DISTANCE) {
+ normal = eyes00_calc_normal(current_position);
+ return float3(1.0, 1.0, 1.0);
+ }
+
+ return float3(0, 0, 0);
+}
+
+float4 eyes00_march(float2 uv, inout float3 normal)
+{
+ uv = uv * 2.0 - 1.0;
+
+ float3 camera_position = float3(0.0, 0.0, -5.0);
+ float3 ro = camera_position;
+ float3 rd = float3(uv.x, uv.y, 1.0);
+
+ float3 shaded_color = __eyes00_march(ro, rd, normal);
+
+ return float4(shaded_color, 1.0);
+}
+
+#endif // _EYES
+
+#endif // __EYES_INC
+
diff --git a/feature_macros.cginc b/feature_macros.cginc
index 9e95569..66f626f 100644
--- a/feature_macros.cginc
+++ b/feature_macros.cginc
@@ -87,6 +87,8 @@
#pragma shader_feature_local _ _GIMMICK_FLAT_COLOR
#pragma shader_feature_local _ _GIMMICK_QUANTIZE_LOCATION
#pragma shader_feature_local _ _GIMMICK_QUANTIZE_LOCATION_AUDIOLINK
+#pragma shader_feature_local _ _GIMMICK_SHEAR_LOCATION
+#pragma shader_feature_local _ _GIMMICK_EYES_00
#endif // __FEATURE_MACROS_INC
diff --git a/globals.cginc b/globals.cginc
index ed6b209..6f7b434 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -311,5 +311,16 @@ float _Gimmick_Quantize_Location_Audiolink_Strength;
#endif
#endif
+#if defined(_GIMMICK_SHEAR_LOCATION)
+float _Gimmick_Shear_Location_Enable_Static;
+float _Gimmick_Shear_Location_Enable_Dynamic;
+float4 _Gimmick_Shear_Location_Strength;
+#endif
+
+#if defined(_GIMMICK_EYES_00)
+float _Gimmick_Eyes00_Enable_Static;
+texture2D _Gimmick_Eyes00_Effect_Mask;
+#endif
+
#endif
diff --git a/pbr.cginc b/pbr.cginc
index b6375cc..ca3fdb5 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -186,18 +186,18 @@ float4 getLitColor(
float3 view_dir = normalize(_WorldSpaceCameraPos - worldPos);
uint normals_mode = round(_Mesh_Normals_Mode);
- bool flat = (normals_mode == 0);
float3 flat_normal = normalize(
(1.0 / _Flatten_Mesh_Normals_Str) * normal +
_Flatten_Mesh_Normals_Str * view_dir);
float3 spherical_normal = normalize(UnityObjectToWorldNormal(normalize(i.objPos)));
- normal = lerp(spherical_normal, flat_normal, flat);
+ normal = lerp(normal, flat_normal, normals_mode == 0);
+ normal = lerp(normal, spherical_normal, normals_mode == 1);
UnityIndirect indirect_light = CreateIndirectLight(vertexLightColor,
view_dir, normal, smoothness, worldPos, ao, uv);
UnityLight direct_light = CreateDirectLight(normal, ao, i);
- if (flat) {
+ if (normals_mode == 0 || normals_mode == 2) {
float e = 0.8;
indirect_light.diffuse += direct_light.color * e;
direct_light.color *= (1 - e);
diff --git a/tooner.shader b/tooner.shader
index 011f616..61304e1 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -247,9 +247,16 @@ Shader "yum_food/tooner"
_Gimmick_Quantize_Location_Audiolink_Enable_Dynamic("Audiolink dynamic", Float) = 0.0
_Gimmick_Quantize_Location_Audiolink_Strength("Strength", Float) = 1.0
+ _Gimmick_Shear_Location_Enable_Static("Enable shear location gimmick", Float) = 0.0
+ _Gimmick_Shear_Location_Enable_Dynamic("Enable shear location gimmick", Float) = 0.0
+ _Gimmick_Shear_Location_Strength("Strength", Vector) = (1, 1, 1, 1)
+
_Gimmick_Vertex_Normal_Slide_Enable_Static("Enable vertex normal slide", Float) = 0.0
_Gimmick_Vertex_Normal_Slide_Enable_Dynamic("Enable vertex normal slide", Float) = 0.0
_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"
}
SubShader
{
@@ -293,6 +300,7 @@ Shader "yum_food/tooner"
#include "tooner_lighting.cginc"
ENDCG
}
+ /*
Pass {
Tags {
"RenderType" = "Opaque"
@@ -357,6 +365,7 @@ Shader "yum_food/tooner"
#include "mochie_shadow_caster.cginc"
ENDCG
}
+ */
}
CustomEditor "ToonerGUI"
}
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index 3c033bc..8eae8ef 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -3,6 +3,7 @@
#include "audiolink.cginc"
#include "clones.cginc"
+#include "eyes.cginc"
#include "globals.cginc"
#include "interpolators.cginc"
#include "iq_sdf.cginc"
@@ -89,6 +90,17 @@ v2f vert(appdata v)
}
#endif
+#if defined(_GIMMICK_SHEAR_LOCATION)
+ if (_Gimmick_Shear_Location_Enable_Dynamic) {
+ v.vertex = mul(float4x4(
+ _Gimmick_Shear_Location_Strength.x, 0, 0, 0,
+ 0, _Gimmick_Shear_Location_Strength.y, 0, 0,
+ 0, 0, _Gimmick_Shear_Location_Strength.z, 0,
+ 0, 0, 0, _Gimmick_Shear_Location_Strength.w),
+ v.vertex);
+ }
+#endif
+
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.objPos = v.vertex;
@@ -760,6 +772,19 @@ float4 effect(inout v2f i)
float4 vertex_light_color = 0;
#endif
+#if defined(_GIMMICK_EYES_00)
+ {
+ float3 eyes00_normal = 0;
+ float3 eyes00_albedo = eyes00_march(i.uv, eyes00_normal).rgb;
+ bool is_ray_hit = (eyes00_albedo.r > 0 || eyes00_albedo.g > 0 || eyes00_albedo.b > 0);
+ if (is_ray_hit) {
+ float mask = _Gimmick_Eyes00_Effect_Mask.SampleGrad(linear_repeat_s, i.uv, iddx, iddy);
+ albedo.rgb = lerp(eyes00_albedo * 1.5, albedo.rgb * 20.0, mask);
+ normal = eyes00_normal;
+ }
+ }
+#endif
+
mixOverlayAlbedo(albedo.rgb, ov);
#if defined(_DECAL0) || defined(_DECAL1) || defined(_DECAL2) || defined(_DECAL3)
float decal_emission = 0;
diff --git a/tooner_outline_pass.cginc b/tooner_outline_pass.cginc
index 9050811..c7b6ded 100644
--- a/tooner_outline_pass.cginc
+++ b/tooner_outline_pass.cginc
@@ -25,6 +25,17 @@ struct tess_factors {
v2f vert(appdata v)
{
+#if defined(_GIMMICK_SHEAR_LOCATION)
+ if (_Gimmick_Shear_Location_Enable_Dynamic) {
+ v.vertex = mul(float4x4(
+ _Gimmick_Shear_Location_Strength.x, 0, 0, 0,
+ 0, _Gimmick_Shear_Location_Strength.y, 0, 0,
+ 0, 0, _Gimmick_Shear_Location_Strength.z, 0,
+ 0, 0, 0, _Gimmick_Shear_Location_Strength.w),
+ v.vertex);
+ }
+#endif
+
float4 objPos = v.vertex;
float4 clipPos = UnityObjectToClipPos(v.vertex);
float3 clipNormal = mul((float3x3) UNITY_MATRIX_MVP, v.normal);