Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-53442

Add billboard

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.9
    • Qt3D
    • 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

        For Gerrit Dashboard: QTBUG-53442
        # Subject Branch Project Status CR V

        Activity

          People

            seanharmer Sean Harmer
            lukegluke Oleg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change