Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flat shading in webGL

Tags:

glsl

webgl

I'm trying to implement flat-shading in webgl,
I knew that varying keyword in vertex shader will interpolation that value and pass it to fragment shader.

I'm trying to disable interpolation, and I found that flat keyword can do this, but it seems cannot use in webgl?

flat varying vec4 fragColor;

always getting error: Illegal use of reserved word 'flat'

like image 719
SSARCandy Avatar asked Dec 11 '22 14:12

SSARCandy


1 Answers

Check out webGL 2. Flat shading is supported. For vertex shadder:

#version 300 es
in vec4 vPos; //vertex position from application
flat out vec4 vClr;//color sent to fragment shader
void main(){
    gl_Position = vPos;
    vClr = gl_Position;//for now just using the position as color
}//end main

For fragment shader

#version 300 es
precision mediump float;
flat in vec4 vClr;
out vec4 fragColor;
void main(){
    fragColor = vClr;
}//end main
like image 50
user3727472 Avatar answered Jan 19 '23 16:01

user3727472