From 46ee648fff31004221d307d0af9cabc0c4250a4c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 27 Aug 2023 12:01:37 +0300 Subject: [WGL/P] Minor formatting and naming changes --- Year 2/Computer Graphics with WebGL/Project/shaders.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Year 2/Computer Graphics with WebGL/Project/shaders.js') 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); -- cgit v1.3.1-26-gb76a