BRDF shader works better now but stil not correct
This commit is contained in:
parent
aac668b094
commit
65810ae975
1 changed files with 38 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
#include <array>
|
||||
#include <cmath>
|
||||
#include "light/light.h"
|
||||
#include "scene/scene.h"
|
||||
#include "shader/brdfshader.h"
|
||||
|
@ -8,6 +9,8 @@ BrdfShader::BrdfShader(char const *fileName, Color const &scale)
|
|||
|
||||
Color BrdfShader::shade(Scene const &scene, Ray const &ray) const {
|
||||
Color illuminationColor;
|
||||
/*
|
||||
* Arvids Code
|
||||
static auto rebase = [](Vector3d const &axis_x,
|
||||
Vector3d const &axis_y,
|
||||
Vector3d const &axis_z,
|
||||
|
@ -55,6 +58,40 @@ Color BrdfShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
std::acos(dotProduct(illum.direction, ray.normal)),
|
||||
std::acos(dotProduct(D, L)));
|
||||
}
|
||||
*/
|
||||
// IMPLEMENT ME
|
||||
return illuminationColor * scale;
|
||||
|
||||
for(auto& light : scene.lights()){
|
||||
Light::Illumination illum = light->illuminate(scene, ray);
|
||||
|
||||
Vector3d invertedDirection = -ray.direction;
|
||||
Vector3d invertedIllum = -illum.direction;
|
||||
|
||||
// the dot-product cant be negative otherwise the light ray would come from the inside
|
||||
if(dotProduct(invertedIllum, ray.normal) < 0)
|
||||
continue;
|
||||
|
||||
// Calculate coordinate System
|
||||
Vector3d axisX = crossProduct(invertedDirection, ray.normal);
|
||||
Vector3d axisY = crossProduct(axisX, ray.normal);
|
||||
|
||||
// Project ray.direction and illum.direction into plane
|
||||
Vector2d projectedIllum = Vector2d(dotProduct(axisX, invertedIllum), dotProduct(axisY, invertedIllum));
|
||||
Vector2d projectedDirection = Vector2d(dotProduct(axisX, invertedDirection), dotProduct(axisY, invertedDirection));
|
||||
|
||||
// get Z coordinate for theta angles
|
||||
double coordinateZDirection = dotProduct(ray.normal, invertedDirection);
|
||||
double coordinateZIllum = dotProduct(ray.normal, invertedIllum);
|
||||
|
||||
// calculate theta1 and 2
|
||||
double theta1Correct = std::atan2(length(projectedDirection), coordinateZDirection);
|
||||
double theta2Correct = std::atan2(length(projectedIllum), coordinateZIllum);
|
||||
|
||||
// calculate phi
|
||||
double phi = std::atan2(projectedIllum.u, projectedIllum.v);
|
||||
|
||||
illuminationColor += brdf->lookupBrdfValues(theta1Correct, 0.0, theta2Correct, phi);
|
||||
|
||||
}
|
||||
return illuminationColor;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue