From a4bf31470f7e2855f13d922e3e7ad1c7767d9afd Mon Sep 17 00:00:00 2001 From: yum Date: Sun, 12 Oct 2025 16:28:53 -0700 Subject: add geometry shader --- 3ner.cginc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to '3ner.cginc') diff --git a/3ner.cginc b/3ner.cginc index 0536fb5..bac74ad 100644 --- a/3ner.cginc +++ b/3ner.cginc @@ -9,6 +9,7 @@ #include "AutoLight.cginc" #include "brdf.cginc" +#include "geometry.cginc" #include "pbr.cginc" #include "lighting.cginc" #include "globals.cginc" @@ -50,6 +51,7 @@ v2f vert(appdata v) { return o; } +//ifex _Tessellation_Enabled==0 struct tess_factors { float edge[3] : SV_TessFactor; float inside : SV_InsideTessFactor; @@ -170,6 +172,50 @@ v2f domain( UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); return o; } +//endex + +//ifex _Geometry_Shader_Enabled==0 +// maxvertexcount == the number of vertices we create +[maxvertexcount(3)] +void geom(triangle v2f tri_in[3], + uint pid: SV_PrimitiveID, + inout TriangleStream tri_out) +{ + v2f v0 = tri_in[0]; + v2f v1 = tri_in[1]; + v2f v2 = tri_in[2]; + +#if defined(_CENTER_OFFSET) + float3 n0 = v0.normal; + float3 n1 = v1.normal; + float3 n2 = v2.normal; +#if defined(_CUSTOM31_FRAGMENT_NORMALS) || defined(_CUSTOM31_TESSELLATION) + float3 tmp; + deform_normal(v0.objPos_orig, n0, tmp); + deform_normal(v1.objPos_orig, n1, tmp); + deform_normal(v2.objPos_orig, n2, tmp); + // the average direction doesn't have to be precise, so don't bother with + // normalize(). + float3 n = (n0 + n1 + n2) * 0.333f; +#else + float3 n = (v0.normal + v1.normal + v2.normal) * 0.333f; +#endif + float height = center_offset(v0.uv0); + v0.objPos += n * height; + v1.objPos += n * height; + v2.objPos += n * height; + propagateObjPos(v0); + propagateObjPos(v1); + propagateObjPos(v2); +#endif + + // Output transformed geometry. + tri_out.Append(v0); + tri_out.Append(v1); + tri_out.Append(v2); + tri_out.RestartStrip(); +} +//endex float4 frag(v2f i, uint facing : SV_IsFrontFace #if defined(_CUSTOM31_TUBES) -- cgit v1.2.3