简体   繁体   中英

How to use flat shading in OpenTK.Graphics.OpenGL4?

I need to use flat shading in OpenTK.

I know there is a function in OpenGL (c++) called glShadeModel , and it was in OpenTK named ( GL. ) ShadeModel , but it's only in OpenTK.Graphics.ES11, and it's pretty old.

How can I do it using OpenTK.Graphics.OpenGL4?

glShadeModel has been replaced by Interpolation qualifiers .

However glShadeModel is still supportend in "desktop" OpenGL if you are using compatibility profile OpenGL Context and are not using a shader program. This means you need to use the immediate mode and you have to draw by glBegin / glEnd sequences or fixed function attributes, without a shader program.

If you are using a core profile OpenGL context and/or a shader program and you want to achieve "flat" shading, you have to use the flat Interpolation qualifier for the vertex shader output variables. For instance:

Vertex shader

#version 460

// [...]
in vec3 aColor;

flat out vec3 vColor;

void main()
{
    vColor = aColor;

    // [...]
} 

Fragment shader

#version 460

flat in vec3 vColor;
out vec4 fragColor; 

void main()
{
    fragColor = vec4(vColor, 1.0);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM