是否可以在 Qt3D 中渲染32位颜色?
attr = Qt3DRender.QAttribute()
attr.setAttributeType(Qt3DRender.QAttribute.VertexAttribute)
attr.setBuffer(buffer)
attr.setVertexBaseType(Qt3DRender.QAttribute.UnsignedByte)
attr.setVertexSize(4) # 4 bytes instead of 3
attr.setByteOffset(0)
attr.setByteStride(4 * 1) # 4 bytes instead of 3
attr.setCount(count)
attr.setName(Qt3DRender.QAttribute.defaultColorAttributeName())
渲染的颜色只有24位。
我需要32位颜色,因为我正在使用屏幕外渲染器(谢谢@Florian Blume(https://github.com/Sonnentierchen/Qt3D-OffscreenRenderer))。我需要这个来捕捉点。到目前为止,它只适用于24位RGB颜色。
# Create a texture to render into.
self.texture = Qt3DRender.QTexture2D(self.output)
self.texture.setFormat(Qt3DRender.QAbstractTexture.RGBA8_UNorm)
self.texture.setMinificationFilter(Qt3DRender.QAbstractTexture.Nearest)
self.texture.setMagnificationFilter(Qt3DRender.QAbstractTexture.Nearest)
我的着色器:
float byte = 256.;
float f_index = float(gl_VertexID);
float remainder = f_index - (byte*byte * floor(f_index/(byte*byte)));
float r = (f_index - remainder) / (byte*byte);
float b = remainder - (byte * floor(remainder/byte));
float g = (remainder - b) / byte;
r = r / (byte - 1.);
g = g / (byte - 1.);
b = b / (byte - 1.);
color = vec4(b, g, r, 1.0);