Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitd942e135e502ee409222b9389a5a03b3f2861582 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-07-01 16:23:30 +0300
Committer
 Syndamia <kamen@syndamia.com>
2024-07-01 16:23:30 +0300
Filesfc8e22dd7a670d93a486b184cfbe732c58f2c126
uni-projects-d942e135e502ee409222b9389a5a03b3f2861582.tar
uni-projects-d942e135e502ee409222b9389a5a03b3f2861582.tar.gz
uni-projects-d942e135e502ee409222b9389a5a03b3f2861582.zip
Parent53434d292ed9ca80bf24bcc5759bf9eff188231a (diff)
[Ray/project-easy] Added solution
1 files changed, 149 insertions, 0 deletions
-rw-r--r--Year 3/Raytracing/9001-project-easy-Implemented-semi-transparent-refraction.patch149
diff --git a/Year 3/Raytracing/9001-project-easy-Implemented-semi-transparent-refraction.patch b/Year 3/Raytracing/9001-project-easy-Implemented-semi-transparent-refraction.patch
new file mode 100644
index 0000000..67dd56c
--- /dev/null
+++ b/Year 3/Raytracing/9001-project-easy-Implemented-semi-transparent-refraction.patch
@@ -0,0 +1,149 @@
+From d4c19a8ade2a2f2d8d6f5a2acea1f801170533c1 Mon Sep 17 00:00:00 2001
+From: Syndamia <kamen@syndamia.com>
+Date: Mon, 1 Jul 2024 15:26:42 +0300
+Subject: [PATCH] [project-easy] Implemented semi-transparent refractions
+
+---
+ flake.lock | 27 +++++++++++++++++++++++++++
+ flake.nix | 26 ++++++++++++++++++++++++++
+ src/main.cpp | 2 +-
+ src/shading.cpp | 8 +++++++-
+ src/shading.h | 4 ++++
+ 5 files changed, 65 insertions(+), 2 deletions(-)
+ create mode 100644 flake.lock
+ create mode 100644 flake.nix
+
+diff --git a/flake.lock b/flake.lock
+new file mode 100644
+index 0000000..25db693
+--- /dev/null
++++ b/flake.lock
+@@ -0,0 +1,27 @@
++{
++ "nodes": {
++ "nixpkgs": {
++ "locked": {
++ "lastModified": 1716061101,
++ "narHash": "sha256-H0eCta7ahEgloGIwE/ihkyGstOGu+kQwAiHvwVoXaA0=",
++ "owner": "nixos",
++ "repo": "nixpkgs",
++ "rev": "e7cc61784ddf51c81487637b3031a6dd2d6673a2",
++ "type": "github"
++ },
++ "original": {
++ "owner": "nixos",
++ "ref": "nixos-23.11",
++ "repo": "nixpkgs",
++ "type": "github"
++ }
++ },
++ "root": {
++ "inputs": {
++ "nixpkgs": "nixpkgs"
++ }
++ }
++ },
++ "root": "root",
++ "version": 7
++}
+diff --git a/flake.nix b/flake.nix
+new file mode 100644
+index 0000000..d0a99fd
+--- /dev/null
++++ b/flake.nix
+@@ -0,0 +1,26 @@
++# Този файл, заедно с flake.lock са си за моета система, да имам копие ако случайно изтрия нещо
++{
++ description = "hexray raytracer in FMI elective";
++
++ inputs = {
++ nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
++ };
++
++ outputs = inputs:
++ let
++ pkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
++ in {
++ devShells."x86_64-linux".default = pkgs.mkShell {
++ nativeBuildInputs = with pkgs; [
++ cmake
++ pkg-config
++ ];
++
++ buildInputs = with pkgs; [
++ SDL2
++ openexr_3
++ zlib
++ ];
++ };
++ };
++}
+diff --git a/src/main.cpp b/src/main.cpp
+index fdca0f5..865a271 100644
+--- a/src/main.cpp
++++ b/src/main.cpp
+@@ -525,7 +525,7 @@ void renderThreadEntry() {
+ }
+ }
+
+-const char* DEFAULT_SCENE = "data/simple.hexray";
++const char* DEFAULT_SCENE = "data/beer.hexray";
+
+ int main(int argc, char** argv)
+ {
+diff --git a/src/shading.cpp b/src/shading.cpp
+index 94c417f..3d63dad 100644
+--- a/src/shading.cpp
++++ b/src/shading.cpp
+@@ -216,19 +216,25 @@ inline std::optional<Vector> refract(const Vector& i, const Vector& n, float ior
+ Color Refraction::computeColor(const Ray& ray, const IntersectionInfo& info)
+ {
+ std::optional<Vector> refr;
++ double transmittance = 1.0;
+ if (dot(ray.dir, info.norm) < 0) {
+ // entering the geometry
+ refr = refract(ray.dir, info.norm, 1 / ior);
+ } else {
+ // leaving the geometry
+ refr = refract(ray.dir, -info.norm, ior);
++
++ // Beer-Lambert law
++ double depth = (ray.start - info.ip).length();
++ // If absorption = 0; then transmittance = 1;
++ transmittance = exp(-1.0 * absorption * depth);
+ }
+ if (!refr) return Color(0, 0, 0);
+ Ray newRay = ray;
+ newRay.start = info.ip - faceforward(ray.dir, info.norm) * 0.000001;
+ newRay.dir = refr.value();
+ newRay.depth++;
+- return raytrace(newRay) * refrColor;
++ return raytrace(newRay) * refrColor * transmittance + insideColor * (1.0 - transmittance);
+ }
+
+ Color Refraction::eval(const IntersectionInfo& x, const Vector& w_in, const Vector& w_out)
+diff --git a/src/shading.h b/src/shading.h
+index 3a00527..005f203 100644
+--- a/src/shading.h
++++ b/src/shading.h
+@@ -148,6 +148,8 @@ class Refraction: public Shader {
+ public:
+ Color refrColor = Color(0.95f, 0.95f, 0.95f);
+ double ior = 1.33;
++ Color insideColor = Color(0.0, 0.0, 0.0);
++ double absorption = 0.0;
+ virtual Color computeColor(const Ray& ray, const IntersectionInfo& info) override;
+ // from BRDF:
+ Color eval(const IntersectionInfo& x, const Vector& w_in, const Vector& w_out) override;
+@@ -160,6 +162,8 @@ public:
+ refrColor = Color(multiplier, multiplier, multiplier);
+ } else pb.getColorProp("refrColor", &refrColor);
+ pb.getDoubleProp("ior", &ior, 1e-6, 10);
++ pb.getColorProp("insideColor", &insideColor);
++ pb.getDoubleProp("absorption", &absorption);
+ }
+ };
+
+--
+2.42.0
+