Adobe AIR: Stage3D and AGAL

3,349 views
3,195 views

Published on

19th July presentation for MYCocoaHeads (XCode developers group) Klang Valley, Malaysia.
http://www.facebook.com/events/328621870554812/

Published in: Technology, Business
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,349
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
57
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Adobe AIR: Stage3D and AGAL

    1. 1. Daniel Freeman
    2. 2. AIR Evolution• ActionScript “Next”• StageText, StageVideo, Stage3D• Native Extensions• ActionScript Workers
    3. 3. UbiquitousStage3D Stage3D Stage3D Stage3DOpen GL DirectX Open GL ES SwiftShaderMac Windows Mobile No GPU Support for older hardware (Intel GMA) soon
    4. 4. Programmable vertices indices Triangle ViewportVertex Shader Assembly Clipping transformed triangle vertices stream Fragment Frame Rasteriser Shader Buffer fragment pixel stream stream textures
    5. 5. winding / backface culling
    6. 6. depth buffering
    7. 7. 2d -1 2d -1 +1 z= 1 z= 0 +1 -1 -1 +1 +1 World StageCoordinates Coordinates
    8. 8. Versatile Interpolated Registers VertexShader FragmentShader v0-v7 Vertex Fragmentshader runs shader runs once per once per vertex fragment
    9. 9. Low Level mov ft3, v1 sub ft0.xy, v0.xy, fc4.xx sub ft0.z, fc4.x, v2.x abs ft1.xy, ft0.xy sub ft1.xy, ft1.xy, ft0.zz mul ft2.xy, ft1.xy, ft1.xy add ft2.x, ft2.x, ft2.y sqt ft2.x, ft2.x add ft2.z, fc4.w, v2.x sub ft2.z, ft2.z, ft2.x pow ft3.w, ft2.z, fc4.z sat ft3.w, ft3.w mov oc, ft3
    10. 10. Registersva0-va7 Attribute Registersvc0-vc127 Constant Registersfc0-fc127 Constant Registersfs0-fs7 Sampler Registersv0-v7 Varying Registersop Output Pointoc Output Colour
    11. 11. Registers vt0-vt7 va0-va7 VertexShader opvc0-vc127 v0-v7 (Interpolated) fs0-fs7 ft0-ft7 FragmentShader ocfc0-fc127
    12. 12. Example 1 : Solid Colour GreenSquare1
    13. 13. protected static const VERTICES:Vector.<Number> = Vector.<Number> ([ // X, Y, Z -0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.5, 0.5, 0.0, -0.5, 0.5, 0.0, ]); protected static const N:int = 3; protected static const INDICES:Vector.<uint> = Vector.<uint> ([ 0, 1, 2, 0, 2, 3 ]); (-0.5, -0.5, 0) 0 1 (0.5, -0.5, 0) 0 1 0 (-0.5, 0.5, 0) 3 2 2 3 2 (0.5, 0.5, 0)
    14. 14. _context3D.setProgramConstantsFromVector( Context3DProgramType.FRAGMENT, 0, // fc0 Vector.<Number>([ 1.0, 0.0, 0.0, 1.0]) // = Red); vertex shader mov op, va0 output point fragment shader mov oc, fc0 output colour
    15. 15. Example 2 : Gradient Fill GreenSquare3
    16. 16. protected static const VERTICES:Vector.<Number> = Vector.<Number> ([ // X, Y, Z, r, g, b -0.5, -0.5, 0.0, 0, 1, 0, 0.5, -0.5, 0.0, 1, 0, 0, 0.5, 0.5, 0.0, 1, 1, 1, -0.5, 0.5, 0.0, 0, 0, 1, ]); protected static const N:int = 6; protected static const INDICES:Vector.<uint> = Vector.<uint> ([ 0, 1, 2, 0, 2, 3 ]); (-0.5, -0.5, 0) 0 1 (0.5, -0.5, 0) 0 1 0 (-0.5, 0.5, 0) 3 2 2 3 2 (0.5, 0.5, 0)
    17. 17. Interpolated Registers VertexShader FragmentShader v0-v7vertex shadermov op, va0 output pointmov v0, va1 interpolate colourfragment shadermov oc, va1 output colour
    18. 18. Example 3 : Rotation GreenSquare4
    19. 19. _transform.appendRotation( 2.0, Vector3D.Z_AXIS );_context3D.setProgramConstantsFromMatrix( Context3DProgramType.VERTEX, 0, //vc0 _transform, true);vertex shaderm44 op, va0, vc0 transformfragment shadermov oc, fc0 output colour
    20. 20. Example 4 : Gradient Cube Flash3DExperiment5
    21. 21. protected static const VERTICES:Vector.<Number> = Vector.<Number> ([ // X, Y, Z, r, g, b -0.5, -0.5, 0.5, 0, 1, 0, 0.5, -0.5, 0.5, 1, 0, 0, 0.5, 0.5, 0.5, 1, 1, 1, -0.5, 0.5, 0.5, 0, 0, 1, -0.5, -0.5, -0.5, 0, 1, 0, 0.5, -0.5, -0.5, 1, 0, 0, 0.5, 0.5, -0.5, 1, 1, 1, -0.5, 0.5, -0.5, 0, 0, 1, ]); protected static const N:int = 6; protected static const INDICES:Vector.<uint> = Vector.<uint> ( [ 0, 1, 2, 0, 2, 3, 4, 6, 5, 4, 7, 6, 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0 ]);
    22. 22. _projectionMatrix.perspectiveFieldOfViewLH( 45.0*Math.PI/180, stage.stageWidth/stage.stageHeight, 0.1,1000.0 ); vertex shader m44 op, va0, vc0 transform mov v0, va1 interpolate fragment shader mov oc, v0 output colour
    23. 23. Example 5 : Texture Cube Flash3DExperiment3
    24. 24. protected static const VERTICES:Vector.<Number> = Vector.<Number> ([ // X, Y, Z, u, v, -1.0, -1.0, -1.0, 0, 0, 1.0, -1.0, -1.0, 0, 1, 1.0, 1.0, -1.0, 1, 1, -1.0, 1.0, -1.0, 1, 0, etc...etc.. u 0 1 0 1 VertexShader FragmentShader v Interpolated 3 2 1
    25. 25. _projectionMatrix.perspectiveFieldOfViewLH( 45.0*Math.PI/180, stage.stageWidth/stage.stageHeight, 0.1,1000.0 ); vertex shader m44 op, va0, vc0 transform mov v0, va1 interpolate uv fragment shader tex ft0, v0, fs0 <2d,linear,nomip> mov oc, ft0 output fragment
    26. 26. Example 6 : Light Source Flash3DExperiment7a Flash3DExperiment8
    27. 27. protected static const VERTICES:Vector.<Number> = Vector.<Number> ([ // X, Y, Z, nX, nY, nZ -1.0, -1.0, -1.0, 0, 0, -1.0, 1.0, -1.0, -1.0, 0, 0, -1.0, 1.0, 1.0, -1.0, 0, 0, -1.0, -1.0, 1.0, -1.0, 0, 0, -1.0, etc...etc... normal
    28. 28. _context3D.setProgramConstantsFromVector( Context3DProgramType.FRAGMENT, 0, Vector.<Number>([ 0.5, 0.5, 0.5, 1.0 ]) ); _context3D.setProgramConstantsFromVector( Context3DProgramType.FRAGMENT, 1, Vector.<Number>([ X, Y, Z, 1.0 ]) ); vertex shader m44 op, va0, vc0 transform m44 v0, va1, vc0 normal fragment shader nrm ft0.xzy, v0 normalise mov ft0.w, fc0.w dp3 ft0, ft0, fc1 dot product sat ft0, ft0 clamp mul oc, ft0, fc0 multiply colour
    29. 29. Example 7 : Phong Shader Flash3DExperimentA
    30. 30. normal interpolated normals
    31. 31. fc0 Half Angle Vector fc1 Ambient Colour fc2 Diffuse Colour fc3 Specular Colourvertex shaderm44 op, va0, vc0 transformm44 v0, va1, vc4 normalfragment shadernrm ft0.xyz, v0 normalise normalmov ft0.w, fc0.w set w to 1dp3 ft0.x, ft0, fc0 dot productsat ft0.x, ft0.x clamppow ft1.x, ft0.x, fc3.w dot product to powermul ft2.xyz, fc2.xyz, ft0.xxx diffuse colouradd ft2.xyz, fc1.xyz, ft2.xyz add ambient colourmul ft3.xyz, fc3.xyz, ft1.xxx specular colouradd oc, ft2.xyz, ft3.xyz combine and output
    32. 32. More Examples
    33. 33. Questions

    ×