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.
Parameters:
bmDest |
Target bitmap. |
bmSrc |
Source bitmap, or NULL for a pure procedural texture. |
mtl |
Material containing a 2D shader function for processing the image. |
Speed:
Medium
Version:
A8.00 C
Remarks
- The bitmap does not need to be locked.
- Only normal 16, 24, or 32 bit bitmaps (1555, 4444, 888, or 8888 format), or floating point textures can
be processed. Bitmaps in a special format, or compressed DDS bitmaps can not be processed.
-
TargetMap
and vecViewPort
are automatically set to the parameters of the source and target bitmaps, thus the postprocessing shaders from the mtlView.c shader library work with this function. A8.11
- The pixel shader function is run for every pixel of the target bitmap, and gets the pixel's xy texture coordinates as input parameters. If the source bitmap has a different size, the texture coordinates must be multiplied with the size ratio for addressing the source bitmap. For best results a blur filter should be applied.
-
bmDest is automatically converted to a render target on the first call of this function. For accessing pixels of the bitmap afterwards, it can be converted back to a pixel format (bmap_to_format) or blitted onto another bitmap (bmap_blit).
Example:
// 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
bmap_process(panTarget.bmap,bmSrc,mtlSepia);
}
See also:
bmap_blit, bmap_fill ► latest
version online