1

在舞台 3d 中,我设置了一个基本三角形,我可以使用附加旋转和附加比例,一切正常,但是在 z 轴上使用附加平移,三角形将消失,平移为 1 或更高。对于其他形状,它只会消失 3 或更高。而且看起来三角形在 0 到 0.9 平移之间并没有变得更小/更远。x 和 y 轴上的平移确实有效。

这是我的着色器代码:

private static const VERTEX_SHADER_SOURCE:String = "m44 op, va0, vc1";
private static const FRAGMENT_SHADER_SOURCE:String = "mov oc, fc0";

我的渲染循环:

addEventListener(Event.ENTER_FRAME, enter);
var t:Number=0;
function enter():void {
    context3D.clear();
    context3D.setProgram(program);

    var m:Matrix3D = new Matrix3D;

    m.appendTranslation(0, 0, t);

    t+=0.01;

    context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 1, m, true);
    context3D.setVertexBufferAt(0, buffer, 0, Context3DVertexBufferFormat.FLOAT_3);
    context3D.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, color);

    context3D.drawTriangles(indexBuffer);
    context3D.present();
}

我的完整代码:

var assembler:AGALMiniAssembler = new AGALMiniAssembler();
assembler.assemble(Context3DProgramType.VERTEX, VERTEX_SHADER_SOURCE);

if (assembler.error) {
    trace("vertex shader error " +assembler.error); 
    return; 
}
var vertexShaderByteCode:ByteArray = assembler.agalcode;
assembler.assemble(Context3DProgramType.FRAGMENT, FRAGMENT_SHADER_SOURCE);

if (assembler.error) {
    trace("fragment shader error " + assembler.error); 
    return; 
}
var fragmentShaderByteCode:ByteArray = assembler.agalcode;
var program:Program3D = context3D.createProgram();

try {
    program.upload(vertexShaderByteCode, fragmentShaderByteCode); 
}
catch (err:Error) {
    trace("couldnt upload shader program" + err); 
    return; 
}

color = new <Number>[0.9296875, 0.9140625, 0.84765625, 1];
var verts:Vector.<Number> = Vector.<Number>([
    0.5, 0, 0,
    -0.5, 0, 0,
    0, 0.5, 0
]);

var buffer:VertexBuffer3D = context3D.createVertexBuffer(3, 3);
buffer.uploadFromVector(verts, 0, 3);

var indices:Vector.<uint> = Vector.<uint>([0, 1, 2])
var indexBuffer:IndexBuffer3D = context3D.createIndexBuffer(3);

indexBuffer.uploadFromVector(indices, 0, 3);    
addEventListener(Event.ENTER_FRAME, enter);
var t:Number=0;

function enter():void {

    context3D.clear();
    context3D.setProgram(program);
    var m:Matrix3D = new Matrix3D;

    m.appendTranslation(0, 0, t);
    t+=0.01;

    context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 1, m, true);
    context3D.setVertexBufferAt(0, buffer, 0, Context3DVertexBufferFormat.FLOAT_3);
    context3D.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, color);

    context3D.drawTriangles(indexBuffer);
    context3D.present();
}
4

0 回答 0