Hello, I am trying to make a screen space shader for Adobe AGAL. The main code is OpenFL but I am using adobe agal shaders. I am trying to get the screen space, convert that from [-1, 1] to [0, 1], and pass that to the frag shader for further processing.
Right now I am using set uv's as [-1, 1] instead of the usual [0, 1] and the code works as intended. However, when I use the calculated space the triangle disappears.
What am I doing wrong? Sorry im new to this forum so I dont quite know how to ask propper questions yet
Here are the vertex/indices:
// Define vertices with texture coordinates
var vertices:Vector<Float> = new Vector<Float>([
-0.4, -0.4, 0, -1, -1, // x, y, z, u, v
- 0.4, 0.4, 0, -1, 1,
0.4, 0.4, 0, 1, 1
]);
Here is the agal shader code:
`
// Vertex and fragment shaders
var vertexShaderAssembler:AGALMiniAssembler = new AGALMiniAssembler();
vertexShaderAssembler.assemble(Context3DProgramType.VERTEX,
"m44 vt0, va0, vc0\n" + // Transform vertex positions by the model-view-projection matrix and store in temp register vt0
"mov op, vt0\n" + // Move transformed position to output position register (op)
// Adjust UV coordinates from [-1,1] to [0, 1]
"add vt1, va1, vc1.xx\n" + // vt1 = va1 + 1, shifting from [-1,1] to [0,2] //DEBUG: Use the example uv [-1, 1] for now
// "add vt1, vt0, vc1.xx\n" + // vt1 = vt0 + 1, shifting from [-1,1] to [0,2] //BUG: Logicaly speaking THIS SHOULD WORK. Were using the calculated screen space
"mul v0, vt1, vc1.yy\n" // v0 = vt1 * 0.5, scaling down to [0,1]
);
var fragmentShaderAssembler:AGALMiniAssembler = new AGALMiniAssembler();
fragmentShaderAssembler.assemble(Context3DProgramType.FRAGMENT,
"tex ft1, v0.xy, fs0 <2d, linear, clamp, nomip>\n" + // Sample the texture with normalized UVs
"mov oc, ft1\n" // Output the sampled color
);
`
Here is the context code
`
context3D.clear(0,.5,.75);
context3D.setTextureAt(0, texture);
context3D.setVertexBufferAt(0, vertexBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);
context3D.setVertexBufferAt(1, vertexBuffer, 3, Context3DVertexBufferFormat.FLOAT_2);
context3D.setProgram(program);
var m:Matrix3D = new Matrix3D();
m.appendRotation(Lib.getTimer() / 40, Vector3D.Z_AXIS);
context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, m, true);
context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 1, new Vector<Float>([1.0, 0.5, 0, 0]), 1);
context3D.drawTriangles(indexBuffer);
context3D.present();
`