From 15f9778a65a0f163627bd229b8f212cc5c7c0c22 Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 28 Oct 2025 21:33:40 -0700 Subject: some ray marching --- 3ner.cginc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to '3ner.cginc') diff --git a/3ner.cginc b/3ner.cginc index da04aba..924e93e 100644 --- a/3ner.cginc +++ b/3ner.cginc @@ -14,6 +14,7 @@ #include "lighting.cginc" #include "globals.cginc" #include "interpolators.cginc" +#include "ray_marching.cginc" #include "vertex.cginc" v2f vert(appdata v) { @@ -21,7 +22,7 @@ v2f vert(appdata v) { return (v2f) asfloat(-1); #endif - v2f o; + v2f o; UNITY_SETUP_INSTANCE_ID(v); UNITY_INITIALIZE_OUTPUT(v2f, o); UNITY_TRANSFER_INSTANCE_ID(v, o); @@ -34,12 +35,18 @@ v2f vert(appdata v) { o.uv01.zw = v.uv1; o.uv23.xy = v.uv2; 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 - // Normal and tangent are in object space. + // Normal and tangent are in object space to allow for object-space + // vertex deformation logic later on. They are converted to world + // space inside the fragment shader. o.normal = v.normal; o.tangent = v.tangent; #if !defined(_VERTEX_DEFORMATION_FRAGMENT_NORMALS) @@ -178,6 +185,9 @@ v2f domain( #endif o.normal = DOMAIN_INTERP(normal); o.tangent = DOMAIN_INTERP(tangent); +#if defined(_RAY_MARCHING_BAKED_ORIGINS) + o.color = DOMAIN_INTERP(color); +#endif propagateObjPos(o); @@ -240,6 +250,14 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace) : SV_Target { return 0; #endif +#if defined(_RAY_MARCHING) + // TODO consider doing assignment inside function. It would clean up this + // call site. + RayMarchResult res = ray_march(i); + i.objPos = res.objPos; + i.normal = res.objNorm; + i.tangent.xyz = res.objTan; +#endif #if defined(_VERTEX_DEFORMATION_FRAGMENT_NORMALS) deform_normal(i.objPos_orig, i.normal, i.tangent.xyz); #endif -- cgit v1.2.3