summaryrefslogtreecommitdiffstats
path: root/3ner.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-02-16 16:32:00 -0800
committeryum <yum.food.vr@gmail.com>2026-02-16 16:36:24 -0800
commit864c2ba12dc864d9cb55cb797ba8919bee5b5913 (patch)
treeaa6cd98a71e4ef05d23f762127d3759a4a3e3e21 /3ner.cginc
parent6504b2c4631bab477838548167b88c1052eac263 (diff)
Add instancing distance culling, scale deformation
* GPU instance distance culling now takes a min/max range * Fold recovers ops from material, allowing state to persist across editor restarts * Add scale node to vertex deformation framework * Remove fold presets - dumb LLM idea, unused * Drop more "undeform" code; unused, was for ray marching, which does not work well * Fix reflection energy compensation; was using cloth math, which makes things too bright
Diffstat (limited to '3ner.cginc')
-rwxr-xr-x3ner.cginc38
1 files changed, 28 insertions, 10 deletions
diff --git a/3ner.cginc b/3ner.cginc
index e675bc2..cf03caf 100755
--- a/3ner.cginc
+++ b/3ner.cginc
@@ -31,11 +31,32 @@ v2f vert(appdata v) {
UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- // Apply instance texture offset transformation if enabled
+ impostor_vert(v.vertex.xyz);
+
+#if defined(_VERTEX_DEFORMATION) && ( \
+ defined(_VERTEX_DEFORMATION_FRAGMENT_NORMALS) || \
+ defined(_VERTEX_DEFORMATION_TESSELLATION)) || \
+ (defined(_IMPOSTORS) && defined(_INSTANCE_TEXTURE_OFFSET))
+ o.objPos_orig = v.vertex;
+#endif
+
+
+ [branch] if (instance_distance_culling()) {
+ return (v2f) asfloat(-1);
+ }
instancing_vert(v);
-#if defined(_IMPOSTORS)
- impostor_vert(v.vertex.xyz);
+#if defined(_INSTANCE_TEXTURE_OFFSET) && defined(UNITY_INSTANCING_ENABLED)
+ // Early exit custom frustum culling.
+ float3 instanceCenter;
+ if (get_instance_center(instanceCenter)) {
+ float4 instanceClipPos = UnityObjectToClipPos(instanceCenter);
+ instanceClipPos /= instanceClipPos.w;
+ float k = 1.05;
+ if (any(instanceClipPos.xy < -k) || any(instanceClipPos.xy > k)) {
+ return (v2f) asfloat(-1);
+ }
+ }
#endif
#if defined(_TESSELLATION)
@@ -47,9 +68,6 @@ v2f vert(appdata v) {
o.uv23.zw = v.uv3;
float3 obj_space_camera_pos = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0));
o.objPos = v.vertex;
-#if defined(_VERTEX_DEFORMATION_FRAGMENT_NORMALS) || defined(_VERTEX_DEFORMATION_TESSELLATION)
- o.objPos_orig = v.vertex;
-#endif
#if defined(_RAY_MARCHING_BAKED_ORIGINS)
o.color = v.color;
#endif
@@ -190,7 +208,10 @@ v2f domain(
o.objPos = DOMAIN_INTERP(objPos);
#endif
-#if defined(_VERTEX_DEFORMATION_FRAGMENT_NORMALS) || defined(_VERTEX_DEFORMATION_TESSELLATION)
+#if defined(_VERTEX_DEFORMATION) && ( \
+ defined(_VERTEX_DEFORMATION_FRAGMENT_NORMALS) || \
+ defined(_VERTEX_DEFORMATION_TESSELLATION)) || \
+ defined(_IMPOSTORS) && defined(_INSTANCE_TEXTURE_OFFSET)
o.objPos_orig = DOMAIN_INTERP(objPos_orig);
o.objPos = o.objPos_orig;
deform(o.objPos);
@@ -266,9 +287,6 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace
return 0;
#endif
- // Apply instancing effects (e.g., distance culling)
- instancing_frag(i);
-
#if defined(_RAY_MARCHING)
const bool is_fragment = true;
ray_march(i, is_fragment);