diff options
| author | yum <yum.food.vr@gmail.com> | 2025-11-01 12:33:40 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-11-01 12:33:40 -0700 |
| commit | 195df414b5310dec05d509dcc7d91b786419e360 (patch) | |
| tree | 051ad35f54e06e9d81090b25b7959ed1260a4452 | |
| parent | 74b584ac77384613226854fe368cdce2a5612939 (diff) | |
deform rd with tangent path & scale by jac_det
| -rw-r--r-- | ray_marching.cginc | 6 | ||||
| -rw-r--r-- | vertex_deformation.slang | 8 |
2 files changed, 6 insertions, 8 deletions
diff --git a/ray_marching.cginc b/ray_marching.cginc index 66d0845..01011c6 100644 --- a/ray_marching.cginc +++ b/ray_marching.cginc @@ -29,11 +29,9 @@ RayMarchResult ray_march(v2f i) { GetRoRd(i, ro, rd); #if defined(_VERTEX_DEFORMATION) - float3 rd_perp = i.normal * dot(i.normal, rd); - float3 rd_tan = rd - rd_perp; float3 tmp = ro; - undeform_normal(tmp, rd_perp, rd_tan); - rd = rd_perp + rd_tan; + undeform_normal(tmp, tmp, rd); + rd = normalize(rd); #endif const float kMinDist = 1e-3; diff --git a/vertex_deformation.slang b/vertex_deformation.slang index c683982..c1faf44 100644 --- a/vertex_deformation.slang +++ b/vertex_deformation.slang @@ -43,8 +43,8 @@ ); \ float jac_det = determinant(jacobian); \ float3x3 itjac = inverse(transpose(jacobian), jac_det); \ - normal = mul(itjac, normal) * jac_det; \ - tangent = mul(jacobian, tangent) + normal = normalize(mul(itjac, normal) * jac_det); \ + tangent = normalize(mul(jacobian, tangent)) #define R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent) \ float3x3 jacobian = float3x3( \ @@ -55,8 +55,8 @@ float jac_det = determinant(jacobian); \ float3x3 inv_jac = inverse(jacobian, jac_det); \ float3x3 trans_jac = transpose(jacobian); \ - normal = mul(trans_jac, normal) * jac_det; \ - tangent = mul(inv_jac, tangent) + normal = normalize(mul(trans_jac, normal) / jac_det); \ + tangent = normalize(mul(inv_jac, tangent) / jac_det) // Syntactic sugar - wraps the previous three macros. #define R3R3_NORMALS(xyz, normal, tangent, fun, ...) \ |
