0

I am using this shaders with this results:

<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 uMV2Matrix;
    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>

<script id="per-fragment-lighting-fs2" type="x-shader/x-fragment">
    precision mediump float;

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

    uniform float uMaterialShininess;

    uniform vec3 uAmbientColor;

    uniform vec3 uPointLightingLocation;
    uniform vec3 uPointLightingSpecularColor;
    uniform vec3 uPointLightingDiffuseColor;

    uniform sampler2D uSampler;

    void main(void) {
        vec4 fragmentColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
        gl_FragColor = fragmentColor;
    }
</script>

enter image description here

But if I add a variable on the shader it changes totally the result, although it's not used on the fragment shader:

<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 uMV2Matrix;
    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;
        **vPosition = vec4(1,1,1,1);**
    }
</script>

enter image description here

Can you help me explain what's going on here?

Thanks!!

Mc-
  • 3,968
  • 10
  • 38
  • 61

1 Answers1

0

The problem with glsl2agal is that is mapping variables differently in the vertex and pixel shader.

For example:

Vertex Shader                   
v0 vPosition                    
v1 vTextureCoord                
v2 vTransformedNormal

Fragment Shader
v1 vPosition
....

That obviously lead to a bad output on the texture but a good vertex positioning.

In order to fix that I had to make a patch to remap all the variables and search and substitute on the generated AGAL code.

Now it's working fine.

Mc-
  • 3,968
  • 10
  • 38
  • 61