Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit70dc2d83a54fe43050c34d6f91ba5a71fdb35d65 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-08-27 11:13:08 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-08-27 11:13:08 +0300
Filesfd8d2e3774075d91abdcd8e2c3fa1f0b50f2d0df
uni-projects-70dc2d83a54fe43050c34d6f91ba5a71fdb35d65.tar
uni-projects-70dc2d83a54fe43050c34d6f91ba5a71fdb35d65.tar.gz
uni-projects-70dc2d83a54fe43050c34d6f91ba5a71fdb35d65.zip
Parentd274224365fb781c93122f1f586d5221e281ae93 (diff)
[WGL/P] Implemented correct ray rotation, following Riccardo Antonelli's formula
1 files changed, 20 insertions, 10 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Project/shaders.js30
diff --git a/Year 2/Computer Graphics with WebGL/Project/shaders.js b/Year 2/Computer Graphics with WebGL/Project/shaders.js
index 152753a..3fe1e27 100644
--- a/Year 2/Computer Graphics with WebGL/Project/shaders.js
+++ b/Year 2/Computer Graphics with WebGL/Project/shaders.js
@@ -35,6 +35,8 @@
var fShader = `
precision highp float;
+ #define MORE_MAGIC 0.01
+
uniform mat4 uProjectionMatrix;
uniform mat4 uViewMatrix;
uniform mat4 uModelMatrix;
@@ -74,21 +76,28 @@ var fShader = `
int rayMarchInBH(vec4 BH, inout vec3 ray, inout vec3 step) {
ray = spherePoint(ray, step, vec4(BH.xyz, BH.a * 3.0));
+
+ // h is used in the step changing calculation
+ float h = length(cross(ray, step));
+
for (int i = 0; i < 100; i++) {
- float dist = linePointDistance(ray, step, BH.xyz);
+ float dist = distance(ray, BH.xyz);
+
if (dist <= BH.a) { // if inside event horizon
return 1;
}
- if (dist > BH.a * 3.0) { // if outside ISCO
+ if (dist > BH.a * 3.0 + 1.0) { // if outside ISCO
return 2;
}
- // Used the help of https://en.wikipedia.org/wiki/Gravitational_lens#Explanation_in_terms_of_spacetime_curvature
- vec3 rayStep = ray + step;
- float theta = 2.0 * BH.a / length(BH.xyz - ray);
- float alpha = -theta - angleBetweenVectors(-step, BH.xyz - rayStep);
- step += normalize(BH.xyz - rayStep) * abs(sin(theta) / sin(alpha) * length(step)) / 100.0;
-
+ // Gravity bends light (actually spacetime, which in turn changes it's path for outside observers).
+ // This is a more or less correct (as far as I can tell) implementation of Riccardo Antonelli's formula
+ // http://rantonels.github.io/starless/#MathJax-Element-29-Frame
+ // Though I found it difficult to understand, so I referred to some of the code from
+ // https://github.com/rantonels/starless/blob/7a0c3c4efdc0666f53dcfa48d310fb2164be2d1a/tracer.py
+ // and
+ // https://github.com/dbrant/BlackHoleRaytracer/blob/master/Equation/SchwarzschildBlackHoleEquation.cs
+ step += normalize(ray - BH.xyz) * -1.5 * (h*h) * MORE_MAGIC / (dist*dist*dist*dist*dist);
ray += step;
}
return 0; // orbits inside
@@ -119,11 +128,12 @@ var fShader = `
}
}
- // if (bhStatus == 0) return vec4(1,0,0,1);
- // if (bhStatus == 1) return vec4(0,1,0,1);
+ if (bhStatus == 0) return vec4(1,0,1,1);
+ if (bhStatus == 1) return vec4(0,1,0,1);
// if (bhStatus == 2) return vec4(1,1,0,1);
if (bhStatus < 2) {
return vec4(0,1,0,1);
+ // return vec4(1,0,0,1);
}
for (int i = 0; i < 5; i++) {