Comments (1)
Answering my own question, the issue was that I was calculating the intersection between the ray and the planes without considering whether the plane was behind the ray or not. Originally, I was calculating the plane-ray intersection as follows:
let d = -normal.dot(&self.a.coords); // Parameter of plane equation
let n_dot_raydir = -normal.dot(&ray.direction);
if n_dot_raydir <= 0. {
return None;
}
// If it exists, calculate the intersection point
let t = (normal.dot(&ray.origin.coords) + d) / n_dot_raydir;
let intersection_point = ray.origin + t * ray.direction;
without taking into consideration the fact that if t
is negative, the intersection point is behind the ray, so it should be discarded.
It is sufficient to check for that condition and discard the point accordingly as follows:
let d = -normal.dot(&self.a.coords); // Parameter of plane equation
let n_dot_raydir = -normal.dot(&ray.direction);
if n_dot_raydir <= 0. {
return None;
}
// If it exists, calculate the intersection point
let t = (normal.dot(&ray.origin.coords) + d) / n_dot_raydir;
if t < 0. {
return None;
}
let intersection_point = ray.origin + t * ray.direction;
Without this, all the object properties (shadows, reflections, refractions) were being affected.
from tinyraytracer.
Related Issues (20)
- Visual Studio OpenMP 2.0 Support HOT 1
- Tinyraytracer in Golang HOT 1
- Wont compile in gitpod HOT 6
- Tinyraytracer in Python HOT 4
- How do you rotate the camera? HOT 1
- Raytracer in shadertoy HOT 1
- Rotating the background (envmap) image HOT 1
- It can't successfully compile HOT 1
- Why my mirror sphere not reflect sea
- Why the mirror don't reflect the sea? HOT 2
- Something I don't understand in your code HOT 6
- I have add a quack!
- Can't get right render image. HOT 2
- Colored Light Sources
- Step 1 is broken HOT 5
- question on Step 6: shadows HOT 3
- Multithreading for performance HOT 3
- Error relating to pragma when running tinyraytracer.cpp HOT 1
- Can you please post the answers to the homework?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyraytracer.