diff options
| -rw-r--r-- | 2ner.cginc | 17 | ||||
| -rw-r--r-- | 2ner.shader | 36 | ||||
| -rw-r--r-- | features.cginc | 5 | ||||
| -rw-r--r-- | globals.cginc | 33 | ||||
| -rw-r--r-- | tessellation.cginc | 47 |
5 files changed, 101 insertions, 37 deletions
@@ -202,7 +202,7 @@ v2f vert(appdata v) { }
float4 frag(v2f i, uint facing : SV_IsFrontFace
-#if defined(_HARNACK_TRACING) || defined(_SHATTER_WAVE) || defined(_VERTEX_DOMAIN_WARPING) || (defined(_CUSTOM30) && !defined(_DEPTH_PREPASS)) || defined(_RAYMARCHED_FOG)
+#if defined(_HARNACK_TRACING) || defined(_SHATTER_WAVE) || defined(_VERTEX_DOMAIN_WARPING) || (defined(_CUSTOM30) && !defined(_DEPTH_PREPASS)) || defined(_RAYMARCHED_FOG) || defined(_TESSELLATION_HEIGHTMAP)
, out float depth : SV_DepthLessEqual
#endif
) : SV_Target {
@@ -279,7 +279,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace }
#endif
-#if defined(_SHATTER_WAVE) || defined(_TESSELLATION_HEIGHTMAP)
+#if defined(_SHATTER_WAVE)
calcNormalInScreenSpace(i.normal, i.objPos);
#endif
@@ -294,8 +294,17 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace #if defined(_VERTEX_DOMAIN_WARPING)
|| _Vertex_Domain_Warping_Octaves > 0.1
#endif
-#if defined(_TESSELLATION_HEIGHTMAP)
- || _Tessellation_Heightmap_Scale > 1E-4
+#if defined(_TESSELLATION_HEIGHTMAP_0)
+ || _Tessellation_Heightmap_0_Scale > 1E-4
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_1)
+ || _Tessellation_Heightmap_1_Scale > 1E-4
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_2)
+ || _Tessellation_Heightmap_2_Scale > 1E-4
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_3)
+ || _Tessellation_Heightmap_3_Scale > 1E-4
#endif
) {
float4 clip_pos = UnityObjectToClipPos(i.objPos);
diff --git a/2ner.shader b/2ner.shader index f010022..e886828 100644 --- a/2ner.shader +++ b/2ner.shader @@ -1644,10 +1644,30 @@ Shader "yum_food/2ner" [ThryToggle(_TESSELLATION)] _Tessellation_Enabled("Enable", Float) = 0 _Tessellation_Factor("Factor", Range(1, 64)) = 1 [HideInInspector] m_start_Tessellation_Heightmap("Heightmap", Float) = 0 - [ThryToggle(_TESSELLATION_HEIGHTMAP)] _Tessellation_Heightmap_Enabled("Enable", Float) = 0 - _Tessellation_Heightmap("Heightmap", 2D) = "black" {} - _Tessellation_Heightmap_Scale("Scale", Float) = 1 - _Tessellation_Heightmap_Offset("Offset", Range(-1, 1)) = 0 + [HideInInspector] m_start_Tessellation_Heightmap_0("Heightmap 0", Float) = 0 + [ThryToggle(_TESSELLATION_HEIGHTMAP_0)] _Tessellation_Heightmap_0_Enabled("Enable", Float) = 0 + _Tessellation_Heightmap_0("Heightmap 0", 2D) = "black" {} + _Tessellation_Heightmap_0_Scale("Scale", Float) = 1 + _Tessellation_Heightmap_0_Offset("Offset", Range(-1, 1)) = 0 + [HideInInspector] m_end_Tessellation_Heightmap_0("Heightmap 0", Float) = 0 + [HideInInspector] m_start_Tessellation_Heightmap_1("Heightmap 1", Float) = 0 + [ThryToggle(_TESSELLATION_HEIGHTMAP_1)] _Tessellation_Heightmap_1_Enabled("Enable", Float) = 0 + _Tessellation_Heightmap_1("Heightmap 1", 2D) = "black" {} + _Tessellation_Heightmap_1_Scale("Scale", Float) = 1 + _Tessellation_Heightmap_1_Offset("Offset", Range(-1, 1)) = 0 + [HideInInspector] m_end_Tessellation_Heightmap_1("Heightmap 1", Float) = 0 + [HideInInspector] m_start_Tessellation_Heightmap_2("Heightmap 2", Float) = 0 + [ThryToggle(_TESSELLATION_HEIGHTMAP_2)] _Tessellation_Heightmap_2_Enabled("Enable", Float) = 0 + _Tessellation_Heightmap_2("Heightmap 2", 2D) = "black" {} + _Tessellation_Heightmap_2_Scale("Scale", Float) = 1 + _Tessellation_Heightmap_2_Offset("Offset", Range(-1, 1)) = 0 + [HideInInspector] m_end_Tessellation_Heightmap_2("Heightmap 2", Float) = 0 + [HideInInspector] m_start_Tessellation_Heightmap_3("Heightmap 3", Float) = 0 + [ThryToggle(_TESSELLATION_HEIGHTMAP_3)] _Tessellation_Heightmap_3_Enabled("Enable", Float) = 0 + _Tessellation_Heightmap_3("Heightmap 3", 2D) = "black" {} + _Tessellation_Heightmap_3_Scale("Scale", Float) = 1 + _Tessellation_Heightmap_3_Offset("Offset", Range(-1, 1)) = 0 + [HideInInspector] m_end_Tessellation_Heightmap_3("Heightmap 3", Float) = 0 [HideInInspector] m_start_Tessellation_Heightmap_Direction_Control("Direction control", Float) = 0 [ThryToggle(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)] _Tessellation_Heightmap_Direction_Control_Enabled("Enable", Float) = 0 _Tessellation_Heightmap_Direction_Control_Vector("Direction (normal/tangent/binormal)", Vector) = (1, 0, 0) @@ -2145,7 +2165,7 @@ Shader "yum_food/2ner" Pass { Name "DEPTHPREPASS" Tags { } - + ColorMask 0 ZWrite On ZTest LEqual @@ -2593,16 +2613,16 @@ Shader "yum_food/2ner" Pass { Name "META" Tags { "LightMode" = "Meta" } - + Cull Off - + CGPROGRAM #pragma vertex vert_meta #pragma fragment frag_meta #pragma shader_feature _EMISSION #pragma shader_feature _METALLICGLOSSMAP #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - + #define META_PASS #include "UnityStandardMeta.cginc" ENDCG diff --git a/features.cginc b/features.cginc index ec7cf35..8e6ebcd 100644 --- a/features.cginc +++ b/features.cginc @@ -326,7 +326,10 @@ //ifex _Tessellation_Enabled==0 #pragma shader_feature_local _TESSELLATION -#pragma shader_feature_local _TESSELLATION_HEIGHTMAP +#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_0 +#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_1 +#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_2 +#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_3 #pragma shader_feature_local _TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL #pragma shader_feature_local _TESSELLATION_RANGE_FACTOR //endex diff --git a/globals.cginc b/globals.cginc index ec88c60..0017758 100644 --- a/globals.cginc +++ b/globals.cginc @@ -499,12 +499,33 @@ float4 _Shatter_Wave_Rotation_Strength; float _Tessellation_Factor;
#endif // _TESSELLATION
-#if defined(_TESSELLATION_HEIGHTMAP)
-texture2D _Tessellation_Heightmap;
-float4 _Tessellation_Heightmap_ST;
-float _Tessellation_Heightmap_Scale;
-float _Tessellation_Heightmap_Offset;
-#endif // _TESSELLATION_HEIGHTMAP
+#if defined(_TESSELLATION_HEIGHTMAP_0)
+texture2D _Tessellation_Heightmap_0;
+float4 _Tessellation_Heightmap_0_ST;
+float _Tessellation_Heightmap_0_Scale;
+float _Tessellation_Heightmap_0_Offset;
+#endif // _TESSELLATION_HEIGHTMAP_0
+
+#if defined(_TESSELLATION_HEIGHTMAP_1)
+texture2D _Tessellation_Heightmap_1;
+float4 _Tessellation_Heightmap_1_ST;
+float _Tessellation_Heightmap_1_Scale;
+float _Tessellation_Heightmap_1_Offset;
+#endif // _TESSELLATION_HEIGHTMAP_1
+
+#if defined(_TESSELLATION_HEIGHTMAP_2)
+texture2D _Tessellation_Heightmap_2;
+float4 _Tessellation_Heightmap_2_ST;
+float _Tessellation_Heightmap_2_Scale;
+float _Tessellation_Heightmap_2_Offset;
+#endif // _TESSELLATION_HEIGHTMAP_2
+
+#if defined(_TESSELLATION_HEIGHTMAP_3)
+texture2D _Tessellation_Heightmap_3;
+float4 _Tessellation_Heightmap_3_ST;
+float _Tessellation_Heightmap_3_Scale;
+float _Tessellation_Heightmap_3_Offset;
+#endif // _TESSELLATION_HEIGHTMAP_3
#if defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)
float3 _Tessellation_Heightmap_Direction_Control_Vector;
diff --git a/tessellation.cginc b/tessellation.cginc index b088334..23df0d4 100644 --- a/tessellation.cginc +++ b/tessellation.cginc @@ -35,8 +35,12 @@ tess_factors patch_constant(InputPatch<v2f, 3> patch) { // un-transformed and maximally transformed locations. Technically we could // miss an intersection in the middle, but I haven't noticed any visible // popping with this approach. -#if defined(_TESSELLATION_HEIGHTMAP) - float max_displacement = _Tessellation_Heightmap_Scale * 0.5 + _Tessellation_Heightmap_Offset; +#if defined(_TESSELLATION_HEIGHTMAP) && (defined(_TESSELLATION_HEIGHTMAP_0) || defined(_TESSELLATION_HEIGHTMAP_1) || defined(_TESSELLATION_HEIGHTMAP_2) || defined(_TESSELLATION_HEIGHTMAP_3)) + float max_displacement = max( + max(_Tessellation_Heightmap_0_Scale * 0.5 + _Tessellation_Heightmap_0_Offset, + _Tessellation_Heightmap_1_Scale * 0.5 + _Tessellation_Heightmap_1_Offset), + max(_Tessellation_Heightmap_2_Scale * 0.5 + _Tessellation_Heightmap_2_Offset, + _Tessellation_Heightmap_3_Scale * 0.5 + _Tessellation_Heightmap_3_Offset)); #else float max_displacement = 0; #endif @@ -119,22 +123,29 @@ v2f domain( #endif #endif -#if defined(_TESSELLATION_HEIGHTMAP) -#if 1 - float raw_noise = _Tessellation_Heightmap.SampleLevel(linear_repeat_s, - o.uv01.xy * _Tessellation_Heightmap_ST.xy, 0).r; - float height = raw_noise * - _Tessellation_Heightmap_Scale + - _Tessellation_Heightmap_Offset + - _Tessellation_Heightmap_Scale * -0.5; -#else - // For whatever reason, it seems like the texture read is initially - // returning a small number when the mesh spawns in VRC. A procedural noise - // works around the issue. - float height = rand2(o.uv01.xy) * _Tessellation_Heightmap_Scale + - _Tessellation_Heightmap_Offset + - _Tessellation_Heightmap_Scale * -0.5; +#if (defined(_TESSELLATION_HEIGHTMAP_0) || defined(_TESSELLATION_HEIGHTMAP_1) || defined(_TESSELLATION_HEIGHTMAP_2) || defined(_TESSELLATION_HEIGHTMAP_3)) + float height = 0; +#if defined(_TESSELLATION_HEIGHTMAP_0) + float heightmap_0_sample = _Tessellation_Heightmap_0.SampleLevel(bilinear_repeat_s, + o.uv01.xy * _Tessellation_Heightmap_0_ST.xy, 0).r; + height += heightmap_0_sample * _Tessellation_Heightmap_0_Scale + _Tessellation_Heightmap_0_Offset; +#endif +#if defined(_TESSELLATION_HEIGHTMAP_1) + float heightmap_1_sample = _Tessellation_Heightmap_1.SampleLevel(bilinear_repeat_s, + o.uv01.xy * _Tessellation_Heightmap_1_ST.xy, 0).r; + height += heightmap_1_sample * _Tessellation_Heightmap_1_Scale + _Tessellation_Heightmap_1_Offset; +#endif +#if defined(_TESSELLATION_HEIGHTMAP_2) + float heightmap_2_sample = _Tessellation_Heightmap_2.SampleLevel(bilinear_repeat_s, + o.uv01.xy * _Tessellation_Heightmap_2_ST.xy, 0).r; + height += heightmap_2_sample * _Tessellation_Heightmap_2_Scale + _Tessellation_Heightmap_2_Offset; #endif +#if defined(_TESSELLATION_HEIGHTMAP_3) + float heightmap_3_sample = _Tessellation_Heightmap_3.SampleLevel(bilinear_repeat_s, + o.uv01.xy * _Tessellation_Heightmap_3_ST.xy, 0).r; + height += heightmap_3_sample * _Tessellation_Heightmap_3_Scale + _Tessellation_Heightmap_3_Offset; +#endif + #if defined(OUTLINE_PASS) && defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL) float3 heightmap_direction = mul(transpose(-float3x3(o.normal, o.tangent, o.binormal)), _Tessellation_Heightmap_Direction_Control_Vector); #elif defined(OUTLINE_PASS) && !defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL) @@ -152,7 +163,7 @@ v2f domain( o.eyeVec.xyz = o.worldPos - _WorldSpaceCameraPos; o.eyeVec.w = 1; - UNITY_TRANSFER_LIGHTING(o, o.uv01.zw); + //UNITY_TRANSFER_LIGHTING(o, v); UNITY_TRANSFER_INSTANCE_ID(patch[0], o); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); #if defined(SHADOW_CASTER_PASS) |
