翻译和广告牌

时间:2015-05-01 15:04:29

标签: javascript three.js glsl webgl

我已经向几何对象添加了一堆精灵顶点,并使用顶点着色器单独为它们设置动画。 现在我想在翻译后对它们进行广告宣传,但我的广告牌矩阵将广告牌转换为整个几何对象。 如何才能让广告牌转换为个人精灵?

int spriteIndex = int(floor(position.x*particleSize));

            float displacementVal = displacement[spriteIndex].w;
            vec3 rotationDisplacement = displacement[spriteIndex].xyz;
            rotationDisplacement = normalize(rotationDisplacement);

            mat4 billboardMatrix = modelViewMatrix;
            int spherical = 1;

              billboardMatrix[0][0] = 1.0;
              billboardMatrix[0][1] = 0.0;
              billboardMatrix[0][2] = 0.0;

              if (spherical == 1)
              {

                billboardMatrix[1][0] = 0.0;
                billboardMatrix[1][1] = 1.0;
                billboardMatrix[1][2] = 0.0;
              }

              billboardMatrix[2][0] = 0.0;
              billboardMatrix[2][1] = 0.0;
              billboardMatrix[2][2] = 1.0;

            vec3 correctedPos = position-vec3((particleSize*float(floor(position.x/particleSize)))+(particleSize/2.),0,0);
            correctedPos = correctedPos + vec3(displacementVal-float(displacementWidth/2),0,0);

            vec4 mvPosition = billboardMatrix *  vec4(correctedPos,1);

            vec4 p = projectionMatrix * mvPosition;

            gl_Position = p;

0 个答案:

没有答案