Sommaire

Shaders




HLL Vertex and Pixel Programs

This implementation of vertex program and fragment program from openGL and vertex shaders 1.1 and pixel shaders 1.4 from directX, is developped to interpret and compile in assembly, pseudo code in a particular syntax.
The functionnalities of vertex program in the lib is designed to work on all cards even if graphic card driver doen't support it.(some divers doesn't have the open gl extension, some cards do not implement the ARB spefs even in software).
Here are some explanation on how to develop vertex shaders and pixel shaders and how to decline technique to fit destination graphic cards.

       Functions:

       sample[.xyzw] ( stage , uv )
       coord( TexCoordn )
       mul_x2 ( a , b )
       mul_x4 ( a , b )
       mul_sat ( a , b )
       dot ( a , b )
       dot_sat ( a , b )
       dotbx2 ( a , b ) ou dotofbx2 ( a , b )
       reciprocal ( x ) ou rcp ( x )
       rsq ( x )
       fractionnal ( x ) ou fract ( x ) ou frac ( x )
       cmp ( value , a , b ) ou compare ( value , a , b ) -> ( value > 0.0 ) ? a : b
       sge ( a , b )
       slt ( a , b )
       mix ( a , b , x )
       lerp ( a , b , x )
       lerp_sat ( a , b , x )
       smoothstep ( a , b , x )
       clamp ( x , min , max )
       max ( x , y )
       min ( x , y )
       normalise ( v ) ou normalize ( v )
       norme ( v ) ou norm ( v )
       inv ( v )
       mod ( x , modulo )
       pow ( x , e )
       log2 ( x )
       exp2 ( x )
       log ( x )
       exp ( x )
       abs ( x )
       floor ( x )
       round ( x )
       trunc ( x )
       degrees ( x )
       radians ( x )
       rsqrt ( x )
       sqrt ( x )
       atan ( x )
       atan2 ( x , y )
       tan ( x )
       asin ( x )
       sin ( x )
       acos ( x )
       cos ( x )
       tgt ( up , v )
       reflect ( u , n )
       refract ( u , n , eta )
       equation ( normal , point )
       plane ( v , eq )
       interpolate( v1 , v2 , t , M ) ou interpolation( v1 , v2 , t , M )
       normal_interpolate( v1 , v2 , t , M ) ou normal_interpolation( v1 , v2 , t , M )
       iter( level )
       ValueToRGB( x )
       RGBToValue( rgb )

Exemples of vertex program that works with lib3d vertex programs



Exemple1: Syntaxe

[VERTEXFORMAT]
       XYZ DIFFUSE TEX0-> vertex buffer format
[DEFINES]
       MATRIX WORLD;   -> link variables, constants
       MATRIX VIEWPROJ;
       CONST zero=;
       CONST one=1.0,1.0,1.0,1.0;
       TEXTURE tex;
       -> the words following [TECHNIQUE] can be the following :
       -> Shaders, Dot3, Multitexture, All Cards due to specification of the technique.
[TECHNIQUE]    All cards
[PASS0]
       [POSITION]      -> pseudo code
       u=iPos*4WORLD;
       oPos=u*4VIEWPROJ;
       [DIFFUSE]
       oDiffuse=one;
       [MAPPING0]
       oTexture0=iTexture0;
       [RENDER_STATE]  -> similar to directx
       Blend   False
       Texture[0]      tex
       ColorOp[0]      Modulate
       ColorArg1[0]    Texture
       ColorArg2[0]    Diffuse
       AlphaOp[0]      Modulate
       AlphaArg1[0]    Texture
       AlphaArg2[0]    Diffuse
       ColorOp[1]      Disable
       AlphaOp[1]      Disable
       Cull    None
       ZBuffer True
       ZBufferWrite    True
       TextureCoordinate[0]    TexCoo0
[END]



Exemple2: Environment mapping exemple

[VERTEXFORMAT]
       XYZ NORMAL TEX0
[DEFINES]
       CONST zero;
       CONST one=1.0,1.0,1.0,1.0;
       CONST half=0.5;
       VECTOR alpha;
       VECTOR color;
       MATRIX WORLD;
       MATRIX VIEWPROJ;
       TEXTURE tex;
       TEXTURE envmap;
[TECHNIQUE]    All cards
[PASS0]
       [POSITION]
       tPos=iPos*4WORLD;
       tNorm=iNorm*3WORLD;
       oPos=tPos*4VIEWPROJ;
       [DIFFUSE]
       c=color;
       oDiffuse=alpha*c;
       oDiffuse.w=one.x;
       [MAPPING0]
       oTexture1.x=iTexture0.x;
       oTexture1.y=iTexture0.y;
       [MAPPING1]
       oTexture1.x=half.x+half.x*tNorm.x;
       oTexture1.y=half.x+half.x*tNorm.y;
       [RENDER_STATE]
       ShadeMode       Smooth
       Texture[0]      tex
       Texture[1]      envmap
       ColorOp[0]      Modulate
       ColorArg1[0]    Texture
       ColorArg2[0]    Diffuse
       AlphaOp[0]      SelectArg2
       AlphaArg2[0]    Diffuse
       ColorOp[1]      Modulate
       ColorArg1[1]    Texture
       ColorArg2[1]    Current
       AlphaOp[1]      Disable
       Cull    Ccw
       ZBuffer True
       ZBufferWrite    True
       TextureCoordinate[0]    TexCoo0
[END]



Exemple3: Extrude silhouette volume of a degenerated edges vertex buffer

[VERTEXFORMAT]
       XYZ NORMAL TEX0
[DEFINES]
       MATRIX WORLD;
       MATRIX VIEWPROJ;
       VECTOR longueur;
       VECTOR Light;
       VECTOR Decal;
       CONST zero=;
       CONST one=1.0,1.0,1.0,1.0;
       TEXTURE tex;
       
[TECHNIQUE]    All cards
[PASS0]
       [POSITION]
       tPos=iPos*4WORLD;
       tNorm=iNorm*3WORLD;
       u=tPos-Light;
       s=sge((u|tNorm),zero);
       u1=tPos+longueur*s*u*rsq(u|u);
       oPos=u1*4VIEWPROJ;
       [DIFFUSE]
       oDiffuse.x=zero.x;
       oDiffuse.y=zero.y;
       oDiffuse.z=zero.z;
       oDiffuse.w=one.w-s.w;
       [MAPPING0]
       oTexture0=iTexture0+Decal;
       [RENDER_STATE]
       ShadeMode       Smooth
       Blend   True
       SrcBlendSrcAlpha
       DstBlendInvSrcAlpha
       Texture[0]      tex
       ColorOp[0]      SelectArg2
       ColorArg1[0]    Texture
       ColorArg2[0]    Diffuse
       AlphaOp[0]      SelectArg2
       AlphaArg2[0]    Diffuse
       ColorOp[1]      Disable
       AlphaOp[1]      Disable
       Cull    Ccw
       ZBuffer True
       ZBufferWrite    False
       TextureCoordinate[0]    TexCoo0
[PASS1]
       [POSITION]
       tPos=iPos*4WORLD;
       tNorm=iNorm*3WORLD;
       u=tPos-Light;
       s=sge((u|tNorm),zero);
       u1=tPos+longueur*s*u*rsq(u|u);
       oPos=u1*4VIEWPROJ;
       [DIFFUSE]
       oDiffuse.x=zero.x;
       oDiffuse.y=zero.y;
       oDiffuse.z=zero.z;
       oDiffuse.w=one.w-s.w;
       [MAPPING0]
       oTexture0=iTexture0+Decal;
       [RENDER_STATE]
       ShadeMode       Smooth
       Blend   True
       SrcBlendSrcAlpha
       DstBlendInvSrcAlpha
       Texture[0]      tex
       ColorOp[0]      SelectArg2
       ColorArg1[0]    Texture
       ColorArg2[0]    Diffuse
       AlphaOp[0]      SelectArg2
       AlphaArg2[0]    Diffuse
       ColorOp[1]      Disable
       AlphaOp[1]      Disable
       Cull    Cw
       ZBuffer True
       ZBufferWrite    False
       TextureCoordinate[0]    TexCoo0
[END]