Skip to content

Commit 7919360

Browse files
committed
Some fixes
1 parent 547f9c6 commit 7919360

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed

App/CL/camera.cl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ typedef struct _Camera
3838
float3 right;
3939
float3 up;
4040
float3 p;
41-
41+
4242
// Image plane width & height in current units
4343
float2 dim;
44-
44+
4545
// Near and far Z
4646
float2 zcap;
4747
// Focal lenght
@@ -78,7 +78,7 @@ __kernel void PerspectiveCamera_GeneratePaths(
7878
int2 globalid;
7979
globalid.x = get_global_id(0);
8080
globalid.y = get_global_id(1);
81-
81+
8282
// Check borders
8383
if (globalid.x < imgwidth && globalid.y < imgheight)
8484
{
@@ -88,7 +88,7 @@ __kernel void PerspectiveCamera_GeneratePaths(
8888
#ifndef NO_PATH_DATA
8989
__global Path* mypath = paths + globalid.y * imgwidth + globalid.x;
9090
#endif
91-
91+
9292
// Prepare RNG
9393
Rng rng;
9494
InitRng(randseed + globalid.x * 157 + 10433 * globalid.y, &rng);
@@ -112,17 +112,17 @@ __kernel void PerspectiveCamera_GeneratePaths(
112112
#else
113113
float2 sample0 = UniformSampler_Sample2D(&rng);
114114
#endif
115-
115+
116116
// Calculate [0..1] image plane sample
117117
float2 imgsample;
118118
imgsample.x = (float)globalid.x / imgwidth + sample0.x / imgwidth;
119119
imgsample.y = (float)globalid.y / imgheight + sample0.y / imgheight;
120-
120+
121121
// Transform into [-0.5, 0.5]
122122
float2 hsample = imgsample - make_float2(0.5f, 0.5f);
123123
// Transform into [-dim/2, dim/2]
124124
float2 csample = hsample * camera->dim;
125-
125+
126126
// Calculate direction to image plane
127127
myray->d.xyz = normalize(camera->focal_length * camera->forward + csample.x * camera->right + csample.y * camera->up);
128128
// Origin == camera position + nearz * d

App/CL/integrator_pt.cl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ __kernel void ShadeSurface(
474474
return;
475475
}
476476

477-
/*if (!bxdf_singular)
477+
if (!bxdf_singular)
478478
{
479479
// Sample light
480480
float3 le = Light_Sample(light_idx, &scene, &diffgeo, TEXTURE_ARGS, sample1, &lightwo, &lightpdf);
@@ -524,18 +524,16 @@ __kernel void ShadeSurface(
524524
}
525525
}
526526
else
527-
{*/
527+
{
528528
// Otherwise save some intersector cycles
529529
Ray_SetInactive(shadowrays + 2 * globalid);
530530
lightsamples[2 * globalid] = 0;
531-
//}
531+
}
532532

533-
if (1/*!light_singular*/)
533+
if (!light_singular)
534534
{
535535
// Sample bxdf
536536
float3 bxdf = Bxdf_Sample(&diffgeo, wi, TEXTURE_ARGS, sample2, &bxdfwo, &bxdfpdf);
537-
bxdfwo *= CRAZY_HIGH_DISTANCE;
538-
539537
bxdflightpdf = Light_GetPdf(light_idx, &scene, &diffgeo, bxdfwo, TEXTURE_ARGS);
540538
bxdfweight = BalanceHeuristic(1, bxdfpdf, 1, bxdflightpdf);
541539

@@ -544,16 +542,18 @@ __kernel void ShadeSurface(
544542
{
545543
wo = bxdfwo;
546544
float ndotwo = fabs(dot(diffgeo.n, normalize(wo)));
547-
radiance = Light_GetLe(light_idx, &scene, &diffgeo, &wo, TEXTURE_ARGS) * bxdf * throughput * ndotwo * bxdfweight / bxdfpdf / selection_pdf;
545+
float3 le = Light_GetLe(light_idx, &scene, &diffgeo, &wo, TEXTURE_ARGS);
546+
radiance = le * bxdf * throughput * ndotwo * bxdfweight / bxdfpdf / selection_pdf;
548547

549548
if (NON_BLACK(radiance))
550549
{
551550
// Generate shadow ray
552-
float shadow_ray_length = CRAZY_HIGH_DISTANCE;
551+
float shadow_ray_length = (1.f - 2.f * CRAZY_LOW_DISTANCE) * length(wo);
553552
float3 shadow_ray_dir = normalize(wo);
554553
float3 shadow_ray_o = diffgeo.p + CRAZY_LOW_DISTANCE * s * diffgeo.n;
555554
int shadow_ray_mask = Bxdf_IsSingular(&diffgeo) ? 0xFFFFFFFF : 0x0000FFFF;
556555

556+
557557
Ray_Init(shadowrays + 2 * globalid + 1, shadow_ray_o, shadow_ray_dir, shadow_ray_length, 0.f, shadow_ray_mask);
558558

559559
// Apply the volume to shadow ray if needed
@@ -575,8 +575,8 @@ __kernel void ShadeSurface(
575575
}
576576
}
577577
else
578-
{
579578
// Otherwise save some intersector cycles
579+
{
580580
Ray_SetInactive(shadowrays + 2 * globalid + 1);
581581
lightsamples[2 * globalid + 1] = 0;
582582
}
@@ -587,7 +587,7 @@ __kernel void ShadeSurface(
587587
Ray_SetInactive(shadowrays + 2 * globalid + 1);
588588
lightsamples[2 * globalid + 1] = 0;
589589
}
590-
590+
591591
// Apply Russian roulette
592592
float q = max(min(0.5f,
593593
// Luminance

App/CL/light.cl

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ THE SOFTWARE.
2828
#include <../App/CL/texture.cl>
2929

3030

31-
int IntersectTriangle(ray const* r, float3 v1, float3 v2, float3 v3, float* a, float* b)
31+
bool IntersectTriangle(ray const* r, float3 v1, float3 v2, float3 v3, float* a, float* b)
3232
{
3333
const float3 e1 = v2 - v1;
3434
const float3 e2 = v3 - v1;
@@ -40,15 +40,15 @@ int IntersectTriangle(ray const* r, float3 v1, float3 v2, float3 v3, float* a, f
4040
const float b2 = dot(r->d.xyz, s2) * invd;
4141
const float temp = dot(e2, s2) * invd;
4242

43-
if (b1 < 0.f || b1 > 1.f || b2 < 0.f || b1 + b2 > 1.f || temp < 0.f || temp > r->o.w)
43+
if (b1 < 0.f || b1 > 1.f || b2 < 0.f || b1 + b2 > 1.f)
4444
{
45-
return 0;
45+
return false;
4646
}
4747
else
4848
{
4949
*a = b1;
5050
*b = b2;
51-
return 1;
51+
return true;
5252
}
5353
}
5454

@@ -138,9 +138,8 @@ float3 AreaLight_GetLe(// Emissive object
138138
)
139139
{
140140
ray r;
141-
r.o.xyz = dg->p + normalize(*wo) * 0.01f;
142-
r.o.w = 100000.f;
143-
r.d.xyz = *wo;
141+
r.o.xyz = dg->p;
142+
r.d.xyz = normalize(*wo);
144143

145144
int shapeidx = light->shapeidx;
146145
int primidx = light->primidx;
@@ -170,6 +169,7 @@ float3 AreaLight_GetLe(// Emissive object
170169

171170

172171
// Intersect ray against this area light
172+
173173
float a, b;
174174
if (IntersectTriangle(&r, v0, v1, v2, &a, &b))
175175
{
@@ -179,27 +179,18 @@ float3 AreaLight_GetLe(// Emissive object
179179

180180
float3 d = p - dg->p;
181181
float ld = length(d);
182+
*wo = p - dg->p;
182183

183184
int matidx = scene->materialids[shape.startidx / 3 + primidx];
184185
Material mat = scene->materials[matidx];
185186

186187
const float3 ke = Texture_GetValue3f(mat.kx.xyz, tx, TEXTURE_ARGS_IDX(mat.kxmapidx));
187188
float ndotv = dot(n, -(normalize(d)));
188-
189-
if (ndotv > 0.f)
190-
{
191-
*wo = d;
192-
float denom = ld * ld;
193-
return denom > 0.f ? ke * ndotv / denom : 0.f;
194-
}
195-
else
196-
{
197-
return 1.f;
198-
}
189+
return ke;
199190
}
200191
else
201192
{
202-
return 1.f;
193+
return 0.f;
203194
}
204195
}
205196

@@ -297,7 +288,7 @@ float AreaLight_GetPdf(// Emissive object
297288
)
298289
{
299290
ray r;
300-
r.o.xyz = dg->p + normalize(wo) * 0.001f;
291+
r.o.xyz = dg->p;
301292
r.d.xyz = wo;
302293

303294
int shapeidx = light->shapeidx;

0 commit comments

Comments
 (0)