Hi,
is it possible to write a shader which handle float or int dependently of which input you use ?
i mean like this
#version 330
in ivec3 in_Vertex3Di;
in vec3 in_Vertex3Df;
in vec2 in_TexCoord0;
uniform mat4 projection;
out vec2 texCoord0;
void main()
{
vec4 vertex;
if( in_Vertex3Di ) {
vertex = vec4( in_Vertex3Di, 1 );
} else {
vertex = vec4( in_Vertex3Df, 1 );
}
gl_Position = projection * vertex;
texCoord0 = in_TexCoord0;
}
You can’t do that, but you could use #defines and build two separate programs from the same shader text.
Thanks for answering.
Can you elaborate about #define ? I presume i must add a string like “#DEFINE XXX Y” to the string buffer before doing the compilation of the shader right ?
otherwise i could use a uniform like this
#version 330
in ivec3 in_Vertex3Di;
in vec3 in_Vertex3Df;
in vec2 in_TexCoord0;
uniform bool integer = false;
uniform mat4 projection;
out vec2 texCoord0;
void main()
{
vec4 vertex;
if( integer ) {
vertex = vec4( in_Vertex3Di, 1 );
} else {
vertex = vec4( in_Vertex3Df, 1 );
}
gl_Position = projection * vertex;
texCoord0 = in_TexCoord0;
}
than
glUniform1i( glGetUniformLocation( shader, “integer” ), TRUE )
which of these would be the better solution ?
edit: is there a tool or IDE to code and test shaders quickly ?
system
Closed
October 19, 2021, 7:19pm
4
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.