Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit5856b28e64b1c3ef39d34c032275f9550e6ac983 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-04-16 19:14:53 +0300
Committer
 Syndamia <kamen@syndamia.com>
2024-04-16 19:14:53 +0300
Files454bd064bfb32556ae666a3f285b16fab6c6b768
uni-projects-5856b28e64b1c3ef39d34c032275f9550e6ac983.tar
uni-projects-5856b28e64b1c3ef39d34c032275f9550e6ac983.tar.gz
uni-projects-5856b28e64b1c3ef39d34c032275f9550e6ac983.zip
Parentb80b72b103fbc51adcc36e91b4d51bd6089d2aaa (diff)
[Ray/h5] Implemented new version of algorithm
1 files changed, 38 insertions, 19 deletions
-rw-r--r--Year 3/Raytracing/0002-h5-Added-OrenNayar-shader.patch57
diff --git a/Year 3/Raytracing/0002-h5-Added-OrenNayar-shader.patch b/Year 3/Raytracing/0002-h5-Added-OrenNayar-shader.patch
index fb7ae5f..8530c8c 100644
--- a/Year 3/Raytracing/0002-h5-Added-OrenNayar-shader.patch
+++ b/Year 3/Raytracing/0002-h5-Added-OrenNayar-shader.patch
@@ -1,14 +1,14 @@
-From 1f1cd2457d7e6bc7e3000fd1303a4d2a857c4b60 Mon Sep 17 00:00:00 2001
+From 898af59f7be5a9d0677c00663393f005842e29c0 Mon Sep 17 00:00:00 2001
From: Syndamia <kamen@syndamia.com>
-Date: Tue, 16 Apr 2024 18:27:57 +0300
+Date: Tue, 16 Apr 2024 19:12:16 +0300
Subject: [PATCH] [h5] Added OrenNayar shader
---
src/main.cpp | 85 ++++++++++++++++++++++++++-----------------------
- src/shading.cpp | 26 +++++++++++++++
- src/shading.h | 20 ++++++++++++
+ src/shading.cpp | 46 ++++++++++++++++++++++++++
+ src/shading.h | 19 +++++++++++
src/vector.h | 5 +++
- 4 files changed, 97 insertions(+), 39 deletions(-)
+ 4 files changed, 116 insertions(+), 39 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index ffb9478..8656207 100644
@@ -127,7 +127,7 @@ index ffb9478..8656207 100644
Uint32 end = SDL_GetTicks();
printf("Elapsed time: %.2f seconds.\n", (end - start) / 1000.0);
diff --git a/src/shading.cpp b/src/shading.cpp
-index 72dbdf2..123642c 100644
+index 72dbdf2..be5c02b 100644
--- a/src/shading.cpp
+++ b/src/shading.cpp
@@ -29,6 +29,7 @@
@@ -138,7 +138,7 @@ index 72dbdf2..123642c 100644
const Color AMBIENT_LIGHT(0.15, 0.15, 0.15);
Color ConstantShader::computeColor(Ray ray, const IntersectionInfo& info)
-@@ -69,6 +70,31 @@ Color Lambert::computeColor(Ray ray, const IntersectionInfo& info)
+@@ -69,6 +70,51 @@ Color Lambert::computeColor(Ray ray, const IntersectionInfo& info)
return direct + ambient;
}
@@ -152,18 +152,38 @@ index 72dbdf2..123642c 100644
+ return ambient;
+ }
+
-+ Vector Vi = lightPos - info.ip;
++ Vector Vi = lightPos - info.ip;
+ Vector Vr = camera.pos - info.ip;
-+ Color Li = lightColor * lightIntensity / Vi.lengthSqr();
++ Color Li = lightColor * lightIntensity / Vi.lengthSqr();
+ const double albedo = 1.0;
+
+ double thetai = angle(info.norm, Vi);
+ double thetar = angle(info.norm, Vr);
-+ double alpha = std::max(thetai, thetar), beta = std::min(thetai, thetar);
++ double alpha = std::max(thetai, thetar);
++ double beta = std::min(thetai, thetar);
+
-+ double surfProj = dot(normalize(project(Vi, info.norm)), normalize(project(Vr, info.norm))); // cos(phii - phir)
++ double cosPhi = dot(normalize(project(Vi, info.norm)),
++ normalize(project(Vr, info.norm))); // cos(phii - phir)
+
-+ Color Lr = albedo * Li * cos(thetai) * (A + (B * std::max(0.0, surfProj) * sin(alpha) * tan(beta)));
++ double betaTerm = 2 * beta / M_PI;
++
++ // C1 is in class
++ double C2 = 0.45 * (sigma2 / (sigma2 + 0.09));
++ if (cosPhi >= 0) C2 *= sin(alpha);
++ else C2 *= sin(alpha) - betaTerm * betaTerm * betaTerm;
++ double C3 = 0.125 * (sigma2 / (sigma2 + 0.09))
++ * sqr((4 * alpha * beta) / sqr(M_PI));
++
++ Color L1 = albedo * Li * cos(thetai)
++ * ( C1
++ + C2 * cosPhi * tan(beta)
++ + C3 * (1 - std::abs(cosPhi)) * tan((alpha + beta) / 2));
++
++ Color L2 = 0.17 * albedo * Li * cos(thetai)
++ * (sigma2 / (sigma2 + 0.13))
++ * (1 - cosPhi * sqr(betaTerm));
++
++ Color Lr = L1 + L2;
+ return diffuse * Lr + ambient;
+}
+
@@ -171,7 +191,7 @@ index 72dbdf2..123642c 100644
diffuse(color), specular(spec), specularExponent(specularExponent), diffuseTex(diffuseTex) {}
diff --git a/src/shading.h b/src/shading.h
-index 2bd1ef2..3ca71bd 100644
+index 2bd1ef2..0815359 100644
--- a/src/shading.h
+++ b/src/shading.h
@@ -28,10 +28,12 @@
@@ -187,13 +207,13 @@ index 2bd1ef2..3ca71bd 100644
class Shader {
-@@ -79,6 +81,24 @@ public:
+@@ -79,6 +81,23 @@ public:
virtual Color computeColor(Ray ray, const IntersectionInfo& info) override;
};
+class OrenNayar : public Shader {
-+ float A;
-+ float B;
++ float sigma2;
++ float C1;
+
+public:
+ Color diffuse;
@@ -202,9 +222,8 @@ index 2bd1ef2..3ca71bd 100644
+ Color color = Color(0.5, 0.5, 0.5),
+ float sigma = 0.0
+ ): diffuse(color), sigma(sigma) {
-+ float sigma2 = sigma * sigma;
-+ A = 1.0 - 0.5 * (sigma2 / (sigma2 + 0.33));
-+ B = 0.45 * (sigma2 / (sigma2 + 0.09));
++ sigma2 = sigma * sigma;
++ C1 = 1 - 0.5 * (sigma2 / (sigma2 + 0.33));
+ }
+ virtual Color computeColor(Ray ray, const IntersectionInfo& info) override;
+};