0
我想這個着色器轉換:這是AGAL輸出是否正確?
<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
and
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
有什麼建議?
我認爲至少這一行是錯誤的:「mov vt0.zw,vc0.xyyy」。據我所知,src和dst必須具有相同的類型,但這裏的src是float4,dst是float2。你想在這條線上做什麼? – skozin