Skip to content

Commit dda4090

Browse files
cancel out normalization
1 parent 80814ab commit dda4090

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/testrender/raytracer.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,16 @@ struct Scene {
282282
OSL_HOSTDEVICE
283283
void project(Dual2<Vec3>& p, const Vec3& N, const Vec3& I) const
284284
{
285-
float cosx = dot(p.dx().normalized(), N);
286-
float cosy = dot(p.dy().normalized(), N);
287-
float cosI = dot(-I.normalized(), N);
285+
Vec3 nI = I.normalized();
286+
float cosI = dot(-nI, N);
288287

289-
if (abs(cosI)>1e-3 )
288+
if (fabsf(cosI)>1e-3f)
290289
{
291-
float deltaX = p.dx().length() * cosx / cosI;
292-
float deltaY = p.dy().length() * cosy / cosI;
290+
float deltaX = dot(p.dx(), N) / cosI;
291+
float deltaY = dot(p.dy(), N) / cosI;
293292

294-
p.dx() += I.normalized() * deltaX;
295-
p.dy() += I.normalized() * deltaY;
293+
p.dx() += nI * deltaX;
294+
p.dy() += nI * deltaY;
296295
}
297296
}
298297

@@ -333,13 +332,13 @@ struct Scene {
333332
Vec3 Lc = n.cross(vb - va);
334333
Lc /= dot(vc - va, Lc);
335334

336-
Vec2 dTdx = dot(La, p.dx()) * ta +
337-
dot(Lb, p.dx()) * tb +
338-
dot(Lc, p.dx()) * tc;
335+
Vec2 dTdx = dot(La, p.dx()) * ta
336+
+ dot(Lb, p.dx()) * tb
337+
+ dot(Lc, p.dx()) * tc;
339338

340-
Vec2 dTdy = dot(La, p.dy()) * ta +
341-
dot(Lb, p.dy()) * tb +
342-
dot(Lc, p.dy()) * tc;
339+
Vec2 dTdy = dot(La, p.dy()) * ta
340+
+ dot(Lb, p.dy()) * tb
341+
+ dot(Lc, p.dy()) * tc;
343342

344343
return Dual2<Vec2>((1 - u - v) * ta + u * tb + v * tc, dTdx, dTdy);
345344
}

src/testrender/simpleraytracer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ SimpleRaytracer::globals_from_hit(ShaderGlobalsType& sg, const Ray& r,
900900
sg.I = direction.val();
901901
sg.dIdx = direction.dx();
902902
sg.dIdy = direction.dy();
903-
Dual2<Vec3> P = r.point(t);
903+
Dual2<Vec3> P = r.point(t);
904904
sg.P = P.val();
905905
sg.N = scene.normal(P, sg.Ng, id, u, v);
906906
// Projecting onto the surface here

0 commit comments

Comments
 (0)