我正在尝试转换此着色器:
<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
有什么建议吗?
答案 0 :(得分:0)
我可以看到一些不一致的地方:
更常见的是常数是问题。您可以通过在位置向量中对它们进行硬编码来测试您的常量是否应该受到指责,如下所示:
对0.0和1.0
的常量进行硬编码var vertices:Vector.<Number> = Vector.<Number>([
-0.3,-0.3, 0.0, 1.0, 1, 0, 0, // x, y, z=0.0, w=1.0, r, g, b
-0.3, 0.3, 0.0, 1.0, 0, 1, 0,
0.3, 0.3, 0.0, 1.0, 0, 0, 1]);
更改顶点数据的大小以匹配
const dataPerVertex:int = 7;
更改缓冲区设置以反映新的尺寸和偏移量
context.setVertexBufferAt (0, vertexbuffer, 0, Context3DVertexBufferFormat.FLOAT_4); //Defines shader input va0 as the position data
context.setVertexBufferAt(1, vertexbuffer, 4, Context3DVertexBufferFormat.FLOAT_3);//Defines shader input va1 as the position data
现在在这里更改您的脚本:
attribute vec4 pos;
在这里:
gl_Position = pos;
如果您的问题消失,则表明您没有发送正确的常量。恢复旧代码并确保正确上传常量。