Skip to content

Commit fd0d17c

Browse files
committed
Fix normal issue
1 parent 3e61af9 commit fd0d17c

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

App/CL/integrator_pt.cl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ __kernel void ShadeSurface(
341341
// Check if we are hitting from the inside
342342

343343
float backfacing = dot(diffgeo.ng, wi) < 0.f;
344-
int twosided = diffgeo.mat.twosided;
344+
int twosided = diffgeo.mat.twosided;
345345
if (twosided && backfacing)
346346
{
347347
// Reverse normal and tangents in this case
@@ -414,6 +414,7 @@ __kernel void ShadeSurface(
414414
// Check if we need to apply normal map
415415
//ApplyNormalMap(&diffgeo, TEXTURE_ARGS);
416416
DifferentialGeometry_ApplyBumpMap(&diffgeo, TEXTURE_ARGS);
417+
//DifferentialGeometry_ApplyNormalMap(&diffgeo, TEXTURE_ARGS);
417418
DifferentialGeometry_CalculateTangentTransforms(&diffgeo);
418419

419420
float lightpdf = 0.f;
@@ -459,7 +460,7 @@ __kernel void ShadeSurface(
459460
// Generate shadow ray
460461
float shadow_ray_length = 0.999f * (1.f - CRAZY_LOW_DISTANCE) * length(wo);
461462
float3 shadow_ray_dir = normalize(wo);
462-
float3 shadow_ray_o = diffgeo.p + CRAZY_LOW_DISTANCE * s * diffgeo.n;
463+
float3 shadow_ray_o = diffgeo.p + CRAZY_LOW_DISTANCE * s * diffgeo.ng;
463464
int shadow_ray_mask = Bxdf_IsSingular(&diffgeo) ? 0xFFFFFFFF : 0x0000FFFF;
464465

465466
Ray_Init(shadowrays + globalid, shadow_ray_o, shadow_ray_dir, shadow_ray_length, 0.f, shadow_ray_mask);
@@ -473,7 +474,7 @@ __kernel void ShadeSurface(
473474
}
474475

475476
// And write the light sample
476-
lightsamples[globalid] = REASONABLE_RADIANCE(radiance);
477+
lightsamples[globalid] = REASONABLE_RADIANCE(radiance);
477478
}
478479
else
479480
{
@@ -511,7 +512,7 @@ __kernel void ShadeSurface(
511512

512513
// Generate ray
513514
float3 indirect_ray_dir = bxdfwo;
514-
float3 indirect_ray_o = diffgeo.p + CRAZY_LOW_DISTANCE * s * diffgeo.n;
515+
float3 indirect_ray_o = diffgeo.p + CRAZY_LOW_DISTANCE * s * diffgeo.ng;
515516

516517
Ray_Init(indirectrays + globalid, indirect_ray_o, indirect_ray_dir, CRAZY_HIGH_DISTANCE, 0.f, 0xFFFFFFFF);
517518
Ray_SetExtra(indirectrays + globalid, make_float2(bxdfpdf, fabs(dot(diffgeo.n, bxdfwo))));

App/CL/normalmap.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void DifferentialGeometry_ApplyNormalMap(DifferentialGeometry* diffgeo, TEXTURE_
3535
float3 mappednormal = 2.f * Texture_Sample2D(diffgeo->uv, TEXTURE_ARGS_IDX(nmapidx)).xyz - make_float3(1.f, 1.f, 1.f);
3636

3737
// Return mapped version
38-
diffgeo->n = normalize(mappednormal.z * diffgeo->n * 0.5f + mappednormal.x * diffgeo->dpdu + mappednormal.y * diffgeo->dpdv);
38+
diffgeo->n = normalize(mappednormal.z * diffgeo->n + mappednormal.x * diffgeo->dpdu - mappednormal.y * diffgeo->dpdv);
3939
diffgeo->dpdv = normalize(cross(diffgeo->n, diffgeo->dpdu));
4040
diffgeo->dpdu = normalize(cross(diffgeo->dpdv, diffgeo->n));
4141
}
@@ -50,7 +50,7 @@ void DifferentialGeometry_ApplyBumpMap(DifferentialGeometry* diffgeo, TEXTURE_AR
5050
float3 mappednormal = 2.f * Texture_SampleBump(diffgeo->uv, TEXTURE_ARGS_IDX(nmapidx)) - make_float3(1.f, 1.f, 1.f);
5151

5252
// Return mapped version
53-
diffgeo->n = normalize(mappednormal.z * diffgeo->n * 0.5f + mappednormal.x * diffgeo->dpdu + mappednormal.y * diffgeo->dpdv);
53+
diffgeo->n = normalize(mappednormal.z * diffgeo->n + mappednormal.x * diffgeo->dpdu + mappednormal.y * diffgeo->dpdv);
5454
diffgeo->dpdv = normalize(cross(diffgeo->n, diffgeo->dpdu));
5555
diffgeo->dpdu = normalize(cross(diffgeo->dpdv, diffgeo->n));
5656
}

App/Core/output.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Baikal
3737
{
3838

3939
/**
40-
\brief Interface for rendering output.
40+
\brief Interface for rendering output surface.
4141
4242
Represents discrete 2D surface with [0..w]x[0..h] coordinate ranges.
4343
*/

0 commit comments

Comments
 (0)