HJGBAUM
HJGBAUM

Reputation: 397

WebGL Computer graphics vec4?

I'm learning WebGL graphics programming and this snippet of code has recently come up.

void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }

What does this mean? I hear it has something to do with rendering light but I have absolutely no clue.

Upvotes: 2

Views: 2761

Answers (1)

nasso
nasso

Reputation: 605

This is a fragment shader.

The fragment shader is executed by your GPU to render each sample (usually, a pixel, but can change when you are using multi sampling for antialiasing).

The fragment shader has a main() function which is the start point of your shader.

Here, you are just assigning a value to the gl_FragColor variable. This is a built-in variable, it'll decide the color of your sample (pixel). It's a vec4 (4 component vector). X is the red component, Y the green, and Z the blue. The last component (w) is the alpha.

So this short code just simply fill your polygons with a green color.

Upvotes: 5

Related Questions