shader uniform

This commit is contained in:
monoid 2021-09-28 15:27:00 +09:00
parent 66326bca06
commit 9922846acc
2 changed files with 13 additions and 6 deletions

View File

@ -27,8 +27,12 @@ class Renderer{
gl : WebGL2RenderingContextStrict;
constructor(gl: WebGL2RenderingContextStrict){
this.gl = gl;
}
init(){
const gl = this.gl;
let program: WebGLProgram;
try{
const program = createProgramFromSource(gl,vert_src,frag_src);
program = createProgramFromSource(gl,vert_src,frag_src);
gl.useProgram(program);
}
catch(e){
@ -40,9 +44,6 @@ class Renderer{
}
else throw e;
}
}
init(){
const gl = this.gl;
const position = [
-0.5,-0.5,
0.5,-0.5,
@ -61,6 +62,9 @@ class Renderer{
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(index),gl.STATIC_DRAW);
let location = gl.getUniformLocation(program, "u_color"); //u_color 변수 위치를 참조
gl.uniform4f(location, 0.8, 0.3, 0.8, 1.0); //해당 위치에 0.2, 0.3, 0.8, 1.0 데이터를 전달
}
draw(){
const gl = this.gl;

View File

@ -1,7 +1,10 @@
#version 300 es
precision highp float;
layout(location=0) out vec4 outColor;
//in vec4 gl_FragCoord;
//in vec2 gl_PointCoord;
uniform vec4 u_color;
void main() {
outColor = vec4(0.0,0.0,1.0,1.0);
outColor = u_color;
}