@Jakob-Weiss
Is there any QT 3d Volume Rendering exmple in Qt? We are also trying to get Texture3d work in shader. Up to now, thanks to your tip, we made Texture2d work. We did the same in Texture3d, but it just didn't work and always shows black. Thanks if there is any tip.
QML is like:
parameters: [
Parameter {
id: mainTex
name: "mainTex"
value: m_mainTexture
},
Parameter {
id: myTex3D
name: "myTex3D"
value: m_mainTex3D
}
]
frag Shader is like:
layout(std140, binding = auto) uniform custom_uniforms {
vec3 maincolor;
};
layout(binding = auto) uniform sampler2D mainTex;
layout(binding = auto) uniform sampler3D myTex3D;
layout(location = 0) in vec3 worldPosition;
layout(location = 1) in vec2 v_texcoord;
layout(location = 0) out vec4 fragColor;
void main()
{
//vec4 txtColor = texture(mainTex, v_texcoord);
vec4 txtColor = texture(myTex3D, vec3(v_texcoord.x,v_texcoord.y,0.5));
float value_3D = txtColor.r * 100;
fragColor = vec4(value_3D,value_3D,value_3D,1.0);
}
C++ is like:
m_texture3D = new Qt3DRender::QTexture3D();
m_texture3D->setSize(128,128,128);
m_texture3D->setFormat(Qt3DRender::QTexture3D::R8_UNorm);
m_texture3D->setLayers(1);
m_texture3D->setGenerateMipMaps(false);
Qt3DRender::QTextureWrapMode wm(Qt3DRender::QTextureWrapMode::ClampToBorder);
m_texture3D->setWrapMode(wm);
//m_texture3D->setMinificationFilter(Qt3DRender::QTexture3D::Linear);
//m_texture3D->setMagnificationFilter(Qt3DRender::QTexture3D::Linear);
rawPixelData3D.resize(128 * 128 * 128 * sizeof(uchar));
uchar *pixels3D = reinterpret_cast<uchar *>(rawPixelData3D.data());
std::memset(pixels3D, 60, 128 * 128 * 128 * sizeof(uchar));
Qt3DRender::QTextureImageDataPtr imageData3D = Qt3DRender::QTextureImageDataPtr::create();
imageData3D->setFormat(QOpenGLTexture::TextureFormat::R8_UNorm);
imageData3D->setWidth(128);
imageData3D->setHeight(128);
imageData3D->setDepth(128);
imageData3D->setMipLevels(1);
imageData3D->setLayers(1);
imageData3D->setPixelFormat(QOpenGLTexture::PixelFormat::Red);
imageData3D->setPixelType(QOpenGLTexture::PixelType::UInt8);
imageData3D->setData(rawPixelData3D, 1, false);
Qt3DRender::QTextureDataUpdate update3D;
update3D.setX(0);
update3D.setY(0);
update3D.setData(imageData3D);
m_texture3D->updateData(update3D);