MysteryPancake
MysteryPancake

Reputation: 1505

OpenGL: Fragment vs Vertex shader for gradients?

I'm new to OpenGL, and I'm trying to understand vertex and fragment shaders. It seems you can use a vertex shader to make a gradient if you define the color you want each of the vertices to be, but it seems you can also make gradients using a fragment shader if you use the FragCoord variable, for example.

My question is, since you seem to be able to make color gradients using both kinds of shaders, which one is better to use? I'm guessing vertex shaders are faster or something since everyone seems to use them, but I just want to make sure.

Upvotes: 2

Views: 678

Answers (1)

Yakov Galka
Yakov Galka

Reputation: 72469

... since everyone seems to use them

Using vertex and fragment shaders are mandatory in modern OpenGL for rendering absolutely everything. So everyone uses both. It's the vertex shader responsibility to compute the color at the vertices, OpenGL's to interpolate it between them, and fragment shader's to write the interpolated value to the output color attachment.

† OK, you can also use a compute shader with imageStore, but I'm talking about the rasterization pipeline here.

Upvotes: 2

Related Questions