File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -152,6 +152,10 @@ struct Tools {
152152 const glm::vec3 &pb,
153153 const glm::vec3 &pc);
154154
155+ static glm::vec3 reflect (const glm::vec3& I, const glm::vec3& N);
156+
157+ static glm::vec3 refract (const glm::vec3& I, const glm::vec3& N, const float & ior);
158+
155159 static float fresnel (const glm::vec3 &rayDirection, const glm::vec3 &normal,
156160 const float &refractiveIndex);
157161
Original file line number Diff line number Diff line change @@ -247,6 +247,21 @@ glm::vec3 SoftRasterizer::Tools::calculateNormalWithWeight(
247247 return glm::normalize (normal);
248248}
249249
250+ glm::vec3 SoftRasterizer::Tools::reflect (const glm::vec3& I, const glm::vec3& N) {
251+ return I - 2 * glm::dot (I, N) * N;
252+ }
253+
254+ glm::vec3 SoftRasterizer::Tools::refract (const glm::vec3& I, const glm::vec3& N, const float & ior) {
255+ float cosi = std::clamp (glm::dot (I, N), -1 .f , 1 .f );
256+ float etai = 1 .f , etat = ior;
257+ glm::vec3 n = N;
258+ if (cosi < 0 ) { cosi = -cosi; }
259+ else { std::swap (etai, etat); n = -N; }
260+ float eta = etai / etat;
261+ float k = 1 - eta * eta * (1 - cosi * cosi);
262+ return k < 0 ? glm::vec3 (0 .f ) : eta * I + (eta * cosi - sqrtf (k)) * n;
263+ }
264+
250265float SoftRasterizer::Tools::fresnel (const glm::vec3 &rayDirection,
251266 const glm::vec3 &normal,
252267 const float &refractiveIndex) {
You can’t perform that action at this time.
0 commit comments