From f1fc3bd51a90432ddb6b7cbc86b8383c923b0dd8 Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 13 Aug 2025 16:51:23 -0700 Subject: add hypotrochoid gimmick --- 2ner.cginc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to '2ner.cginc') diff --git a/2ner.cginc b/2ner.cginc index 1e6af31..0e6fa82 100644 --- a/2ner.cginc +++ b/2ner.cginc @@ -25,6 +25,7 @@ #include "ssao.cginc" #include "ssfd.cginc" #include "tessellation.cginc" +#include "trochoid.cginc" #include "unigram_letter_grid.cginc" #include "vertex_domain_warping.cginc" #include "yum_brdf.cginc" @@ -117,6 +118,11 @@ v2f vert(appdata v) { v.vertex.xyz = domainWarpVertexPosition(v.vertex.xyz); #endif +#if defined(_TROCHOID) + o.orig_pos = v.vertex.xyz; + v.vertex.xyz = trochoid_map(v.vertex.xyz); +#endif + #if defined(OUTLINE_PASS) [branch] if (!_Outlines_Enabled_Dynamic) { @@ -299,6 +305,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace #if defined(_SHATTER_WAVE) calcNormalInScreenSpace(i.normal, i.objPos); + i.normal = UnityObjectToWorldNormal(i.normal); #endif #if defined(_SHATTER_WAVE) || defined(_VERTEX_DOMAIN_WARPING) || defined(_TESSELLATION_HEIGHTMAP) @@ -399,6 +406,24 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace #endif #endif +#if defined(_TROCHOID) + float3 normal_obj = trochoid_normal(i.orig_pos); + + // We need tangents that are perpendicular to the new normal. + // A common way to generate them is to cross with a fixed "up" vector. + float3 tangent_obj = normalize(cross(normal_obj, float3(0, 1, 0))); + float3 binormal_obj = cross(normal_obj, tangent_obj); + + i.normal = UnityObjectToWorldNormal(normal_obj); + i.tangent = float4(normalize(mul((float3x3)unity_ObjectToWorld, tangent_obj)), 1); + i.binormal = normalize(mul((float3x3)unity_ObjectToWorld, binormal_obj)); + i.normal *= facing ? 1 : -1; + + float theta = 1 - atan2(i.orig_pos.y, i.orig_pos.x) / PI; + float3 color = _Trochoid_Color_Ramp.SampleLevel(linear_clamp_s, float2(theta, 0.5), 0).rgb; + pbr.albedo.xyz = color; +#endif + #if defined(_HARNACK_TRACING) HarnackTracingOutput harnack_output = HarnackTracing(i); pbr.albedo = float4(1, 1, 1, 0.2); -- cgit v1.2.3