diff options
| author | yum <yum.food.vr@gmail.com> | 2025-10-28 21:33:40 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-10-28 21:33:40 -0700 |
| commit | 15f9778a65a0f163627bd229b8f212cc5c7c0c22 (patch) | |
| tree | b4b6c90defa76b9086b3b1f02bcd2a6401e019e7 /3ner.cginc | |
| parent | 6c93421c1a10caf9e4f6996e1109379a504c19a7 (diff) | |
some ray marching
Diffstat (limited to '3ner.cginc')
| -rw-r--r-- | 3ner.cginc | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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 |
