Skip to content

Commit

Permalink
Carry energy through specular reflection, metallic reflection, and tr…
Browse files Browse the repository at this point in the history
…ansmission. (#1514)

* Carry energy through specular and metallic reflection and transmission.

* Fix copy/paste typo.
  • Loading branch information
ThatRedox authored and leMaik committed Dec 28, 2022
1 parent 8694ff0 commit a2e8943
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions chunky/src/java/se/llbit/chunky/renderer/scene/PathTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state, int add
reflected.specularReflection(ray, random);

if (pathTrace(scene, reflected, state, 1, false)) {
ray.emittance.x = ray.color.x * reflected.emittance.x;
ray.emittance.y = ray.color.y * reflected.emittance.y;
ray.emittance.z = ray.color.z * reflected.emittance.z;

if (doMetal) {
// use the albedo color as specular color
ray.color.x *= reflected.color.x;
Expand Down Expand Up @@ -299,6 +303,10 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state, int add
Ray reflected = new Ray();
reflected.specularReflection(ray, random);
if (pathTrace(scene, reflected, state, 1, false)) {
ray.emittance.x = ray.color.x * reflected.emittance.x;
ray.emittance.y = ray.color.y * reflected.emittance.y;
ray.emittance.z = ray.color.z * reflected.emittance.z;

ray.color.x = reflected.color.x;
ray.color.y = reflected.color.y;
ray.color.z = reflected.color.z;
Expand Down Expand Up @@ -337,6 +345,11 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state, int add
ray.color.x = ray.color.x * pDiffuse + (1 - pDiffuse);
ray.color.y = ray.color.y * pDiffuse + (1 - pDiffuse);
ray.color.z = ray.color.z * pDiffuse + (1 - pDiffuse);

ray.emittance.x = ray.color.x * refracted.emittance.x;
ray.emittance.y = ray.color.y * refracted.emittance.y;
ray.emittance.z = ray.color.z * refracted.emittance.z;

ray.color.x *= refracted.color.x;
ray.color.y *= refracted.color.y;
ray.color.z *= refracted.color.z;
Expand All @@ -356,6 +369,11 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state, int add
ray.color.x = ray.color.x * pDiffuse + (1 - pDiffuse);
ray.color.y = ray.color.y * pDiffuse + (1 - pDiffuse);
ray.color.z = ray.color.z * pDiffuse + (1 - pDiffuse);

ray.emittance.x = ray.color.x * transmitted.emittance.x;
ray.emittance.y = ray.color.y * transmitted.emittance.y;
ray.emittance.z = ray.color.z * transmitted.emittance.z;

ray.color.x *= transmitted.color.x;
ray.color.y *= transmitted.color.y;
ray.color.z *= transmitted.color.z;
Expand Down

0 comments on commit a2e8943

Please sign in to comment.