Stage3d中的怪异着色器行为

时间:2013-03-06 18:20:04

标签: actionscript-3 shader stage3d

我在Stage3d上使用这个顶点着色器:

<script id="per-fragment-lighting-vs2" type="x-shader/x-vertex">
    attribute vec3 aVertexPosition;
    attribute vec3 aVertexNormal;
    attribute vec2 aTextureCoord;

    uniform mat4 uMVMatrix;
    uniform mat4 uPMatrix;
    uniform mat3 uNMatrix;

    varying vec2 vTextureCoord;
    varying vec3 vTransformedNormal;
    varying vec4 vPosition;


    void main(void) {
        vPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
        gl_Position = uPMatrix * vPosition;
        vTextureCoord = aTextureCoord;
        vTransformedNormal = uNMatrix * aVertexNormal;
    }
</script>

结果如下:

enter image description here

如果我像这样编辑着色器:

<script id="per-fragment-lighting-vs2" type="x-shader/x-vertex">
    attribute vec3 aVertexPosition;
    attribute vec3 aVertexNormal;
    attribute vec2 aTextureCoord;

    uniform mat4 uMVMatrix;
    uniform mat4 uPMatrix;
    uniform mat3 uNMatrix;

    varying vec2 vTextureCoord;
    varying vec3 vTransformedNormal;
    varying vec4 vPosition;


    void main(void) {
        **gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0);**
        vTextureCoord = aTextureCoord;
        vTransformedNormal = uNMatrix * aVertexNormal;
    }
</script>

并预测动作中的透视图我得到了正确的UV显示,虽然它有不同的视角,看起来还不错。

enter image description here

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您很可能在第一个着色器实现中颠倒了矩阵乘法序列,因此您应首先乘以透视,然后乘以MV。

    void main(void) {
        vPosition = uPMatrix * vec4(aVertexPosition, 1.0);
        gl_Position = uMVMatrix * vPosition;
        vTextureCoord = aTextureCoord;
        vTransformedNormal = uNMatrix * aVertexNormal;
   }