bmap_process (BMAP* bmDest, BMAP* bmSrc, MATERIAL* mtl);

Fills a bitmap with a pixel shader function from a source bitmap. This function is very fast on shader hardware, and can be called every frame without much impact on the frame rate. It can be used for postprocessing images or for creating and updating procedural textures in real time. Using a floating point target texture, this function can also be used to perform a huge number of calculations on the GPU.


bmDest Target bitmap.
bmSrc Source bitmap, or NULL for a pure procedural texture.
mtl Material containing a 2D shader function for processing the image.




A8.00  C 



// convert an image to sepia colors and display it on the screen

PANEL* panTarget = { bmap = "#256x256x24"; flags = SHOW; } // target bmap
BMAP* bmSrc = "image.tga"; // source bmap

MATERIAL* mtlSepia = { // sepia coloring pixel shader
  effect = "
  Texture TargetMap; // source bitmap
  sampler2D smpSrc = sampler_state { texture = <TargetMap>; };
  float4 SepiaColor1 = {0.2, 0.05, 0.0, 1.0};   
  float4 SepiaColor2 = {1.0, 0.9,  0.5, 1.0}; 

  float4 process_sepia(float2 Tex: TEXCOORD0): COLOR 
    float4 Color = tex2D( smpSrc, Tex.xy);
    float sepiaLerp = dot( float3(0.3, 0.59, 0.11), Color);
    return lerp(SepiaColor1,SepiaColor2,sepiaLerp);

  technique Sepia {
    pass p1 {
      AlphaBlendEnable = false;	
      PixelShader = compile ps_2_0 process_sepia();

function main()
  wait(1); // until DirectX device is opened

See also:

bmap_blit, bmap_fill

► latest version online