Hello everyone… i am working on a project. My doubt is somehow relates to this…
i want to render some entities…some are simple polygons(filled with same color), some have gradient, some have texture, some have both…(see the screenshot A,B,C,D)
I am able to to this…
I prepared different shaders…
like for A--------------- (basic_shader)
#shader vertex
#version 130
in vec3 pos;
void main()
{
gl_Position = vec4(pos, 1);
}
#shader fragment
#version 130
uniform vec4 u_Color;
void main()
{
gl_FragColor = u_Color;
}
for B--------color_vertex_shader–
#shader vertex
#version 130
in vec3 pos;
in vec3 col;
out vec3 eachcol;
void main()
{
gl_Position = vec4(pos, 1);
eachcol=col;
}
#shader fragment
#version 130
out vec4 u_Color;
in vec3 eachcol;
void main()
{
u_Color = vec4(eachcol,1.0);
}
for C-----------
#shader vertex
#version 130
in vec3 pos;
in vec2 texCoord;
out vec2 v_TexCoord;
void main()
{
gl_Position = vec4(pos, 1);
v_TexCoord=texCoord;
}
#shader fragment
#version 130
in vec2 v_TexCoord;
uniform vec4 u_Color;
uniform sampler2D u_Texture;
void main()
{
vec4 texColor = texture(u_Texture,v_TexCoord) ;
gl_FragColor = texColor;
}
and for D--------------------
#shader vertex
#version 130
in vec3 pos;
in vec3 col;
in vec2 texCoord;
out vec3 v_Col;
out vec2 v_TexCoord;
void main()
{
gl_Position = vec4(pos, 1);
v_Col=col;
v_TexCoord=texCoord;
}
#shader fragment
#version 130
in vec3 v_Col;
in vec2 v_TexCoord;
uniform sampler2D u_Texture;
void main()
{
vec4 texColor = texture(u_Texture,v_TexCoord) * vec4(v_Col,1.0);
gl_FragColor = texColor;
}
//-------
Can i make a single shader and use them for A,B,C,D ??