Added light loss to refraction shader

This commit is contained in:
Maximilian Giller 2023-01-24 20:23:16 +01:00
parent 3b76969ff2
commit dcae587b8c
2 changed files with 10 additions and 4 deletions

View file

@ -1,8 +1,8 @@
#include "scene/scene.h"
#include "shader/refractionshader.h"
RefractionShader::RefractionShader(float indexInside, float indexOutside, Color const &objectColor) : indexInside(
indexInside), indexOutside(indexOutside), objectColor(objectColor)
RefractionShader::RefractionShader(float indexInside, float indexOutside, Color const &objectColor, float lightLoss) : indexInside(
indexInside), indexOutside(indexOutside), objectColor(objectColor), lightLoss(lightLoss)
{}
Color RefractionShader::shade(Scene const &scene, Ray const &ray) const
@ -51,7 +51,12 @@ Color RefractionShader::shade(Scene const &scene, Ray const &ray) const
}
// Send out a new refracted ray into the scene
return scene.traceRay(refractionRay) * objectColor;
Color hitColor = scene.traceRay(refractionRay);
// Calculate light lost
float lightRemaining = 1;
if (refractionRay.primitive == ray.primitive) lightRemaining = 1 - lightLoss + exp(-refractionRay.length / 10) * lightLoss;
return hitColor * objectColor * lightRemaining;
}
return Color(0.0f, 0.0f, 0.0f);
}

View file

@ -8,7 +8,7 @@ class RefractionShader : public Shader
public:
// Constructor
RefractionShader(float indexInside, float indexOutside, Color const &objectColor = Color(1, 1, 1));
RefractionShader(float indexInside, float indexOutside, Color const &objectColor = Color(1, 1, 1), float lightLoss = 0);
// Shader functions
Color shade(Scene const &scene, Ray const &ray) const override;
@ -18,6 +18,7 @@ public:
private:
float indexInside;
float indexOutside;
float lightLoss;
Color objectColor;
};