Sign in to follow this  
Flimflam

Working around the new reach profile limitations in XNA4 - Shadow Mapping

Recommended Posts

Hey guys,

I'll preface this by saying that my 3D skills are lacking. I have focused the majority of my programming power on creating neat 2D games with interesting technical effects.

I decided I was going to work on a 3D project to get my feet wet and I'm trying to tackle a few tough problems.

My first problem comes in the form of shadow mapping. The Reach profile in the new XNA version (Want to target this, requiring end users have a DX10 card isn't something I'm interested in doing, despite wanting some of the old functionality I used to get without requiring this...)

I've been looking into shadow mapping, and every example (even the official one) uses SurfaceFormat.Single for the shadow texture. I've tried toying with these samples and converting them to a format available to Reach but the results are always really bad, with all sorts of terrible artifacts all over the subject and the casted shadow.

Does anyone have any information on doing basic shadow mapping with a surface format like Color, or anything available to Reach?

Share this post


Link to post
Share on other sites
You can encode a single float value in 3 components of a Color surface using something like this in your shader:

float4 RGBAEncode(float value) {
value = clamp(value, 0.0f, 0.99999f);

const float4 bitMask = float4(0.0f, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
const float4 bitShift = float4(256.0f * 256.0f * 256.0f, 256.0f * 256.0f, 256.0f, 1.0f);

float4 comp = value * bitShift;
comp = frac(comp);
comp -= comp.xxyz * bitMasl;

return comp;
}

float RGBADecode(float4 value) {
const float4 bits = float4(1.0 / (256.0 * 256.0 * 256.0),
1.0 / (256.0 * 256.0),
1.0 / 256.0,
1);

return dot(value.xyzw , bits);
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this