Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Project / shaders.js
diff options
context:
space:
mode:
Commit46ee648fff31004221d307d0af9cabc0c4250a4c (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-08-27 12:01:37 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-08-27 12:01:37 +0300
Files5c2041dec852318c1ba7ddb16f43abbeb942b53d /Year 2/Computer Graphics with WebGL/Project/shaders.js
uni-projects-46ee648fff31004221d307d0af9cabc0c4250a4c.tar
uni-projects-46ee648fff31004221d307d0af9cabc0c4250a4c.tar.gz
uni-projects-46ee648fff31004221d307d0af9cabc0c4250a4c.zip
Parent87e9c9fa25b21bec3a658dcebc6c765a511d838e (diff)
[WGL/P] Minor formatting and naming changes
1 files changed, 6 insertions, 2 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Project/shaders.js8
diff --git a/Year 2/Computer Graphics with WebGL/Project/shaders.js b/Year 2/Computer Graphics with WebGL/Project/shaders.js
index 88e57c8..1657f5b 100644
--- a/Year 2/Computer Graphics with WebGL/Project/shaders.js
+++ b/Year 2/Computer Graphics with WebGL/Project/shaders.js
@@ -38,7 +38,7 @@ var vShader =`
var fShader = `
precision highp float;
- #define MORE_MAGIC 0.01
+ #define MAGIC_STEP 0.01
#define STAR_COLOR vec3(0.95,0.5,0.215)
varying vec3 vColor;
@@ -102,7 +102,7 @@ var fShader = `
// 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);
+ step += normalize(ray - BH.xyz) * -1.5 * (h*h) * MAGIC_STEP / (dist*dist*dist*dist*dist);
ray += step;
}
return 1; // orbits inside
@@ -128,7 +128,10 @@ var fShader = `
return vec4(color, 1);
}
+ // I think this slightly differs than the norm, but ray is the current position of my ray
+ // and step is a direction vector, so moving the ray forward is as simple as ray += step
vec4 rayMarch(vec3 ray, vec3 step) {
+ // Does the ray pass through any blackholes
int bhStatus = 2;
for (int i = 0; i < 5; i++) {
if (linePointDistance(ray, step, uBH[i].xyz) < uBH[i].a * 3.0) {
@@ -140,6 +143,7 @@ var fShader = `
return vec4(0,1,0,1);
}
+ // Does the ray hit a star
for (int i = 0; i < 5; i++) {
if (linePointDistance(ray, step, uStars[i].xyz) < uStars[i].a) {
return calculateColor(bhStatus == 2, uStars[i], ray, step);