Stage3D错误#3632:AGAL链接:在片段着色器中读取变量1但不由顶点着色器写入

时间:2016-05-11 15:04:41

标签: stage3d

我是AGAL的初学者,我确信这并不复杂。

我有一个顶点和片段着色器,只需绘制一个没有光效的纹理框,下面是代码:

            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"
        );

我也有一个没有纹理,只有颜色和光效的Box的AGAL代码,这里是着色器的代码:

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

问题是,如何组合2个代码,我想要一个带有纹理贴图的盒子模型,以显示光效。

我这样做了:

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

但它给了我一个错误: “错误:错误#3632:AGAL链接:在片段着色器中读取变量1,但顶点着色器不写入。     在flash.display3D :: Program3D / upload()     在Context3DExample / setupScene()     在Context3DExample / contextCreated()“

我确信有经验的人可以在5分钟内解决这个问题。 感谢

2 个答案:

答案 0 :(得分:0)

看起来你忘了连接一个字符串,即

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

应该是

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

请注意第一行的额外\n+

答案 1 :(得分:0)

这里找到的答案是代码(基于nikitablack的答案):

        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

我拿出了ft1&#34;我不需要在我的代码中否定这个verctor就可以了。并且我没有在最后添加环境颜色,只是再次添加纹理,所以它会变得明亮和清晰,只有一些阴影。