Open volcoma opened 7 years ago
Fist of all whats with the weird order of the faces? Shouldn't it be +X ,-X, +Y, -Y, +Z, -Z ?
It already is: https://github.com/bkaradzic/bgfx/blob/master/include/bgfx/defines.h#L437
#define BGFX_CUBE_MAP_POSITIVE_X UINT8_C(0x00) //!< Cubemap +x.
#define BGFX_CUBE_MAP_NEGATIVE_X UINT8_C(0x01) //!< Cubemap -x.
#define BGFX_CUBE_MAP_POSITIVE_Y UINT8_C(0x02) //!< Cubemap +y.
#define BGFX_CUBE_MAP_NEGATIVE_Y UINT8_C(0x03) //!< Cubemap -y.
#define BGFX_CUBE_MAP_POSITIVE_Z UINT8_C(0x04) //!< Cubemap +z.
#define BGFX_CUBE_MAP_NEGATIVE_Z UINT8_C(0x05) //!< Cubemap -z.
Ok reading the docs now I setup my view matrix like so:
switch (face)
{
case 0:
t.set_rotation(-Z, +Y, +X); break;
case 1:
t.set_rotation(+Z, +Y, -X); break;
case 2:
t.set_rotation(+X, -Z, +Y); break;
case 3:
t.set_rotation(+X, +Z, -Y); break;
case 4:
t.set_rotation(+X, +Y, +Z); break;
case 5:
t.set_rotation(-X, +Y, -Z); break;
}
which gives me the same result which only works properly on directx, but on opengl the faces are messed up exactly the same as I mentioned above. Considering I use Left handed coordinate system for both.
Is it possible that the blit function creates the issue maybe copying to the wrong region or something? I render each face to a standard render target then blit the render target to the cubemap face like so:
bgfx::blit(pass.id, bgfx::getTexture(cubemap_fbo->handle), 0, 0, 0, face, bgfx::getTexture(output->handle));
I fought for a few hours with this issue, but the solution is simply to render everything flipped on the Y axis of the output when originBottomLeft
is true. (So basically all your shaders need to have a switch to flip the rendering).
IIUC, this is due to bgfx abstracting the sampling origin differences when uploading textures, but not when rendering to a buffer, so your cubemap sides end up vertically flipped in respect to how sampling behaves.
Ok so I have an issue with cubemap faces of a render target in opengl only. I generate reflection probes for my scene and for every reflection probe I render 6 faces to a cubemap and I am setting the view matrix for each face like so:
After each side is rendered I blit it into a cubemap to the corresponding face of the cubemap. Fist of all whats with the weird order of the faces? Shouldn't it be +X ,-X, +Y, -Y, +Z, -Z ?Then when I sample it I get the following RIGHT result with DX11:
and this result with opengl
In the shader I sample with a reflection vector created like this drawing a clip quad vertex_shader:
fragment_shader
Event if I flip the .y of the reflection vector I get this:
This only happens with opengl. If in opengl I create the view matrix like so:
and flip the y of the reflection vector when sampling from it i get the right result in opengl too... Something is really fishy here and i cant figure it out. Maybe the blit function is blitting to the wrong face or something or maybe I am doing something wrong?