This commit is contained in:
Kbz-8
2024-01-27 13:42:21 +01:00
parent d0b0d83209
commit adf35bd66a
2 changed files with 32 additions and 9 deletions

View File

@ -7,19 +7,44 @@ const vertex_shader_source = `
uniform mat4 uNormalMat;
varying highp vec3 vLighting;
/*
vec3 lightColor = vec3(1.0, 0.8, 0.8);
vec3 lightDir = normalize(vec3(-0.2, -1.0, -0.3));
vec3 viewPos = vec3(0.0, 0.0, 0.0);
vec3 calculateLighting()
{
vec3 norm = normalize(aNormal);
// ambient
vec3 ambient = 0.3 * lightColor;
// diffuse
float diff = max(dot(lightDir, norm), 0.0);
vec3 diffuse = diff * lightColor;
// specular
vec3 viewDir = normalize(viewPos - vec3(aPos.xyz));
vec3 reflectDir = reflect(-lightDir, norm);
vec3 halfwayDir = normalize(lightDir + viewDir);
float spec = pow(max(dot(norm, halfwayDir), 0.0), 32.0);
vec3 specular = vec3(0.3) * spec; // assuming bright white light color
return (ambient + diffuse + specular);
}
*/
void main()
{
gl_Position = uProj * uModView * aPos;
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 vec3 directionalVector = normalize(vec3(1, 15, -1.75));
highp vec4 transformedNormal = uNormalMat * vec4(aNormal, 1.0);
highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);
vLighting = ambientLight + (directionalLightColor * directional);
// vLighting = calculateLighting();
}
`;