Simples Shader - Using Default variables

Hello,

I need to write a simple GLSL shader and I’m trying to avoid uniform inputs for the moment, only to see if the built in functions and vars are working and to get to know it a bit better.

My question is, how can I access the different object material layers in the fragment shader?

I can acess one layer as such:

sampler2D material; -> this value will be already set to the current object texture, right?

and it will be set to the texture the object has at that moment, so I can afterwards set it to:

gl_fragColor = texture2D(material, coord);

but how can I use multiple layers assuming the object already has 3 layers of texture? (Assuming I want a modulate effect)

something like this?

sampler2D material1;
sampler2D material2;

gl_fragColor = texture2D(material1, coord) * texture2D(material2, coord);

and using the same technique, is it possible to mix all this with the vertex color? if so, how can I access the vertex color? gl_Color? gl_FrontColor? I’m trying to acess it but it just wont return anything rather than black (0, 0, 0)

regards

Sure. Whatever you want.

Also just FYI, on these forums, you can mark a multi-line block as source code by preceding and following it by 3 back-ticks (```). Like I’ve done with your code above. This also does some syntax colorization, which makes the code easier to read.

Sure.

In the old compatibility profile, these are the tokens you want to read and write in the vertex shader and fragment shader if you wanted to pass the input vertex attribute “color” value through the vertex and fragment shaders unmodified:

Vertex shader:

    gl_FrontColor = gl_Color;

Fragment shader:

    gl_FragColor = gl_Color;

Of course you can add in whatever extra math you want here, or not even use the input values if you don’t need them. And if you wanted to implement two-sided lighting (where the vertex shader computes a different “color” for the front and the back sides), then you’d also write gl_BackColor from the vertex shader.

If, instead of using these old compatibility APIs and symbols, you’re instead specifying vertex attributes using generic vertex attributes as used in the later OpenGL versions (e.g. glVertexAttribPointer()), then there’s no need to use these compatibility profile inputs (in fact, on GL drivers other than NVidia’s, you can’t). Just declare your own attribute inputs, varyings, and outputs and pass the data through. For instance:

Vertex shader:

layout( location = 3 ) in  vec4 IN_color;         // Input vertex attribute
layout( location = 0 ) out vec4 OUT_color;        // Output varying
...
void main()
{
   OUT_color = IN_color;
}

Fragment shader:

layout( location = 0 ) out vec4 IN_color;        // Input varying
layout( location = 0 ) out vec4 OUT_color;       // Output to framebuffer (ROP)
...
void main()
{
   OUT_color = IN_color;
}

Thanks mate, thats the way I needed