summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--2ner.cginc21
-rw-r--r--2ner.shader8
-rw-r--r--features.cginc4
-rw-r--r--globals.cginc5
4 files changed, 38 insertions, 0 deletions
diff --git a/2ner.cginc b/2ner.cginc
index e814fd8..f0efe83 100644
--- a/2ner.cginc
+++ b/2ner.cginc
@@ -64,7 +64,28 @@ v2f vert(appdata v) {
v.tangent.xyz = tangent_tmp;
#endif
+#if defined(_FOCAL_LENGTH_CONTROL)
+ UNITY_BRANCH
+ if (_Focal_Length_Enabled_Dynamic) {
+ float4 fl_worldPos_unscaled = mul(unity_ObjectToWorld, v.vertex);
+ float4 fl_viewPos_unscaled = mul(UNITY_MATRIX_V, fl_worldPos_unscaled);
+
+ float4 fl_objPos = float4(v.vertex.xyz * _Focal_Length_Multiplier, v.vertex.w);
+ float4 fl_worldPos = mul(unity_ObjectToWorld, fl_objPos);
+ float4 fl_viewPos = mul(UNITY_MATRIX_V, fl_worldPos);
+ fl_viewPos.xy /= _Focal_Length_Multiplier;
+
+ float2 fl_compensation = fl_viewPos_unscaled.xy - fl_viewPos.xy;
+ fl_viewPos.xy += fl_compensation;
+
+ o.pos = mul(UNITY_MATRIX_P, fl_viewPos);
+ } else {
+ o.pos = UnityObjectToClipPos(v.vertex);
+ }
+#else
o.pos = UnityObjectToClipPos(v.vertex);
+#endif
+
o.uv01 = v.uv01;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.objPos = v.vertex;
diff --git a/2ner.shader b/2ner.shader
index f6e4626..4476282 100644
--- a/2ner.shader
+++ b/2ner.shader
@@ -395,6 +395,14 @@ Shader "yum_food/2ner"
[HideInInspector] m_end_Outline_Stencil("Outline Stencil", Float) = 0
//endex
+ //ifex _Focal_Length_Control_Enabled==0
+ [HideInInspector] m_start_Focal_Length_Control("Focal Length Control", Float) = 0
+ [ThryToggle(_FOCAL_LENGTH_CONTROL)] _Focal_Length_Control_Enabled("Enable", Float) = 0
+ [MaterialToggle] _Focal_Length_Enabled_Dynamic("Enable (dynamic)", Float) = 0
+ _Focal_Length_Multiplier("Focal length multiplier", Float) = 1.0
+ [HideInInspector] m_end_Focal_Length_Control("Focal Length Control", Float) = 0
+ //endex
+
[HideInInspector] m_lightingOptions("Lighting Options", Float) = 0
//ifex _Receive_Shadows_Enabled==0
[HideInInspector] m_start_Shadow_Receiving("Receive shadows", Float) = 0
diff --git a/features.cginc b/features.cginc
index 95928a1..4c818f8 100644
--- a/features.cginc
+++ b/features.cginc
@@ -95,5 +95,9 @@
#pragma shader_feature_local _EXTRA_STENCIL_COLOR_PASS
//endex
+//ifex _Focal_Length_Control_Enabled==0
+#pragma shader_feature_local _FOCAL_LENGTH_CONTROL
+//endex
+
#endif // __FEATURES_INC
diff --git a/globals.cginc b/globals.cginc
index 88f8809..d86620b 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -221,4 +221,9 @@ float _Masked_Stencil_Z_Fail_Op;
float4 _ExtraStencilColor;
#endif // EXTRA_STENCIL_COLOR_PASS
+#if defined(_FOCAL_LENGTH_CONTROL)
+float _Focal_Length_Enabled_Dynamic;
+float _Focal_Length_Multiplier;
+#endif // _FOCAL_LENGTH_CONTROL
+
#endif // __GLOBALS_INC