Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Project / shaders.js
diff options
context:
space:
mode:
1 files changed, 34 insertions, 1 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Project/shaders.js35
diff --git a/Year 2/Computer Graphics with WebGL/Project/shaders.js b/Year 2/Computer Graphics with WebGL/Project/shaders.js
index d936756..33fc743 100644
--- a/Year 2/Computer Graphics with WebGL/Project/shaders.js
+++ b/Year 2/Computer Graphics with WebGL/Project/shaders.js
@@ -15,6 +15,17 @@
attribute vec3 aNormal;
varying vec3 vColor;
+ varying vec3 vXYZ;
+
+ // Black Hole variables
+ attribute float aBH;
+ varying float vBH;
+ attribute vec3 aBHXYZ;
+ varying vec3 vBHXYZ;
+ attribute float aSR;
+ varying float vSR;
+ attribute float aR;
+ varying float vR;
void main ()
{
@@ -27,14 +38,36 @@
vec3 light = normalize(-uLightDir);
vec3 normal = vec3(normalize(nMatrix*vec4(aNormal,0)));
vColor += aColor*uDiffuseColor*max(dot(normal,light),0.0);
+ vXYZ = (uModelMatrix * vec4(aXYZ,1)).xyz;
+
+ vBH = aBH; vBHXYZ = aBHXYZ; vSR = aSR; vR = aR;
}
`;
var fShader = `
precision mediump float;
+
varying vec3 vColor;
+ varying vec3 vXYZ;
+
+ varying float vBH;
+ varying vec3 vBHXYZ;
+ varying float vSR;
+ varying float vR;
+
void main()
{
- gl_FragColor = vec4(vColor,1);
+ if (vBH > 0.5 && distance(vXYZ, vBHXYZ) <= vR) {
+ float dist = distance(vXYZ, vBHXYZ);
+ if (dist < vSR) {
+ gl_FragColor = vec4(0,0,0,1);
+ }
+ else {
+ gl_FragColor = vec4(vColor,0.5);
+ }
+ }
+ else {
+ gl_FragColor = vec4(vColor,1.0);
+ }
}
`;