pouic long boiiiiiiii

This commit is contained in:
Kbz-8
2024-01-24 23:49:04 +01:00
parent c429586dc7
commit d0b0d83209
3 changed files with 154 additions and 52 deletions

View File

@ -1,25 +1,35 @@
const vertex_shader_source = `
attribute vec4 aPos;
attribute vec4 aColor;
attribute vec3 aNormal;
uniform mat4 uModView;
uniform mat4 uProj;
uniform mat4 uNormalMat;
varying lowp vec4 vColor;
varying highp vec3 vLighting;
void main()
{
gl_Position = uProj * uModView * aPos;
vColor = aColor;
highp vec3 ambientLight = vec3(0.3, 0.3, 0.3);
highp vec3 directionalLightColor = vec3(1, 1, 1);
highp vec3 directionalVector = normalize(vec3(0.85, 0.8, 0.75));
highp vec4 transformedNormal = uNormalMat * vec4(aNormal, 1.0);
highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);
vLighting = ambientLight + (directionalLightColor * directional);
}
`;
const fragment_shader_source = `
varying lowp vec4 vColor;
varying highp vec3 vLighting;
void main()
{
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
highp vec3 color = vec3(1.0, 1.0, 1.0);
gl_FragColor = vec4(color * vLighting, 1.0);
}
`;
@ -50,7 +60,7 @@ function loadShader(gl, type, source)
if(!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
{
alert(`An error occurred compiling the shaders: ${gl.getShaderInfoLog(shader)}`);
alert(`An error occurred while compiling the shaders: ${gl.getShaderInfoLog(shader)}`);
gl.deleteShader(shader);
return null;
}