Skip to content

Commit 982c282

Browse files
committed
update readme
1 parent 897d481 commit 982c282

File tree

10 files changed

+164
-28
lines changed

10 files changed

+164
-28
lines changed

README.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ This works fine when we can implicitly define intersecting method for each geome
3333
intersection with implicit geometries to calculating it with all triangles!
3434

3535
This gives an extremely low performance when model with many faces is loaded:
36-
| < 200 faces (~60 fps) | ~6000 faces (< 10 fps) |
36+
37+
| < 200 faces (~60 fps) | ~6000 faces (< 10 fps) |
3738
| -------------------------------- | ------------------------------- |
3839
| ![](results/BVH/simplescene.png) | ![](results/BVH/marioScene.png) |
3940

@@ -55,9 +56,10 @@ We can go even further with a stanford dragon (2,349,078 triangles)
5556
| ![](results/BVH/Dragon.png) |
5657

5758
Visualizer:
58-
| Wahoo | Dragon | Mineway Castle |
59-
| ------------------------------- | ----------------------------- | --------------------------- |
60-
| 5117 triangles | 2,349,078 triangles | 6,490,766 triangles |
59+
60+
| Wahoo | Dragon | Mineway Castle |
61+
| ------------------------ | ------------------------------ | ----------------------------- |
62+
| 5117 triangles | 2,349,078 triangles | 6,490,766 triangles |
6163
| ![](results/BVH/BVH.png) | ![](results/BVH/DragonBVH.png) | ![](results/BVH/CoverBVH.png) |
6264

6365
# Disney BRDF Model
@@ -79,7 +81,7 @@ float sheenTint 0 1 .5
7981
float clearcoat 0 1 0
8082
float clearcoatGloss 0 1 1
8183

82-
| JSON Input |
84+
| Input Format
8385
| ------------------------------------- |
8486
| ![](results/DisneyBRDF/jsonInput.png) |
8587

@@ -92,3 +94,42 @@ GUI allowing for dynamically changing parameters:
9294
A brief demo illustrates the usage:
9395

9496
https://github.com/user-attachments/assets/62e0fcce-20bc-49f6-b9c6-eea6904767dc
97+
98+
# Direct Lighting & Multi-Importance Sampling
99+
100+
Consider the following 2 scenarios:
101+
102+
1. When light is very small in size
103+
2. When we want to implement point light/directional light/spot light
104+
105+
When light is small in size, it is less likely for a diffused BRDF to gather meaningful light contribution.
106+
Therefore, each time when light hit a surface, we can consider sample radiance directly from a light in the scene.
107+
This way of calculating radiance contribution is called direct lighting.
108+
109+
The direct radiance from different sample point:
110+
111+
| Direct Lighting Radiance |
112+
| ------------------------------- |
113+
| ![](results/MIS/DIRadiance.png) |
114+
115+
But direct lighting behaves poor when sampling from a light with large area
116+
117+
Veach Scene:
118+
119+
| BSDF Lighting | Direct Lighting | MIS Lighting |
120+
| ---------------------------- | -------------------------- | ----------------------------- |
121+
| ![](results/MIS/MISBSDF.png) | ![](results/MIS/MISDI.png) | ![](results/MIS/MISVeach.png) |
122+
123+
So a good practice might be to combine the two method. To ensure energy-conserving contribution, we use Power Heuristic to calculate the appropriate weight for the directional light radiance.
124+
125+
Also by having an additional directional light contribution, we can acchieve a faster convergence. In order to make a correct contribution to our final color. At each bounce, multiply the sampled radiance with corresponding throughput (radiance `*` accumThroughput `*` BSDF(wo, wdirect)).
126+
127+
| Accumulative Color (depth = 1) |
128+
| ------------------------------- |
129+
| ![](results/MIS/accumColor.png) |
130+
131+
Some results:
132+
133+
| MIS On | MIS Off |
134+
| -------------------------- | --------------------------- |
135+
| ![](results/MIS/MISOn.png) | ![](results/MIS/MISOff.png) |

results/MIS/DIRadiance.png

328 KB
Loading

results/MIS/MISBSDF.png

10 Bytes
Loading

results/MIS/accumColor.png

141 KB
Loading

results/MIS/beforeMIS.png

1.37 MB
Loading

