yes
This commit is contained in:
parent
27eaf87e8b
commit
4e5b1897cf
@ -7,19 +7,44 @@ const vertex_shader_source = `
|
|||||||
uniform mat4 uNormalMat;
|
uniform mat4 uNormalMat;
|
||||||
|
|
||||||
varying highp vec3 vLighting;
|
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()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = uProj * uModView * aPos;
|
gl_Position = uProj * uModView * aPos;
|
||||||
|
|
||||||
highp vec3 ambientLight = vec3(0.3, 0.3, 0.3);
|
highp vec3 ambientLight = vec3(0.3, 0.3, 0.3);
|
||||||
highp vec3 directionalLightColor = vec3(1, 1, 1);
|
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 vec4 transformedNormal = uNormalMat * vec4(aNormal, 1.0);
|
||||||
|
|
||||||
highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);
|
highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);
|
||||||
vLighting = ambientLight + (directionalLightColor * directional);
|
vLighting = ambientLight + (directionalLightColor * directional);
|
||||||
|
|
||||||
|
// vLighting = calculateLighting();
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ export default class extends AbstractView
|
|||||||
this.gl = null;
|
this.gl = null;
|
||||||
this.shader_prog = null;
|
this.shader_prog = null;
|
||||||
this.buffers = null;
|
this.buffers = null;
|
||||||
this.rotation = 0.0;
|
|
||||||
this.programInfo = null;
|
this.programInfo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +45,9 @@ export default class extends AbstractView
|
|||||||
normalMatrix: this.gl.getUniformLocation(this.shader_prog, "uNormalMat"),
|
normalMatrix: this.gl.getUniformLocation(this.shader_prog, "uNormalMat"),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.gl.enable(this.gl.CULL_FACE);
|
||||||
|
this.gl.cullFace(this.gl.BACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
async join_game()
|
async join_game()
|
||||||
@ -77,7 +79,7 @@ export default class extends AbstractView
|
|||||||
this.gl.depthFunc(this.gl.LEQUAL);
|
this.gl.depthFunc(this.gl.LEQUAL);
|
||||||
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
|
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
const fieldOfView = (45 * Math.PI) / 180;
|
const fieldOfView = (90 * Math.PI) / 180;
|
||||||
const aspect = this.gl.canvas.clientWidth / this.gl.canvas.clientHeight;
|
const aspect = this.gl.canvas.clientWidth / this.gl.canvas.clientHeight;
|
||||||
const zNear = 0.1;
|
const zNear = 0.1;
|
||||||
const zFar = 100.0;
|
const zFar = 100.0;
|
||||||
@ -96,12 +98,8 @@ export default class extends AbstractView
|
|||||||
projectionMatrix
|
projectionMatrix
|
||||||
);
|
);
|
||||||
|
|
||||||
this.rotation += 0.025;
|
// rendering player bar
|
||||||
|
this.renderCube(0.0, -5.0, -8.0, 0.0, 5);
|
||||||
this.renderCube(0.0, 0.0, -15.0, this.rotation);
|
|
||||||
this.renderCube(0.0, 1.0, -15.0, this.rotation + 0.1);
|
|
||||||
this.renderCube(-2.0, 0.0, -15.0, this.rotation + 4.3);
|
|
||||||
this.renderCube(2.0, 3.0, -15.0, this.rotation - 12.4, 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCube(x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
|
renderCube(x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user