diff options
| Commit | 7994fe1a000768b6ad21997039ab5960d4c530af (patch) | |
|---|---|---|
| Author | 2023-08-26 14:25:30 +0300 | |
| Committer | 2023-08-26 14:25:30 +0300 | |
| Files | b55d7bbeeedad70f9a28e1b97c75dc22f022f67d | |
| uni-projects-7994fe1a000768b6ad21997039ab5960d4c530af.tar uni-projects-7994fe1a000768b6ad21997039ab5960d4c530af.tar.gz uni-projects-7994fe1a000768b6ad21997039ab5960d4c530af.zip | ||
| Parent | f5fa572ab70664129ae8c2d81665752f0f8f7f88 (diff) | |
[WGL/P] Fully implemented ray tracing
2 files changed, 1 insertions, 29 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/Project.html | 14 | ||||
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/shaders.js | 16 |
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html index cf55554..fc9bae8 100644 --- a/Year 2/Computer Graphics with WebGL/Project/Project.html +++ b/Year 2/Computer Graphics with WebGL/Project/Project.html @@ -125,17 +125,6 @@ h2 { gl.canvas.height = gl.canvas.offsetHeight;
gl.viewport(0,0,gl.canvas.width,gl.canvas.height);
- // (Look at Presentation 6, Slide 21, the prespective projection diagram)
- // Since we're gonna be raycasting, we need to know where the near side is and it's
- // dimentions in our coordinate system, so we can offset the rays properly.
- // First, we pass the viewPort to convert our pixel coordinates to percentage of the
- // screen.
- gl.uniform2f(uViewPort, gl.canvas.width, gl.canvas.height);
- w = 2 * Math.tan(PERSPECTIVE_ANGLE / 360 * Math.PI) * PERSPECTIVE_NEAR;
- // The height of the near wall is determined by the aspect ratio.
- gl.uniform2f(uPerspSize, w, gl.canvas.height / gl.canvas.width * w);
- gl.uniform1f(uPerspDist, PERSPECTIVE_NEAR);
-
drawFrame();
}
window.onresize = resizeglcanvas;
@@ -146,9 +135,6 @@ h2 { lookUpdate();
gl.uniform3fv(uEye, pos);
- gl.uniform3fv(uEyeForward, forward.toCartesian());
- gl.uniform3fv(uEyeUp, up.toCartesian());
- gl.uniform3fv(uEyeLeft, left.toCartesian());
skybox.draw();
star.draw();
diff --git a/Year 2/Computer Graphics with WebGL/Project/shaders.js b/Year 2/Computer Graphics with WebGL/Project/shaders.js index c3a2ab4..c34ab1c 100644 --- a/Year 2/Computer Graphics with WebGL/Project/shaders.js +++ b/Year 2/Computer Graphics with WebGL/Project/shaders.js @@ -42,13 +42,6 @@ var fShader = ` uniform vec4 uBH[5];
uniform vec3 uEye;
- uniform vec3 uEyeForward;
- uniform vec3 uEyeUp;
- uniform vec3 uEyeLeft;
-
- uniform vec2 uViewPort;
- uniform vec2 uPerspSize;
- uniform float uPerspDist;
// Thanks https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Vector_formulation
float linePointDistance(vec3 linePoint, vec3 lineDir, vec3 point) {
@@ -87,14 +80,7 @@ var fShader = ` void main()
{
- // Refer to Project.html for more info, but in brief, we're transforming
- // the screen pixel coordinates to the proper 3D coordinates
- vec2 offset = gl_FragCoord.xy / uViewPort; // from pixel coordinates to [0,1]
- offset = 2.0 * offset - 1.0; // to [-1,1]
- offset.x *= uPerspSize.x;
- offset.y *= uPerspSize.y;
-
- vec3 ray = normalize(uEyeForward * uPerspDist + offset.y * uEyeUp - offset.x * uEyeLeft);
+ vec3 ray = normalize(vXYZ - uEye);
gl_FragColor = rayMarch(ray, ray);
}
|
