I have just implemented bloom in my engine but on the OpenGL side I have these black artifacts. [attachment=7631:Ogl0.png][attachment=7628:Ogl1.png]
In Direct3D 9 they are fine. [attachment=7629:Dx0.png][attachment=7630:Dx1.png]
They are both using the exact same shaders, being fed the exact same data, and using the same HDR formats (16-bit float).
I know that the problem is in the blur filters, both horizontal and vertical, but I can’t see why it is happening, especially when it doesn’t happen in Direct3D 9.
Horizontal blur.
#version 130 precision mediump float; invariant gl_Position; float shadow2dDepth(sampler2D s,vec2 v){return texture(s,v).z;} out vec2 LSG_VERT_OUT_PIXEL_IN_379_0/*_vOut2dTex0*/; in vec2 _vIn2dTex0; in vec3 _vInPos; uniform mat4x4 g_mModelViewProjMatrix;
for ( int I = 0; I < 9; I++ ) { _vOutColor += (texture( g_sSampler2dTex0, LSG_VERT_OUT_PIXEL_IN_379_0/*_vIn2dTex0*/ + vec2( g_fOffsets, 0.0 ) ) * g_fWeights);
}
_vOutColor.w = 1.0; }
I know it looks a little strange. This was generated output from my own shader language, and I added back some of the whitespace to make it more readable.
g_fOffsets has normal-looking values from -0.0049999999 to 0.0049999999.
I found out that my bright pass is writing NaN values to the texture due to a dot() with a zero-vector (black texels). Why it doesn’t have to all black texels I have no clue, but I applied the appropriate checks and fixed it.
Thank you.
L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
I found out that my bright pass is writing NaN values to the texture due to a dot() with a zero-vector (black texels).
Dot has no division, only multiplications... so it should not be the cause of NaN-value. The issue must be somewhere before that.. like it already was a NaN-value vector. Possible cause exponent of the floating point is not correctly interpreted (all bits are set to 1, according to IEEE-754).
In glsl, the pow(x, y) function return value is undefined if x < 0 or if x = 0 && y = 0. I once had a situation where the specular multiplier and specular exponent of a specular map were both zero at some texels, which caused pow to return NaN. You can also check for that.
I guess I was thinking dot() was a target because the returned value is relative to the lengths of the input vectors, and as we all know, a 0-vector has to be handled as a special case in order to avoid division by 0.
However it is correct in reality that both dot() and cross() have no divides.
Except apparently in OpenGL and OpenGL ES 2 implementations. It was the cause for the large black blocks. Simply by changing from this (bright pass, the only pass before doing a horizontal blur):
float fLuminance = dot( vAverage.rgb, vWeight ); if( fLuminance < g_fThresh ) { vAverage = vec4( 0.0f, 0.0f, 0.0f, 1.0f ); } to this: float fLuminance = dot( vAverage.rgb, vWeight ); if( fLuminance < g_fThresh || isnan( fLuminance ) ) { vAverage = vec4( 0.0f, 0.0f, 0.0f, 1.0f ); } made the blocks go away. I rendered the result of the horizontal blue before and after this change and confirmed that without this change, the first blur has black streaks, with the change it is perfect.
Meanwhile, since a typical dot() and cross() do not have divides, Direct3D 9 was working fine. This appears to be unnecessary extra work being done by OpenGL. There is no reason for it to generate NaN here, unless it is specifically testing for the case of a 0-length input vector.
I do still have black dots (rather than blocks) and those appear in Direct3D 9 also, but I haven’t yet been able to find the cause. Since I can render the bright pass and blurs, and they are always perfect, I know that it is in the last stage which combines them and does the tone mapping.
Anyway I will find it eventually.
L. Spiro
[EDIT] I was thinking about another idea I have been entertaining—that the source image has NaN values in it that I could never see before because they are black pixels and the end result is still black. Just tested it and it is correct. It isn’t in the pow() but it is in the main image result. I will remove my dot() checks since they are now superfluous, and will find the actual cause of my woes soon. [/EDIT]
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
However it is correct in reality that both dot() and cross() have no divides.
Except apparently in OpenGL and OpenGL ES 2 implementations. It was the cause for the large black blocks. Simply by changing from this (bright pass, the only pass before doing a horizontal blur):
I don't think that makes sense. As far as I know, the only way for dot to return NaN is if one of the components are NaN. Are you sure the input is good..?
The dot() was not the culprit, the source image was. Something I had not considered accepting before because the results were always exactly what I had expected (a [0,0,0] input generates a [0,0,0] output regardless of any Nan’s). I changed my checks for isnan() to those output by my main shader (which generates the image to be pre-processed), which I have used since the beginning, and that alone eliminated all errors in OpenGL. Actually, now only Direct3D 9 has remaining problems.
However my check for isnan() comes at the very end of that shader, and is present in ALL variants. If a NaN is present, it cannot possibly be due to an NaN value being stored in the main image. So now OpenGL and OpenG ES 2 are working while Direct3D 9 is in the wrong. With my above change, only Direct3D 9 has black artifacts, and OpenGL is entirely 100% perfect, including the overall luminance calculation which was also sometimes turning full black due to NaN.
From here out I need to focus on the Direct3D side of things, but I gained enough insight from this topic that I should be able to solve the remaining issues on my own.
L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid