summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Editor/tooner.cs133
-rw-r--r--audiolink.cginc2
-rw-r--r--downstairs_02.cginc150
-rw-r--r--feature_macros.cginc1
-rw-r--r--fog.cginc83
-rw-r--r--globals.cginc35
-rw-r--r--interpolators.cginc1
-rw-r--r--math.cginc2
-rw-r--r--mochie_shadow_caster.cginc49
-rw-r--r--pbr_overlay.cginc464
-rw-r--r--pema_quad_intrinsics.cginc259
-rw-r--r--texture_macros.cginc189
-rw-r--r--tooner.shader35
-rw-r--r--tooner_lighting.cginc706
-rw-r--r--trochoid_math.cginc29
15 files changed, 1169 insertions, 969 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index 310cfa6..a100027 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -1909,6 +1909,73 @@ public class ToonerGUI : ShaderGUI {
EditorGUI.indentLevel -= 1;
}
+ if (Mathf.Round(choice) == 11) {
+ EditorGUI.indentLevel += 1;
+
+ bc = FindProperty("_Gimmick_DS2_11_Fog_Enable");
+ enabled = (bc.floatValue != 0.0);
+ EditorGUI.BeginChangeCheck();
+ enabled = Toggle("Fog enable", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+
+ if (enabled) {
+ bc = FindProperty("_Gimmick_DS2_11_Fog_Density");
+ FloatProperty(bc, "Fog density");
+ bc = FindProperty("_Gimmick_DS2_11_Fog_Sun_Direction");
+ VectorProperty(bc, "Fog sun direction");
+ bc = FindProperty("_Gimmick_DS2_11_Fog_Sun_Exponent");
+ FloatProperty(bc, "Fog sun exponent");
+ bc = FindProperty("_Gimmick_DS2_11_Fog_Color");
+ ColorProperty(bc, "Fog color");
+ bc = FindProperty("_Gimmick_DS2_11_Fog_Sun_Color");
+ ColorProperty(bc, "Fog sun color");
+ }
+
+ bc = FindProperty("_Gimmick_DS2_11_Snow_Color");
+ ColorProperty(bc, "Snow color");
+ bc = FindProperty("_Gimmick_DS2_11_Snowline");
+ FloatProperty(bc, "Snowline");
+ bc = FindProperty("_Gimmick_DS2_11_Snowline_Width");
+ FloatProperty(bc, "Snowline width");
+ bc = FindProperty("_Gimmick_DS2_11_Snowline_Noise_Scale");
+ FloatProperty(bc, "Snowline noise scale");
+ bc = FindProperty("_Gimmick_DS2_11_Rock_Color");
+ ColorProperty(bc, "Rock color");
+ bc = FindProperty("_Gimmick_DS2_11_Rockline");
+ FloatProperty(bc, "Rockline");
+ bc = FindProperty("_Gimmick_DS2_11_Rockline_Width");
+ FloatProperty(bc, "Rockline width");
+ bc = FindProperty("_Gimmick_DS2_11_Rockline_Noise_Scale");
+ FloatProperty(bc, "Rockline noise scale");
+ bc = FindProperty("_Gimmick_DS2_11_Grass_Color");
+ ColorProperty(bc, "Grass color");
+ 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_Distance_Culling_Enable");
+ enabled = (bc.floatValue != 0.0);
+ EditorGUI.BeginChangeCheck();
+ enabled = Toggle("Distance culling enable", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+
+ if (enabled) {
+ EditorGUI.indentLevel += 1;
+
+ bc = FindProperty("_Gimmick_DS2_11_Activation_Center");
+ VectorProperty(bc, "Activation center");
+ bc = FindProperty("_Gimmick_DS2_11_Activation_Radius");
+ FloatProperty(bc, "Activation radius");
+
+ EditorGUI.indentLevel -= 1;
+ }
+
+ EditorGUI.indentLevel -= 1;
+ }
+
EditorGUI.indentLevel -= 1;
}
@@ -1997,6 +2064,24 @@ public class ToonerGUI : ShaderGUI {
EditorGUI.EndChangeCheck();
bc.floatValue = enabled ? 1.0f : 0.0f;
+ bc = FindProperty("_Trochoid_Distance_Culling_Enable");
+ enabled = (bc.floatValue != 0.0);
+ EditorGUI.BeginChangeCheck();
+ enabled = Toggle("Distance culling enable", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+
+ if (enabled) {
+ EditorGUI.indentLevel += 1;
+
+ bc = FindProperty("_Trochoid_Activation_Center");
+ VectorProperty(bc, "Activation center");
+ bc = FindProperty("_Trochoid_Activation_Radius");
+ FloatProperty(bc, "Activation radius");
+
+ EditorGUI.indentLevel -= 1;
+ }
+
EditorGUI.indentLevel -= 1;
}
@@ -2491,6 +2576,53 @@ public class ToonerGUI : ShaderGUI {
EditorGUI.indentLevel -= 1;
}
+ void DoGimmickFog1() {
+ MaterialProperty bc;
+
+ bc = FindProperty("_Gimmick_Fog_01_Enable_Static");
+ bool enabled = (bc.floatValue != 0.0);
+ EditorGUI.BeginChangeCheck();
+ enabled = Toggle("Fog 01", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+ SetKeyword("_GIMMICK_FOG_01", enabled);
+
+ if (!enabled) {
+ return;
+ }
+ EditorGUI.indentLevel += 1;
+
+ bc = FindProperty("_Gimmick_Fog_01_Density");
+ RangeProperty(bc, "Density");
+ bc = FindProperty("_Gimmick_Fog_01_Sun_Direction");
+ VectorProperty(bc, "Sun direction");
+ bc = FindProperty("_Gimmick_Fog_01_Color");
+ ColorProperty(bc, "Color");
+ bc = FindProperty("_Gimmick_Fog_01_Sun_Color");
+ ColorProperty(bc, "Sun color");
+ bc = FindProperty("_Gimmick_Fog_01_Sun_Exponent");
+ FloatProperty(bc, "Sun exponent");
+ bc = FindProperty("_Gimmick_Fog_01_Distance_Culling_Enable");
+ enabled = (bc.floatValue != 0.0);
+ EditorGUI.BeginChangeCheck();
+ enabled = Toggle("Distance culling enable", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+
+ if (enabled) {
+ EditorGUI.indentLevel += 1;
+
+ bc = FindProperty("_Gimmick_Fog_01_Activation_Center");
+ VectorProperty(bc, "Activation center");
+ bc = FindProperty("_Gimmick_Fog_01_Activation_Radius");
+ FloatProperty(bc, "Activation radius");
+
+ EditorGUI.indentLevel -= 1;
+ }
+
+ EditorGUI.indentLevel -= 1;
+ }
+
void DoGimmickAurora() {
MaterialProperty bc;
@@ -2616,6 +2748,7 @@ public class ToonerGUI : ShaderGUI {
DoGimmickLetterGrid2();
DoGimmickAudiolinkChroma00();
DoGimmickFog0();
+ DoGimmickFog1();
DoGimmickAurora();
DoGimmickGerstnerWater();
DoClones();
diff --git a/audiolink.cginc b/audiolink.cginc
index 01e5783..4a3f5f1 100644
--- a/audiolink.cginc
+++ b/audiolink.cginc
@@ -1,7 +1,7 @@
#ifndef __AUDIOLINK
#define __AUDIOLINK
-#if defined (_GIMMICK_QUANTIZE_LOCATION_AUDIOLINK) || defined(_GIMMICK_AL_CHROMA_00) || defined(_GIMMICK_FOG_00)
+#if defined (_GIMMICK_QUANTIZE_LOCATION_AUDIOLINK) || defined(_GIMMICK_AL_CHROMA_00) || defined(_GIMMICK_FOG_00) || defined(_RENDERING_CUTOUT_IGN) || defined(_GIMMICK_DS2)
#include "Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.cginc"
diff --git a/downstairs_02.cginc b/downstairs_02.cginc
index 970ca6c..53074b5 100644
--- a/downstairs_02.cginc
+++ b/downstairs_02.cginc
@@ -1,8 +1,11 @@
#include "atrix256.cginc"
+#include "audiolink.cginc"
#include "globals.cginc"
+#include "fog.cginc"
#include "interpolators.cginc"
#include "iq_sdf.cginc"
#include "math.cginc"
+#include "noise.cginc"
#include "oklab.cginc"
#include "poi.cginc"
@@ -17,6 +20,7 @@ struct Gimmick_DS2_Output {
float3 emission;
float3 normal;
float3 worldPos;
+ float4 fog;
float metallic;
float roughness;
};
@@ -140,6 +144,7 @@ Gimmick_DS2_Output Gimmick_DS2_00(v2f i)
Gimmick_DS2_Output o;
o.albedo = float4(shaded_color * 5, 1.0);
o.emission = shaded_color;
+ o.fog = 0;
o.normal = normal;
o.metallic = 0;
o.roughness = 1;
@@ -252,6 +257,7 @@ Gimmick_DS2_Output Gimmick_DS2_01(inout v2f i)
Gimmick_DS2_Output o;
o.albedo = hit ? float4(color, 1) : 0;
o.emission = o.albedo;
+ o.fog = 0;
o.normal = normal;
o.metallic = 0;
o.roughness = 0;
@@ -350,6 +356,7 @@ Gimmick_DS2_Output Gimmick_DS2_10(inout v2f i)
//o.albedo = hit ? float4(color, 1) : 0;
o.albedo = hit ? 1 : 0;
o.emission = color;
+ o.fog = 0;
o.normal = normal;
o.metallic = 0;
o.roughness = 0.3;
@@ -472,6 +479,7 @@ Gimmick_DS2_Output Gimmick_DS2_02(inout v2f i)
Gimmick_DS2_Output o;
o.albedo = float4(color, 1);
o.emission = o.albedo;
+ o.fog = 0;
o.normal = normal;
o.metallic = 0;
o.roughness = 0;
@@ -638,6 +646,7 @@ Gimmick_DS2_Output Gimmick_DS2_03(inout v2f i)
o.albedo = float4(color, 1);
//o.emission = o.albedo;
o.emission = 0;
+ o.fog = 0;
o.normal = normal;
o.metallic = hit;
o.roughness = 0.1;
@@ -645,5 +654,146 @@ Gimmick_DS2_Output Gimmick_DS2_03(inout v2f i)
return o;
}
+float ds2_11_height(float2 p)
+{
+ float sc = .4;
+ float2 offset = _Time[0] * .00 + _Gimmick_DS2_11_XZ_Offset.xz;
+ //float t = 0;
+
+ float h = 0;
+ float hsc = 2.0;
+ uint octaves = 11;
+ float corrective_term = 0;
+ float cur_factor = 1;
+ float alpha = _Gimmick_DS2_11_Alpha;
+ float alpha_rcp = 1 / alpha;
+ //for (uint i = 0; i < octaves; i += sqrt(i+1)) {
+ for (uint i = 0; i < octaves; i++) {
+ corrective_term += cur_factor;
+ h += _Gimmick_DS2_Noise.SampleLevel(linear_repeat_s, (p - offset) * .01 * pow(alpha_rcp, i) / sc, 0) * sc * hsc * cur_factor;
+ cur_factor *= alpha;
+ }
+ h /= corrective_term;
+
+ // `scale_factor` goes from [0, 1] based on radius.
+ float2 center = p + (float2(0, .05));
+ float scale_factor = 1 - exp(-dot(center, center) * 16);
+ h *= scale_factor;
+ h -= (1 - scale_factor) * sc * hsc * .15;
+ h += .015;
+
+ return h;
+}
+
+float3 ds2_11_calc_normal(float3 p)
+{
+ float epsilon = 4E-4;
+ return normalize(float3(
+ ds2_11_height(p.xz - float2(epsilon, 0)) - ds2_11_height(p.xz + float2(epsilon, 0)),
+ 2 * epsilon,
+ ds2_11_height(p.xz - float2(0, epsilon)) - ds2_11_height(p.xz + float2(0, epsilon))
+ ));
+}
+
+Gimmick_DS2_Output Gimmick_DS2_11(inout v2f i, ToonerData tdata)
+{
+ float3 camera_position = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1));
+ float3 rd = normalize(i.objPos - camera_position);
+ float3 ro = camera_position + rd * 1E-2;
+
+ [branch]
+ if (_Gimmick_DS2_11_Distance_Culling_Enable) {
+ float3 activation_center = _Gimmick_DS2_11_Activation_Center;
+ float activation_radius = _Gimmick_DS2_11_Activation_Radius;
+ float cur_radius = length(_WorldSpaceCameraPos - activation_center);
+ [branch]
+ //if (cur_radius > activation_radius) {
+ if (_WorldSpaceCameraPos.y > activation_center.y + activation_radius) {
+ return (Gimmick_DS2_Output)0;
+ }
+ }
+
+ #define DS2_11_MARCH_STEPS 20
+ float t = 0.0;
+ float dt0 = 0.002;
+ float dt = dt0;
+ // last height, last y
+ float lh = 0;
+ float ly = 0;
+
+ // https://iquilezles.org/articles/terrainmarching/
+ bool hit = false;
+ for (uint ii = 0; ii < DS2_11_MARCH_STEPS; ii++) {
+ float3 p = ro + rd * t;
+ float h = ds2_11_height(p.xz);
+ if (p.y < h) {
+ t = t - dt + dt * (lh - ly) / (p.y - ly - h + lh);
+ hit = true;
+ break;
+ }
+ t += dt;
+ dt = dt0 * ii;
+ lh = h;
+ ly = p.y;
+ }
+
+ float3 final_pos = ro + t * rd;
+ float3 final_pos_world = mul(unity_ObjectToWorld, float4(final_pos, 1));
+ float4 final_color = 1;
+
+ float snowline_noise = 0;
+ float alpha = 0.6;
+ float alpha_rcp = 1 / alpha;
+ for (uint ii = 0; ii < 8; ii++) {
+ snowline_noise += _Gimmick_DS2_Noise.SampleLevel(linear_repeat_s, final_pos.xz * _Gimmick_DS2_11_Snowline_Noise_Scale * pow(alpha_rcp, ii), 0) * pow(alpha, ii);
+ }
+ float snowline = snowline_noise * _Gimmick_DS2_11_Snowline_Width - _Gimmick_DS2_11_Snowline;
+ float rockline_noise = 0;
+ for (uint ii = 0; ii < 8; ii++) {
+ rockline_noise += _Gimmick_DS2_Noise.SampleLevel(linear_repeat_s, final_pos.xz * _Gimmick_DS2_11_Rockline_Noise_Scale * pow(alpha_rcp, ii), 0) * pow(alpha, ii);
+ }
+ float rockline = rockline_noise * _Gimmick_DS2_11_Rockline_Width - _Gimmick_DS2_11_Rockline;
+
+ final_color.rgb = lerp(
+ _Gimmick_DS2_11_Rock_Color,
+ _Gimmick_DS2_11_Snow_Color,
+ saturate(final_pos_world.y - snowline));
+
+ final_color.rgb = lerp(
+ _Gimmick_DS2_11_Grass_Color,
+ final_color.rgb,
+ saturate(final_pos_world.y - rockline));
+
+ final_color *= hit;
+
+ float4 fog = 0;
+ [branch]
+ if (_Gimmick_DS2_11_Fog_Enable) {
+ fog = apply_fog(
+ length(final_pos_world - _WorldSpaceCameraPos),
+ _Gimmick_DS2_11_Fog_Density,
+ UnityObjectToWorldNormal(rd),
+ normalize(_Gimmick_DS2_11_Fog_Sun_Direction),
+ _Gimmick_DS2_11_Fog_Sun_Color,
+ _Gimmick_DS2_11_Fog_Sun_Exponent,
+ _Gimmick_DS2_11_Fog_Color) * hit;
+ }
+
+ float3 normal = UnityObjectToWorldNormal(ds2_11_calc_normal(final_pos));
+ //normal = MY_BLEND_NORMALS(float3(0, 1, 0), normal, hit);
+ //normal = float3(0, 1, 0);
+ //normal = MY_BLEND_NORMALS(normal, float3(0, 1, 0), fog.a);
+
+ Gimmick_DS2_Output o;
+ o.albedo = final_color;
+ o.emission = 0;
+ o.fog = fog;
+ o.normal = normal;
+ o.metallic = 0;
+ o.roughness = 1;
+ o.worldPos = final_pos_world;
+ return o;
+}
+
#endif // _GIMMICK_DS2
#endif // __DOWNSTAIRS_02_INC
diff --git a/feature_macros.cginc b/feature_macros.cginc
index 2502ebd..502491e 100644
--- a/feature_macros.cginc
+++ b/feature_macros.cginc
@@ -270,6 +270,7 @@
#pragma shader_feature_local _ _GIMMICK_FOG_00_EMITTER_1
#pragma shader_feature_local _ _GIMMICK_FOG_00_EMITTER_2
#pragma shader_feature_local _ _GIMMICK_FOG_00_RAY_MARCH_0
+#pragma shader_feature_local _ _GIMMICK_FOG_01
#pragma shader_feature_local _ _UNITY_FOG
#pragma shader_feature_local _ _GIMMICK_AURORA
#pragma shader_feature_local _ _GIMMICK_GERSTNER_WATER
diff --git a/fog.cginc b/fog.cginc
index fec9c47..5863d59 100644
--- a/fog.cginc
+++ b/fog.cginc
@@ -294,9 +294,9 @@ Fog00PBR getFog00(v2f i, ToonerData tdata) {
UnityIndirect indirect_light;
direct_light.dir = getDirectLightDirection(i);
direct_light.ndotl = 0; // Not used
- direct_light.color = getDirectLightColor();
+ direct_light.color = getDirectLightColor() *_Direct_Lighting_Factor;
// TODO try per-sample baked lighting
- indirect_light.diffuse = getIndirectDiffuse(i, /*vertex_light_color=*/0);
+ indirect_light.diffuse = getIndirectDiffuse(i, /*vertex_light_color=*/0) * _Indirect_Diffuse_Lighting_Factor;
// TODO consider doing specular. At time of writing it seems pointless.
indirect_light.specular = 0;
@@ -425,5 +425,84 @@ Fog00PBR getFog00(v2f i, ToonerData tdata) {
#endif // _GIMMICK_FOG_00
+#if defined(_GIMMICK_FOG_01) || defined(_GIMMICK_DS2)
+
+struct Fog01PBR {
+ float4 albedo;
+ float depth;
+};
+
+float4 apply_fog(
+ float t,
+ float density,
+ float3 rd,
+ float3 sun_dir,
+ float4 sun_color,
+ float sun_exponent,
+ float4 fog_color) {
+ float fog_amount = 1 - exp(-t * density);
+ float sun_amount = pow(max(dot(rd, sun_dir), 0), sun_exponent);
+ float4 color =
+ lerp(
+ fog_color,
+ sun_color,
+ sun_amount);
+ return float4(color.rgb, fog_amount * color.a);
+}
+
+Fog01PBR getFog01(v2f i, ToonerData tdata) {
+ float3 cam_pos = _WorldSpaceCameraPos;
+ float3 obj_pos = i.worldPos;
+
+ if (_Gimmick_Fog_01_Distance_Culling_Enable) {
+ float3 activation_center = _Gimmick_Fog_01_Activation_Center;
+ float activation_radius = _Gimmick_Fog_01_Activation_Radius;
+ float cur_radius = length(_WorldSpaceCameraPos - activation_center);
+ [branch]
+ //if (cur_radius > activation_radius) {
+ if (_WorldSpaceCameraPos.y > activation_center.y + activation_radius) {
+ return (Fog01PBR)0;
+ }
+ }
+
+ float3 world_pos_depth_hit;
+ float2 screen_uv;
+ float eye_depth_world;
+ {
+ float3 full_vec_eye_to_geometry = i.worldPos - _WorldSpaceCameraPos;
+ float3 world_dir = normalize(i.worldPos - _WorldSpaceCameraPos);
+ float perspective_divide = 1.0 / i.pos.w;
+ float perspective_factor = length(full_vec_eye_to_geometry * perspective_divide);
+ screen_uv = i.screenPos.xy * perspective_divide;
+ eye_depth_world =
+ GetLinearZFromZDepth_WorksWithMirrors(
+ SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, tdata.screen_uv),
+ screen_uv) * perspective_factor;
+ world_pos_depth_hit = _WorldSpaceCameraPos + eye_depth_world * world_dir;
+ }
+
+ const float3 rd = normalize(obj_pos - cam_pos);
+ float3 ro = cam_pos + rd * 1E-5;
+
+ Fog01PBR pbr;
+ pbr.albedo = apply_fog(eye_depth_world,
+ _Gimmick_Fog_01_Density, rd,
+ normalize(_Gimmick_Fog_01_Sun_Direction),
+ _Gimmick_Fog_01_Sun_Color,
+ _Gimmick_Fog_01_Sun_Exponent,
+ _Gimmick_Fog_01_Color);
+ pbr.albedo.rgb = aces_filmic(pbr.albedo.rgb);
+
+ //pbr.albedo.rgb = eye_depth_world / 100000;
+ //pbr.albedo.a = 1;
+
+ float4 clip_pos = mul(UNITY_MATRIX_VP, float4(ro, 1));
+ pbr.depth = clip_pos.z / clip_pos.w;
+
+ return pbr;
+}
+
+#endif // _GIMMICK_FOG_01
+
#endif // __FOG_INC
diff --git a/globals.cginc b/globals.cginc
index 3ed4af2..e7455e3 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -788,6 +788,27 @@ float _Gimmick_DS2_02_Domain_Warping_Speed;
float4 _Gimmick_DS2_03_Period;
float4 _Gimmick_DS2_03_Count;
float _Gimmick_DS2_03_Edge_Length;
+// 11
+float _Gimmick_DS2_11_Fog_Enable;
+float _Gimmick_DS2_11_Fog_Density;
+float3 _Gimmick_DS2_11_Fog_Sun_Direction;
+float4 _Gimmick_DS2_11_Fog_Sun_Color;
+float4 _Gimmick_DS2_11_Fog_Color;
+float _Gimmick_DS2_11_Snowline;
+float _Gimmick_DS2_11_Snowline_Width;
+float _Gimmick_DS2_11_Snowline_Noise_Scale;
+float3 _Gimmick_DS2_11_Snow_Color;
+float _Gimmick_DS2_11_Rockline;
+float _Gimmick_DS2_11_Rockline_Width;
+float _Gimmick_DS2_11_Rockline_Noise_Scale;
+float3 _Gimmick_DS2_11_Rock_Color;
+float3 _Gimmick_DS2_11_Grass_Color;
+float _Gimmick_DS2_11_Alpha;
+float3 _Gimmick_DS2_11_XZ_Offset;
+float _Gimmick_DS2_11_Fog_Sun_Exponent;
+float _Gimmick_DS2_11_Distance_Culling_Enable;
+float3 _Gimmick_DS2_11_Activation_Center;
+float _Gimmick_DS2_11_Activation_Radius;
#endif
#if defined(_PIXELLATE)
@@ -806,6 +827,9 @@ float _Trochoid_Radius_Power;
float _Trochoid_Radius_Scale;
float _Trochoid_Height_Scale;
float _Trochoid_Enable_Fragment_Normals;
+float _Trochoid_Distance_Culling_Enable;
+float3 _Trochoid_Activation_Center;
+float _Trochoid_Activation_Radius;
#endif
#if defined(_FACE_ME_WORLD_Y)
@@ -940,6 +964,17 @@ float _Gimmick_Fog_00_Emitter2_Scale_Y;
#endif
#endif
+#if defined(_GIMMICK_FOG_01) || defined(_GIMMICK_DS2)
+float _Gimmick_Fog_01_Density;
+float3 _Gimmick_Fog_01_Sun_Direction;
+float4 _Gimmick_Fog_01_Color;
+float4 _Gimmick_Fog_01_Sun_Color;
+float _Gimmick_Fog_01_Sun_Exponent;
+float _Gimmick_Fog_01_Distance_Culling_Enable;
+float3 _Gimmick_Fog_01_Activation_Center;
+float _Gimmick_Fog_01_Activation_Radius;
+#endif
+
#if defined(_GIMMICK_GERSTNER_WATER)
float _Gimmick_Gerstner_Water_M;
float _Gimmick_Gerstner_Water_h;
diff --git a/interpolators.cginc b/interpolators.cginc
index 2193339..d363d50 100644
--- a/interpolators.cginc
+++ b/interpolators.cginc
@@ -10,6 +10,7 @@ struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
+ float4 tangent : TANGENT;
float2 uv0 : TEXCOORD0;
#if !defined(_OPTIMIZE_INTERPOLATORS)
float2 uv1 : TEXCOORD1;
diff --git a/math.cginc b/math.cginc
index 507ca74..6b39bdb 100644
--- a/math.cginc
+++ b/math.cginc
@@ -279,7 +279,7 @@ float3x3 invert(float3x3 m)
uint gcd(uint a, uint b)
{
uint tmp = a * b;
- #define GCD_MAX_ITER 10
+ #define GCD_MAX_ITER 8
for (uint i = 0; i < GCD_MAX_ITER; i++) {
tmp = b;
b = a % b;
diff --git a/mochie_shadow_caster.cginc b/mochie_shadow_caster.cginc
index 0d15d41..c4731d8 100644
--- a/mochie_shadow_caster.cginc
+++ b/mochie_shadow_caster.cginc
@@ -1,7 +1,11 @@
#include "UnityCG.cginc"
#include "atrix256.cginc"
+#include "audiolink.cginc"
#include "gerstner.cginc"
+#include "globals.cginc"
+#include "pbr_overlay.cginc"
+#include "interpolators.cginc"
#include "trochoid_math.cginc"
#ifndef __MOCHIE_SHADOW_CASTER_INC
@@ -37,25 +41,6 @@
#pragma multi_compile_instancing
#pragma multi_compile_shadowcaster
-#include "UnityCG.cginc"
-#include "globals.cginc"
-
-struct appdata {
- float4 vertex : POSITION;
- float3 normal : NORMAL;
- float2 uv : TEXCOORD0;
-
- UNITY_VERTEX_INPUT_INSTANCE_ID
-};
-
-struct v2f {
- float4 pos : SV_POSITION;
- float2 uv : TEXCOORD0;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- UNITY_VERTEX_OUTPUT_STEREO
- float3 worldPos : TEXCOORD1;
- float2 screenPos : TEXCOORD2;
-};
v2f vert (appdata v){
#if defined(_DISCARD)
@@ -65,9 +50,9 @@ v2f vert (appdata v){
#endif
#if defined(_TROCHOID)
{
- v.vertex.xyz = cyl2_to_troch_map(cyl_to_cyl2_map(cart_to_cyl_map(v.vertex.xyz)));
+ v.vertex.xyz = cart_to_troch_map(v.vertex.xyz);
}
-#endif
+#endif // _TROCHOID
#if !defined(_SCROLL) && defined(_GIMMICK_GERSTNER_WATER)
{
GerstnerParams p = getGerstnerParams();
@@ -85,7 +70,7 @@ v2f vert (appdata v){
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
- o.uv = v.uv;
+ o.uv0 = v.uv0;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
float2 suv = o.pos * float2(0.5, 0.5 * _ProjectionParams.x);
@@ -106,19 +91,34 @@ float4 frag (v2f i) : SV_Target {
}
#if defined(_BASECOLOR_MAP)
- float4 albedo = _MainTex.SampleBias(linear_repeat_s, i.uv, _Global_Sample_Bias);
+ float4 albedo = _MainTex.SampleBias(GET_SAMPLER_PBR, UV_SCOFF(i, _MainTex_ST, 0), _Global_Sample_Bias);
albedo *= _Color;
#else
float4 albedo = _Color;
#endif // _BASECOLOR_MAP
+
+ PbrOverlay ov;
+ getOverlayAlbedoRoughnessMetallic(ov, i);
+ float roughness = 0;
+ float metallic = 0;
+ float overlay_glitter_mask;
+ float one = 1;
+ mixOverlayAlbedoRoughnessMetallic(albedo, roughness, metallic, ov, one, overlay_glitter_mask);
+
#if defined(_RENDERING_CUTOUT)
#if defined(_RENDERING_CUTOUT_STOCHASTIC)
float ar = rand2(i.uv0);
clip(albedo.a - ar);
#elif defined(_RENDERING_CUTOUT_IGN)
+ float frame = 0;
+ if (AudioLinkIsAvailable()) {
+ frame = ((float) AudioLinkData(ALPASS_GENERALVU + int2(1, 0)).x);
+ } else {
+ frame = floor(_Frame_Counter);
+ }
float ar = ign_anim(
floor(tdata.screen_uv_round * _Rendering_Cutout_Noise_Scale) + _Rendering_Cutout_Ign_Seed,
- floor(_Frame_Counter), _Rendering_Cutout_Ign_Speed);
+ frame, _Rendering_Cutout_Ign_Speed);
clip(albedo.a - ar);
#elif defined(_RENDERING_CUTOUT_NOISE_MASK)
float ar = _Rendering_Cutout_Noise_Mask.SampleLevel(point_repeat_s, tdata.screen_uv * _ScreenParams.xy * _Rendering_Cutout_Noise_Mask_TexelSize.xy, 0);
@@ -128,6 +128,7 @@ float4 frag (v2f i) : SV_Target {
#endif
albedo.a = 1;
#endif
+
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
return 0;
}
diff --git a/pbr_overlay.cginc b/pbr_overlay.cginc
new file mode 100644
index 0000000..2ebbb10
--- /dev/null
+++ b/pbr_overlay.cginc
@@ -0,0 +1,464 @@
+#include "texture_macros.cginc"
+#include "UnityStandardUtils.cginc"
+
+#ifndef __PBR_OVERLAY_INC
+#define __PBR_OVERLAY_INC
+
+struct PbrOverlay {
+#if defined(_PBR_OVERLAY0)
+ float4 ov0_albedo;
+#if defined(_PBR_OVERLAY0_ROUGHNESS)
+ float ov0_roughness;
+#endif
+#if defined(_PBR_OVERLAY0_METALLIC)
+ float ov0_metallic;
+#endif
+ float ov0_mask;
+#endif
+#if defined(_PBR_OVERLAY1)
+ float4 ov1_albedo;
+#if defined(_PBR_OVERLAY1_ROUGHNESS)
+ float ov1_roughness;
+#endif
+#if defined(_PBR_OVERLAY1_METALLIC)
+ float ov1_metallic;
+#endif
+ float ov1_mask;
+#endif
+#if defined(_PBR_OVERLAY2)
+ float4 ov2_albedo;
+#if defined(_PBR_OVERLAY2_ROUGHNESS)
+ float ov2_roughness;
+#endif
+#if defined(_PBR_OVERLAY2_METALLIC)
+ float ov2_metallic;
+#endif
+ float ov2_mask;
+#endif
+#if defined(_PBR_OVERLAY3)
+ float4 ov3_albedo;
+#if defined(_PBR_OVERLAY3_ROUGHNESS)
+ float ov3_roughness;
+#endif
+#if defined(_PBR_OVERLAY3_METALLIC)
+ float ov3_metallic;
+#endif
+ float ov3_mask;
+#endif
+};
+
+void getOverlayAlbedoRoughnessMetallic(inout PbrOverlay ov,
+ v2f i)
+{
+#if defined(_PBR_OVERLAY0)
+#if defined(_PBR_OVERLAY0_BASECOLOR_MAP)
+ ov.ov0_albedo = _PBR_Overlay0_BaseColorTex.SampleBias(GET_SAMPLER_OV0,
+ UV_SCOFF(i, _PBR_Overlay0_BaseColorTex_ST, _PBR_Overlay0_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias);
+ ov.ov0_albedo *= _PBR_Overlay0_BaseColor;
+#else
+ ov.ov0_albedo = _PBR_Overlay0_BaseColor;
+#endif // _PBR_OVERLAY0_BASECOLOR_MAP
+
+#if defined(_PBR_OVERLAY0_ROUGHNESS)
+#if defined(_PBR_OVERLAY0_ROUGHNESS_MAP)
+ ov.ov0_roughness = _PBR_Overlay0_RoughnessTex.SampleBias(GET_SAMPLER_OV0,
+ UV_SCOFF(i, _PBR_Overlay0_RoughnessTex_ST, _PBR_Overlay0_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias);
+ ov.ov0_roughness *= _PBR_Overlay0_Roughness;
+#else
+ ov.ov0_roughness = _PBR_Overlay0_Roughness;
+#endif // _PBR_OVERLAY0_ROUGHNESS_MAP
+#endif
+
+#if defined(_PBR_OVERLAY0_METALLIC)
+#if defined(_PBR_OVERLAY0_METALLIC_MAP)
+ ov.ov0_metallic = _PBR_Overlay0_MetallicTex.SampleBias(GET_SAMPLER_OV0,
+ UV_SCOFF(i, _PBR_Overlay0_MetallicTex_ST, _PBR_Overlay0_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias);
+ ov.ov0_metallic *= _PBR_Overlay0_Metallic;
+#else
+ ov.ov0_metallic = _PBR_Overlay0_Metallic;
+#endif // _PBR_OVERLAY0_METALLIC_MAP
+#endif
+
+#if defined(_PBR_OVERLAY0_MASK)
+ ov.ov0_mask = _PBR_Overlay0_Mask.SampleLevel(GET_SAMPLER_OV0,
+ UV_SCOFF(i, _PBR_Overlay0_Mask_ST, _PBR_Overlay0_UV_Select),
+ get_uv_by_channel(i, _PBR_Overlay0_UV_Select), 0);
+ ov.ov0_mask = ((bool) round(_PBR_Overlay0_Mask_Invert)) ? 1.0 - ov.ov0_mask : ov.ov0_mask;
+#else
+ ov.ov0_mask = 1;
+#endif
+ ov.ov0_albedo.a *= ov.ov0_mask;
+#endif // _PBR_OVERLAY0
+
+#if defined(_PBR_OVERLAY1)
+#if defined(_PBR_OVERLAY1_BASECOLOR_MAP)
+ ov.ov1_albedo = _PBR_Overlay1_BaseColorTex.SampleBias(GET_SAMPLER_OV1,
+ UV_SCOFF(i, _PBR_Overlay1_BaseColorTex_ST, _PBR_Overlay1_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias);
+ ov.ov1_albedo *= _PBR_Overlay1_BaseColor;
+#else
+ ov.ov1_albedo = _PBR_Overlay1_BaseColor;
+#endif // _PBR_OVERLAY1_BASECOLOR_MAP
+
+#if defined(_PBR_OVERLAY1_ROUGHNESS)
+#if defined(_PBR_OVERLAY1_ROUGHNESS_MAP)
+ ov.ov1_roughness = _PBR_Overlay1_RoughnessTex.SampleBias(GET_SAMPLER_OV1,
+ UV_SCOFF(i, _PBR_Overlay1_RoughnessTex_ST, _PBR_Overlay1_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias);
+ ov.ov1_roughness *= _PBR_Overlay1_Roughness;
+#else
+ ov.ov1_roughness = _PBR_Overlay1_Roughness;
+#endif // _PBR_OVERLAY1_ROUGHNESS_MAP
+#endif
+
+#if defined(_PBR_OVERLAY1_METALLIC)
+#if defined(_PBR_OVERLAY1_METALLIC_MAP)
+ ov.ov1_metallic = _PBR_Overlay1_MetallicTex.SampleBias(GET_SAMPLER_OV1,
+ UV_SCOFF(i, _PBR_Overlay1_MetallicTex_ST, _PBR_Overlay1_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias);
+ ov.ov1_metallic *= _PBR_Overlay1_Metallic;
+#else
+ ov.ov1_metallic = _PBR_Overlay1_Metallic;
+#endif // _PBR_OVERLAY1_METALLIC_MAP
+#endif
+
+#if defined(_PBR_OVERLAY1_MASK)
+ ov.ov1_mask = _PBR_Overlay1_Mask.SampleLevel(GET_SAMPLER_OV1,
+ UV_SCOFF(i, _PBR_Overlay1_Mask_ST, _PBR_Overlay1_UV_Select), 0);
+ ov.ov1_mask = ((bool) round(_PBR_Overlay1_Mask_Invert)) ? 1.0 - ov.ov1_mask : ov.ov1_mask;
+#else
+ ov.ov1_mask = 1;
+#endif
+ ov.ov1_albedo.a *= ov.ov1_mask;
+#endif // _PBR_OVERLAY1
+
+#if defined(_PBR_OVERLAY2)
+#if defined(_PBR_OVERLAY2_BASECOLOR_MAP)
+ ov.ov2_albedo = _PBR_Overlay2_BaseColorTex.SampleBias(GET_SAMPLER_OV2,
+ UV_SCOFF(i, _PBR_Overlay2_BaseColorTex_ST, _PBR_Overlay2_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias);
+ ov.ov2_albedo *= _PBR_Overlay2_BaseColor;
+#else
+ ov.ov2_albedo = _PBR_Overlay2_BaseColor;
+#endif // _PBR_OVERLAY2_BASECOLOR_MAP
+
+#if defined(_PBR_OVERLAY2_ROUGHNESS)
+#if defined(_PBR_OVERLAY2_ROUGHNESS_MAP)
+ ov.ov2_roughness = _PBR_Overlay2_RoughnessTex.SampleBias(GET_SAMPLER_OV2,
+ UV_SCOFF(i, _PBR_Overlay2_RoughnessTex_ST, _PBR_Overlay2_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias);
+ ov.ov2_roughness *= _PBR_Overlay2_Roughness;
+#else
+ ov.ov2_roughness = _PBR_Overlay2_Roughness;
+#endif // _PBR_OVERLAY2_ROUGHNESS_MAP
+#endif
+
+#if defined(_PBR_OVERLAY2_METALLIC)
+#if defined(_PBR_OVERLAY2_METALLIC_MAP)
+ ov.ov2_metallic = _PBR_Overlay2_MetallicTex.SampleBias(GET_SAMPLER_OV2,
+ UV_SCOFF(i, _PBR_Overlay2_MetallicTex_ST, _PBR_Overlay2_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias);
+ ov.ov2_metallic *= _PBR_Overlay2_Metallic;
+#else
+ ov.ov2_metallic = _PBR_Overlay2_Metallic;
+#endif // _PBR_OVERLAY2_METALLIC_MAP
+#endif
+
+#if defined(_PBR_OVERLAY2_MASK)
+ ov.ov2_mask = _PBR_Overlay2_Mask.SampleLevel(GET_SAMPLER_OV2,
+ UV_SCOFF(i, _PBR_Overlay2_Mask_ST, _PBR_Overlay2_UV_Select), 0);
+ ov.ov2_mask = ((bool) round(_PBR_Overlay2_Mask_Invert)) ? 1.0 - ov.ov2_mask : ov.ov2_mask;
+#else
+ ov.ov2_mask = 1;
+#endif
+ ov.ov2_albedo.a *= ov.ov2_mask;
+#endif // _PBR_OVERLAY2
+
+#if defined(_PBR_OVERLAY3)
+#if defined(_PBR_OVERLAY3_BASECOLOR_MAP)
+ ov.ov3_albedo = _PBR_Overlay3_BaseColorTex.SampleBias(GET_SAMPLER_OV3,
+ UV_SCOFF(i, _PBR_Overlay3_BaseColorTex_ST, _PBR_Overlay3_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias);
+ ov.ov3_albedo *= _PBR_Overlay3_BaseColor;
+#else
+ ov.ov3_albedo = _PBR_Overlay3_BaseColor;
+#endif // _PBR_OVERLAY3_BASECOLOR_MAP
+
+#if defined(_PBR_OVERLAY3_ROUGHNESS)
+#if defined(_PBR_OVERLAY3_ROUGHNESS_MAP)
+ ov.ov3_roughness = _PBR_Overlay3_RoughnessTex.SampleBias(GET_SAMPLER_OV3,
+ UV_SCOFF(i, _PBR_Overlay3_RoughnessTex_ST, _PBR_Overlay3_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias);
+ ov.ov3_roughness *= _PBR_Overlay3_Roughness;
+#else
+ ov.ov3_roughness = _PBR_Overlay3_Roughness;
+#endif // _PBR_OVERLAY3_ROUGHNESS_MAP
+#endif
+
+#if defined(_PBR_OVERLAY3_METALLIC)
+#if defined(_PBR_OVERLAY3_METALLIC_MAP)
+ ov.ov3_metallic = _PBR_Overlay3_MetallicTex.SampleBias(GET_SAMPLER_OV3,
+ UV_SCOFF(i, _PBR_Overlay3_MetallicTex_ST, _PBR_Overlay3_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias);
+ ov.ov3_metallic *= _PBR_Overlay3_Metallic;
+#else
+ ov.ov3_metallic = _PBR_Overlay3_Metallic;
+#endif // _PBR_OVERLAY3_METALLIC_MAP
+#endif
+
+#if defined(_PBR_OVERLAY3_MASK)
+ ov.ov3_mask = _PBR_Overlay3_Mask.SampleLevel(GET_SAMPLER_OV3,
+ UV_SCOFF(i, _PBR_Overlay3_Mask_ST, _PBR_Overlay3_UV_Select), 0);
+ ov.ov3_mask = ((bool) round(_PBR_Overlay3_Mask_Invert)) ? 1.0 - ov.ov3_mask : ov.ov3_mask;
+#else
+ ov.ov3_mask = 1;
+#endif
+ ov.ov3_albedo.a *= ov.ov3_mask;
+#endif // _PBR_OVERLAY3
+}
+
+void mixOverlayAlbedoRoughnessMetallic(inout float4 albedo,
+ inout float roughness, inout float metallic, PbrOverlay ov,
+ float mask, out float glitter_mask) {
+ glitter_mask = 1;
+ // Calculate alpha masks before we start mutating alpha.
+#if defined(_PBR_OVERLAY0)
+ float a0 = saturate(ov.ov0_albedo.a * _PBR_Overlay0_Alpha_Multiplier);
+ if (_PBR_Overlay0_Constrain_By_Alpha) {
+ bool in_range = (albedo.a > _PBR_Overlay0_Constrain_By_Alpha_Min) *
+ (albedo.a < _PBR_Overlay0_Constrain_By_Alpha_Max);
+ a0 *= in_range;
+ }
+ a0 *= mask;
+ a0 *= ov.ov0_mask;
+ glitter_mask *= 1 - a0 * _PBR_Overlay0_Mask_Glitter;
+#endif
+#if defined(_PBR_OVERLAY1)
+ float a1 = saturate(ov.ov1_albedo.a * _PBR_Overlay1_Alpha_Multiplier);
+ if (_PBR_Overlay1_Constrain_By_Alpha) {
+ bool in_range = (albedo.a > _PBR_Overlay1_Constrain_By_Alpha_Min) *
+ (albedo.a < _PBR_Overlay1_Constrain_By_Alpha_Max);
+ a1 *= in_range;
+ }
+ a1 *= mask;
+ a1 *= ov.ov1_mask;
+ glitter_mask *= 1 - a1 * _PBR_Overlay1_Mask_Glitter;
+#endif
+#if defined(_PBR_OVERLAY2)
+ float a2 = saturate(ov.ov2_albedo.a * _PBR_Overlay2_Alpha_Multiplier);
+ if (_PBR_Overlay2_Constrain_By_Alpha) {
+ bool in_range = (albedo.a > _PBR_Overlay2_Constrain_By_Alpha_Min) *
+ (albedo.a < _PBR_Overlay2_Constrain_By_Alpha_Max);
+ a2 *= in_range;
+ }
+ a2 *= mask;
+ a2 *= ov.ov2_mask;
+ glitter_mask *= 1 - a2 * _PBR_Overlay2_Mask_Glitter;
+#endif
+#if defined(_PBR_OVERLAY3)
+ float a3 = saturate(ov.ov3_albedo.a * _PBR_Overlay3_Alpha_Multiplier);
+ if (_PBR_Overlay3_Constrain_By_Alpha) {
+ bool in_range = (albedo.a > _PBR_Overlay3_Constrain_By_Alpha_Min) *
+ (albedo.a < _PBR_Overlay3_Constrain_By_Alpha_Max);
+ a3 *= in_range;
+ }
+ a3 *= mask;
+ a3 *= ov.ov3_mask;
+ glitter_mask *= 1 - a3 * _PBR_Overlay3_Mask_Glitter;
+#endif
+
+#if defined(_PBR_OVERLAY0)
+#if defined(_PBR_OVERLAY0_MIX_ALPHA_BLEND)
+ albedo.rgb = lerp(albedo.rgb, ov.ov0_albedo.rgb, a0);
+#if defined(_PBR_OVERLAY0_ROUGHNESS)
+ roughness = lerp(roughness, ov.ov0_roughness, a0);
+#endif
+#if defined(_PBR_OVERLAY0_METALLIC)
+ metallic = lerp(metallic, ov.ov0_metallic, a0);
+#endif
+ albedo.a = max(albedo.a, a0);
+#elif defined(_PBR_OVERLAY0_MIX_ADD)
+ albedo.rgb += ov.ov0_albedo * mask * ov.ov0_mask;
+#elif defined(_PBR_OVERLAY0_MIX_MIN)
+ albedo.rgb = lerp(albedo.rgb, min(albedo.rgb, ov.ov0_albedo), mask * ov.ov0_mask);
+#elif defined(_PBR_OVERLAY0_MIX_MAX)
+ albedo.rgb = max(albedo.rgb, ov.ov0_albedo * mask * ov.ov0_mask);
+#elif defined(_PBR_OVERLAY0_MIX_MULTIPLY)
+ albedo.rgb = lerp(albedo.rgb, albedo.rgb * ov.ov0_albedo, mask * ov.ov0_mask);
+#endif
+#endif
+
+#if defined(_PBR_OVERLAY1)
+#if defined(_PBR_OVERLAY1_MIX_ALPHA_BLEND)
+ albedo.rgb = lerp(albedo.rgb, ov.ov1_albedo.rgb, a1);
+#if defined(_PBR_OVERLAY1_ROUGHNESS)
+ roughness = lerp(roughness, ov.ov1_roughness, a1);
+#endif
+#if defined(_PBR_OVERLAY1_METALLIC)
+ metallic = lerp(metallic, ov.ov1_metallic, a1);
+#endif
+ albedo.a = max(albedo.a, a1);
+#elif defined(_PBR_OVERLAY1_MIX_ADD)
+ albedo.rgb += ov.ov1_albedo * mask * ov.ov1_mask;
+#elif defined(_PBR_OVERLAY1_MIX_MIN)
+ albedo.rgb = lerp(albedo.rgb, min(albedo.rgb, ov.ov1_albedo), mask * ov.ov1_mask);
+#elif defined(_PBR_OVERLAY1_MIX_MAX)
+ albedo.rgb = max(albedo.rgb, ov.ov1_albedo * mask * ov.ov1_mask);
+#elif defined(_PBR_OVERLAY1_MIX_MULTIPLY)
+ albedo.rgb = lerp(albedo.rgb, albedo.rgb * ov.ov1_albedo, mask * ov.ov1_mask);
+#endif
+#endif
+
+#if defined(_PBR_OVERLAY2)
+#if defined(_PBR_OVERLAY2_MIX_ALPHA_BLEND)
+ albedo.rgb = lerp(albedo.rgb, ov.ov2_albedo.rgb, a2);
+#if defined(_PBR_OVERLAY2_ROUGHNESS)
+ roughness = lerp(roughness, ov.ov2_roughness, a2);
+#endif
+#if defined(_PBR_OVERLAY2_METALLIC)
+ metallic = lerp(metallic, ov.ov2_metallic, a2);
+#endif
+ albedo.a = max(albedo.a, a2);
+#elif defined(_PBR_OVERLAY2_MIX_ADD)
+ albedo.rgb += ov.ov2_albedo * mask * ov.ov2_mask;
+#elif defined(_PBR_OVERLAY2_MIX_MIN)
+ albedo.rgb = lerp(albedo.rgb, min(albedo.rgb, ov.ov2_albedo), mask * ov.ov2_mask);
+#elif defined(_PBR_OVERLAY2_MIX_MAX)
+ albedo.rgb = max(albedo.rgb, ov.ov2_albedo * mask * ov.ov2_mask);
+#elif defined(_PBR_OVERLAY2_MIX_MULTIPLY)
+ albedo.rgb = lerp(albedo.rgb, albedo.rgb * ov.ov2_albedo, mask * ov.ov2_mask);
+#endif
+#endif
+
+#if defined(_PBR_OVERLAY3)
+#if defined(_PBR_OVERLAY3_MIX_ALPHA_BLEND)
+ albedo.rgb = lerp(albedo.rgb, ov.ov3_albedo.rgb, a3);
+#if defined(_PBR_OVERLAY3_ROUGHNESS)
+ roughness = lerp(roughness, ov.ov3_roughness, a3);
+#endif
+#if defined(_PBR_OVERLAY3_METALLIC)
+ metallic = lerp(metallic, ov.ov3_metallic, a3);
+#endif
+ albedo.a = max(albedo.a, a3);
+#elif defined(_PBR_OVERLAY3_MIX_ADD)
+ albedo.rgb += ov.ov3_albedo * mask * ov.ov3_mask;
+#elif defined(_PBR_OVERLAY3_MIX_MIN)
+ albedo.rgb = lerp(albedo.rgb, min(albedo.rgb, ov.ov3_albedo), mask * ov.ov3_mask);
+#elif defined(_PBR_OVERLAY3_MIX_MAX)
+ albedo.rgb = max(albedo.rgb, ov.ov3_albedo * mask * ov.ov3_mask);
+#elif defined(_PBR_OVERLAY3_MIX_MULTIPLY)
+ albedo.rgb = lerp(albedo.rgb, albedo.rgb * ov.ov3_albedo, mask * ov.ov3_mask);
+#endif
+#endif
+}
+
+void applyOverlayNormal(inout float3 raw_normal, float4 albedo, PbrOverlay ov, v2f i)
+{
+ float3 raw_normal_2;
+#if defined(_PBR_OVERLAY0) && defined(_PBR_OVERLAY0_NORMAL_MAP)
+ float a0 = 1;
+ if (_PBR_Overlay0_Constrain_By_Alpha) {
+ bool in_range = (albedo.a > _PBR_Overlay0_Constrain_By_Alpha_Min) *
+ (albedo.a < _PBR_Overlay0_Constrain_By_Alpha_Max);
+ a0 *= in_range;
+ }
+ // Use UVs to smoothly blend between fully detailed normals when close up and
+ // flat normals when far away. If we don't do this, then we see moire effects
+ // on e.g. striped normal maps.
+ raw_normal_2 = UnpackScaleNormal(_PBR_Overlay0_NormalTex.SampleBias(GET_SAMPLER_OV0,
+ UV_SCOFF(i, _PBR_Overlay0_NormalTex_ST, _PBR_Overlay0_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias),
+ _PBR_Overlay0_Tex_NormalStr * ov.ov0_mask * a0);
+
+ raw_normal = BlendNormals(
+ raw_normal,
+ raw_normal_2);
+#endif // _PBR_OVERLAY0 && _PBR_OVERLAY0_NORMAL_MAP
+#if defined(_PBR_OVERLAY1) && defined(_PBR_OVERLAY1_NORMAL_MAP)
+ float a1 = 1;
+ if (_PBR_Overlay1_Constrain_By_Alpha) {
+ bool in_range = (albedo.a > _PBR_Overlay1_Constrain_By_Alpha_Min) *
+ (albedo.a < _PBR_Overlay1_Constrain_By_Alpha_Max);
+ a1 *= in_range;
+ }
+ raw_normal_2 = UnpackScaleNormal(_PBR_Overlay1_NormalTex.SampleBias(GET_SAMPLER_OV1,
+ UV_SCOFF(i, _PBR_Overlay1_NormalTex_ST, _PBR_Overlay1_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias),
+ _PBR_Overlay1_Tex_NormalStr * ov.ov1_mask * a1);
+
+ raw_normal = BlendNormals(
+ raw_normal,
+ raw_normal_2);
+#endif // _PBR_OVERLAY1 && _PBR_OVERLAY1_NORMAL_MAP
+#if defined(_PBR_OVERLAY2) && defined(_PBR_OVERLAY2_NORMAL_MAP)
+ float a2 = 1;
+ if (_PBR_Overlay2_Constrain_By_Alpha) {
+ bool in_range = (albedo.a > _PBR_Overlay2_Constrain_By_Alpha_Min) *
+ (albedo.a < _PBR_Overlay2_Constrain_By_Alpha_Max);
+ a2 *= in_range;
+ }
+ raw_normal_2 = UnpackScaleNormal(_PBR_Overlay2_NormalTex.SampleBias(GET_SAMPLER_OV2,
+ UV_SCOFF(i, _PBR_Overlay2_NormalTex_ST, _PBR_Overlay2_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias),
+ _PBR_Overlay2_Tex_NormalStr * ov.ov2_mask * a2);
+
+ raw_normal = BlendNormals(
+ raw_normal,
+ raw_normal_2);
+#endif // _PBR_OVERLAY2 && _PBR_OVERLAY2_NORMAL_MAP
+#if defined(_PBR_OVERLAY3) && defined(_PBR_OVERLAY3_NORMAL_MAP)
+ float a3 = 1;
+ if (_PBR_Overlay3_Constrain_By_Alpha) {
+ bool in_range = (albedo.a > _PBR_Overlay3_Constrain_By_Alpha_Min) *
+ (albedo.a < _PBR_Overlay3_Constrain_By_Alpha_Max);
+ a3 *= in_range;
+ }
+ raw_normal_2 = UnpackScaleNormal(_PBR_Overlay3_NormalTex.SampleBias(GET_SAMPLER_OV3,
+ UV_SCOFF(i, _PBR_Overlay3_NormalTex_ST, _PBR_Overlay3_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias),
+ _PBR_Overlay3_Tex_NormalStr * ov.ov3_mask * a3);
+
+ raw_normal = BlendNormals(
+ raw_normal,
+ raw_normal_2);
+#endif // _PBR_OVERLAY3 && _PBR_OVERLAY3_NORMAL_MAP
+}
+
+float3 getOverlayEmission(PbrOverlay ov, v2f i)
+{
+ float3 em = 0;
+#if defined(_PBR_OVERLAY0_EMISSION_MAP)
+ em += _PBR_Overlay0_EmissionTex.SampleBias(GET_SAMPLER_OV0,
+ UV_SCOFF(i, _PBR_Overlay0_EmissionTex_ST, _PBR_Overlay0_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias) *
+ _PBR_Overlay0_Emission * ov.ov0_mask;
+#endif
+
+#if defined(_PBR_OVERLAY1_EMISSION_MAP)
+ em += _PBR_Overlay1_EmissionTex.SampleBias(GET_SAMPLER_OV1,
+ UV_SCOFF(i, _PBR_Overlay1_EmissionTex_ST, _PBR_Overlay1_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias) *
+ _PBR_Overlay1_Emission * ov.ov1_mask;
+#endif
+
+#if defined(_PBR_OVERLAY2_EMISSION_MAP)
+ em += _PBR_Overlay2_EmissionTex.SampleBias(GET_SAMPLER_OV2,
+ UV_SCOFF(i, _PBR_Overlay2_EmissionTex_ST, _PBR_Overlay2_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias) *
+ _PBR_Overlay2_Emission * ov.ov2_mask;
+#endif
+
+#if defined(_PBR_OVERLAY3_EMISSION_MAP)
+ em += _PBR_Overlay3_EmissionTex.SampleBias(GET_SAMPLER_OV3,
+ UV_SCOFF(i, _PBR_Overlay3_EmissionTex_ST, _PBR_Overlay3_UV_Select),
+ _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias) *
+ _PBR_Overlay3_Emission * ov.ov3_mask;
+#endif
+ return em;
+}
+
+#endif // __PBR_OVERLAY_INC
+
diff --git a/pema_quad_intrinsics.cginc b/pema_quad_intrinsics.cginc
deleted file mode 100644
index 0a411a0..0000000
--- a/pema_quad_intrinsics.cginc
+++ /dev/null
@@ -1,259 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Author: pema99
-
-// This file contains functions that simulate Quad and Wave Intrinsics without access to either.
-// For more information on those, see: https://github.com/Microsoft/DirectXShaderCompiler/wiki/Wave-Intrinsics
-
-// To use the functions, you must call SETUP_QUAD_INTRINSICS(pos) at the start of your fragment shader,
-// where 'pos' is the pixel position, ie. the fragment input variable with the SV_Position semantic.
-// Note that some functions will require SM 5.0, ie. #pragma target 5.0.
-
-// The file is a bit difficult to read, so here is a quick reference of all the functions it provides:
-//
-// Basic getters:
-// uint QuadGetLaneID() - Get the ID of the current lane (0-3), from top left to bottom right.
-// uint2 QuadGetLanePosition() - Get the position of the current lane (0,0 - 1,1), from top left to bottom right.
-//
-// Shuffles and broadcasts:
-// <float_type> QuadReadAcrossX(<float_type> value) - Read the value of the lane opposite this one on the X axis.
-// <float_type> QuadReadAcrossY(<float_type> value) - Read the value of the lane opposite this one on the Y axis.
-// <float_type> QuadReadAcrossDiagonal(<float_type> value) - Read the value of the lane opposite this one on the diagonal.
-// <float_type> QuadReadLaneAt(<float_type> value, uint2 quadLaneID) - Read the value of the lane at the given position.
-// <float_type> QuadReadLaneAt(<float_type> value, uint quadLaneID) - Read the value of the lane with the given ID.
-// void QuadReadAll(<float_type> value, out <float_type> topLeft, out <float_type> topRight, out <float_type> bottomLeft, out <float_type> bottomRight) - Read the value of all lanes.
-//
-// Reductions:
-// bool QuadAny(bool expr) - Check if any lane evaluate the expression to true.
-// bool QuadAll(bool expr) - Check if all lanes evaluate the expression to true.
-// <float_type> QuadSum(<float_type> value) - Sum the values on all lanes.
-// <float_type> QuadProduct(<float_type> value) - Multiply the values on all lanes.
-// <float_type> QuadMin(<float_type> value) - Find the minimum value on all lanes.
-// <float_type> QuadMax(<float_type> value) - Find the maximum value on all lanes.
-// <integer_type> QuadBitAnd(<integer_type> value) - Bitwise AND the values on all lanes.
-// <integer_type> QuadBitOr(<integer_type> value) - Bitwise OR the values on all lanes.
-// <integer_type> QuadBitXor(<integer_type> value) - Bitwise XOR the values on all lanes.
-// uint4 QuadBallot(bool expr) - Create a bitmask of which lanes evaluate the expression to true.
-// uint QuadCountBits(bool expr) - Count the number of lanes that evaluate the expression to true.
-//
-// Scans:
-// <float_type> QuadPrefixSum(<float_type> value) - Sum the values on all lanes up to and exlcuding this one.
-// <float_type> QuadPrefixProduct(<float_type> value) - Multiply the values on all lanes up to and exlcuding this one.
-// uint QuadPrefixCountBits(bool expr) - Count the number of lanes that evaluate the expression to true up to and excluding this one.
-
-#ifndef QUAD_INTRINSICS
-#define QUAD_INTRINSICS
-
-// Setup functions
-static uint2 GLOBAL_QUAD_INDEX = uint2(0, 0);
-
-#define SETUP_QUAD_INTRINSICS(SV_Position) \
- GLOBAL_QUAD_INDEX = (uint2)(SV_Position).xy & 1;
-
-// ID getters
-uint QuadGetLaneID()
-{
- return ((GLOBAL_QUAD_INDEX.y * 1) << 1) + (GLOBAL_QUAD_INDEX.x & 1);
-}
-
-uint2 QuadGetLanePosition()
-{
- return GLOBAL_QUAD_INDEX;
-}
-
-// Helper functions
-#define GENERIC_QUAD_FLOAT_HELPERS(T) \
-T QUAD_ADD_HELPER(T a, T b) \
-{ \
- return a + b; \
-} \
-
-// NOTE: The reason we don't implement these for all types is because the HLSL compiler selects
-// overloads based on the size of the type - thus, we can't have any instances that take parameters
-// of the same size, as the overloads will overlap.
-GENERIC_QUAD_FLOAT_HELPERS(float);
-GENERIC_QUAD_FLOAT_HELPERS(float2);
-GENERIC_QUAD_FLOAT_HELPERS(float3);
-GENERIC_QUAD_FLOAT_HELPERS(float4);
-GENERIC_QUAD_FLOAT_HELPERS(float3x3);
-GENERIC_QUAD_FLOAT_HELPERS(float4x4);
-
-#define GENERIC_QUAD_INTEGER_HELPERS(T) \
-T QUAD_BITAND_HELPER(T a, T b) \
-{ \
- return a & b; \
-} \
- \
-T QUAD_BITOR_HELPER(T a, T b) \
-{ \
- return a | b; \
-} \
- \
-T QUAD_BITXOR_HELPER(T a, T b) \
-{ \
- return a ^ b; \
-}
-
-GENERIC_QUAD_INTEGER_HELPERS(uint);
-GENERIC_QUAD_INTEGER_HELPERS(uint2);
-GENERIC_QUAD_INTEGER_HELPERS(uint3);
-GENERIC_QUAD_INTEGER_HELPERS(uint4);
-GENERIC_QUAD_FLOAT_HELPERS(uint3x3);
-GENERIC_QUAD_FLOAT_HELPERS(uint4x4);
-
-uint QUAD_COUNT_BITS_HELPER(uint a, uint b)
-{
- return a + b;
-}
-
-// Generic intrinsics
-#define GENERIC_QUAD_REDUCTION(T, Name, OP) \
-T Name(T value) \
-{ \
- T topLeft, topRight, bottomLeft, bottomRight; \
- QuadReadAll(value, topLeft, topRight, bottomLeft, bottomRight); \
- return OP(OP(OP(topLeft, topRight), bottomLeft), bottomRight); \
-}
-
-#define GENERIC_QUAD_SCAN(T, Name, OP) \
-T Name(T value) \
-{ \
- T topLeft, topRight, bottomLeft, bottomRight; \
- QuadReadAll(value, topLeft, topRight, bottomLeft, bottomRight); \
- T allValues[4] = { topLeft, topRight, bottomLeft, bottomRight }; \
- \
- T prefix = 0; \
- for (int i = 0; i < QuadGetLaneID(); i++) \
- { \
- prefix = OP(prefix, allValues[i]); \
- } \
- return prefix; \
-}
-
-#define GENERIC_QUAD_FLOAT_INTRINSICS(T) \
-T QuadReadAcrossX(T value) \
-{ \
- T diff = ddx_fine(value); \
- float sign = GLOBAL_QUAD_INDEX.x == 0 ? 1 : -1; \
- return (sign * diff) + value; \
-} \
- \
-T QuadReadAcrossY(T value) \
-{ \
- T diff = ddy_fine(value); \
- float sign = GLOBAL_QUAD_INDEX.y == 0 ? 1 : -1; \
- return (sign * diff) + value; \
-} \
- \
-T QuadReadAcrossDiagonal(T value) \
-{ \
- T oppositeX = QuadReadAcrossX(value); \
- T oppositeDiagonal = QuadReadAcrossY(oppositeX); \
- return oppositeDiagonal; \
-} \
- \
-T QuadReadLaneAt(T value, uint2 quadLaneID) \
-{ \
- uint2 offset = 0; \
- bool2 correct = quadLaneID == GLOBAL_QUAD_INDEX; \
- if (all(correct)) \
- { \
- return value; \
- } \
- else if (correct.x) \
- { \
- return QuadReadAcrossY(value); \
- } \
- else if (correct.y) \
- { \
- return QuadReadAcrossX(value); \
- } \
- else \
- { \
- return QuadReadAcrossDiagonal(value); \
- } \
-} \
- \
-T QuadReadLaneAt(T value, uint quadLaneID) \
-{ \
- uint2 offset = 0; \
- return QuadReadLaneAt(value, uint2(quadLaneID & 1, (quadLaneID & 2) >> 1)); \
-} \
- \
-void QuadReadAll(T value, out T topLeft, out T topRight, out T bottomLeft, out T bottomRight) \
-{ \
- topLeft = QuadReadLaneAt(value, uint2(0, 0)); \
- topRight = QuadReadLaneAt(value, uint2(1, 0)); \
- bottomLeft = QuadReadLaneAt(value, uint2(0, 1)); \
- bottomRight = QuadReadLaneAt(value, uint2(1, 1)); \
-} \
- \
-GENERIC_QUAD_REDUCTION(T, QuadSum, QUAD_ADD_HELPER) \
-GENERIC_QUAD_REDUCTION(T, QuadProduct, mul) \
-GENERIC_QUAD_REDUCTION(T, QuadMin, min) \
-GENERIC_QUAD_REDUCTION(T, QuadMax, max) \
- \
-GENERIC_QUAD_SCAN(T, QuadPrefixSum, QUAD_ADD_HELPER) \
-GENERIC_QUAD_SCAN(T, QuadPrefixProduct, mul) \
-
-GENERIC_QUAD_FLOAT_INTRINSICS(float);
-GENERIC_QUAD_FLOAT_INTRINSICS(float2);
-GENERIC_QUAD_FLOAT_INTRINSICS(float3);
-GENERIC_QUAD_FLOAT_INTRINSICS(float4);
-GENERIC_QUAD_FLOAT_INTRINSICS(float3x3);
-GENERIC_QUAD_FLOAT_INTRINSICS(float4x4);
-
-// Generic, integer-specific intrincs
-#define GENERIC_QUAD_INTEGER_INTRINSICS(T) \
-GENERIC_QUAD_REDUCTION(T, QuadBitAnd, QUAD_BITAND_HELPER) \
-GENERIC_QUAD_REDUCTION(T, QuadBitOr, QUAD_BITOR_HELPER) \
-GENERIC_QUAD_REDUCTION(T, QuadBitXor, QUAD_BITXOR_HELPER)
-
-GENERIC_QUAD_INTEGER_INTRINSICS(uint);
-GENERIC_QUAD_INTEGER_INTRINSICS(uint2);
-GENERIC_QUAD_INTEGER_INTRINSICS(uint3);
-GENERIC_QUAD_INTEGER_INTRINSICS(uint4);
-GENERIC_QUAD_INTEGER_INTRINSICS(uint3x3);
-GENERIC_QUAD_INTEGER_INTRINSICS(uint4x4);
-
-// Monomorphic intrinsics
-bool QuadAny(bool expr)
-{
- return QuadReadLaneAt(expr, 0) || QuadReadLaneAt(expr, 1) || QuadReadLaneAt(expr, 2) || QuadReadLaneAt(expr, 3);
-}
-
-bool QuadAll(bool expr)
-{
- return QuadReadLaneAt(expr, 0) && QuadReadLaneAt(expr, 1) && QuadReadLaneAt(expr, 2) && QuadReadLaneAt(expr, 3);
-}
-
-uint4 QuadBallot(bool expr)
-{
- uint4 result;
- result.x = QuadReadLaneAt(expr ? 1 : 0, 0);
- result.y = QuadReadLaneAt(expr ? 1 : 0, 1);
- result.z = QuadReadLaneAt(expr ? 1 : 0, 2);
- result.w = QuadReadLaneAt(expr ? 1 : 0, 3);
- return result;
-}
-
-uint QuadCountBits(bool expr)
-{
- uint4 ballot = QuadBallot(expr);
- return ballot.x + ballot.y + ballot.z + ballot.w;
-}
-
-GENERIC_QUAD_SCAN(uint, QuadPrefixCountBitsHelper, QUAD_COUNT_BITS_HELPER);
-uint QuadPrefixCountBits(bool expr)
-{
- return QuadPrefixCountBitsHelper(expr ? 1 : 0);
-}
-
-// Clean up helper macros
-#undef GENERIC_QUAD_INTEGER_HELPERS
-#undef GENERIC_QUAD_FLOAT_HELPERS
-#undef GENERIC_QUAD_REDUCTION
-#undef GENERIC_QUAD_SCAN
-#undef GENERIC_QUAD_FLOAT_INTRINSICS
-#undef GENERIC_QUAD_INTEGER_INTRINSICS
-
-#endif
diff --git a/texture_macros.cginc b/texture_macros.cginc
new file mode 100644
index 0000000..c82e432
--- /dev/null
+++ b/texture_macros.cginc
@@ -0,0 +1,189 @@
+#ifndef __TEXTURE_MACROS_INC
+#define __TEXTURE_MACROS_INC
+
+#include "interpolators.cginc"
+
+float2 get_uv_by_channel(v2f i, uint which_channel) {
+ switch (which_channel) {
+ case 0:
+ return i.uv0;
+ break;
+#if !defined(_OPTIMIZE_INTERPOLATORS)
+ case 1:
+ return i.uv1;
+ break;
+#if !defined(LIGHTMAP_ON)
+ case 2:
+ return i.uv2;
+ break;
+ case 3:
+ return i.uv3;
+ break;
+ case 4:
+ return i.uv4;
+ break;
+ case 5:
+ return i.uv5;
+ break;
+ case 6:
+ return i.uv6;
+ break;
+ case 7:
+ return i.uv7;
+ break;
+#endif
+#endif // _OPTIMIZE_INTERPOLATORS
+ default:
+ return 0;
+ break;
+ }
+}
+
+#define UV_SCOFF(i, tex_st, which_channel) get_uv_by_channel(i, round(which_channel)) * (tex_st).xy + (tex_st).zw
+
+#if defined(_PBR_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_PBR linear_repeat_s
+#elif defined(_PBR_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_PBR linear_clamp_s
+#elif defined(_PBR_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_PBR point_repeat_s
+#elif defined(_PBR_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_PBR point_clamp_s
+#elif defined(_PBR_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_PBR bilinear_repeat_s
+#elif defined(_PBR_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_PBR bilinear_clamp_s
+#else
+#define GET_SAMPLER_PBR bilinear_clamp_s
+#endif
+
+#if defined(_PBR_OVERLAY0_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_OV0 linear_repeat_s
+#elif defined(_PBR_OVERLAY0_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_OV0 linear_clamp_s
+#elif defined(_PBR_OVERLAY0_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_OV0 point_repeat_s
+#elif defined(_PBR_OVERLAY0_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_OV0 point_clamp_s
+#elif defined(_PBR_OVERLAY0_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_OV0 bilinear_repeat_s
+#elif defined(_PBR_OVERLAY0_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_OV0 bilinear_clamp_s
+#else
+#define GET_SAMPLER_OV0 linear_clamp_s
+#endif
+
+#if defined(_PBR_OVERLAY1_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_OV1 linear_repeat_s
+#elif defined(_PBR_OVERLAY1_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_OV1 linear_clamp_s
+#elif defined(_PBR_OVERLAY1_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_OV1 point_repeat_s
+#elif defined(_PBR_OVERLAY1_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_OV1 point_clamp_s
+#elif defined(_PBR_OVERLAY1_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_OV1 bilinear_repeat_s
+#elif defined(_PBR_OVERLAY1_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_OV1 bilinear_clamp_s
+#else
+#define GET_SAMPLER_OV1 linear_clamp_s
+#endif
+
+#if defined(_PBR_OVERLAY2_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_OV2 linear_repeat_s
+#elif defined(_PBR_OVERLAY2_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_OV2 linear_clamp_s
+#elif defined(_PBR_OVERLAY2_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_OV2 point_repeat_s
+#elif defined(_PBR_OVERLAY2_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_OV2 point_clamp_s
+#elif defined(_PBR_OVERLAY2_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_OV2 bilinear_repeat_s
+#elif defined(_PBR_OVERLAY2_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_OV2 bilinear_clamp_s
+#else
+#define GET_SAMPLER_OV2 linear_clamp_s
+#endif
+
+#if defined(_PBR_OVERLAY3_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_OV3 linear_repeat_s
+#elif defined(_PBR_OVERLAY3_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_OV3 linear_clamp_s
+#elif defined(_PBR_OVERLAY3_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_OV3 point_repeat_s
+#elif defined(_PBR_OVERLAY3_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_OV3 point_clamp_s
+#elif defined(_PBR_OVERLAY3_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_OV3 bilinear_repeat_s
+#elif defined(_PBR_OVERLAY3_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_OV3 bilinear_clamp_s
+#else
+#define GET_SAMPLER_OV3 linear_clamp_s
+#endif
+
+#if defined(_RIM_LIGHTING0_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_RL0 linear_repeat_s
+#elif defined(_RIM_LIGHTING0_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_RL0 linear_clamp_s
+#elif defined(_RIM_LIGHTING0_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_RL0 point_repeat_s
+#elif defined(_RIM_LIGHTING0_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_RL0 point_clamp_s
+#elif defined(_RIM_LIGHTING0_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_RL0 bilinear_repeat_s
+#elif defined(_RIM_LIGHTING0_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_RL0 bilinear_clamp_s
+#else
+#define GET_SAMPLER_RL0 linear_clamp_s
+#endif
+
+#if defined(_RIM_LIGHTING1_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_RL1 linear_repeat_s
+#elif defined(_RIM_LIGHTING1_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_RL1 linear_clamp_s
+#elif defined(_RIM_LIGHTING1_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_RL1 point_repeat_s
+#elif defined(_RIM_LIGHTING1_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_RL1 point_clamp_s
+#elif defined(_RIM_LIGHTING1_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_RL1 bilinear_repeat_s
+#elif defined(_RIM_LIGHTING1_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_RL1 bilinear_clamp_s
+#else
+#define GET_SAMPLER_RL1 linear_clamp_s
+#endif
+
+#if defined(_RIM_LIGHTING2_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_RL2 linear_repeat_s
+#elif defined(_RIM_LIGHTING2_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_RL2 linear_clamp_s
+#elif defined(_RIM_LIGHTING2_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_RL2 point_repeat_s
+#elif defined(_RIM_LIGHTING2_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_RL2 point_clamp_s
+#elif defined(_RIM_LIGHTING2_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_RL2 bilinear_repeat_s
+#elif defined(_RIM_LIGHTING2_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_RL2 bilinear_clamp_s
+#else
+#define GET_SAMPLER_RL2 linear_clamp_s
+#endif
+
+#if defined(_RIM_LIGHTING3_SAMPLER_LINEAR_REPEAT)
+#define GET_SAMPLER_RL3 linear_repeat_s
+#elif defined(_RIM_LIGHTING3_SAMPLER_LINEAR_CLAMP)
+#define GET_SAMPLER_RL3 linear_clamp_s
+#elif defined(_RIM_LIGHTING3_SAMPLER_POINT_REPEAT)
+#define GET_SAMPLER_RL3 point_repeat_s
+#elif defined(_RIM_LIGHTING3_SAMPLER_POINT_CLAMP)
+#define GET_SAMPLER_RL3 point_clamp_s
+#elif defined(_RIM_LIGHTING3_SAMPLER_BILINEAR_REPEAT)
+#define GET_SAMPLER_RL3 bilinear_repeat_s
+#elif defined(_RIM_LIGHTING3_SAMPLER_BILINEAR_CLAMP)
+#define GET_SAMPLER_RL3 bilinear_clamp_s
+#else
+#define GET_SAMPLER_RL3 linear_clamp_s
+#endif
+
+#endif // __TEXTURE_MACROS_INC
+
diff --git a/tooner.shader b/tooner.shader
index 3dad795..a802100 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -827,6 +827,27 @@ Shader "yum_food/tooner"
_Gimmick_DS2_03_Period("Period", Vector) = (1, 1, 1, 1)
_Gimmick_DS2_03_Count("Count", Vector) = (1, 1, 1, 1)
_Gimmick_DS2_03_Edge_Length("Edge length", Float) = 0.1
+ // Effect 11
+ _Gimmick_DS2_11_Fog_Enable("Fog enable", Float) = 0
+ _Gimmick_DS2_11_Fog_Density("Fog density", Float) = 1
+ _Gimmick_DS2_11_Fog_Sun_Direction("Fog sun direction", Vector) = (0, 0, 0, 0)
+ _Gimmick_DS2_11_Fog_Sun_Exponent("Fog sun exponent", Float) = 1
+ [HDR] _Gimmick_DS2_11_Fog_Color("Fog color", Color) = (1, 1, 1, 1)
+ [HDR] _Gimmick_DS2_11_Fog_Sun_Color("Fog sun color", Color) = (1, 1, 1, 1)
+ _Gimmick_DS2_11_Snowline("Snowline", Float) = 1
+ _Gimmick_DS2_11_Snowline_Width("Snowline width", Float) = 0.1
+ _Gimmick_DS2_11_Snowline_Noise_Scale("Snowline noise scale", Float) = 1
+ [HDR] _Gimmick_DS2_11_Snow_Color("Snow color", Color) = (1, 1, 1, 1)
+ _Gimmick_DS2_11_Rockline("Rockline", Float) = 0
+ _Gimmick_DS2_11_Rockline_Width("Rockline width", Float) = 0.1
+ _Gimmick_DS2_11_Rockline_Noise_Scale("Rockline noise scale", Float) = 1
+ [HDR] _Gimmick_DS2_11_Rock_Color("Rock color", Color) = (1, 1, 1, 1)
+ [HDR] _Gimmick_DS2_11_Grass_Color("Grass color", Color) = (1, 1, 1, 1)
+ _Gimmick_DS2_11_Alpha("Alpha", Range(0, 1)) = 0.5
+ _Gimmick_DS2_11_XZ_Offset("XZ offset", Vector) = (0, 0, 0, 0)
+ _Gimmick_DS2_11_Distance_Culling_Enable("Distance culling enable", Float) = 0
+ _Gimmick_DS2_11_Activation_Center("Activation center", Vector) = (0, 0, 0, 0)
+ _Gimmick_DS2_11_Activation_Radius("Activation radius", Float) = 1
_Gimmick_Halo00_Enable_Static("Enable halo", Float) = 0.0
@@ -854,6 +875,9 @@ Shader "yum_food/tooner"
_Trochoid_Radius_Scale("Radius scale", Float) = 1.0
_Trochoid_Height_Scale("Height scale", Float) = 1.0
_Trochoid_Enable_Fragment_Normals("Enable fragment normals", Float) = 1.0
+ _Trochoid_Distance_Culling_Enable("Distance culling enable", Float) = 0
+ _Trochoid_Activation_Center("Activation center", Vector) = (0, 0, 0, 0)
+ _Trochoid_Activation_Radius("Activation radius", Float) = 1
_FaceMeWorldY_Enable_Static("Enable face me gimmick", Float) = 0.0
_FaceMeWorldY_Enable_Dynamic("Enable face me gimmick", Float) = 0.0
@@ -992,6 +1016,16 @@ Shader "yum_food/tooner"
_Gimmick_Fog_00_Ray_March_0_Enable_Static("enable ray march effect 0", Float) = 0
_Gimmick_Fog_00_Ray_March_0_Seed("seed", Float) = 0
+ _Gimmick_Fog_01_Enable_Static("Enable fog 01", Float) = 0
+ _Gimmick_Fog_01_Density("Density", Range(0, 1)) = 1
+ _Gimmick_Fog_01_Sun_Direction("Sun direction", Vector) = (0.866, 0.5, 0, 0)
+ _Gimmick_Fog_01_Sun_Exponent("Sun exponent", Float) = 1
+ [HDR] _Gimmick_Fog_01_Color("Color", Color) = (1, 1, 1, 1)
+ [HDR] _Gimmick_Fog_01_Sun_Color("Sun color", Color) = (1, 1, 1, 1)
+ _Gimmick_Fog_01_Distance_Culling_Enable("Distance culling enable", Float) = 0
+ _Gimmick_Fog_01_Activation_Center("Activation center", Vector) = (0, 0, 0, 0)
+ _Gimmick_Fog_01_Activation_Radius("Activation radius", Float) = 1
+
_Gimmick_Aurora_Enable_Static("Enable aurora", Float) = 0
_Gimmick_Gerstner_Water_Enable_Static("Enable water (gerstner)", Float) = 0
@@ -1138,6 +1172,7 @@ Shader "yum_food/tooner"
CGPROGRAM
#pragma target 5.0
#pragma multi_compile_instancing
+
#include "feature_macros.cginc"
#pragma vertex vert
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index 21741fa..a48a14d 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -20,7 +20,7 @@
#include "motion.cginc"
#include "oklab.cginc"
#include "pbr.cginc"
-#include "pema_quad_intrinsics.cginc"
+#include "pbr_overlay.cginc"
#include "poi.cginc"
#include "shear_math.cginc"
#include "tone.cginc"
@@ -139,35 +139,7 @@ v2f vert(appdata v)
#if defined(_TROCHOID)
{
o.objPos_pre_trochoid = v.vertex.xyz;
-//#define TROCHOID_DECOMPOSE
-#define TROCHOID_SCREEN_SPACE_NORMALS
-#if defined(TROCHOID_DECOMPOSE)
- v.vertex.xyz = cyl2_to_troch_map(cyl_to_cyl2_map(cart_to_cyl_map(v.vertex.xyz)));
- // Let h(v) be the trochoid of the cartesian coordinates v.
- // We evaluate h(v) by first mapping it to cylindrical coordinates, then applying a trochoid function defined on those coordinates:
- // h(v) = h_cyl(g(v))
- // g(v) maps v to cylindrical coordinates.
- // h_cyl(v) evaluates the trochoid function on cylindrical coordinates.
- // We want to compute h'(v), i.e. its Jacobian.
- // By the chain rule:
- // h'(v) = h_cyl'(g(v)) * g'(v)
- // The reality is a little more complex: we also apply a distortion to the cylindrical coordinates:
- // h(v) = h_cyl(f(g(v)))
- // where f(v) is that distortion.
- // Again, by the chain rule:
- // h'(v) = h_cyl'(f(g(v))) * f'(g(v)) * g'(v)
- float3x3 j0 = cart_to_cyl_jacobian(o.objPos_pre_trochoid);
- float3x3 j1 = cyl_to_cyl2_jacobian(cart_to_cyl_map(o.objPos_pre_trochoid));
- float3x3 j2 = cyl2_to_troch_jacobian(cyl_to_cyl2_map(cart_to_cyl_map(o.objPos_pre_trochoid)));
- float3x3 vector_mover = transpose(invert(mul(mul(j2, j1), j0)));
- v.normal = mul(vector_mover, v.normal);
- v.tangent.xyz = mul(vector_mover, v.tangent.xyz);
-#else
v.vertex.xyz = cart_to_troch_map(v.vertex.xyz);
- float3x3 vector_mover = transpose(invert(cart_to_troch_jacobian(o.objPos_pre_trochoid)));
- v.normal = mul(vector_mover, v.normal);
- v.tangent.xyz = mul(vector_mover, v.tangent.xyz);
-#endif
}
#endif // _TROCHOID
#if defined(_FACE_ME_WORLD_Y)
@@ -627,404 +599,6 @@ float2 matcap_distortion0(float2 matcap_uv) {
return matcap_uv;
}
-float2 get_uv_by_channel(v2f i, uint which_channel) {
- switch (which_channel) {
- case 0:
- return i.uv0;
- break;
-#if !defined(_OPTIMIZE_INTERPOLATORS)
- case 1:
- return i.uv1;
- break;
-#if !defined(LIGHTMAP_ON)
- case 2:
- return i.uv2;
- break;
- case 3:
- return i.uv3;
- break;
- case 4:
- return i.uv4;
- break;
- case 5:
- return i.uv5;
- break;
- case 6:
- return i.uv6;
- break;
- case 7:
- return i.uv7;
- break;
-#endif
-#endif // _OPTIMIZE_INTERPOLATORS
- default:
- return 0;
- break;
- }
-}
-
-#define UV_SCOFF(i, tex_st, which_channel) get_uv_by_channel(i, round(which_channel)) * (tex_st).xy + (tex_st).zw
-
-#if defined(_PBR_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_PBR linear_repeat_s
-#elif defined(_PBR_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_PBR linear_clamp_s
-#elif defined(_PBR_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_PBR point_repeat_s
-#elif defined(_PBR_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_PBR point_clamp_s
-#elif defined(_PBR_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_PBR bilinear_repeat_s
-#elif defined(_PBR_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_PBR bilinear_clamp_s
-#else
-#define GET_SAMPLER_PBR bilinear_clamp_s
-#endif
-
-#if defined(_PBR_OVERLAY0_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_OV0 linear_repeat_s
-#elif defined(_PBR_OVERLAY0_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_OV0 linear_clamp_s
-#elif defined(_PBR_OVERLAY0_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_OV0 point_repeat_s
-#elif defined(_PBR_OVERLAY0_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_OV0 point_clamp_s
-#elif defined(_PBR_OVERLAY0_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_OV0 bilinear_repeat_s
-#elif defined(_PBR_OVERLAY0_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_OV0 bilinear_clamp_s
-#else
-#define GET_SAMPLER_OV0 linear_clamp_s
-#endif
-
-#if defined(_PBR_OVERLAY1_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_OV1 linear_repeat_s
-#elif defined(_PBR_OVERLAY1_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_OV1 linear_clamp_s
-#elif defined(_PBR_OVERLAY1_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_OV1 point_repeat_s
-#elif defined(_PBR_OVERLAY1_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_OV1 point_clamp_s
-#elif defined(_PBR_OVERLAY1_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_OV1 bilinear_repeat_s
-#elif defined(_PBR_OVERLAY1_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_OV1 bilinear_clamp_s
-#else
-#define GET_SAMPLER_OV1 linear_clamp_s
-#endif
-
-#if defined(_PBR_OVERLAY2_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_OV2 linear_repeat_s
-#elif defined(_PBR_OVERLAY2_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_OV2 linear_clamp_s
-#elif defined(_PBR_OVERLAY2_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_OV2 point_repeat_s
-#elif defined(_PBR_OVERLAY2_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_OV2 point_clamp_s
-#elif defined(_PBR_OVERLAY2_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_OV2 bilinear_repeat_s
-#elif defined(_PBR_OVERLAY2_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_OV2 bilinear_clamp_s
-#else
-#define GET_SAMPLER_OV2 linear_clamp_s
-#endif
-
-#if defined(_PBR_OVERLAY3_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_OV3 linear_repeat_s
-#elif defined(_PBR_OVERLAY3_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_OV3 linear_clamp_s
-#elif defined(_PBR_OVERLAY3_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_OV3 point_repeat_s
-#elif defined(_PBR_OVERLAY3_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_OV3 point_clamp_s
-#elif defined(_PBR_OVERLAY3_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_OV3 bilinear_repeat_s
-#elif defined(_PBR_OVERLAY3_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_OV3 bilinear_clamp_s
-#else
-#define GET_SAMPLER_OV3 linear_clamp_s
-#endif
-
-#if defined(_RIM_LIGHTING0_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_RL0 linear_repeat_s
-#elif defined(_RIM_LIGHTING0_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_RL0 linear_clamp_s
-#elif defined(_RIM_LIGHTING0_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_RL0 point_repeat_s
-#elif defined(_RIM_LIGHTING0_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_RL0 point_clamp_s
-#elif defined(_RIM_LIGHTING0_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_RL0 bilinear_repeat_s
-#elif defined(_RIM_LIGHTING0_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_RL0 bilinear_clamp_s
-#else
-#define GET_SAMPLER_RL0 linear_clamp_s
-#endif
-
-#if defined(_RIM_LIGHTING1_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_RL1 linear_repeat_s
-#elif defined(_RIM_LIGHTING1_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_RL1 linear_clamp_s
-#elif defined(_RIM_LIGHTING1_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_RL1 point_repeat_s
-#elif defined(_RIM_LIGHTING1_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_RL1 point_clamp_s
-#elif defined(_RIM_LIGHTING1_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_RL1 bilinear_repeat_s
-#elif defined(_RIM_LIGHTING1_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_RL1 bilinear_clamp_s
-#else
-#define GET_SAMPLER_RL1 linear_clamp_s
-#endif
-
-#if defined(_RIM_LIGHTING2_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_RL2 linear_repeat_s
-#elif defined(_RIM_LIGHTING2_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_RL2 linear_clamp_s
-#elif defined(_RIM_LIGHTING2_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_RL2 point_repeat_s
-#elif defined(_RIM_LIGHTING2_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_RL2 point_clamp_s
-#elif defined(_RIM_LIGHTING2_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_RL2 bilinear_repeat_s
-#elif defined(_RIM_LIGHTING2_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_RL2 bilinear_clamp_s
-#else
-#define GET_SAMPLER_RL2 linear_clamp_s
-#endif
-
-#if defined(_RIM_LIGHTING3_SAMPLER_LINEAR_REPEAT)
-#define GET_SAMPLER_RL3 linear_repeat_s
-#elif defined(_RIM_LIGHTING3_SAMPLER_LINEAR_CLAMP)
-#define GET_SAMPLER_RL3 linear_clamp_s
-#elif defined(_RIM_LIGHTING3_SAMPLER_POINT_REPEAT)
-#define GET_SAMPLER_RL3 point_repeat_s
-#elif defined(_RIM_LIGHTING3_SAMPLER_POINT_CLAMP)
-#define GET_SAMPLER_RL3 point_clamp_s
-#elif defined(_RIM_LIGHTING3_SAMPLER_BILINEAR_REPEAT)
-#define GET_SAMPLER_RL3 bilinear_repeat_s
-#elif defined(_RIM_LIGHTING3_SAMPLER_BILINEAR_CLAMP)
-#define GET_SAMPLER_RL3 bilinear_clamp_s
-#else
-#define GET_SAMPLER_RL3 linear_clamp_s
-#endif
-
-struct PbrOverlay {
-#if defined(_PBR_OVERLAY0)
- float4 ov0_albedo;
-#if defined(_PBR_OVERLAY0_ROUGHNESS)
- float ov0_roughness;
-#endif
-#if defined(_PBR_OVERLAY0_METALLIC)
- float ov0_metallic;
-#endif
- float ov0_mask;
-#endif
-#if defined(_PBR_OVERLAY1)
- float4 ov1_albedo;
-#if defined(_PBR_OVERLAY1_ROUGHNESS)
- float ov1_roughness;
-#endif
-#if defined(_PBR_OVERLAY1_METALLIC)
- float ov1_metallic;
-#endif
- float ov1_mask;
-#endif
-#if defined(_PBR_OVERLAY2)
- float4 ov2_albedo;
-#if defined(_PBR_OVERLAY2_ROUGHNESS)
- float ov2_roughness;
-#endif
-#if defined(_PBR_OVERLAY2_METALLIC)
- float ov2_metallic;
-#endif
- float ov2_mask;
-#endif
-#if defined(_PBR_OVERLAY3)
- float4 ov3_albedo;
-#if defined(_PBR_OVERLAY3_ROUGHNESS)
- float ov3_roughness;
-#endif
-#if defined(_PBR_OVERLAY3_METALLIC)
- float ov3_metallic;
-#endif
- float ov3_mask;
-#endif
-};
-
-void getOverlayAlbedoRoughnessMetallic(inout PbrOverlay ov,
- v2f i)
-{
-#if defined(_PBR_OVERLAY0)
-#if defined(_PBR_OVERLAY0_BASECOLOR_MAP)
- ov.ov0_albedo = _PBR_Overlay0_BaseColorTex.SampleBias(GET_SAMPLER_OV0,
- UV_SCOFF(i, _PBR_Overlay0_BaseColorTex_ST, _PBR_Overlay0_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias);
- ov.ov0_albedo *= _PBR_Overlay0_BaseColor;
-#else
- ov.ov0_albedo = _PBR_Overlay0_BaseColor;
-#endif // _PBR_OVERLAY0_BASECOLOR_MAP
-
-#if defined(_PBR_OVERLAY0_ROUGHNESS)
-#if defined(_PBR_OVERLAY0_ROUGHNESS_MAP)
- ov.ov0_roughness = _PBR_Overlay0_RoughnessTex.SampleBias(GET_SAMPLER_OV0,
- UV_SCOFF(i, _PBR_Overlay0_RoughnessTex_ST, _PBR_Overlay0_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias);
- ov.ov0_roughness *= _PBR_Overlay0_Roughness;
-#else
- ov.ov0_roughness = _PBR_Overlay0_Roughness;
-#endif // _PBR_OVERLAY0_ROUGHNESS_MAP
-#endif
-
-#if defined(_PBR_OVERLAY0_METALLIC)
-#if defined(_PBR_OVERLAY0_METALLIC_MAP)
- ov.ov0_metallic = _PBR_Overlay0_MetallicTex.SampleBias(GET_SAMPLER_OV0,
- UV_SCOFF(i, _PBR_Overlay0_MetallicTex_ST, _PBR_Overlay0_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias);
- ov.ov0_metallic *= _PBR_Overlay0_Metallic;
-#else
- ov.ov0_metallic = _PBR_Overlay0_Metallic;
-#endif // _PBR_OVERLAY0_METALLIC_MAP
-#endif
-
-#if defined(_PBR_OVERLAY0_MASK)
- ov.ov0_mask = _PBR_Overlay0_Mask.SampleLevel(GET_SAMPLER_OV0,
- UV_SCOFF(i, _PBR_Overlay0_Mask_ST, _PBR_Overlay0_UV_Select),
- get_uv_by_channel(i, _PBR_Overlay0_UV_Select), 0);
- ov.ov0_mask = ((bool) round(_PBR_Overlay0_Mask_Invert)) ? 1.0 - ov.ov0_mask : ov.ov0_mask;
-#else
- ov.ov0_mask = 1;
-#endif
- ov.ov0_albedo.a *= ov.ov0_mask;
-#endif // _PBR_OVERLAY0
-
-#if defined(_PBR_OVERLAY1)
-#if defined(_PBR_OVERLAY1_BASECOLOR_MAP)
- ov.ov1_albedo = _PBR_Overlay1_BaseColorTex.SampleBias(GET_SAMPLER_OV1,
- UV_SCOFF(i, _PBR_Overlay1_BaseColorTex_ST, _PBR_Overlay1_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias);
- ov.ov1_albedo *= _PBR_Overlay1_BaseColor;
-#else
- ov.ov1_albedo = _PBR_Overlay1_BaseColor;
-#endif // _PBR_OVERLAY1_BASECOLOR_MAP
-
-#if defined(_PBR_OVERLAY1_ROUGHNESS)
-#if defined(_PBR_OVERLAY1_ROUGHNESS_MAP)
- ov.ov1_roughness = _PBR_Overlay1_RoughnessTex.SampleBias(GET_SAMPLER_OV1,
- UV_SCOFF(i, _PBR_Overlay1_RoughnessTex_ST, _PBR_Overlay1_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias);
- ov.ov1_roughness *= _PBR_Overlay1_Roughness;
-#else
- ov.ov1_roughness = _PBR_Overlay1_Roughness;
-#endif // _PBR_OVERLAY1_ROUGHNESS_MAP
-#endif
-
-#if defined(_PBR_OVERLAY1_METALLIC)
-#if defined(_PBR_OVERLAY1_METALLIC_MAP)
- ov.ov1_metallic = _PBR_Overlay1_MetallicTex.SampleBias(GET_SAMPLER_OV1,
- UV_SCOFF(i, _PBR_Overlay1_MetallicTex_ST, _PBR_Overlay1_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias);
- ov.ov1_metallic *= _PBR_Overlay1_Metallic;
-#else
- ov.ov1_metallic = _PBR_Overlay1_Metallic;
-#endif // _PBR_OVERLAY1_METALLIC_MAP
-#endif
-
-#if defined(_PBR_OVERLAY1_MASK)
- ov.ov1_mask = _PBR_Overlay1_Mask.SampleLevel(GET_SAMPLER_OV1,
- UV_SCOFF(i, _PBR_Overlay1_Mask_ST, _PBR_Overlay1_UV_Select), 0);
- ov.ov1_mask = ((bool) round(_PBR_Overlay1_Mask_Invert)) ? 1.0 - ov.ov1_mask : ov.ov1_mask;
-#else
- ov.ov1_mask = 1;
-#endif
- ov.ov1_albedo.a *= ov.ov1_mask;
-#endif // _PBR_OVERLAY1
-
-#if defined(_PBR_OVERLAY2)
-#if defined(_PBR_OVERLAY2_BASECOLOR_MAP)
- ov.ov2_albedo = _PBR_Overlay2_BaseColorTex.SampleBias(GET_SAMPLER_OV2,
- UV_SCOFF(i, _PBR_Overlay2_BaseColorTex_ST, _PBR_Overlay2_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias);
- ov.ov2_albedo *= _PBR_Overlay2_BaseColor;
-#else
- ov.ov2_albedo = _PBR_Overlay2_BaseColor;
-#endif // _PBR_OVERLAY2_BASECOLOR_MAP
-
-#if defined(_PBR_OVERLAY2_ROUGHNESS)
-#if defined(_PBR_OVERLAY2_ROUGHNESS_MAP)
- ov.ov2_roughness = _PBR_Overlay2_RoughnessTex.SampleBias(GET_SAMPLER_OV2,
- UV_SCOFF(i, _PBR_Overlay2_RoughnessTex_ST, _PBR_Overlay2_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias);
- ov.ov2_roughness *= _PBR_Overlay2_Roughness;
-#else
- ov.ov2_roughness = _PBR_Overlay2_Roughness;
-#endif // _PBR_OVERLAY2_ROUGHNESS_MAP
-#endif
-
-#if defined(_PBR_OVERLAY2_METALLIC)
-#if defined(_PBR_OVERLAY2_METALLIC_MAP)
- ov.ov2_metallic = _PBR_Overlay2_MetallicTex.SampleBias(GET_SAMPLER_OV2,
- UV_SCOFF(i, _PBR_Overlay2_MetallicTex_ST, _PBR_Overlay2_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias);
- ov.ov2_metallic *= _PBR_Overlay2_Metallic;
-#else
- ov.ov2_metallic = _PBR_Overlay2_Metallic;
-#endif // _PBR_OVERLAY2_METALLIC_MAP
-#endif
-
-#if defined(_PBR_OVERLAY2_MASK)
- ov.ov2_mask = _PBR_Overlay2_Mask.SampleLevel(GET_SAMPLER_OV2,
- UV_SCOFF(i, _PBR_Overlay2_Mask_ST, _PBR_Overlay2_UV_Select), 0);
- ov.ov2_mask = ((bool) round(_PBR_Overlay2_Mask_Invert)) ? 1.0 - ov.ov2_mask : ov.ov2_mask;
-#else
- ov.ov2_mask = 1;
-#endif
- ov.ov2_albedo.a *= ov.ov2_mask;
-#endif // _PBR_OVERLAY2
-
-#if defined(_PBR_OVERLAY3)
-#if defined(_PBR_OVERLAY3_BASECOLOR_MAP)
- ov.ov3_albedo = _PBR_Overlay3_BaseColorTex.SampleBias(GET_SAMPLER_OV3,
- UV_SCOFF(i, _PBR_Overlay3_BaseColorTex_ST, _PBR_Overlay3_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias);
- ov.ov3_albedo *= _PBR_Overlay3_BaseColor;
-#else
- ov.ov3_albedo = _PBR_Overlay3_BaseColor;
-#endif // _PBR_OVERLAY3_BASECOLOR_MAP
-
-#if defined(_PBR_OVERLAY3_ROUGHNESS)
-#if defined(_PBR_OVERLAY3_ROUGHNESS_MAP)
- ov.ov3_roughness = _PBR_Overlay3_RoughnessTex.SampleBias(GET_SAMPLER_OV3,
- UV_SCOFF(i, _PBR_Overlay3_RoughnessTex_ST, _PBR_Overlay3_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias);
- ov.ov3_roughness *= _PBR_Overlay3_Roughness;
-#else
- ov.ov3_roughness = _PBR_Overlay3_Roughness;
-#endif // _PBR_OVERLAY3_ROUGHNESS_MAP
-#endif
-
-#if defined(_PBR_OVERLAY3_METALLIC)
-#if defined(_PBR_OVERLAY3_METALLIC_MAP)
- ov.ov3_metallic = _PBR_Overlay3_MetallicTex.SampleBias(GET_SAMPLER_OV3,
- UV_SCOFF(i, _PBR_Overlay3_MetallicTex_ST, _PBR_Overlay3_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias);
- ov.ov3_metallic *= _PBR_Overlay3_Metallic;
-#else
- ov.ov3_metallic = _PBR_Overlay3_Metallic;
-#endif // _PBR_OVERLAY3_METALLIC_MAP
-#endif
-
-#if defined(_PBR_OVERLAY3_MASK)
- ov.ov3_mask = _PBR_Overlay3_Mask.SampleLevel(GET_SAMPLER_OV3,
- UV_SCOFF(i, _PBR_Overlay3_Mask_ST, _PBR_Overlay3_UV_Select), 0);
- ov.ov3_mask = ((bool) round(_PBR_Overlay3_Mask_Invert)) ? 1.0 - ov.ov3_mask : ov.ov3_mask;
-#else
- ov.ov3_mask = 1;
-#endif
- ov.ov3_albedo.a *= ov.ov3_mask;
-#endif // _PBR_OVERLAY3
-}
-
struct DecalParams {
float4 color;
texture2D tex;
@@ -1325,246 +899,6 @@ void applyDecal(inout float4 albedo,
#endif
}
-void mixOverlayAlbedoRoughnessMetallic(inout float4 albedo,
- inout float roughness, inout float metallic, PbrOverlay ov,
- float mask, out float glitter_mask) {
- glitter_mask = 1;
- // Calculate alpha masks before we start mutating alpha.
-#if defined(_PBR_OVERLAY0)
- float a0 = saturate(ov.ov0_albedo.a * _PBR_Overlay0_Alpha_Multiplier);
- if (_PBR_Overlay0_Constrain_By_Alpha) {
- bool in_range = (albedo.a > _PBR_Overlay0_Constrain_By_Alpha_Min) *
- (albedo.a < _PBR_Overlay0_Constrain_By_Alpha_Max);
- a0 *= in_range;
- }
- a0 *= mask;
- a0 *= ov.ov0_mask;
- glitter_mask *= 1 - a0 * _PBR_Overlay0_Mask_Glitter;
-#endif
-#if defined(_PBR_OVERLAY1)
- float a1 = saturate(ov.ov1_albedo.a * _PBR_Overlay1_Alpha_Multiplier);
- if (_PBR_Overlay1_Constrain_By_Alpha) {
- bool in_range = (albedo.a > _PBR_Overlay1_Constrain_By_Alpha_Min) *
- (albedo.a < _PBR_Overlay1_Constrain_By_Alpha_Max);
- a1 *= in_range;
- }
- a1 *= mask;
- a1 *= ov.ov1_mask;
- glitter_mask *= 1 - a1 * _PBR_Overlay1_Mask_Glitter;
-#endif
-#if defined(_PBR_OVERLAY2)
- float a2 = saturate(ov.ov2_albedo.a * _PBR_Overlay2_Alpha_Multiplier);
- if (_PBR_Overlay2_Constrain_By_Alpha) {
- bool in_range = (albedo.a > _PBR_Overlay2_Constrain_By_Alpha_Min) *
- (albedo.a < _PBR_Overlay2_Constrain_By_Alpha_Max);
- a2 *= in_range;
- }
- a2 *= mask;
- a2 *= ov.ov2_mask;
- glitter_mask *= 1 - a2 * _PBR_Overlay2_Mask_Glitter;
-#endif
-#if defined(_PBR_OVERLAY3)
- float a3 = saturate(ov.ov3_albedo.a * _PBR_Overlay3_Alpha_Multiplier);
- if (_PBR_Overlay3_Constrain_By_Alpha) {
- bool in_range = (albedo.a > _PBR_Overlay3_Constrain_By_Alpha_Min) *
- (albedo.a < _PBR_Overlay3_Constrain_By_Alpha_Max);
- a3 *= in_range;
- }
- a3 *= mask;
- a3 *= ov.ov3_mask;
- glitter_mask *= 1 - a3 * _PBR_Overlay3_Mask_Glitter;
-#endif
-
-#if defined(_PBR_OVERLAY0)
-#if defined(_PBR_OVERLAY0_MIX_ALPHA_BLEND)
- albedo.rgb = lerp(albedo.rgb, ov.ov0_albedo.rgb, a0);
-#if defined(_PBR_OVERLAY0_ROUGHNESS)
- roughness = lerp(roughness, ov.ov0_roughness, a0);
-#endif
-#if defined(_PBR_OVERLAY0_METALLIC)
- metallic = lerp(metallic, ov.ov0_metallic, a0);
-#endif
- albedo.a = max(albedo.a, a0);
-#elif defined(_PBR_OVERLAY0_MIX_ADD)
- albedo.rgb += ov.ov0_albedo * mask * ov.ov0_mask;
-#elif defined(_PBR_OVERLAY0_MIX_MIN)
- albedo.rgb = lerp(albedo.rgb, min(albedo.rgb, ov.ov0_albedo), mask * ov.ov0_mask);
-#elif defined(_PBR_OVERLAY0_MIX_MAX)
- albedo.rgb = max(albedo.rgb, ov.ov0_albedo * mask * ov.ov0_mask);
-#elif defined(_PBR_OVERLAY0_MIX_MULTIPLY)
- albedo.rgb = lerp(albedo.rgb, albedo.rgb * ov.ov0_albedo, mask * ov.ov0_mask);
-#endif
-#endif
-
-#if defined(_PBR_OVERLAY1)
-#if defined(_PBR_OVERLAY1_MIX_ALPHA_BLEND)
- albedo.rgb = lerp(albedo.rgb, ov.ov1_albedo.rgb, a1);
-#if defined(_PBR_OVERLAY1_ROUGHNESS)
- roughness = lerp(roughness, ov.ov1_roughness, a1);
-#endif
-#if defined(_PBR_OVERLAY1_METALLIC)
- metallic = lerp(metallic, ov.ov1_metallic, a1);
-#endif
- albedo.a = max(albedo.a, a1);
-#elif defined(_PBR_OVERLAY1_MIX_ADD)
- albedo.rgb += ov.ov1_albedo * mask * ov.ov1_mask;
-#elif defined(_PBR_OVERLAY1_MIX_MIN)
- albedo.rgb = lerp(albedo.rgb, min(albedo.rgb, ov.ov1_albedo), mask * ov.ov1_mask);
-#elif defined(_PBR_OVERLAY1_MIX_MAX)
- albedo.rgb = max(albedo.rgb, ov.ov1_albedo * mask * ov.ov1_mask);
-#elif defined(_PBR_OVERLAY1_MIX_MULTIPLY)
- albedo.rgb = lerp(albedo.rgb, albedo.rgb * ov.ov1_albedo, mask * ov.ov1_mask);
-#endif
-#endif
-
-#if defined(_PBR_OVERLAY2)
-#if defined(_PBR_OVERLAY2_MIX_ALPHA_BLEND)
- albedo.rgb = lerp(albedo.rgb, ov.ov2_albedo.rgb, a2);
-#if defined(_PBR_OVERLAY2_ROUGHNESS)
- roughness = lerp(roughness, ov.ov2_roughness, a2);
-#endif
-#if defined(_PBR_OVERLAY2_METALLIC)
- metallic = lerp(metallic, ov.ov2_metallic, a2);
-#endif
- albedo.a = max(albedo.a, a2);
-#elif defined(_PBR_OVERLAY2_MIX_ADD)
- albedo.rgb += ov.ov2_albedo * mask * ov.ov2_mask;
-#elif defined(_PBR_OVERLAY2_MIX_MIN)
- albedo.rgb = lerp(albedo.rgb, min(albedo.rgb, ov.ov2_albedo), mask * ov.ov2_mask);
-#elif defined(_PBR_OVERLAY2_MIX_MAX)
- albedo.rgb = max(albedo.rgb, ov.ov2_albedo * mask * ov.ov2_mask);
-#elif defined(_PBR_OVERLAY2_MIX_MULTIPLY)
- albedo.rgb = lerp(albedo.rgb, albedo.rgb * ov.ov2_albedo, mask * ov.ov2_mask);
-#endif
-#endif
-
-#if defined(_PBR_OVERLAY3)
-#if defined(_PBR_OVERLAY3_MIX_ALPHA_BLEND)
- albedo.rgb = lerp(albedo.rgb, ov.ov3_albedo.rgb, a3);
-#if defined(_PBR_OVERLAY3_ROUGHNESS)
- roughness = lerp(roughness, ov.ov3_roughness, a3);
-#endif
-#if defined(_PBR_OVERLAY3_METALLIC)
- metallic = lerp(metallic, ov.ov3_metallic, a3);
-#endif
- albedo.a = max(albedo.a, a3);
-#elif defined(_PBR_OVERLAY3_MIX_ADD)
- albedo.rgb += ov.ov3_albedo * mask * ov.ov3_mask;
-#elif defined(_PBR_OVERLAY3_MIX_MIN)
- albedo.rgb = lerp(albedo.rgb, min(albedo.rgb, ov.ov3_albedo), mask * ov.ov3_mask);
-#elif defined(_PBR_OVERLAY3_MIX_MAX)
- albedo.rgb = max(albedo.rgb, ov.ov3_albedo * mask * ov.ov3_mask);
-#elif defined(_PBR_OVERLAY3_MIX_MULTIPLY)
- albedo.rgb = lerp(albedo.rgb, albedo.rgb * ov.ov3_albedo, mask * ov.ov3_mask);
-#endif
-#endif
-}
-
-void applyOverlayNormal(inout float3 raw_normal, float4 albedo, PbrOverlay ov, v2f i)
-{
- float3 raw_normal_2;
-#if defined(_PBR_OVERLAY0) && defined(_PBR_OVERLAY0_NORMAL_MAP)
- float a0 = 1;
- if (_PBR_Overlay0_Constrain_By_Alpha) {
- bool in_range = (albedo.a > _PBR_Overlay0_Constrain_By_Alpha_Min) *
- (albedo.a < _PBR_Overlay0_Constrain_By_Alpha_Max);
- a0 *= in_range;
- }
- // Use UVs to smoothly blend between fully detailed normals when close up and
- // flat normals when far away. If we don't do this, then we see moire effects
- // on e.g. striped normal maps.
- raw_normal_2 = UnpackScaleNormal(_PBR_Overlay0_NormalTex.SampleBias(GET_SAMPLER_OV0,
- UV_SCOFF(i, _PBR_Overlay0_NormalTex_ST, _PBR_Overlay0_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias),
- _PBR_Overlay0_Tex_NormalStr * ov.ov0_mask * a0);
-
- raw_normal = BlendNormals(
- raw_normal,
- raw_normal_2);
-#endif // _PBR_OVERLAY0 && _PBR_OVERLAY0_NORMAL_MAP
-#if defined(_PBR_OVERLAY1) && defined(_PBR_OVERLAY1_NORMAL_MAP)
- float a1 = 1;
- if (_PBR_Overlay1_Constrain_By_Alpha) {
- bool in_range = (albedo.a > _PBR_Overlay1_Constrain_By_Alpha_Min) *
- (albedo.a < _PBR_Overlay1_Constrain_By_Alpha_Max);
- a1 *= in_range;
- }
- raw_normal_2 = UnpackScaleNormal(_PBR_Overlay1_NormalTex.SampleBias(GET_SAMPLER_OV1,
- UV_SCOFF(i, _PBR_Overlay1_NormalTex_ST, _PBR_Overlay1_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias),
- _PBR_Overlay1_Tex_NormalStr * ov.ov1_mask * a1);
-
- raw_normal = BlendNormals(
- raw_normal,
- raw_normal_2);
-#endif // _PBR_OVERLAY1 && _PBR_OVERLAY1_NORMAL_MAP
-#if defined(_PBR_OVERLAY2) && defined(_PBR_OVERLAY2_NORMAL_MAP)
- float a2 = 1;
- if (_PBR_Overlay2_Constrain_By_Alpha) {
- bool in_range = (albedo.a > _PBR_Overlay2_Constrain_By_Alpha_Min) *
- (albedo.a < _PBR_Overlay2_Constrain_By_Alpha_Max);
- a2 *= in_range;
- }
- raw_normal_2 = UnpackScaleNormal(_PBR_Overlay2_NormalTex.SampleBias(GET_SAMPLER_OV2,
- UV_SCOFF(i, _PBR_Overlay2_NormalTex_ST, _PBR_Overlay2_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias),
- _PBR_Overlay2_Tex_NormalStr * ov.ov2_mask * a2);
-
- raw_normal = BlendNormals(
- raw_normal,
- raw_normal_2);
-#endif // _PBR_OVERLAY2 && _PBR_OVERLAY2_NORMAL_MAP
-#if defined(_PBR_OVERLAY3) && defined(_PBR_OVERLAY3_NORMAL_MAP)
- float a3 = 1;
- if (_PBR_Overlay3_Constrain_By_Alpha) {
- bool in_range = (albedo.a > _PBR_Overlay3_Constrain_By_Alpha_Min) *
- (albedo.a < _PBR_Overlay3_Constrain_By_Alpha_Max);
- a3 *= in_range;
- }
- raw_normal_2 = UnpackScaleNormal(_PBR_Overlay3_NormalTex.SampleBias(GET_SAMPLER_OV3,
- UV_SCOFF(i, _PBR_Overlay3_NormalTex_ST, _PBR_Overlay3_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias),
- _PBR_Overlay3_Tex_NormalStr * ov.ov3_mask * a3);
-
- raw_normal = BlendNormals(
- raw_normal,
- raw_normal_2);
-#endif // _PBR_OVERLAY3 && _PBR_OVERLAY3_NORMAL_MAP
-}
-
-float3 getOverlayEmission(PbrOverlay ov, v2f i)
-{
- float3 em = 0;
-#if defined(_PBR_OVERLAY0_EMISSION_MAP)
- em += _PBR_Overlay0_EmissionTex.SampleBias(GET_SAMPLER_OV0,
- UV_SCOFF(i, _PBR_Overlay0_EmissionTex_ST, _PBR_Overlay0_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay0_Mip_Bias) *
- _PBR_Overlay0_Emission * ov.ov0_mask;
-#endif
-
-#if defined(_PBR_OVERLAY1_EMISSION_MAP)
- em += _PBR_Overlay1_EmissionTex.SampleBias(GET_SAMPLER_OV1,
- UV_SCOFF(i, _PBR_Overlay1_EmissionTex_ST, _PBR_Overlay1_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay1_Mip_Bias) *
- _PBR_Overlay1_Emission * ov.ov1_mask;
-#endif
-
-#if defined(_PBR_OVERLAY2_EMISSION_MAP)
- em += _PBR_Overlay2_EmissionTex.SampleBias(GET_SAMPLER_OV2,
- UV_SCOFF(i, _PBR_Overlay2_EmissionTex_ST, _PBR_Overlay2_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay2_Mip_Bias) *
- _PBR_Overlay2_Emission * ov.ov2_mask;
-#endif
-
-#if defined(_PBR_OVERLAY3_EMISSION_MAP)
- em += _PBR_Overlay3_EmissionTex.SampleBias(GET_SAMPLER_OV3,
- UV_SCOFF(i, _PBR_Overlay3_EmissionTex_ST, _PBR_Overlay3_UV_Select),
- _Global_Sample_Bias + _PBR_Overlay3_Mip_Bias) *
- _PBR_Overlay3_Emission * ov.ov3_mask;
-#endif
- return em;
-}
-
#if defined(_PIXELLATE)
float2 pixellate_uv(int2 px_res, float2 uv)
{
@@ -1615,7 +949,7 @@ float4 effect(inout v2f i, out float depth)
depth = 0;
#endif
-#if defined(TROCHOID_SCREEN_SPACE_NORMALS)
+#if defined(_TROCHOID)
{
float3 my_pos;
[branch]
@@ -1624,15 +958,10 @@ float4 effect(inout v2f i, out float depth)
} else {
my_pos = i.objPos.xyz;
}
- float3 neighbor_x = QuadReadAcrossX(my_pos);
- float3 neighbor_y = QuadReadAcrossY(my_pos);
- uint2 lane_pos = QuadGetLaneID();
- float x_sign = (lane_pos == 1 || lane_pos == 3) ? 1 : -1;
- float y_sign = (lane_pos == 0 || lane_pos == 1) ? 1 : -1;
- float3 tan1 = (neighbor_x - my_pos) * x_sign;
- float3 tan2 = (neighbor_y - my_pos) * y_sign;
+ float3 tan1 = ddx(my_pos);
+ float3 tan2 = ddy(my_pos);
float3 normal = cross(tan1, tan2);
- i.normal = UnityObjectToWorldNormal(normal);
+ i.normal = -UnityObjectToWorldNormal(normal);
i.tangent.xyz = UnityObjectToWorldDir(tan1);
}
#endif
@@ -2036,9 +1365,15 @@ float4 effect(inout v2f i, out float depth)
float ar = rand2(i.uv0);
clip(albedo.a - ar);
#elif defined(_RENDERING_CUTOUT_IGN)
+ float frame = 0;
+ if (AudioLinkIsAvailable()) {
+ frame = ((float) AudioLinkData(ALPASS_GENERALVU + int2(1, 0)).x);
+ } else {
+ frame = floor(_Frame_Counter);
+ }
float ar = ign_anim(
floor(tdata.screen_uv_round * _Rendering_Cutout_Noise_Scale) + _Rendering_Cutout_Ign_Seed,
- floor(_Frame_Counter), _Rendering_Cutout_Ign_Speed);
+ frame, _Rendering_Cutout_Ign_Speed);
clip(albedo.a - ar);
#elif defined(_RENDERING_CUTOUT_NOISE_MASK)
float ar = _Rendering_Cutout_Noise_Mask.SampleLevel(point_repeat_s, tdata.screen_uv * _ScreenParams.xy * _Rendering_Cutout_Noise_Mask_TexelSize.xy, 0);
@@ -2758,6 +2093,17 @@ float4 effect(inout v2f i, out float depth)
return albedo;
}
#endif
+#if defined(_GIMMICK_FOG_01)
+ {
+ Fog01PBR pbr = getFog01(i, tdata);
+ albedo = pbr.albedo;
+ depth = pbr.depth;
+#if defined(_RENDERING_TRANSPARENT) || defined(_RENDERING_TRANSCLIPPING)
+ albedo.rgb *= albedo.a;
+#endif
+ return albedo;
+ }
+#endif
#if defined(_GIMMICK_AURORA)
{
AuroraPBR pbr = getAurora(i);
@@ -2809,6 +2155,9 @@ float4 effect(inout v2f i, out float depth)
case 10:
ds2 = Gimmick_DS2_10(i);
break;
+ case 11:
+ ds2 = Gimmick_DS2_11(i, tdata);
+ break;
default:
ds2 = (Gimmick_DS2_Output)0;
break;
@@ -2857,6 +2206,7 @@ float4 effect(inout v2f i, out float depth)
result.rgb += glitter_color_unlit * _Glitter_Brightness;
#endif
#if defined(_GIMMICK_DS2)
+ result = ds2.fog + result * (1 - ds2.fog.a);
result.rgb += ds2.emission * _Gimmick_DS2_Emission_Factor * ds2_mask;
#endif
@@ -2927,8 +2277,6 @@ fixed4 frag(v2f i
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
- SETUP_QUAD_INTRINSICS(i.pos);
-
/*
#if defined(_TROCHOID)
float3x3 vector_mover = cyl2_to_troch_jacobian(i.objPos_pre_trochoid);
diff --git a/trochoid_math.cginc b/trochoid_math.cginc
index 82daf9c..bae5e01 100644
--- a/trochoid_math.cginc
+++ b/trochoid_math.cginc
@@ -17,9 +17,14 @@ float3 cyl2_to_troch_map(float3 v)
const float d = _Trochoid_d;
const float rrrr = (R - r) * R / r;
- float rr_gcd = gcd(round(R), round(r));
+#if 1
+ float rr_gcd = gcd(abs(round(R)), abs(round(r)));
float rr_lcm = (R * r) / rr_gcd;
float rr_lcm_factor = rr_lcm / R;
+#else
+ float rr_lcm_factor = r;
+#endif
+
float toff = _Time[0] * _Trochoid_Speed;
float x =
@@ -39,7 +44,8 @@ float3 cyl2_to_troch_map(float3 v)
float3 cyl_to_cyl2_map(float3 v)
{
- return float3(v.x * .5, pow(v.y, _Trochoid_Radius_Power) * _Trochoid_Radius_Scale, v.z * _Trochoid_Height_Scale);
+ float power_scale = pow(100, _Trochoid_Radius_Power - 1);
+ return float3(v.x * .5, pow(v.y, _Trochoid_Radius_Power) * _Trochoid_Radius_Scale * power_scale, v.z * _Trochoid_Height_Scale);
}
float3 cart_to_cyl_map(float3 v)
@@ -49,6 +55,18 @@ float3 cart_to_cyl_map(float3 v)
float3 cart_to_troch_map(float3 v)
{
+ [branch]
+ if (_Trochoid_Distance_Culling_Enable) {
+ float3 activation_center = _Trochoid_Activation_Center;
+ float activation_radius = _Trochoid_Activation_Radius;
+ float cur_radius = length(_WorldSpaceCameraPos - activation_center);
+ [branch]
+ //if (cur_radius > activation_radius) {
+ if (_WorldSpaceCameraPos.y > activation_center.y + activation_radius) {
+ return v;
+ }
+ }
+
return cyl2_to_troch_map(cyl_to_cyl2_map(cart_to_cyl_map(v)));
}
@@ -69,9 +87,14 @@ float3x3 cyl2_to_troch_jacobian(float3 v)
const float d = _Trochoid_d;
const float rrrr = (R - r) * R / r;
- float rr_gcd = gcd(round(R), round(r));
+#if 1
+ float rr_gcd = gcd(abs(round(R)), abs(round(r)));
float rr_lcm = (R * r) / rr_gcd;
float rr_lcm_factor = rr_lcm / R;
+#else
+ float rr_lcm_factor = r;
+#endif
+
float toff = _Time[0] * _Trochoid_Speed;
#if 1