I'm Work ing on a minecraft-like game (in OpenGL with c++) and I'm tryping to Implement Transparency for Blocks like windows, ice, leafs and water. I've tried to implement Weighted Blended Order-Independent Transparency as it's explained at LearnOpenGL. It basicly seems to work, but all Textures, rendered with the transparent Shader lose their opaqueness, even the Texels with Alpha=1.0.
So my Question is: Is this the normal behavior of this OIT technique?
And do you have any Ideas how I could work around this?
The gray glas frames should be opaque, but you can see the leafs from behind. (Ice, leafs and glass are all rendered using the transparent shader)
This is the Fragmentshader im using to dispaly transparent Textures.
#version 400 core
layout(location = 0) out vec4 accum;
layout(location = 1) out float reveal;
in float v_lightValue;
in vec2 v_texCoord;
uniform sampler2D u_texture;
uniform vec4 u_color;
const vec4 fogcolor = vec4(0.6, 0.7, 1.0, 1.0);
const float fogdensity = 0.0003;
void main(){
// Calculation of the Colors including 'fog' if the fragment are further away
vec4 texColor = texture(u_texture, v_texCoord);
float z = gl_FragCoord.z / gl_FragCoord.w;
float fog = clamp(exp(-fogdensity * z * z+1)/2, 0.0, 1.0);
vec4 color = mix(fogcolor, vec4(texColor.xyz * v_lightValue, texColor.w), fog);
// the weight function from learnopengl.com
float weight =
max(min(1.0, max(max(color.r, color.g), color.b) * color.a), color.a) *
clamp(0.03 / (1e-5 + pow(z / 200, 4.0)), 1e-2, 3e3);
// blend func: GL_ONE, GL_ONE
// switch to pre-multiplied alpha and weight
accum = vec4(color.rgb * color.a, color.a) * weight;
// blend func: GL_ZERO, GL_ONE_MINUS_SRC_ALPHA
reveal = color.a;
}
Please tell me if there is any further information needed to answer this question. As you can see, I'm new to StackExchange :)