summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Editor/tooner.cs13
-rw-r--r--cnlohr.cginc2
-rw-r--r--downstairs_02.cginc29
-rw-r--r--globals.cginc6
-rw-r--r--pbr.cginc21
-rw-r--r--tooner.shader6
-rw-r--r--tooner_lighting.cginc27
7 files changed, 73 insertions, 31 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index 4364a3c..0c06a28 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -2049,8 +2049,8 @@ public class ToonerGUI : ShaderGUI {
bc = FindProperty("_Gimmick_DS2_11_Alpha");
RangeProperty(bc, "Alpha");
- bc = FindProperty("_Gimmick_DS2_11_XZ_Offset");
- VectorProperty(bc, "XZ offset");
+ bc = FindProperty("_Gimmick_DS2_11_Offset");
+ VectorProperty(bc, "Offset");
bc = FindProperty("_Gimmick_DS2_11_Octaves");
FloatProperty(bc, "Octaves");
bc = FindProperty("_Gimmick_DS2_11_March_Initial_Offset");
@@ -2067,6 +2067,12 @@ public class ToonerGUI : ShaderGUI {
FloatProperty(bc, "Coord scale");
bc = FindProperty("_Gimmick_DS2_11_Height_Scale");
FloatProperty(bc, "Height scale");
+ bc = FindProperty("_Gimmick_DS2_11_Height_Power");
+ FloatProperty(bc, "Height power");
+ bc = FindProperty("_Gimmick_DS2_11_Valley_Power");
+ FloatProperty(bc, "Valley power");
+ bc = FindProperty("_Gimmick_DS2_11_Valley_Depth");
+ FloatProperty(bc, "Valley depth");
bc = FindProperty("_Gimmick_DS2_11_Early_Exit_Cutoff_Cos_Theta");
FloatProperty(bc, "Early exit cutoff (cos theta)");
@@ -2086,6 +2092,9 @@ public class ToonerGUI : ShaderGUI {
EditorGUI.indentLevel -= 1;
}
+ bc = FindProperty("_Gimmick_DS2_11_Normal_Epsilon");
+ FloatProperty(bc, "Normal epsilon");
+
EditorGUI.indentLevel -= 1;
}
diff --git a/cnlohr.cginc b/cnlohr.cginc
index 73fb80c..ef4aa79 100644
--- a/cnlohr.cginc
+++ b/cnlohr.cginc
@@ -43,7 +43,7 @@ bool isMirror() { return _VRChatMirrorMode != 0; }
// Source:
// https://github.com/cnlohr/shadertrixx?tab=readme-ov-file#eye-center-position
float3 getCenterCamPos() {
-#if defined(USING_STEREO_MATRICES)
+#if defined(USING_STEREO_MATRICES) || defined(UNITY_SINGLE_PASS_STEREO)
return (unity_StereoWorldSpaceCameraPos[0] + unity_StereoWorldSpaceCameraPos[1]) / 2;
#else
return isMirror() ? _VRChatMirrorCameraPos : _WorldSpaceCameraPos.xyz;
diff --git a/downstairs_02.cginc b/downstairs_02.cginc
index e940e34..a102f5f 100644
--- a/downstairs_02.cginc
+++ b/downstairs_02.cginc
@@ -659,7 +659,7 @@ float ds2_11_height(float2 p)
{
float sc = .4;
float sc_rcp = 2.5;
- float2 offset = _Gimmick_DS2_11_XZ_Offset.xz * _Gimmick_DS2_11_Simulation_Scale;
+ float2 offset = _Gimmick_DS2_11_Offset.xz * _Gimmick_DS2_11_Simulation_Scale;
float2 pp = (p - offset) * sc_rcp;
p /= _Gimmick_DS2_11_Simulation_Scale;
@@ -691,20 +691,31 @@ float ds2_11_height(float2 p)
h /= 1 / (1 - alpha);
h *= h;
- // `scale_factor` goes from [0, 1] based on radius.
+#if 0
+ // `scale_factor` goes from [0, 1] based on radius. 0 at center, 1 at infinity.
float2 center = p;
float scale_factor = 1 - exp(-dot(center, center) * 16);
h *= scale_factor;
h = ((h - (1 - scale_factor) * sc_hsc * .15) + .015) * _Gimmick_DS2_11_Simulation_Scale;
+#else
+ float2 center = p;
+ float scale_factor = exp(-dot(center, center) * _Gimmick_DS2_11_Valley_Power);
+ h -= scale_factor * sc_hsc * _Gimmick_DS2_11_Valley_Depth * _Gimmick_DS2_11_Simulation_Scale;
+ h += sc_hsc * _Gimmick_DS2_11_Offset.y * _Gimmick_DS2_11_Simulation_Scale;
+#endif
+
+ h += 1;
+ h = pow(h, _Gimmick_DS2_11_Height_Power);
+ h -= 1;
return h;
}
float3 ds2_11_calc_normal(float3 p)
{
+ float epsilon = _Gimmick_DS2_11_Normal_Epsilon * length(_WorldSpaceCameraPos - p);
#if 0
// 4-point anti aliasing in an X shape with full central differences. 16 taps.
- float epsilon = 1E-3;
float3 result = 0;
for (uint i = 0; i < 4; i++) {
float2 pp = p.xz + epsilon * (float2(i % 2, (i/2) % 2) - .5) * 2;
@@ -715,9 +726,8 @@ float3 ds2_11_calc_normal(float3 p)
);
}
return normalize(result);
-#elif 0
+#elif 1
// Full central differences. 4 taps.
- float epsilon = 1E-3;
return normalize(float3(
ds2_11_height(p.xz - float2(epsilon, 0)) - ds2_11_height(p.xz + float2(epsilon, 0)),
2 * epsilon,
@@ -725,7 +735,6 @@ float3 ds2_11_calc_normal(float3 p)
));
#elif 0
// Abridged central differences along stochastic diagonal. 6 taps.
- float epsilon = 1E-3;
float noise = _Gimmick_DS2_Noise.SampleLevel(linear_repeat_s, p.xz * 1000, 0) * TAU;
float2 axis = float2(cos(noise), sin(noise));
float2 p0 = p.xz + (epsilon * axis);
@@ -743,13 +752,12 @@ float3 ds2_11_calc_normal(float3 p)
ds2_11_height(p1 - float2(0, epsilon)) - c1
);
return normalize(n0 + n1);
-#elif 1
+#elif 0
// Full central differences rotated a random amount about the original point. 4 taps.
- float epsilon = 8E-4;
float3 pp = p * 64;
float noise = _Gimmick_DS2_Noise.SampleLevel(linear_repeat_s, pp.xz, 0) * TAU;
float2 axis = float2(cos(noise), sin(noise));
- float2 p0 = p.xz + (epsilon * axis) * 1.20710678;
+ float2 p0 = p.xz + (epsilon * axis) * 1.20710678 * 0;
float3 n0 = float3(
ds2_11_height(p0 - float2(epsilon, 0)) - ds2_11_height(p0 + float2(epsilon, 0)),
2 * epsilon,
@@ -758,7 +766,6 @@ float3 ds2_11_calc_normal(float3 p)
return normalize(n0);
#elif 1
// Abridged central differences along diagonal oriented tangent to circle centered at the origin. 6 taps.
- float epsilon = 1E-3;
float2 n2 = normalize(p.xz);
float2 ortho = float2(-n2.y, n2.x);
float2 p0 = p.xz + (epsilon * .7071 * ortho);
@@ -778,7 +785,6 @@ float3 ds2_11_calc_normal(float3 p)
return normalize(n0 + n1);
#elif 0
// Abridged central differences along diagonal oriented normal to circle centered at the origin. 6 taps.
- float epsilon = 1E-3;
float2 n2 = normalize(p.xz);
float2 p0 = p.xz + (epsilon * .5 * n2);
float2 p1 = p.xz - (epsilon * .5 * n2);
@@ -797,7 +803,6 @@ float3 ds2_11_calc_normal(float3 p)
return normalize(n0 + n1);
#else
// Abridged central differences. 3 taps.
- float epsilon = 1E-3;
float center = ds2_11_height(p.xz);
return normalize(float3(
ds2_11_height(p.xz - float2(epsilon, 0)) - center,
diff --git a/globals.cginc b/globals.cginc
index 33f0ae2..ba33105 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -836,10 +836,14 @@ float _Gimmick_DS2_11_March_Backtrack_Steps;
float _Gimmick_DS2_11_Simulation_Scale;
float _Gimmick_DS2_11_Coord_Scale;
float _Gimmick_DS2_11_Height_Scale;
-float3 _Gimmick_DS2_11_XZ_Offset;
+float _Gimmick_DS2_11_Height_Power;
+float3 _Gimmick_DS2_11_Offset;
float _Gimmick_DS2_11_Distance_Culling_Enable;
float _Gimmick_DS2_11_Activation_Y;
float _Gimmick_DS2_11_Early_Exit_Cutoff_Cos_Theta;
+float _Gimmick_DS2_11_Normal_Epsilon;
+float _Gimmick_DS2_11_Valley_Power;
+float _Gimmick_DS2_11_Valley_Depth;
#endif
#if defined(_PIXELLATE)
diff --git a/pbr.cginc b/pbr.cginc
index 3d74dc6..c9b6e28 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -112,7 +112,7 @@ float4 getIndirectDiffuse(v2f i, float4 vertexLightColor, float3 normal) {
}
float3 getIndirectSpecular(v2f i, float3 view_dir, float3 normal,
- float smoothness, float metallic, float3 worldPos, float2 uv) {
+ float smoothness, float metallic, float3 worldPos) {
float3 specular = 0;
#if defined(FORWARD_BASE_PASS)
@@ -235,8 +235,8 @@ float4 getLitColor(
direct_light.color = getDirectLightColor();
#endif
indirect_light.diffuse = getIndirectDiffuse(i, vertexLightColor, normal) + diffuse_contrib;
- indirect_light.specular = getIndirectSpecular(i, view_dir, normal, smoothness,
- metallic, worldPos, uv);
+ indirect_light.specular = getIndirectSpecular(i, view_dir, normal,
+ smoothness, metallic, worldPos);
}
if (normals_mode == 0) {
@@ -423,18 +423,19 @@ float4 getLitColor(
}
cc_mask *= cc_mask2_tmp;
#endif
- float3 cc_normal = _Clearcoat_Use_Texture_Normals ? normal : i.normal;
+ const float3 cc_normal = _Clearcoat_Use_Texture_Normals ? normal : i.normal;
// Diffuse specular
const float cc_roughness = max(1E-4, _Clearcoat_Roughness);
+ const float3 cc_indirect_specular = getIndirectSpecular(
+ i, view_dir,
+ cc_normal,
+ /*smoothness=*/1 - cc_roughness,
+ /*metallic=*/0,
+ worldPos);
{
// TODO fold this into the full BRDF and apply the brightness corrections
// described in the filament whitepaper:
// https://google.github.io/filament/Filament.html
- metallic = 0;
- smoothness = 1.0 - _Clearcoat_Roughness;
- indirect_light.specular = getIndirectSpecular(i, view_dir, cc_normal, smoothness,
- metallic, worldPos, uv);
-
const float3 l = reflect(-view_dir, cc_normal);
const float3 h = normalize(l + view_dir);
const float NoH = dot(cc_normal, h);
@@ -448,7 +449,7 @@ float4 getLitColor(
LoH,
h,
Fc);
- pbr.rgb += cc_term * indirect_light.specular * cc_mask;
+ pbr.rgb += cc_term * cc_indirect_specular * cc_mask;
}
// Direct
{
diff --git a/tooner.shader b/tooner.shader
index 4d8a422..9e9cd4a 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -872,10 +872,14 @@ Shader "yum_food/tooner"
_Gimmick_DS2_11_Simulation_Scale("Simulation scale", Float) = 1
_Gimmick_DS2_11_Coord_Scale("Coord scale", Float) = 1
_Gimmick_DS2_11_Height_Scale("Height scale", Float) = 1
- _Gimmick_DS2_11_XZ_Offset("XZ offset", Vector) = (0, 0, 0, 0)
+ _Gimmick_DS2_11_Height_Power("Height power", Float) = 1
+ _Gimmick_DS2_11_Offset("XZ offset", Vector) = (0, 0, 0, 0)
_Gimmick_DS2_11_Distance_Culling_Enable("Distance culling enable", Float) = 0
_Gimmick_DS2_11_Activation_Y("Activation Y", Float) = 0
_Gimmick_DS2_11_Early_Exit_Cutoff_Cos_Theta("Early exit cutoff (cos theta)", Float) = 0
+ _Gimmick_DS2_11_Normal_Epsilon("Normal epsilon", Float) = 0.001
+ _Gimmick_DS2_11_Valley_Power("Valley power", Float) = 8
+ _Gimmick_DS2_11_Valley_Depth("Valley scale", Float) = .15
_Gimmick_Halo00_Enable_Static("Enable halo", Float) = 0.0
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index 0a2139c..f8c3b52 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -669,6 +669,7 @@ void applyDecalImpl(
float2 d0_uv =
((get_uv_by_channel(i, p.uv_select) - 0.5) - p.tex_st.zw) * p.tex_st.xy + 0.5;
+ [branch]
if (abs(p.angle) > 1E-6) {
float theta = p.angle * 2.0 * 3.14159265;
float2x2 rot = float2x2(
@@ -679,6 +680,7 @@ void applyDecalImpl(
d0_uv = (p.tiling_mode == 0) ? saturate(d0_uv) : d0_uv;
float d0_uv_fwidth = -1;
+ [branch]
if (p.domain_warping) {
p.domain_warping_octaves = min(p.domain_warping_octaves, 10);
for (uint ii = 0; ii < p.domain_warping_octaves; ii++) {
@@ -690,6 +692,7 @@ void applyDecalImpl(
}
float4 d0_c = 0;
+ [branch]
if (p.base_color_mode == 0) {
d0_c = p.tex.SampleBias(
linear_repeat_s,
@@ -2214,11 +2217,15 @@ float4 effect(inout v2f i, out float depth)
#endif
float3 diffuse_contrib = 0;
-#if defined(_GIMMICK_FOG_01)
- if (!round(_Gimmick_Fog_01_Overlay_Mode)) {
+ // TODO restore this
+ // For some dumb fucking dipshit reason, this is incompatible with clearcoat
+ // in worlds. Probably the compiler optimizer shitting the bed.
+#if 0 && defined(_GIMMICK_FOG_01)
+ [branch]
+ if (!_Gimmick_Fog_01_Overlay_Mode) {
Fog01PBR fog_01_pbr = getFog01(i, tdata);
albedo = fog_01_pbr.albedo;
- depth = fog_01_pbr.depth;
+ //depth = fog_01_pbr.depth;
#if defined(_RENDERING_TRANSPARENT) || defined(_RENDERING_TRANSCLIPPING)
albedo.rgb *= albedo.a;
#endif
@@ -2288,7 +2295,8 @@ float4 effect(inout v2f i, out float depth)
#endif
#if defined(_GIMMICK_FOG_01)
- if (round(_Gimmick_Fog_01_Overlay_Mode)) {
+ [branch]
+ if (_Gimmick_Fog_01_Overlay_Mode) {
float4 fog_color = apply_fog(
length(i.worldPos.xyz - getCenterCamPos()),
_Gimmick_Fog_01_Density,
@@ -2359,6 +2367,17 @@ float4 effect(inout v2f i, out float depth)
return result;
}
+fixed4 frag_debug(v2f i)
+{
+ float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos);
+ float3 indirect_specular = getIndirectSpecular(i, view_dir, i.normal,
+ /*smoothness=*/1, /*metallic=*/0, i.worldPos);
+ const float3 l = reflect(-view_dir, i.normal);
+ const float3 h = normalize(l + view_dir);
+ const float NoH = dot(i.normal, h);
+ return float4(saturate(NoH) * indirect_specular, 1);
+}
+
fixed4 frag(v2f i
#if defined(EXPERIMENT__CUSTOM_DEPTH)
, out float depth: SV_DepthGreaterEqual