Hey all,

I'm trying to use soft stencil shadows pretty much the way the documentation suggests. It works, but the screen turns black based on how the camera is oriented. See video:
[video:youtube]https://youtu.be/shUZnGCqvxo[/video]

It feels as if I have to line up something with the camera, but I'm not sure what!?

Thanks

Here's the code:
Code
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
#include <mtlView.c>

#include "t_player.h"


#define PRAGMA_PATH "models"

///////////////////////////////

MATERIAL* mtlBlur = 
{
	effect = "
	texture TargetMap;
	texture StencilMap;
	sampler smpSource = sampler_state { texture = <TargetMap>; };
	sampler smpStencil = sampler_state { texture = <StencilMap>; };
	float4 vecViewPort; // contains viewport pixel size in zw components
	
	float4 blurPS( float2 Tex : TEXCOORD0) : COLOR0
	{
		float4 Color = tex2D(smpSource, Tex.xy);  
		float4 Stencil = 0;    
		const float fDist = 2;
		
		for (float i=-fDist; i<=fDist; i+=fDist)
		{
			for (float j=-fDist; j<=fDist; j+=fDist)
			{
				Stencil += tex2D(smpStencil, Tex.xy + float2(i*vecViewPort.z, j*vecViewPort.w));
			}
		}
		//return 1 - tex2D(smpStencil, Tex.xy).a;
		Color.rgb -= 0.12 * Stencil.a;
		return Color;
	}
	
	technique Blur
	{
		pass P0
		{ 	    
			PixelShader = compile ps_2_0 blurPS();
		}
	}
	
	technique Fallback
	{
		pass P0 { }
	}
  ";
}

VIEW* vStencil = { 
  material = mtlBlur;
  flags = CHILD | PROCESS_TARGET; 
}

///////////////////////////////

function main()
{
	sun_light = 0;
	d3d_anisotropy = 7;
	video_mode = 12;
	d3d_antialias = 9;
	
	shadow_stencil = 4; // activate z-fail accelerated stencil shadows
	
	level_load("test_2.WMB");
	
	render_stencil = bmap_createblack(screen_size.x, screen_size.y, 32);
	camera.stage = vStencil;

}