summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-03-25 19:12:49 -0700
committeryum <yum.food.vr@gmail.com>2025-03-25 19:12:49 -0700
commit274f601c9c49f69e4acef24b56982190b5b0bf93 (patch)
tree8c241e6cb0310485edb7db96d42d164189753c4b
parentccdda956f7de812bb9c318161c6852301a60d413 (diff)
Continue work on tessellation
-rw-r--r--2ner.cginc11
-rw-r--r--2ner.shader28
-rw-r--r--features.cginc1
-rw-r--r--glitter.cginc2
-rw-r--r--globals.cginc8
-rw-r--r--shatter_wave.cginc6
-rw-r--r--tessellation.cginc36
7 files changed, 67 insertions, 25 deletions
diff --git a/2ner.cginc b/2ner.cginc
index e8d6ae3..1c2743c 100644
--- a/2ner.cginc
+++ b/2ner.cginc
@@ -66,17 +66,13 @@ v2f vert(appdata v) {
UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
-#if defined(_SHATTER_WAVE)
- shatterWaveVert(v.vertex.xyz, v.normal, v.tangent);
-#endif
-
#if defined(_SPHERIZE)
{
- float3 tgt_normal = normalize(v.vertex.xyz);
+ float3 tgt_normal = normalize(o.objPos.xyz);
float3 tgt_tangent = normalize(float3(tgt_normal.y, -tgt_normal.x, 0));
float3 tgt_pos = tgt_normal * _Spherize_Radius;
- v.normal = normalize(lerp(v.normal, tgt_normal, _Spherize_Strength));
- v.vertex.xyz = lerp(v.vertex.xyz, tgt_pos, _Spherize_Strength);
+ o.normal = normalize(lerp(o.normal, tgt_normal, _Spherize_Strength));
+ o.objPos.xyz = lerp(o.objPos.xyz, tgt_pos, _Spherize_Strength);
}
#endif
@@ -184,6 +180,7 @@ float4 frag(v2f i
i.normal = normalize(i.normal);
#if defined(_SHATTER_WAVE)
+ shatterWaveFrag(i.normal, i.objPos);
{
float4 clip_pos = mul(UNITY_MATRIX_VP, float4(i.worldPos, 1.0));
depth = clip_pos.z / clip_pos.w;
diff --git a/2ner.shader b/2ner.shader
index 377f705..8af036e 100644
--- a/2ner.shader
+++ b/2ner.shader
@@ -523,8 +523,12 @@ Shader "yum_food/2ner"
//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
+ _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
+ [HideInInspector] m_end_Tessellation_Heightmap("Heightmap", Float) = 0
[HideInInspector] m_end_Tessellation("Tessellation", Float) = 0
//endex
@@ -993,11 +997,6 @@ 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"
@@ -1189,6 +1188,11 @@ Shader "yum_food/2ner"
#pragma vertex vert
#pragma fragment frag
+ //ifex _Tessellation_Enabled==0
+ #pragma hull hull
+ #pragma domain domain
+ //endex
+
#define FORWARD_BASE_PASS
#include "2ner.cginc"
@@ -1239,6 +1243,11 @@ Shader "yum_food/2ner"
#pragma vertex vert
#pragma fragment frag
+ //ifex _Tessellation_Enabled==0
+ #pragma hull hull
+ #pragma domain domain
+ //endex
+
#define FORWARD_ADD_PASS
#include "2ner.cginc"
@@ -1336,6 +1345,11 @@ Shader "yum_food/2ner"
#pragma vertex vert
#pragma fragment frag
+ //ifex _Tessellation_Enabled==0
+ #pragma hull hull
+ #pragma domain domain
+ //endex
+
#define OUTLINE_PASS
#include "2ner.cginc"
diff --git a/features.cginc b/features.cginc
index da2cd69..9a96cd2 100644
--- a/features.cginc
+++ b/features.cginc
@@ -206,6 +206,7 @@
//ifex _Tessellation_Enabled==0
#pragma shader_feature_local _TESSELLATION
+#pragma shader_feature_local _TESSELLATION_HEIGHTMAP
//endex
//ifex _Spherize_Enabled==0
diff --git a/glitter.cginc b/glitter.cginc
index 2f7a796..e31bc5c 100644
--- a/glitter.cginc
+++ b/glitter.cginc
@@ -7,7 +7,7 @@
struct GlitterParams {
float4 color;
- float layers;
+ uint layers;
float cell_size;
float size;
float major_minor_ratio;
diff --git a/globals.cginc b/globals.cginc
index 9cabad6..c653e9d 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -425,8 +425,12 @@ float3 _Shatter_Wave_Direction;
#endif // _SHATTER_WAVE
#if defined(_TESSELLATION)
-float3 _Tessellation_Edge_Factors;
-float _Tessellation_Inside_Factor;
+float _Tessellation_Factor;
+#if defined(_TESSELLATION_HEIGHTMAP)
+texture2D _Tessellation_Heightmap;
+float4 _Tessellation_Heightmap_ST;
+float _Tessellation_Heightmap_Scale;
+#endif // _TESSELLATION_HEIGHTMAP
#endif // _TESSELLATION
#if defined(_SPHERIZE)
diff --git a/shatter_wave.cginc b/shatter_wave.cginc
index 72f8097..87a21cc 100644
--- a/shatter_wave.cginc
+++ b/shatter_wave.cginc
@@ -23,6 +23,12 @@ void shatterWaveVert(inout float3 objPos, float3 objNormal, float3 objTangent) {
float3 objPos_proj = dot(objPos, wave_axis) * normalize(wave_axis);
float offset = exp(-length(objPos_proj - wave_center * wave_axis) * _Shatter_Wave_Power) * _Shatter_Wave_Amplitude;
objPos += objNormal * offset;
+
+ float phase = (wave_t / _Shatter_Wave_Period) + 0.5;
+}
+
+void shatterWaveFrag(inout float3 normal, float3 objPos) {
+ normal = normalize(cross(ddy(objPos), ddx(objPos)));
}
#endif // _SHATTER_WAVE
diff --git a/tessellation.cginc b/tessellation.cginc
index c77cd83..92aca3a 100644
--- a/tessellation.cginc
+++ b/tessellation.cginc
@@ -3,6 +3,7 @@
#include "globals.cginc"
#include "interpolators.cginc"
+#include "shatter_wave.cginc"
//ifex _Tessellation_Enabled==0
@@ -14,10 +15,10 @@ struct tess_factors {
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;
+ f.edge[0] = _Tessellation_Factor;
+ f.edge[1] = _Tessellation_Factor;
+ f.edge[2] = _Tessellation_Factor;
+ f.inside = _Tessellation_Factor;
#else
f.edge[0] = 1;
f.edge[1] = 1;
@@ -50,16 +51,35 @@ v2f domain(
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);
+#if defined(_TESSELLATION)
+ o.objPos = DOMAIN_INTERP(tpos);
+#else
o.objPos = DOMAIN_INTERP(pos);
- o.worldPos = DOMAIN_INTERP(worldPos);
+#endif
o.normal = DOMAIN_INTERP(normal);
o.tangent = DOMAIN_INTERP(tangent);
o.binormal = DOMAIN_INTERP(binormal);
- o.eyeVec = DOMAIN_INTERP(eyeVec);
+ o.uv01 = DOMAIN_INTERP(uv01);
+
+#if defined(_SHATTER_WAVE)
+ shatterWaveVert(o.objPos.xyz, o.normal, o.tangent);
+ o.binormal = cross(o.normal, o.tangent);
+#endif
+
+#if defined(_TESSELLATION_HEIGHTMAP)
+ float height = _Tessellation_Heightmap.SampleLevel(linear_repeat_s, o.uv01.xy * _Tessellation_Heightmap_ST.xy + _Tessellation_Heightmap_ST.zw, 0).r * _Tessellation_Heightmap_Scale;
+ o.objPos.xyz += o.normal * height;
+#endif
+
+ o.pos = UnityObjectToClipPos(o.objPos);
+ o.worldPos = mul(unity_ObjectToWorld, o.objPos);
+ o.eyeVec.xyz = normalize(o.worldPos - _WorldSpaceCameraPos);
+ o.eyeVec.w = 1;
// TODO what about UNITY_LIGHTING_COORDS(7,8) and instance id and shit?
+ //UNITY_TRANSFER_LIGHTING(o, DOMAIN_INTERP(_unity_lightcoords));
+ UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
+ UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
return o;
}