Good news everyone. Since a few hours a version of the Pixel Bender 3D compiler has reached the public beta phase. You can download it here.
Now you’re able to write vertex and fragment shaders not only with assembler-like opcodes, but with a lot more readable language.
Instead of:
mov ft0, v0 tex ft1, ft0, fs1 <2d,clamp,linear> mov oc, ft1
You can write much more readable code like this:
void evaluateFragment() { float4 color = sample(textureImage, float2(uv.x, uv.y)); result = color; }
To use a PD3D shader in Molehill you have to write three pixelshaders. The first one is the vertex shader that calculates the vertex position, the second one will be the material vertex shader which (optionally) prepares and calculates data for the fragment shader and finally the fragment shader which is responsible to set the pixel color. Here is an example of the most simple shader you can imagine:
Vertex Shader:
vertex kernel default <namespace : "AIF Test"; vendor : "Adobe"; version : 1;> { parameter float4x4 objectToClipSpaceTransform; input vertex float4 vertexPosition <id : "PB3D_POSITION";> output float4 vertexClipPosition; void evaluateVertex() { vertexClipPosition = vertexPosition * objectToClipSpaceTransform; } }
Material Vertex Shader & Fragment Shader:
material kernel color <namespace : "AIF Test"; vendor : "Adobe"; version : 1;> { input vertex float4 vertexColor <id : "PB3D_COLOR";> interpolated float4 color; output float4 result; void evaluateVertex() { color = vertexColor; } void evaluateFragment() { result = color; } }
To compile a shader program from these three shaders you can use the included PBASMCompiler:
var inputVertexProgram:PBASMProgram = new PBASMProgram(compiledVertexProgramBinary); var inputMaterialVertexProgram:PBASMProgram = new PBASMProgram(compiledMaterialVertexProgramBinary); var inputFragmentProgram:PBASMProgram = new PBASMProgram(compiledMaterialFragmentProgramBinary); var programs:AGALProgramPair = PBASMCompiler.compile(inputVertexProgram, inputMaterialVertexProgram, inputFragmentProgram); var agalVertexBinary:ByteArray = programs.vertexProgram.byteCode; var agalFragmentBinary:ByteArray = programs.fragmentProgram.byteCode; program = context3D.createProgram(); program.upload(agalVertexBinary, agalFragmentBinary);
For a description how to connect a pixelshader to data streams look into the PDF and the examples that are included in the PB3D release. The documentation is already pretty good ;)
If you have no idea what I’m talking about and you’re have heard the word pixelshader for the first time, take a look at Thibault’s intro to Molehill and Michael’s Simple 2D Molehill example.



