17 halp_meta(name,
"Cubemap Composer")
18 halp_meta(category,
"Visuals/3D")
19 halp_meta(c_name,
"cubemap_composer")
22 "https://ossia.io/score-docs/processes/cubemap-composer.html")
23 halp_meta(uuid,
"a7c3e8f1-5b2d-4a9e-8f3c-1d6e9b4a2c5f")
27 halp::texture_input<
"+X", halp::custom_variable_texture> pos_x;
28 halp::texture_input<
"-X", halp::custom_variable_texture> neg_x;
29 halp::texture_input<
"+Y", halp::custom_variable_texture> pos_y;
30 halp::texture_input<
"-Y", halp::custom_variable_texture> neg_y;
31 halp::texture_input<
"+Z", halp::custom_variable_texture> pos_z;
32 halp::texture_input<
"-Z", halp::custom_variable_texture> neg_z;
37 halp::gpu_texture_output<
"Cubemap"> cubemap;
40 QRhiTexture* m_cubemapTex{};
57 auto checkFace = [&](
const auto& tex) {
58 if(tex.texture.bytes && tex.texture.width > 0 && tex.texture.height > 0)
60 int s = std::max(tex.texture.width, tex.texture.height);
61 maxSize = std::max(maxSize, s);
64 checkFace(inputs.pos_x);
65 checkFace(inputs.neg_x);
66 checkFace(inputs.pos_y);
67 checkFace(inputs.neg_y);
68 checkFace(inputs.pos_z);
69 checkFace(inputs.neg_z);
75 if(maxSize != m_faceSize)
79 m_cubemapTex->deleteLater();
80 m_cubemapTex =
nullptr;
86 if(!m_cubemapTex && m_faceSize > 0)
88 auto& rhi = *renderer.
state.rhi;
89 m_cubemapTex = rhi.newTexture(
90 QRhiTexture::RGBA8, QSize{m_faceSize, m_faceSize}, 1,
91 QRhiTexture::CubeMap | QRhiTexture::MipMapped
92 | QRhiTexture::UsedWithGenerateMips);
93 m_cubemapTex->create();
94 outputs.cubemap.texture.handle = m_cubemapTex;
103 m_cubemapTex->deleteLater();
104 m_cubemapTex =
nullptr;
107 outputs.cubemap.texture.handle =
nullptr;
110 void runInitialPasses(
120 bool anyUploaded =
false;
123 auto uploadFace = [&](
const auto& tex,
int layer) {
124 if(!tex.texture.bytes || tex.texture.width <= 0 || tex.texture.height <= 0)
129 tex.texture.bytes, tex.texture.width, tex.texture.height,
130 QImage::Format_RGBA8888);
132 if(img.width() != m_faceSize || img.height() != m_faceSize)
134 m_faceSize, m_faceSize, Qt::IgnoreAspectRatio,
135 Qt::SmoothTransformation);
137 img = img.convertToFormat(QImage::Format_RGBA8888);
139 QRhiTextureSubresourceUploadDescription subresDesc(img);
140 QRhiTextureUploadEntry entry(layer, 0, subresDesc);
141 QRhiTextureUploadDescription desc({entry});
142 res->uploadTexture(m_cubemapTex, desc);
146 uploadFace(inputs.pos_x, 0);
147 uploadFace(inputs.neg_x, 1);
148 uploadFace(inputs.pos_y, 2);
149 uploadFace(inputs.neg_y, 3);
150 uploadFace(inputs.pos_z, 4);
151 uploadFace(inputs.neg_z, 5);
155 res->generateMips(m_cubemapTex);