Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.9
-
None
Description
In my application I needed billboard entities (2D elements in 3D world that always face the camera). I didn't figure out how to replace vertex shader in QDiffuseMapMaterial object effortlessly, so I have created the material same as QDiffuseMapMaterial, but with additional billBoardMode parameter (with corresponding getter,setter and etc. functions, alike setTextureScale property) and special vertex shader (see below).
It would be great, if at least diffusemap and better if normaldiffusemap, normaldiffusemapalpha and other materials have this functionality in Qt3D 5.7, if it is relevant for anybody else.
Here vertex shader code for my class:
#version 150 core in vec3 vertexPosition; in vec3 vertexNormal; in vec2 vertexTexCoord; out vec3 worldPosition; out vec3 worldNormal; out vec2 texCoord; uniform mat4 modelView; uniform mat4 modelMatrix; uniform mat3 modelNormalMatrix; uniform mat4 projectionMatrix; uniform mat4 mvp; uniform float texCoordScale; uniform int billBoardMode; //0 - no billboard; //1 - spherical billboard fixed-size (scale can be modified throw transform) //2 - cylindrical billboard fixed-size (scale can be modified throw transform) void main() { texCoord = vertexTexCoord * texCoordScale; worldNormal = normalize( modelNormalMatrix * vertexNormal ); worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) ); if (billBoardMode == 0) { gl_Position = mvp * vec4( vertexPosition, 1.0 ); } else { mat4 mvm = modelView; if (billBoardMode <= 2) { mvm[0] = modelMatrix[0]; if (billBoardMode == 1) mvm[1] = modelMatrix[1]; //spherical mvm[2] = modelMatrix[2]; gl_Position = projectionMatrix * mvm * vec4( vertexPosition, 1.0 ); } } }
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-53442 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
182053,2 | Add billboard material | dev | qt/qt3d | Status: NEW | 0 | 0 |