I read a lot of articles about homogeneous expressions that relate to branching in order to change the behavior of large "shaders" shaders. I started working with uber shader (opengl lwjgl), but then I realized that the simple act of adding an if statement given by the uniform in the fragment shader that performs simple calculations reduced my fps by 5 compared to individual shaders without uniform if statements. I have not set a limit on my fps limit, it just refreshes as quickly as possible. I'm going to add a normal display and a parallax display, and I see two routes:
Uber vertex shader:
#version 400 core
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 textureCoords;
layout(location = 2)in vec3 normal;
**UNIFORM float RenderFlag;**
void main(void){
if(RenderFlag ==0){
}
if(RenderFlag ==1){
}
gl_Position = MVPmatrix *vec4(position,1);
}
Uber barcode:
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 textureCoords;
layout(location = 2)in vec3 normal;
**UNIFORM float RenderFlag;**
**UNIFORM float reflectionFlag;**
will have some reflection of the skybox added to it, like reflective
surface.
void main(void){
if(RenderFlag ==0){
if(reflectionFlag){
vec4 reflectColor = texture(cube_texture, ReflectDirR) ;
}
}
if(RenderFlag ==1){
if(reflectionFlag){
vec4 reflectColor = texture(cube_texture, ReflectDirR) ;
}
}
gl_Position = MVPmatrix *vec4(position,1);
}
( ) - , , if. , , 4 , ( : : : ) , .
1: GLSL , BOTH, ?
2: if , -
finalColor = finalColor + reflectionColor * X
where X = a uniform variable, if none X == 0, if Reflection X==some amount.
user4161529