summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x3ner.shader9
-rwxr-xr-xfeatures.cginc2
-rwxr-xr-xglobals.cginc5
-rwxr-xr-xlighting.cginc10
-rwxr-xr-xmath.cginc8
5 files changed, 31 insertions, 3 deletions
diff --git a/3ner.shader b/3ner.shader
index 1d10d40..1369c18 100755
--- a/3ner.shader
+++ b/3ner.shader
@@ -728,8 +728,13 @@ Shader "yum_food/3ner"
_Glitter_Base_Roughness_Override("Base Roughness Override", Range(0, 1)) = 0.5
[HideInInspector] m_end_Glitter_Base_Roughness_Override("Base Roughness Override", Float) = 0
//endex
- [HideInInspector] m_end_Glitter("Glitter", Float) = 0
- //endex
+
+ //ifex _Glitter_Normal_Override_Enabled==0
+ [HideInInspector] m_start_Glitter_Normal_Override("Normal Override", Float) = 0
+ [ThryToggle(_GLITTER_NORMAL_OVERRIDE)] _Glitter_Normal_Override_Enabled("Enable", Float) = 0
+ _Glitter_Normal_Override("Normal override (object space)", 2D) = "bump" {}
+ [HideInInspector] m_end_Glitter_Normal_Override("Normal Override", Float) = 0
+ //endex
//ifex _Parallax_Heightmap_Enabled==0
[HideInInspector] m_start_Parallax_Heightmap("Parallax Heightmap", Float) = 0
diff --git a/features.cginc b/features.cginc
index 4a833b8..5d560a6 100755
--- a/features.cginc
+++ b/features.cginc
@@ -75,6 +75,8 @@
#pragma shader_feature_local _GLITTER
#pragma shader_feature_local _GLITTER_MASK
#pragma shader_feature_local _GLITTER_BASE_ROUGHNESS_OVERRIDE
+#pragma shader_feature_local _GLITTER_NORMAL_OVERRIDE
+
//endex
//ifex _Vertex_Deformation_Enabled==0
diff --git a/globals.cginc b/globals.cginc
index bf2f2be..af0f367 100755
--- a/globals.cginc
+++ b/globals.cginc
@@ -174,6 +174,11 @@ float4 _Glitter_Mask_ST;
float _Glitter_Base_Roughness_Override;
#endif // _GLITTER_BASE_ROUGHNESS_OVERRIDE
+#if defined(_GLITTER_NORMAL_OVERRIDE)
+texture2D _Glitter_Normal_Override;
+float4 _Glitter_Normal_Override_ST;
+#endif // _GLITTER_NORMAL_OVERRIDE
+
#if defined(_UV_SCROLL)
float2 _UV_Scroll_Speed;
#endif // _UV_SCROLL
diff --git a/lighting.cginc b/lighting.cginc
index 4330562..8642c1d 100755
--- a/lighting.cginc
+++ b/lighting.cginc
@@ -285,9 +285,17 @@ void GetLighting(v2f i, Pbr pbr, out LightData data) {
#else
float glitter_roughness = pbr.roughness;
#endif
+#if defined(_GLITTER_NORMAL_OVERRIDE)
+ float3 glitter_normal = _Glitter_Normal_Override.Sample(bilinear_clamp_s, i.uv01.xy) * 2 - 1;
+ glitter_normal = glitter_normal.xzy * float3(-1, 1, -1);
+ float3x3 tbn = tbn_from_normal_tangent(glitter_normal, i.tangent);
+#else
+ float3 glitter_normal = pbr.normal;
+ float3x3 tbn = pbr.tbn;
+#endif
data.glitter = GetGlitterLighting(
_Glitter_Amount, _Glitter_Roughness, _Glitter_Angular_Cells,
- _Glitter_Filter_Size, UV_SCOFF(i, _Glitter_Mask_ST, _Glitter_UV_Channel), pbr.tbn, glitter_roughness, pbr.normal,
+ _Glitter_Filter_Size, UV_SCOFF(i, _Glitter_Mask_ST, _Glitter_UV_Channel), tbn, glitter_roughness, glitter_normal,
data.common.V, data.direct.H, glitter_indirect_dir);
#endif
diff --git a/math.cginc b/math.cginc
index 0692440..270ca15 100755
--- a/math.cginc
+++ b/math.cginc
@@ -334,4 +334,12 @@ float3 srgb_to_linear(float3 srgb_color) {
return lerp(lo, hi, step(0.04045f, srgb_color));
}
+float3x3 tbn_from_normal_tangent(float3 normal, float4 tangent) {
+ float3 n = normal;
+ float3 t = tangent.xyz;
+ t = normalize(t - n * dot(n, t)); // Gram-Schmidt to avoid skew
+ float3 b = normalize(cross(n, t)) * tangent.w;
+ return float3x3(t, b, n);
+}
+
#endif // __MATH_INC