Home:ALL Converter>Does the fragment shader work on vertices, fragments or pixels?

Does the fragment shader work on vertices, fragments or pixels?

Ask Time:2021-09-22T05:51:10         Author:OpenGLUSER

Json Formatter

I tried rendering a cube.

These are the vertices:

unsigned int indices[] = {
    0, 1, 2,
    3, 1, 2,
    0, 1, 5,
    0, 4, 5,
    2, 3, 7,
    2, 7, 6,
    4, 5, 6,
    6, 7, 5,
    2, 0, 6,
    0, 4, 6,
    3, 1, 7,
    1, 7, 5
};

float vertices[] = {
    1.0f, 1.0f, 0.0f,        //0
    1.0f, -1.0f, 0.0f,        //1
    -1.0f, 1.0f, 0.0f,        //2
    -1.0f, -1.0f, 0.0f,        //3
    
    1.0f, 1.0f, 2.0f,        //4
    1.0f, -1.0f, 2.0f,        //5
    -1.0f, 1.0f, 2.0f,        //6
    -1.0f, -1.0f, 2.0f        //7
};

When I added color to my cube, I only had to define the colors 8 times:

float colors[] = {
        1.0f, 1.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 0.0f, 1.0f
    };

My first question is, does that mean that each color in my array is for a different vertex?

My second question is that I read somewhere and I saw this: "So the fragment shader itself doesn't actually operate on each fragment, it appears to operate on 3 "vertices" and then some other part of the pipeline interpolates whatever the pixel is." Is this text correct?

Author:OpenGLUSER,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69275922/does-the-fragment-shader-work-on-vertices-fragments-or-pixels
yy