scenes/MISConverge.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"Materials":
3+
{
4+
"light":
5+
{
6+
"TYPE":"Emitting",
7+
"RGB":[1.0, 1.0, 1.0],
8+
"EMITTANCE":10.0
9+
},
10+
"diffuse_white":
11+
{
12+
"TYPE":"Diffuse",
13+
"RGB":[0.98, 0.98, 0.98]
14+
},
15+
"diffuse_red":
16+
{
17+
"TYPE":"Diffuse",
18+
"RGB":[0.85, 0.35, 0.35]
19+
},
20+
"diffuse_green":
21+
{
22+
"TYPE":"Diffuse",
23+
"RGB":[0.35, 0.85, 0.35]
24+
},
25+
"specular_white":
26+
{
27+
"TYPE":"Specular",
28+
"RGB":[0.98, 0.98, 0.98],
29+
"METALLIC":1,
30+
"SUBSURFACE":0.0,
31+
"SPECULAR":1,
32+
"ROUGHNESS":0.3,
33+
"SPECULARTINT":0.0,
34+
"ANISOTROPIC":0.0,
35+
"SHEEN":0.0,
36+
"SHEENTINT":0.0,
37+
"CLEARCOAT":0.0,
38+
"CLEARCOATGLOSS":0.0
39+
}
40+
},
41+
"Camera":
42+
{
43+
"RES":[800,800],
44+
"FOVY":45.0,
45+
"ITERATIONS":3000,
46+
"DEPTH":8,
47+
"FILE":"cornell",
48+
"EYE":[0.0,5.0,10.5],
49+
"LOOKAT":[0.0,5.0,0.0],
50+
"UP":[0.0,1.0,0.0]
51+
},
52+
"Objects":
53+
[
54+
{
55+
"TYPE":"cube",
56+
"MATERIAL":"diffuse_white",
57+
"TRANS":[0.0,0.0,0.0],
58+
"ROTAT":[0.0,0.0,0.0],
59+
"SCALE":[5.0,0.005,5.0]
60+
},
61+
{
62+
"TYPE":"mesh",
63+
"MATERIAL":"specular_white",
64+
"FILENAME":"D:\\Fall2024\\CIS5650\\Project3-CUDA-Path-Tracer\\scenes\\objs\\Dragon.obj",
65+
"TRANS":[0.0,4.6,0.0],
66+
"ROTAT":[-85.0,0.0,0.0],
67+
"SCALE":[0.04, 0.04, 0.04]
68+
}
69+
],
70+
"Lights":
71+
[
72+
{
73+
"TYPE":"Area",
74+
"TRANS":[0.0,9.8,0.0],
75+
"ROTAT":[-90.0,0.0,0.0],
76+
"SCALE":[0.3,0.3,0.3],
77+
"MATERIAL":
78+
{
79+
"RGB":[1, 1, 1],
80+
"EMITTANCE":200.0,
81+
"ROUGHNESS":1.0
82+
}
83+
}
84+
]
85+
86+
}

scenes/cornellNoSphere.json

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"METALLIC":1,
3030
"SUBSURFACE":0.0,
3131
"SPECULAR":1,
32-
"ROUGHNESS":0.0,
32+
"ROUGHNESS":0.3,
3333
"SPECULARTINT":0.0,
3434
"ANISOTROPIC":0.0,
3535
"SHEEN":0.0,
@@ -42,7 +42,7 @@
4242
{
4343
"RES":[800,800],
4444
"FOVY":45.0,
45-
"ITERATIONS":5000,
45+
"ITERATIONS":3000,
4646
"DEPTH":8,
4747
"FILE":"cornell",
4848
"EYE":[0.0,5.0,10.5],
@@ -51,13 +51,6 @@
5151
},
5252
"Objects":
5353
[
54-
{
55-
"TYPE":"cube",
56-
"MATERIAL":"light",
57-
"TRANS":[0.0,10.0,0.0],
58-
"ROTAT":[0.0,0.0,0.0],
59-
"SCALE":[1.5,0.15,1.5]
60-
},
6154
{
6255
"TYPE":"cube",
6356
"MATERIAL":"diffuse_white",
@@ -101,6 +94,25 @@
10194
"ROTAT":[-85.0,0.0,0.0],
10295
"SCALE":[0.04, 0.04, 0.04]
10396
}
104-
]
97+
],
98+
"Lights":
99+
[
100+
{
101+
"TYPE":"Area",
102+
"TRANS":[0.0,9.8,0.0],
103+
"ROTAT":[-90.0,0.0,0.0],
104+
"SCALE":[1,1,1],
105+
"MATERIAL":
106+
{
107+
"RGB":[0.79, 0.79, 0.79],
108+
"EMITTANCE":40.0,
109+
"ROUGHNESS":1.0
110+
}
111+
}
112+
],
113+
"Environment":
114+
{
115+
"FILENAME": "D:\\Fall2024\\CIS5650\\Project3-CUDA-Path-Tracer\\scenes\\hdri\\night1.hdr"
116+
}
105117

106118
}

src/interactions.cu

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,24 @@ __device__ void MIS(
143143
//MIS
144144
float pdf_disney_for_direct = 0;
145145
float pdf_direct_for_disney = 0;
146-
glm::vec3 Li_disney_for_direct = glm::vec3(0.f);
147-
glm::vec3 Li_direct_for_disney = glm::vec3(0.f);
146+
glm::vec3 bsdf_direct = glm::vec3(0.f);
147+
bsdf_direct = Evaluate_disneyBSDF(m, wtl * wi_direct, wol, pdf_disney_for_direct, false, false);
148148

149-
//Li_direct_for_disney = Evaluate_Li(ltw * wi_disney, intersect, pdf_direct_for_disney, intersection.directLightId, num_lights, envMap, dev_nodes, dev_triangles, dev_lights);
150-
Li_disney_for_direct = Evaluate_disneyBSDF(m, wtl * wi_direct, wol, pdf_disney_for_direct, false, false);
151-
152-
153-
154-
//float weight_disney = PowerHeuristic(1, pdf_disney, 1, pdf_direct_for_disney);
155149
float weight_direct = PowerHeuristic(1, pdf_direct, 1, pdf_disney_for_direct);
156150

157151
if (pdf_direct > 1e-6f)
158152
{
159-
glm::vec3 radiance = pathSegment.throughput * Li_direct * Li_disney_for_direct * AbsDot(wi_direct, normal) / pdf_direct * weight_direct;
153+
glm::vec3 radiance = pathSegment.throughput * Li_direct * AbsDot(wi_direct, normal) / pdf_direct * weight_direct * bsdf_direct;
160154
currAccum += radiance.x < 0 || radiance.y < 0 || radiance.z < 0 ? glm::vec3(0) : radiance;
161155
}
162156

163-
//pathSegment.accumLight += Li_disney;
157+
//pathSegment.accumLight += bsdf_direct * AbsDot(wi_direct, normal) / pdf_disney_for_direct;
164158
//pathSegment.remainingBounces = 0;
165159
}
166160

167161
pathSegment.remainingBounces--;
168162
glm::vec3 offset = normal * (isInternal ? 1e-3f : -(1e-3f));
169-
pathSegment.accumLight = currAccum;
163+
//pathSegment.accumLight = currAccum;
170164

171165
wi = glm::normalize(ltw * wi_disney);
172166
pathSegment.throughput *= Li_disney * AbsCosTheta(wi_disney) / pdf_disney;

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int main(int argc, char** argv)
4848

4949
const char* sceneFile = argv[1];
5050
// Load scene file
51-
scene = new Scene("D:\\Fall2024\\CIS5650\\Project3-CUDA-Path-Tracer\\scenes\\DisneyBRDF.json");
51+
scene = new Scene("D:\\Fall2024\\CIS5650\\Project3-CUDA-Path-Tracer\\scenes\\PT_veachScene.json");
5252
//scene->createBRDFDisplay();
5353
// test loading obj
5454
Material newMaterial(glm::vec3(15, 154, 255) / 255.f);

src/pathtrace.cu

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,10 @@ __global__ void shadeMaterialNaive(
410410
// If the material indicates that the object was a light, "light" the ray
411411
if (material.emittance > 0.0f) {
412412
pathSegment.remainingBounces = 0;
413-
pathSegment.accumLight += pathSegment.throughput * materialColor * material.emittance;
413+
glm::vec3 radiance = pathSegment.throughput * materialColor * material.emittance + pathSegment.accumLight;
414+
//float maxRadiance = glm::max(radiance.x, glm::max(radiance.y, radiance.z));
415+
//radiance *= maxRadiance > 0.97f ? 0.97f / maxRadiance : 1.0;
416+
pathSegment.accumLight = radiance;
414417
}
415418
else
416419
{

0 commit comments

Comments
 (0)