Yesterday great news were published concerning the 3D on the web :

Adobe released their Flash Player 11 "Incubator" Public Beta, which includes a full low-level 3D API which is GPU-accelerated, see Adobe Labs

Unity announced in this blog post that they're working on a way to export to Flash (using the same lowlevel 3D API)

As you will see while reading the documentation or Thibault tutorial, most of the work in 3D is handled by shaders : they are short programs that get sent and run on the GPU, handling all the 3D transformations, but also Lighting, Texturing, and providing an infinite amount of custom effects.

In AS3, shaders are written in assembler and put into a string of your program, such as :



var shader : String = "dp4 op.x, va0, vc0

" + "dp4 op.y, va0, vc1

" + "dp4 op.z, va0, vc2

" + "dp4 op.w, va0, vc3

" + "mov v0, va1.xyzw

" ;

And you have to write a lot of boilerplate code to make sure that your vertex buffer works well with your shader. Adobe announced that they are working on PixelBender3D Toolkit, that will enable you to test and compile shaders, but this won't suppress the boilerplate code and you will still have to use a 3rd party tool to edit your shaders, which as a programmer I find annoying.

This is for this reason that I have developed a new shader language for Haxe, called HxSL (for Haxe Shader Language). You can directly embed HxSL code into your Haxe program, by using Haxe Metadata :

@:shader ( { var input : { pos : Float3, } ; var color : Float3; function vertex ( mpos : M44, mproj : M44 ) { out = pos . xyzw * mpos * mproj; color = pos; } function fragment ( ) { out = color . xyzw; } } ) class Shader extends format . hxsl . Shader { }

When you compile your program, a Haxe macro will simply check the shader correctness and report you any syntax or logic error directly in your IDE as it would have done for another error. If success, it will generate a few methods that will generate all the boilerplate code for you.

In order to use this shader, you will simply have to do :



shader . init ( { mpos : mpos, mproj : project } , { } ) ; shader . bind ( vbuf ) ; context3D . drawTriangles ( ibuf ) ;

HxSL is a high level shader language so you don't have to write any assembler. You can also include constant values such as 1.56 or constant vectors such as [1,-1,0,0.5] - which is not possible to do using Flash11 assembler.

If you want to get started with Haxe/Flash11 now, simply follow the Tutorial on Haxe Website and read the HxSL Documentation.

Forgot to say : one nice thing with HxSL is that it can be compiled to other high-level shader languages such as GLSL for OpenGL/WebGL or HLSL for DirectX. Haxe being multiplatform itself, this opens a lot of possibilities for cross platform 3D development in the near future.