From d274224365fb781c93122f1f586d5221e281ae93 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 26 Aug 2023 20:51:37 +0300 Subject: [WGL/P] Implemented a better but still wrong ray rotation --- .../Project/Project.html | 4 ++-- .../Computer Graphics with WebGL/Project/shaders.js | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'Year 2/Computer Graphics with WebGL/Project') diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html index 29d26f1..ab7e618 100644 --- a/Year 2/Computer Graphics with WebGL/Project/Project.html +++ b/Year 2/Computer Graphics with WebGL/Project/Project.html @@ -104,9 +104,9 @@ h2 { skybox = new Skybox(10000, [0,0,0], undefined); stars = [ - new Star([1000,0,1000], 50), + new Star([1100,0,1000], 50), // new Star([1000,0,900], 30), - new Star([950,0,1100], 40), + // new Star([950,0,1100], 40), ]; // new Star([1000,0,-1000], 50) // new Star([0,0,0], 100) diff --git a/Year 2/Computer Graphics with WebGL/Project/shaders.js b/Year 2/Computer Graphics with WebGL/Project/shaders.js index 9b9cf1e..152753a 100644 --- a/Year 2/Computer Graphics with WebGL/Project/shaders.js +++ b/Year 2/Computer Graphics with WebGL/Project/shaders.js @@ -67,8 +67,13 @@ var fShader = ` return lineOrigin + min(-b + sqrt(Delta), -b - sqrt(Delta)) * lineDir; } + // Thanks https://en.wikipedia.org/wiki/Dot_product#Geometric_definition + float angleBetweenVectors(vec3 v1, vec3 v2) { + return acos(radians(dot(v1, v2) / (length(v1) * length(v2)))); + } + int rayMarchInBH(vec4 BH, inout vec3 ray, inout vec3 step) { - ray += step * linePointDistance(ray, step, BH.xyz); + ray = spherePoint(ray, step, vec4(BH.xyz, BH.a * 3.0)); for (int i = 0; i < 100; i++) { float dist = linePointDistance(ray, step, BH.xyz); if (dist <= BH.a) { // if inside event horizon @@ -77,10 +82,16 @@ var fShader = ` if (dist > BH.a * 3.0) { // if outside ISCO return 2; } - step += normalize(BH.xyz - ray) * (3.5 - dist / BH.a) * 0.05; + + // 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; + ray += step; } - return 0; // inside photon sphere + return 0; // orbits inside } vec4 calculateColor(bool notBent, vec4 star, vec3 ray, vec3 step) { @@ -108,6 +119,9 @@ var fShader = ` } } + // if (bhStatus == 0) return vec4(1,0,0,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); } -- cgit v1.3.1-26-gb76a