@@ -102,12 +102,12 @@ constexpr Vec3 cubeMapVertexPos[8] = { { -1.0f, -1.0f, -1.0f }, { -1.0f, -1.0f,
102102 { 1 .0f , 1 .0f , -1 .0f }, { 1 .0f , 1 .0f , 1 .0f } };
103103// left-bottom left-top right-top right-bottom
104104constexpr uint32_t cubeMapVertexIndex[6 ][4 ] = {
105- { 4 , 6 , 7 , 5 }, // right
106- { 1 , 3 , 2 , 0 }, // left
107- { 2 , 3 , 7 , 6 }, // top
108- { 1 , 0 , 4 , 5 }, // bottom
109- { 5 , 7 , 3 , 1 }, // back
110- { 0 , 2 , 6 , 4 } // front
105+ { 5 , 7 , 6 , 4 }, // +X ( right face)
106+ { 0 , 2 , 3 , 1 }, // -X ( left face)
107+ { 0 , 1 , 5 , 4 }, // +Y ( top face)
108+ { 3 , 2 , 6 , 7 }, // -Y ( bottom face)
109+ { 1 , 3 , 7 , 5 }, // +Z ( back face)
110+ { 4 , 6 , 2 , 0 } // -Z ( front face)
111111};
112112
113113struct VertexCubeMap final { // NOLINT(cppcoreguidelines-pro-type-member-init)
@@ -265,7 +265,7 @@ class RenderPass final {
265265 : mBuffers { std::move (buffer) }, mType { type }, mChannels { std::move (channels) } {
266266 std::string vertexSrc = shaderVersionDirective;
267267 std::string pixelSrc = shaderVersionDirective;
268- if (type == NodeType::CubeMap) {
268+ if (type == NodeType::CubeMap || type == NodeType::CubeMapFlippedY ) {
269269 vertexSrc += shaderCubeMapDef;
270270 pixelSrc += shaderCubeMapDef;
271271 }
@@ -352,9 +352,9 @@ class RenderPass final {
352352 ImVec2 size, base, fbSize, uniformSize;
353353 if (buffer) {
354354 base = { 0 , 0 };
355- size = mType == NodeType::CubeMap ? cubeMapSize : screenSize;
355+ size = ( mType == NodeType::CubeMap || mType == NodeType::CubeMapFlippedY) ? cubeMapSize : screenSize;
356356 fbSize = size;
357- uniformSize = mType == NodeType::CubeMap ? cubeMapSize : canvasSize;
357+ uniformSize = ( mType == NodeType::CubeMap || mType == NodeType::CubeMapFlippedY) ? cubeMapSize : canvasSize;
358358 glViewport (0 , 0 , static_cast <GLsizei>(size.x ), static_cast <GLsizei>(size.y ));
359359 glDisable (GL_SCISSOR_TEST);
360360 buffer->bind (static_cast <uint32_t >(size.x ), static_cast <uint32_t >(size.y ));
@@ -395,6 +395,16 @@ class RenderPass final {
395395 VertexCubeMap{ ImVec2{ base.x + size.x , base.y + size.y }, ImVec2{ uniformSize.x , 0.0 },
396396 cubeMapVertexPos[cubeMapVertexIndex[idx][3 ]] }, // right-bottom
397397 };
398+
399+ // For Y-flipped cubemaps, also flip Y coordinates of all faces
400+ // to match ShaderToy's UNPACK_FLIP_Y_WEBGL behavior
401+ if (mType == NodeType::CubeMapFlippedY) {
402+ for (auto & [pos, coord, point] : vertices) {
403+ // Flip the 3D point's Y coordinate
404+ point[1 ] = -point[1 ];
405+ }
406+ }
407+
398408 for (auto & [pos, coord, point] : vertices) {
399409 pos.x = pos.x / fbSize.x * 2 .0f - 1 .0f ;
400410 pos.y = 1 .0f - pos.y / fbSize.y * 2 .0f ;
0 commit comments