вторник, 11 декабря 2012 г.

AGAL condition operators in flash player 11.6

Hi. Flash player beta 11.6 brings good news to us. Now we can use more serious stuff in shaders. Condition operators are among them.

And as usual - thre's no info about new features. That's sad. Let's try to investigate it by ourselfs.
First thing we should do to make new stauff works is to request context3d with extended mode:

stage3D.requestContext3D(Context3DRenderMode.AUTO, Context3DProfile.BASELINE_EXTENDED);

Next, we should use new AGALMiniAssembler (goodbye my lovely AGALMacroAssembler :'( and hello again ugly assembler). We should take new method assemble2() which returns created program3D.

var assembler:AGALMiniAssembler = new AGALMiniAssembler(true);
var program:Program3D = assembler.assemble2(_context3D, 2, vertexShader, fragmentShader);

And here our shaders. Vertex first:

var vertexShader:String = 'm44 op, va0, vc0'; // nothing unusual


var fragmentShader:String = '';
fragmentShader += 'mov ft0, fc3' + '\n'; // move constant to temporary register simply because we can't compare constants (Error #3625: AGAL validation failed: Bad AGAL source operands. Both are constants (this must be precomputed) at token 2 of fragment program.)
fragmentShader += 'ife ft0.x, fc2.x' + '\n'; // if(ft0.x == 1)
fragmentShader += 'mov ft1, fc0' + '\n'; // ft1 = (1, 0, 0, 1) - can't write to oc directly (Error #3751: AGAL validation failed: Output registers can not be written inside conditionals.)
fragmentShader += 'els' + '\n'; // else
fragmentShader += 'mov ft1, fc1' + '\n'; // ft1 = (0, 1, 0, 1)
fragmentShader += 'mul ft1, ft1, fc1.w' + '\n'; // ft1 * 1 - just to show that several statements inside condition works
fragmentShader += 'eif' + '\n'; // end if
fragmentShader += 'mov oc, ft1' + '\n'; // oc = ft1

Here fc0 - red color, fc1 - green color, fc2.x - 1 (one), and fc3.x varies depending on input. Inside my loop I check right mouse. If it pressed, I set fc3.x to 0 (zero) otherwise to 1 (one). Take look at demo (remember - you should install flash player 11.6) and press right mouse button.


That's all for today.

6 комментариев:

  1. Они убрали поддержку extended profile :'(

  2. No, it's still available in 11.6 beta. But as official announce said this features will not be included in 11.6 release. Maybe later.

  3. Я уже скачал уйму всяческих playerglobal.swc, и ни в одном не было Extended Profile.. В Product Details FAQ на этой странице:
    Сказано, что сейчас они убрали эту возможность, и неизвестно, добавят ли вообще

  4. That's right. It's only beta features. Will wait for 11.7 beta...

  5. What about FP 11.7 ? Does condition operators worked on it?