Shaders Simple vertex shader question

F207

Member
Hi all,

I have a simple question about what is happening in a pass-through shaders with respect to "v_vColour" from the vertex shader and how "v_vColour" is then being used in the fragment shader.

Where I feel a bit confused is, what is the value of "v_vColour" if you never set it to anything. Is GLSL ignoring it because it's not defined and then not using it in this default line from the fragment shader:
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );

Or is "v_vColour" by default have each vector component set to 1 since multiplying anything by 1 does nothing
 
v_vColour is the vertex-colour taken from the vertex attribute in_Colour. Each vertex can have a colour and you usually set it in GML with draw_set_colour() and draw_set_alpha() or with the colour and alpha parameters in the draw_,,,_ext() functions.

So usually if you dont change the vertex colour its vec4(1.0, 1.0, 1.0, 1.0).

If you don't need it for your shader to work you can safely remove all in_Colour and v_vColour from the vertex and fragment shader.
 

NightFrost

Member
I've noticed not everyone realizes they can use ext draw commands to control an alpha manipulating [fragment] shader that way, and instead write a uniform.
 

F207

Member
v_vColour is the vertex-colour taken from the vertex attribute in_Colour. Each vertex can have a colour and you usually set it in GML with draw_set_colour() and draw_set_alpha() or with the colour and alpha parameters in the draw_,,,_ext() functions.

So usually if you dont change the vertex colour its vec4(1.0, 1.0, 1.0, 1.0).

If you don't need it for your shader to work you can safely remove all in_Colour and v_vColour from the vertex and fragment shader.
Hey, The Reverend himself! I've been watching your shader videos lately, thanks for the great work you do for the community!

That was the answer I was looking for, and after reading it it occurred to me I could probably test it out by doing a draw_sprite_general() and setting all the colors to c_white. When I did that it indeed did effectively nothing to the sprite, it just appeared as normal.
 

F207

Member
@The Reverend

EDIT: Ok I made a silly mistake while trying to follow along with the corner ID video. I forgot to actually set the corner ID function to true before doing the visual tests where you were drawing a sprite after using this code "CornerTest = mod(in_Colour.r*255.0,2.0);". So I was only getting a solid white sprite when trying to this visual test myself which was really throwing off mu understanding. This is starting to make sense now........until I make another mistake.

Ok I have a follow up question related to this. I'm watching your video about the corner ID's, and something about this is confusing me. If in this thread we're saying that the vertex colors are going to default to all white, then wouldn't the corner ID's always result in the least significant bit being 1?

At around 10:30 (linked at the bottom) of the video we see the first test run of showing what the corner ID value is for the red channel, and we see two of the vertices being black.

This really confuses me because if we didn't alter the vertex colors first, shouldn't every vertex color be all white? Because this goes back to my original question in this thread, that if we don't alter the vertex color ourselves, then the the following line of a simple pass-through shader:
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );

Would mean that each channel of v_vColour has to 1, otherwise it would alter the original image.

I hope what I'm asking makes sense. Shaders are hard :(


 
Last edited:
Top