Organize imports and work on integrating lighting
This commit is contained in:
parent
0cd383794c
commit
affb1b4f4f
2 changed files with 169 additions and 154 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import passthroughVertexShader from '../../../shaders/passthrough-vs.glsl';
|
||||
import { createShader } from './create-shader';
|
||||
import { loadUniform } from './load-uniform';
|
||||
|
||||
|
|
@ -15,9 +14,10 @@ export class FragmentShaderOnlyProgram {
|
|||
|
||||
constructor(
|
||||
private gl: WebGL2RenderingContext,
|
||||
passthroughVertexShaderSource: string,
|
||||
fragmentShaderSource: string
|
||||
) {
|
||||
this.createProgram(fragmentShaderSource);
|
||||
this.createProgram(passthroughVertexShaderSource, fragmentShaderSource);
|
||||
this.prepareScreenQuad('a_position');
|
||||
this.queryUniforms();
|
||||
}
|
||||
|
|
@ -74,13 +74,16 @@ export class FragmentShaderOnlyProgram {
|
|||
console.log(this.uniforms);
|
||||
}
|
||||
|
||||
private createProgram(fragmentShaderSource: string) {
|
||||
private createProgram(
|
||||
passthroughVertexShaderSource: string,
|
||||
fragmentShaderSource: string
|
||||
) {
|
||||
this.program = this.gl.createProgram();
|
||||
|
||||
const vertexShader = createShader(
|
||||
this.gl,
|
||||
this.gl.VERTEX_SHADER,
|
||||
passthroughVertexShader
|
||||
passthroughVertexShaderSource
|
||||
);
|
||||
this.gl.attachShader(this.program, vertexShader);
|
||||
this.shaders.push(vertexShader);
|
||||
|
|
|
|||
|
|
@ -18,18 +18,27 @@ export const loadUniform = (
|
|||
> = new Map();
|
||||
{
|
||||
converters.set(WebGL2RenderingContext.FLOAT, (gl, v, l) => {
|
||||
if (v.length == 0) {
|
||||
return;
|
||||
}
|
||||
gl.uniform1fv(l, new Float32Array(v));
|
||||
});
|
||||
|
||||
converters.set(
|
||||
WebGL2RenderingContext.FLOAT_VEC2,
|
||||
(gl, v: vec2 | Array<vec2>, l) => {
|
||||
if (v.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v[0] instanceof Array) {
|
||||
const result = new Float32Array(v.length * 2);
|
||||
|
||||
for (let i = 0; i < v.length; i++) {
|
||||
result[2 * i] = (v[i] as Array<number>).x;
|
||||
result[2 * i + 1] = (v[i] as Array<number>).y;
|
||||
}
|
||||
|
||||
gl.uniform2fv(l, new Float32Array(result));
|
||||
} else {
|
||||
gl.uniform2fv(l, v as vec2);
|
||||
|
|
|
|||
Loading…
Reference in a new issue