Fixed some major mathematical errors
This commit is contained in:
parent
37753f96af
commit
70963aaf71
1 changed files with 9 additions and 10 deletions
|
@ -23,8 +23,8 @@ Color RefractionShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
|
||||
// Check whether we are entering or leaving the object
|
||||
if (dotProduct(v, n) > 0) {
|
||||
eta1 = indexInside;
|
||||
eta2 = indexOutside;
|
||||
n = -n;
|
||||
std::swap(eta1, eta2);
|
||||
}
|
||||
|
||||
// Calculate refraction percentage
|
||||
|
@ -49,17 +49,16 @@ Color RefractionShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
n * std::sqrt(denominator));
|
||||
|
||||
// Calculate reflected ray direction
|
||||
Vector3d cosTheta1 = crossProduct(v, n);
|
||||
Vector3d cosTheta2 = -1.0f * crossProduct(n, t);
|
||||
auto cosTheta1 = dotProduct(-n, normalized(v));
|
||||
auto cosTheta2 = std::sqrt(denominator);
|
||||
|
||||
Vector3d polarizationParallel = (eta2 * cosTheta1 - eta1 * cosTheta2) /
|
||||
auto polarizationParallel = (eta2 * cosTheta1 - eta1 * cosTheta2) /
|
||||
(eta2 * cosTheta1 + eta1 * cosTheta2);
|
||||
Vector3d polarizationOrthogonal = (eta1 * cosTheta1 - eta2 * cosTheta2) /
|
||||
auto polarizationOrthogonal = (eta1 * cosTheta1 - eta2 * cosTheta2) /
|
||||
(eta1 * cosTheta1 + eta2 * cosTheta2);
|
||||
|
||||
Vector3d reflectionVector = normalized(
|
||||
0.5f * (polarizationParallel * polarizationParallel + polarizationOrthogonal * polarizationOrthogonal));
|
||||
|
||||
auto reflectionFactor = (polarizationParallel * polarizationParallel + polarizationOrthogonal * polarizationOrthogonal) / 2;
|
||||
Vector3d reflectionVector = v - 2.0f * dotProduct(n, v) * n;
|
||||
// Calculate rays
|
||||
Vector3d rayOrigin = ray.origin + ray.length * ray.direction;
|
||||
Ray refractionRay = Ray(rayOrigin, t);
|
||||
|
@ -74,7 +73,7 @@ Color RefractionShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
Color refractionColor = scene.traceRay(refractionRay);
|
||||
Color reflectionColor = scene.traceRay(reflectionRay);
|
||||
|
||||
Color resultingColor = denominator * refractionColor + (1-denominator) * reflectionColor;
|
||||
Color resultingColor = (1-reflectionFactor) * refractionColor + reflectionFactor * reflectionColor;
|
||||
|
||||
return resultingColor;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue