diff options
| author | yum <yum.food.vr@gmail.com> | 2025-03-25 18:12:12 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-03-25 18:12:12 -0700 |
| commit | f46f3023bb716950db30b48c245c82ad2d6ad2a3 (patch) | |
| tree | 8b35e27b0113247ba0698e45e5c2faa4915fe4f3 | |
| parent | 2d49d9db4712ae3cbd604ec7c9f8627e4f74bde6 (diff) | |
Begin sketching out tessellation feature
| -rw-r--r-- | 2ner.cginc | 4 | ||||
| -rw-r--r-- | 2ner.shader | 15 | ||||
| -rw-r--r-- | features.cginc | 6 | ||||
| -rw-r--r-- | globals.cginc | 5 | ||||
| -rw-r--r-- | interpolators.cginc | 3 | ||||
| -rw-r--r-- | tessellation.cginc | 70 |
6 files changed, 101 insertions, 2 deletions
@@ -16,6 +16,7 @@ #include "poi.cginc"
#include "shatter_wave.cginc"
#include "ssfd.cginc"
+#include "tessellation.cginc"
#include "yum_brdf.cginc"
#include "yum_pbr.cginc"
#include "yum_lighting.cginc"
@@ -129,6 +130,9 @@ v2f vert(appdata v) { o.pos = UnityObjectToClipPos(v.vertex);
#endif
+#if defined(_TESSELLATION)
+ o.tpos = v.vertex;
+#endif
o.uv01.xy = v.uv0;
o.uv01.zw = v.uv1;
#if defined(_MIRROR_UVS_IN_MIRROR)
diff --git a/2ner.shader b/2ner.shader index 9c38983..d6047e1 100644 --- a/2ner.shader +++ b/2ner.shader @@ -514,12 +514,20 @@ Shader "yum_food/2ner" _Shatter_Wave_Direction("Direction", Vector) = (0, 1, 0, 0) [HideInInspector] m_end_Shatter_Wave("Shatter wave", Float) = 0 - //ifex _Mirror_UVs_In_Mirror==0 + //ifex _Mirror_UVs_In_Mirror_Enabled==0 [HideInInspector] m_start_Mirror_UVs_In_Mirror("Mirror UVs in mirror", Float) = 0 [ThryToggle(_MIRROR_UVS_IN_MIRROR)] _Mirror_UVs_In_Mirror_Enabled("Enable", Float) = 0 [HideInInspector] m_end_Mirror_UVs_In_Mirror("Mirror UVs in mirror", Float) = 0 //endex + //ifex _Tessellation_Enabled==0 + [HideInInspector] m_start_Tessellation("Tessellation", Float) = 0 + [ThryToggle(_TESSELLATION)] _Tessellation_Enabled("Enable", Float) = 0 + _Tessellation_Edge_Factors("Edge factors", Vector) = (1, 1, 1, 1) + _Tessellation_Inside_Factor("Inside factor", Float) = 1 + [HideInInspector] m_end_Tessellation("Tessellation", Float) = 0 + //endex + //ifex _Vertex_Domain_Warping_Enabled==0 [HideInInspector] m_start_Vertex_Domain_Warping("Vertex domain warping", Float) = 0 [ThryToggle(_VERTEX_DOMAIN_WARPING)]_Vertex_Domain_Warping_Enabled("Enable", Float) = 0 @@ -977,6 +985,11 @@ Shader "yum_food/2ner" #pragma vertex vert #pragma fragment frag + //ifex _Tessellation_Enabled==0 + #pragma hull hull + #pragma domain domain + //endex + #define MASKED_STENCIL1_PASS #include "2ner.cginc" diff --git a/features.cginc b/features.cginc index 1b2b70a..163da78 100644 --- a/features.cginc +++ b/features.cginc @@ -200,9 +200,13 @@ #pragma shader_feature_local _SHATTER_WAVE //endex -//ifex _Mirror_UVs_In_Mirror==0 +//ifex _Mirror_UVs_In_Mirror_Enabled==0 #pragma shader_feature_local _MIRROR_UVS_IN_MIRROR //endex +//ifex _Tessellation_Enabled==0 +#pragma shader_feature_local _TESSELLATION +//endex + #endif // __FEATURES_INC diff --git a/globals.cginc b/globals.cginc index d1fc5b6..ba223ee 100644 --- a/globals.cginc +++ b/globals.cginc @@ -424,4 +424,9 @@ float _Shatter_Wave_Power; float3 _Shatter_Wave_Direction;
#endif // _SHATTER_WAVE
+#if defined(_TESSELLATION)
+float3 _Tessellation_Edge_Factors;
+float _Tessellation_Inside_Factor;
+#endif // _TESSELLATION
+
#endif // __GLOBALS_INC
diff --git a/interpolators.cginc b/interpolators.cginc index 9db505c..b003abf 100644 --- a/interpolators.cginc +++ b/interpolators.cginc @@ -14,6 +14,9 @@ struct appdata { };
struct v2f {
+#if defined(_TESSELLATION)
+ float4 tpos : INTERNALTESSPOS;
+#endif
float4 pos : SV_POSITION;
float4 uv01 : TEXCOORD0;
float3 objPos : TEXCOORD1;
diff --git a/tessellation.cginc b/tessellation.cginc new file mode 100644 index 0000000..c77cd83 --- /dev/null +++ b/tessellation.cginc @@ -0,0 +1,70 @@ +#ifndef __TESSELLATION_INC +#define __TESSELLATION_INC + +#include "globals.cginc" +#include "interpolators.cginc" + +//ifex _Tessellation_Enabled==0 + +struct tess_factors { + float edge[3] : SV_TessFactor; + float inside : SV_InsideTessFactor; +}; + +tess_factors patch_constant(InputPatch<v2f, 3> patch) { + tess_factors f; +#if defined(_TESSELLATION) + f.edge[0] = _Tessellation_Edge_Factors[0]; + f.edge[1] = _Tessellation_Edge_Factors[1]; + f.edge[2] = _Tessellation_Edge_Factors[2]; + f.inside = _Tessellation_Inside_Factor; +#else + f.edge[0] = 1; + f.edge[1] = 1; + f.edge[2] = 1; + f.inside = 1; +#endif + return f; +} + +[UNITY_domain("tri")] +[UNITY_outputcontrolpoints(3)] +[UNITY_outputtopology("triangle_cw")] +[UNITY_partitioning("fractional_odd")] +[UNITY_patchconstantfunc("patch_constant")] +v2f hull( + InputPatch<v2f, 3> patch, + uint id : SV_OutputControlPointID) +{ + return patch[id]; +} + +[UNITY_domain("tri")] +v2f domain( + tess_factors factors, + OutputPatch<v2f, 3> patch, + float3 baryc : SV_DomainLocation) +{ + v2f o; +#define DOMAIN_INTERP(fieldName) \ + patch[0].fieldName * baryc.x + \ + patch[1].fieldName * baryc.y + \ + patch[2].fieldName * baryc.z + o.pos = DOMAIN_INTERP(pos); + o.uv01 = DOMAIN_INTERP(uv01); + o.objPos = DOMAIN_INTERP(pos); + o.worldPos = DOMAIN_INTERP(worldPos); + o.normal = DOMAIN_INTERP(normal); + o.tangent = DOMAIN_INTERP(tangent); + o.binormal = DOMAIN_INTERP(binormal); + o.eyeVec = DOMAIN_INTERP(eyeVec); + + // TODO what about UNITY_LIGHTING_COORDS(7,8) and instance id and shit? + return o; +} + + +//endex + +#endif // __TESSELLATION_INC + |
