我正在尝试转换此着色器:
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec2 pos;
attribute vec4 aVertexColor;
varying vec4 vColor;
void main(void) {
gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);
vColor = aVertexColor;
}
</script>
和
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec4 vColor;
void main(void) {
gl_FragColor = vColor;
}
</script>
结果(这个输出对你来说看起来不错吗?或者我遗漏了一些东西):
mov vt0.zw, vc0.xyyy
mov vt0.x, va0.x
mov vt0.y, va0.y
mov op, vt0
mov v0, va1
和
mov oc, v0
但是,如果我将 AGAL 顶点着色器更改为一些非常简单的工作,我将无法显示任何内容:
mov op, va0n
mov v0, va1n
当我通过以下方式将 GLSL 转换为 AGAL 时,我添加了常量:
var constval:Array;
for (var constant:String in result.consts) {
trace(constant, result.consts[constant]);
constval = result.consts[constant];
context.setProgramConstantsFromVector( type, int(constant.slice(2)), Vector.<Number>([constval[0], constval[1], constval[2], constval[3]]) )
}
我准备了所有这样的缓冲区:
var vertices:Vector.<Number> = Vector.<Number>([
-0.3,-0.3,0, 1, 0, 0, // x, y, z, r, g, b
-0.3, 0.3, 0, 0, 1, 0,
0.3, 0.3, 0, 0, 0, 1]);
const dataPerVertex:int = 6;
vertexbuffer = context.createVertexBuffer(vertices.length/dataPerVertex, dataPerVertex);
vertexbuffer.uploadFromVector(vertices, 0, vertices.length/dataPerVertex );
var indices:Vector.<uint> = Vector.<uint>([0, 1, 2]);
indexbuffer = context.createIndexBuffer(3);
indexbuffer.uploadFromVector (indices, 0, 3);
context.setVertexBufferAt (0, vertexbuffer, 0, Context3DVertexBufferFormat.FLOAT_3); //Defines shader input va0 as the position data
context.setVertexBufferAt(1, vertexbuffer, 3, Context3DVertexBufferFormat.FLOAT_3);//Defines shader input va1 as the position data
有什么建议么?