p8mode

01-18-2013, 01:24 AM

hello.

i have started reading about opengl(es) eg from "opengl es programming guide 2.0". Conceptually when drawing a simple triangle and setting a different colour for each vertex (eg vertex1 = red, vertex2 = blue, vertex 3 = green) my understanding is ...

the vertex shader shades each vertex with its allocated colour (it could do more but it does this too).

then opengl transform the three vertices to fragments (which are esentially pixels, if theyre not culled or excluded from the rendered scene for some reason). the fragment shader then (among other possible things) shades each generated fragment.

its helpful/necessary to separate the vertex and fragment shaders since a single vertex could map to many fragments (or in fact possibly more than one vertex could map to the same fragment).

(1) is this understanding (if somewhat simplistic) essentially correct?

in this simple case (just drawing a triangle with a different colour for each vertex) the fragment shader is esentially superfluous...it would just set the colour for the corresponding fragments that was set for the corresponding vertices by the vertex shader?

(2) supposing i wanted to (have opengl) interpolate the colours of the vertices so that the interior of the triangle was coloured with a kind of gradient depending on how far it was from each vertex. where would this happen? the fragment shader only gets the pixels corresponding to the vertices of the triangle and not the interior, (so i cant do it there) right?

thanks very much in advance for any clarification.

i have started reading about opengl(es) eg from "opengl es programming guide 2.0". Conceptually when drawing a simple triangle and setting a different colour for each vertex (eg vertex1 = red, vertex2 = blue, vertex 3 = green) my understanding is ...

the vertex shader shades each vertex with its allocated colour (it could do more but it does this too).

then opengl transform the three vertices to fragments (which are esentially pixels, if theyre not culled or excluded from the rendered scene for some reason). the fragment shader then (among other possible things) shades each generated fragment.

its helpful/necessary to separate the vertex and fragment shaders since a single vertex could map to many fragments (or in fact possibly more than one vertex could map to the same fragment).

(1) is this understanding (if somewhat simplistic) essentially correct?

in this simple case (just drawing a triangle with a different colour for each vertex) the fragment shader is esentially superfluous...it would just set the colour for the corresponding fragments that was set for the corresponding vertices by the vertex shader?

(2) supposing i wanted to (have opengl) interpolate the colours of the vertices so that the interior of the triangle was coloured with a kind of gradient depending on how far it was from each vertex. where would this happen? the fragment shader only gets the pixels corresponding to the vertices of the triangle and not the interior, (so i cant do it there) right?

thanks very much in advance for any clarification.