Skip to content

Commit 5357020

Browse files
committed
Fixed again that dimple bug...
1 parent f379d9d commit 5357020

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/rayon/gpu_renderers/optix/optix_programs.cu

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@ __device__ __forceinline__ float hexagonalDimplePattern_optix(float3 p)
585585
if (ang < dimple_radius)
586586
{
587587
float t = ang / dimple_radius;
588-
return -dimple_depth * cosf(t * M_PIf * 0.5f);
588+
// Full half-period cosine (Hann profile): C1-continuous at boundary, eliminating jump artifacts.
589+
return -dimple_depth * 0.5f * (1.0f + cosf(t * M_PIf));
589590
}
590591
return 0.0f;
591592
}
@@ -645,9 +646,17 @@ extern "C" __global__ void __closesthit__ch()
645646

646647
if (base_disp < -0.001f)
647648
{
648-
float3 helper = fabsf(base_normal.x) > 0.8f ? make_float3(0, 1, 0) : make_float3(1, 0, 0);
649-
float3 t1 = normalize3(cross3(helper, base_normal));
650-
float3 t2 = cross3(base_normal, t1);
649+
// Duff et al. 2017 "Building an Orthonormal Basis, Revisited":
650+
// continuously varying basis — no seam from a sudden helper-vector switch.
651+
float nz_sign = copysignf(1.0f, base_normal.z);
652+
float nz_a = -1.0f / (nz_sign + base_normal.z);
653+
float nz_b = base_normal.x * base_normal.y * nz_a;
654+
float3 t1 = make_float3(1.0f + nz_sign * base_normal.x * base_normal.x * nz_a,
655+
nz_sign * nz_b,
656+
-nz_sign * base_normal.x);
657+
float3 t2 = make_float3(nz_b,
658+
nz_sign + base_normal.y * base_normal.y * nz_a,
659+
-base_normal.y);
651660

652661
const float h = 0.015f;
653662
float3 p_hat = base_normal;
@@ -660,12 +669,6 @@ extern "C" __global__ void __closesthit__ch()
660669
float3 grad_tan = dd1 * t1 + dd2 * t2;
661670
float3 delta_n = (-displacement_scale) * grad_tan;
662671

663-
float3 view_dir = normalize3(-ray_dir);
664-
float ndv = fmaxf(0.0f, dot3(base_normal, view_dir));
665-
float atten_t = fmaxf(0.0f, fminf(1.0f, (ndv - 0.1f) / 0.3f));
666-
float atten = atten_t * atten_t * (3.0f - 2.0f * atten_t); // smoothstep
667-
delta_n = atten * delta_n;
668-
669672
float max_len = 0.4f;
670673
float len = length3(delta_n);
671674
if (len > max_len && len > 1e-6f)

src/rayon/gpu_renderers/shaders/shader_golf.cu

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,17 @@ __device__ bool hit_golf_ball_sphere(f3 center, float radius, const ray_simple &
7878

7979
if (base_displacement < -0.001f)
8080
{
81-
f3 helper = fabsf(base_normal.x) > 0.8f ? f3(0, 1, 0) : f3(1, 0, 0);
82-
f3 t1 = normalize(cross(helper, base_normal));
83-
f3 t2 = cross(base_normal, t1);
81+
// Duff et al. 2017 "Building an Orthonormal Basis, Revisited":
82+
// continuously varying basis — no seam from a sudden helper-vector switch.
83+
float nz_sign = copysignf(1.0f, base_normal.z);
84+
float nz_a = -1.0f / (nz_sign + base_normal.z);
85+
float nz_b = base_normal.x * base_normal.y * nz_a;
86+
f3 t1 = f3(1.0f + nz_sign * base_normal.x * base_normal.x * nz_a,
87+
nz_sign * nz_b,
88+
-nz_sign * base_normal.x);
89+
f3 t2 = f3(nz_b,
90+
nz_sign + base_normal.y * base_normal.y * nz_a,
91+
-base_normal.y);
8492

8593
const float h = 0.015f;
8694
f3 p_hat = base_normal;
@@ -95,11 +103,6 @@ __device__ bool hit_golf_ball_sphere(f3 center, float radius, const ray_simple &
95103
f3 delta_n =
96104
f3(-displacement_scale * grad_tan.x, -displacement_scale * grad_tan.y, -displacement_scale * grad_tan.z);
97105

98-
f3 view_dir = normalize(f3(-r.dir.x, -r.dir.y, -r.dir.z));
99-
float ndv = fmaxf(0.0f, dot(base_normal, view_dir));
100-
float atten = smoothstep(0.1f, 0.4f, ndv);
101-
delta_n = f3(delta_n.x * atten, delta_n.y * atten, delta_n.z * atten);
102-
103106
float max_len = 0.4f;
104107
float len = delta_n.length();
105108
if (len > max_len && len > 1e-6f)

0 commit comments

Comments
 (0)