Skip to content

Commit

Permalink
NEE now accounts for BRDF.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbikker committed Dec 20, 2024
1 parent 2affe64 commit c8c6093
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tiny_bvh_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void Tick( float delta_time_s, fenster& f, uint32_t* buf )
// wavefront step 0: render on the GPU
init->SetArguments( N, rd.eye, rd.p0, rd.p1, rd.p2, frameIdx, cwbvhNodes, cwbvhTris );
init->Run( 1 ); // init atomic counters, set buffer ptrs etc.
generate->SetArguments( raysOut, frameIdx * 19191 );
generate->SetArguments( raysOut, spp * 19191 );
generate->Run2D( oclint2( SCRWIDTH, SCRHEIGHT ) );
for (int i = 0; i < 2; i++)
{
Expand Down
7 changes: 4 additions & 3 deletions wavefront.cl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void kernel Shade( global float4* accumulator,
float4 v0 = verts[vertIdx];
uint mat = as_uint( v0.w ) >> 24;
// end path on light
float3 lightColor = (float3)( 10 );
float3 lightColor = (float3)( 20 );
if (mat == 1)
{
if (depth == 0) accumulator[pixelIdx] += (float4)( T * lightColor, 1 );
Expand All @@ -185,21 +185,22 @@ void kernel Shade( global float4* accumulator,
float3 P = (float3)( RandomFloat( &seed ) * 9 - 4.5f, 30, RandomFloat( &seed ) * 5 - 3.5f );
float3 L = P - I;
float NdotL = dot( N, L );
float3 diff = (float3)(1); // material color; simply white for now
float3 BRDF = diff * INVPI; // lambert BRDF: albedo / pi
if (NdotL > 0)
{
uint newShadowIdx = atomic_inc( &connectTasks );
float dist2 = dot( L, L ), dist = sqrt( dist2 );
L *= 1.0f / dist;
float NLdotL = fabs( L.y ); // actually, fabs( dot( L, LN ) )
shadowOut[newShadowIdx].T = (float4)( lightColor * T * NdotL * NLdotL * (1.0f / dist2), 0 );
shadowOut[newShadowIdx].T = (float4)( lightColor * BRDF * T * NdotL * NLdotL * (1.0f / dist2), 0 );
shadowOut[newShadowIdx].O = (float4)( I + L * 0.001f, as_float( pixelIdx ) );
shadowOut[newShadowIdx].D = (float4)( L, dist - 0.002f );
}
// indirect illumination: diffuse bounce
if (depth < 2)
{
uint newRayIdx = atomic_inc( &extendTasks );
float3 BRDF = (float3)(1) /* just white for now */ * INVPI;
float3 R = CosWeightedDiffReflection( N, &seed );
float PDF = dot( N, R ) * INVPI;
T *= dot( N, R ) * BRDF * (1.0f / PDF);
Expand Down

0 comments on commit c8c6093

Please sign in to comment.