render_stencil

StencilMap

Stencil buffer target for a view. If a bitmap is assigned to this pointer, the content of the stencil buffer is copied into this bitmap after rendering, instead of drawn over the screen. This way postprocessing effects can be applied to the stencil buffer, such as blurring stencil shadows. The stencil target texture is available to shaders through the texture variable StencilMap.

Type:

BMAP* (lite-c)
texture (shader code)

Remarks:

Edition:

A7.10  C   LC 

Example:

function main()
{
  ...
  shadow_stencil = 4; // activate z-fail accelerated stencil shadows
  effect_load(mat_shadow,"st_stencilblur.fx"); // autogenerate render_stencil by assigning a stencil shader  
...
// st_stencilblur.fx - Poisson blur shader

texture StencilMap; // stencil buffer image in the alpha channel
sampler smpStencil = sampler_state { texture = <StencilMap> }; 
float4 vecViewPort; // contains viewport pixel size in zw components

static const float fDist = 4.0;   // blur factor
static const float fStrength = 0.15;  // shadow darkness

static const float2 fTaps_Poisson[12] = {
	{-.326,-.406},{-.840,-.074},{-.696, .457},{-.203, .621},
	{ .962,-.195},{ .473,-.480},{ .519, .767},{ .185,-.893},
	{ .507, .064},{ .896, .412},{-.322,-.933},{-.792,-.598}
};

float4 blurPoissonPS( float2 Tex : TEXCOORD0) : COLOR0 
{
   float4 Stencil = 0;
   for (int i=0; i < NUM_TAPS; i++)
     Stencil += tex2D(smpStencil,Tex.xy + fTaps_Poisson[i]*fDist*vecViewPort.zw);
   return Stencil * fStrength;
}

technique stencilblur { 
  pass one { 
     PixelShader = compile ps_2_0 blurPoissonPS(); 
  }
} 

See also:

VIEW, BMAP, view.bmap, view.stage, view.material, render_target, render_zbuffer, PROCESS_SCREEN, shadow_stencil

► latest version online