actionscript 3 - Is this AGAL output correct? -
i trying convert shaders:
<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>
and
<script id="shader-fs" type="x-shader/x-fragment"> precision mediump float; varying vec4 vcolor; void main(void) { gl_fragcolor = vcolor; } </script>
having result (does output looks you? or missing something):
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
but not able display anything, if alter agal vertex shader much simple works:
mov op, va0n mov v0, va1n
i add together constants when convert glsl agal via:
var constval:array; (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]]) ) }
and prepare buffers this:
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 position info context.setvertexbufferat(1, vertexbuffer, 3, context3dvertexbufferformat.float_3);//defines shader input va1 position info
any suggestions?
there number of inconsistencies can see:
where setting values in constval? assign vector.([constval[0], constval[1], constval[2], constval[3]]) variable , inspect in debugger. do array values have x=0.0 , y=1.0? are setting constants before set vertex buffers? it's possible constants overwritten other render code. your vertex buffer float_3 format both position , colour vertex shader asks vec2 attribute position , vec4 colour.it's more constants problem. can test if constants blame hardcoding them in position vector, so:
hard code constants 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]);
change size of vertex info match
const datapervertex:int = 7;
change buffer settings reflect new sizes , offsets
context.setvertexbufferat (0, vertexbuffer, 0, context3dvertexbufferformat.float_4); //defines shader input va0 position info context.setvertexbufferat(1, vertexbuffer, 4, context3dvertexbufferformat.float_3);//defines shader input va1 position info
now alter script here:
attribute vec4 pos;
and here:
gl_position = pos;
if problems go away, suggest aren't sending right constants. revert old code , create sure you're uploading constants properly.
actionscript-3 flash 3d stage3d agal
No comments:
Post a Comment