Stage3D Error #3632: AGAL linkage: Varying 1 is read in the fragment shader but not written to by the vertex shader

93 Views Asked by At

I am a beginner in AGAL, I'm sure this is not complicated.

I have a vertex and fragment shader, for simply drawing a box with a texture without light effect, here is the code:

            vertexAssembly.assemble( Context3DProgramType.VERTEX,
            "m44 op, va0, vc0\n" + // pos to clipspace
            "mov v0, va1"  // copy uv
        );
        fragmentAssembly.assemble(Context3DProgramType.FRAGMENT,
            "tex ft1, v0, fs0 <2d,linear,nomip>\n" +
            "mov oc, ft1"
        );

I also have AGAL code for a Box with no texture, just color, and with light effect, here is the code for the shaders:

        private const VERTEX_SHADER_LIGHT:String = 
        "mov vt0, va0\n"+
        "m44 op, vt0, vc0\n"+
        "nrm vt1.xyz, va0.xyz\n"+
        "mov vt1.w, va0.w\n"+   
        "mov v1, vt1\n" +
        "mov v2, va1"

    private const FRAGMENT_SHADER_LIGHT:String = 
        "dp3 ft1, fc2, v1 \n"+
        "neg ft1, ft1 \n"+
        "max ft1, ft1, fc0 \n"+
        "mul ft2, fc4, ft1 \n"+
        "mul ft2, ft2, fc3 \n"+
        "add oc, ft2, fc1";

Question is, how do I combine the 2 codes, I want a box model with texture map, to show with light effect.

I did this:

        private const VERTEX_SHADER_LIGHT:String = 
        "m44 op, va0, vc0\n" + // pos to clipspace
        "mov v0, va1"  // copy uv
        //"mov vt0, va0\n"+
        //"m44 op, vt0, vc0\n"+
        "nrm vt1.xyz, va0.xyz\n"+
        "mov vt1.w, va0.w\n"+   
        "mov v1, vt1\n" +
        "mov v2, va1"

    private const FRAGMENT_SHADER_LIGHT:String = 
        "tex ft1, v0, fs0 <2d,linear,nomip>\n" +
        "mov oc, ft1 \n" + 
        "dp3 ft1, fc2, v1 \n"+
        "neg ft1, ft1 \n"+
        "max ft1, ft1, fc0 \n"+
        "mul ft2, fc4, ft1 \n"+
        "mul ft2, ft2, fc3 \n"+
        "add oc, ft2, fc1";

but it gives me an error: "Error: Error #3632: AGAL linkage: Varying 1 is read in the fragment shader but not written to by the vertex shader. at flash.display3D::Program3D/upload() at Context3DExample/setupScene() at Context3DExample/contextCreated()"

I'm sure someone with experiance can solve this in 5 minutes. Thanks

2

There are 2 best solutions below

10
nikitablack On

Looks like you forgot to concatenate a string, i.e.

"mov v0, va1"  // copy uv
"nrm vt1.xyz, va0.xyz\n"

should be

"mov v0, va1\n" +  // copy uv
"nrm vt1.xyz, va0.xyz\n"

Notice extra \n and + on the first line.

0
Shai Quantz On

Found the answer here is the code (based on nikitablack answer bellow):

        private const VERTEX_SHADER_LIGHT:String = "" +

        "m44 op, va0, vc0\n" +// pos to clipspace
        "mov v0, va1\n" +// pass uv
        "mov v1, va0"; // pas normal for vertex shader. 


    private const FRAGMENT_SHADER_LIGHT:String = "" +

    "tex ft0, v0, fs0 <2d,linear,nomip>\n" + // read from texture
    "nrm ft1.xyz, v1.xyz\n" + // renormalize normal
    "dp3 ft1, fc2.xyz, ft1.xyz \n" + // directional light contribution
    //"neg ft1, ft1 \n" + // negation because we have a vector "from" light 
    "max ft1, ft1, fc0 \n"+ // clamp to [0, dot]
    "mul ft1, ft1, fc3 \n"+ // contribution from light
    "mul ft1, ft1, ft0 \n"+ // contribution from light + texture
    //"add oc, ft1, fc1"; // final color as surface + ambient
    "add oc, ft1, ft0"; // final color as surface + texture

I took out the "neg of ft1" no need to negate this verctor in my code it is OK as it is. and I didn't add the ambient color at the end, just the texture once again so it will become bright and clear, with just a bit of shading.