Why is an error occurring in this GLSL shader program?

62 Views Asked by At

I'm currently attempting to create a program that renders a surface determined by the coordinates of 16 control points.(with webGL2) However, it seems that there's an error in this shader program, and the rendering doesn't appear correctly. Right now, I'm setting 16 points as individual vec4 uniform variables and creating an array of those uniforms to access them within a loop in the main function. I know this method is hard coding, but I'd like to at least make something appear on the screen for now.

this is my vertex shader program

#version 300 es
#define M_PI 3.1415926535897932384626433832795
layout(location=${loc_aTexCoords}) in vec2 aTexCoords;

uniform mat4 MVP;
uniform mat4 MV;
uniform mat4 matNormal;

uniform vec4 CP0;
uniform vec4 CP1;
uniform vec4 CP2;
uniform vec4 CP3;
uniform vec4 CP4;
uniform vec4 CP5;
uniform vec4 CP6;
uniform vec4 CP7;
uniform vec4 CP8;
uniform vec4 CP9;
uniform vec4 CP10;
uniform vec4 CP11;
uniform vec4 CP12;
uniform vec4 CP13;
uniform vec4 CP14;
uniform vec4 CP15;

vec4 array[16] = [CP15, CP12, CP13, CP14,
                    CP11, CP8, CP9, CP10,
                    CP3, CP0, CP1, CP2,
                    CP7, CP4, CP5, CP6];

out vec2 vTexCoords;

float B(t,n){
    if(n==0){
        return (1.0-t)*(1.0-t)*(1.0-t)/6.0
    }
    else if(n==1){
        return (3.0*t*t*t-6.0*t*t+4.0)/6.0
    }
    else if(n==2){
        return (-3.0*t*t*t+3.0*t*t+3.0*t+1.0)/6.0
    }
    else if(n==3){
        return t*t*t/6.0
    }
    return 0.0;
}

void main() 
{
    vec4 p = [0,0,0,0];
    
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            p += B(aTexCoords.s,i)*B(aTexCoords.t,j)*array[4*i+j];
        }
    }

    gl_Position = MVP * p
    vTexCoords = aTexCoords;
}





let p1 = [points.Points[0],points.Points[1],points.Points[2],1];
let p2 = [points.Points[3],points.Points[4],points.Points[5],1];
//and more...
gl.uniform4fv(patch.shader.loc_uniforms["CP0"],p1);
gl.uniform4fv(patch.shader.loc_uniforms["CP1"],p2);
//and more...

and this is how I update uniforms in js

0

There are 0 best solutions below