Vous êtes sur la page 1sur 4

FLSL (Flare3D Layer Shader Language).

The FLSLFilters are precompiled shader functions that you can combine, change their order, change the mode they are blended, change the technique to use for each filter, among others, They are an extensible shader lab to experiment for programmers and artists. Each FLSLFilter could be a complete shader or just a fragment of it. AGAL is an assembler language, FLSL is more like PixelBender3D. FLSL is to AGAL like C/C++ for Assembler. We are using the FLSLCompiler for internal use, so we will give you some examples how to start with, but it has really poor error cheeking and you should expect to get some unexpected results sometimes ;) The compiler class is in flare.materials.flsl.FLSLCompiler. To compile a shader just call to FLSLCompiler.compile( sourceShader:String ), and it will returns a ByteArray with the compiled shader.

FLSL What??
You need to have some knowledge about 3D shader math, matrices multiplications and any other shader language it will really helpfully. The most simple shader will look like this, where the vertex position are multiplied by the worldViewProjection matrix to get them projected on the screen:
<namespace:"flare", name:"BasicTransform"> // this recives the worldViewPorjection matrix from flare3d. public WORLD_VIEW_PROJ worldViewProj; // this property can also be changed outside the shader. public float4 color = float4( 1, 0, 0, 1 ); // use the vertex position input. input POSITION position; private float4 myVertex() { float4 pos = float4( position, 1 ); return pos * worldViewProj; }

private float4 myFragment() { return color; } technique "basic" { vertex myVertex(); fragment myFragment() }

the upper case keywords are constants defined by flare3d to get the data directly from the engine at render time. the inputs are vertex attributes such as POSITION, NORMAL, UV0, UV1, etc...you can get access to them into the vertex function but not in the fragment/pixel function. The next example is a basic texture filter you can combine with the last one to get your vertices projected and textured. Of course, you can combine all in one single shader, to get a complete and specific shader.
<namespace:"flare", name:"BssicTexture" public texture myTexture; public float1 alpha = 1; input UV0 uv0; interpolated float4 iUV; private void myVertex() { iUV = uv0; } private float4 myFragment() { return sample( myTexture, iUV.xy, "2d,repeat,linear,miplinear" ) * alpha; } technique "basicTexture" { vertex myVertex(); fragment myFragment(); } >

The interpolated variable, are the data you send from the vertex function to the fragment/pixel function, you can (need to) set them in the vertex, but you can only read into the fragment function. The interpolated variables, can only be float4, and you need to write all registers.

FLSL Functions:
// vectors could be float1, float2, float3 or float4 depending of the function. float4 sample( texture, sampleCoord, flags );

vector = length( vector1, vector2 ) vector = clamp( vector1, minValue, maxValue ); vector = normalize( vector ); vector = dot( vector1, vector2 ); vector = min( vector1, vector2 ); vector = max( vector1, vector2 ); vector = sqrt( vector ); vector = rsq( vector ); // 1 / sqrt(value) vector = pow( vector, powValue ); vector = sin( vector ); vector = cos( vector ); vector = cross( vector1, vector2 ); // cross product between vectors. vector = abs( vector ); // absolute value vector = neg( vector ); // negate the value = value *= -1 vector = saturate( vector ); // clamp the value from 0 to 1 kill( value ); // kill the pixel if the value is less than 0 vector = sge( vector1, vector2 ); // if grater than = vector1 > vector2 ? 1 : 0 vector = slt( vector1, vector2 ); // if lower than = vector1 < vector2 ? 1 : 0 vector = log( value ) //not yet implemented vector = exp( value ) //not yet implemented

Matrix constants:
VIEW_PROJ = Device3D.viewProj WORLD_VIEW_PROJ = Device3D.worldViewProj WORLD_VIEW = Device3D.worldView WORLD = Device3D.global VIEW = Device3D.view PROJ = Device3D.proj IWORLD = Device3D.invGlobal SPECIAL0 = Device3D.special0 SPECIAL1 = Device3D.special1 SPECIAL2 = Device3D.special2

Input Constants:
POSITION UV0 UV1 NORMAL TANGENTS BITANGENTS COLOR // this are not currently calculated by the engine, it will, in case the model has vertex color information. SKIN_WEIGHTS SKIN_INDICES

On ActionScript Side:
Once you got you shader you can use it trough FLSLFilter class:

var filter:FLSLFilter = new FLSLFilter( compiledShaderBytes, blendMode = "normal", techniqueName:String = null );

For parameters: You can define the default values directly on the shader, but you can also make changes to the values. All params are Vector.<Number> type values, and when you change one of them you need to call to filter.update() method to update all values on the materials.
filter.params.color.value = Vector.<Number>( [1,0,0,1] );

or
filter.params.color.value[0] filter.params.color.value[1] filter.params.color.value[2] filter.params.color.value[3] = = = = 1; 0; 0; 1;

and then...
filter.update();

For textures:
filter.textures.myTexture.value = someTexture3D;

Vous aimerez peut-être aussi