Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (9 posts)

Tips for shadow mapping in the Reach profile?

Last post 10/12/2010 7:17 PM by KIKIAlex. 8 replies.
  • 10/12/2010 1:28 AM

    Tips for shadow mapping in the Reach profile?

    Hey guys,

    I'm trying to figure out how to do basic shadow mapping with the Reach profile and because my knowledge of this area of development is so minuscule (never done much in 3D until now), I'm having a very difficult time figuring this out.

    Every sample or tutorial I've ever seen uses the SurfaceFormat.Single for the shadow texture. As we all know, Reach sadly doesn't support this format so I'm out of luck. Is it possible to get even decent results with a format available to reach? (I'm guessing SurfaceFormat.Color since that's about all it supports...) And if so, can someone shed some light on how I can go about it?

    It's becoming increasingly difficult to work around all the limitations imposed by the move to XNA 4 if I don't want to tell everyone with a DX9 card to piss off. I don't really want to stick to XNA 3.1 because it's pretty much in the back of Microsoft's mind now that 4.0 is out.

    On a different note, something was brought up on gamedev.net forums related to the removal of effect compilation at runtime in XNA. The project I was working on was actually going to utilize this, and now I learn it's impossible. Well, I guess I can't say it's impossible, the official workaround to the removal of these two functions is to require that people running my program download the full .net 4.0 runtime, visual studio 2010, and the full XNA sdk, so I can use the content pipeline to build the effects at runtime. I seem to be the only guy who thinks that's completely unrealistic though. I don't suppose fxc.exe can be redistributed with your own programs so that I can pass the resulting byte code to the Effect constructor?
  • 10/12/2010 1:48 AM In reply to

    Re: Tips for shadow mapping in the Reach profile?

    flimflam:
    Every sample or tutorial I've ever seen uses the SurfaceFormat.Single for the shadow texture.


    8 bit precision (using Color format) may be enough for some shadow maps if you are very careful with the projection range, and if you do not support self shadowing (which requires vastly more precision to look good), but it's very fiddly to make this work. There are games that have done it, but it's not something I can really recommend.

    For shadow mapping in Reach, I would use ID based shadow maps instead of depth shadow maps.  ID based shadowing is actually IMHO a much underrated technique even for HiDef games - it does have some limitations (self shadowing is tricky) but performs great and completely avoids all the usual precision and acne problems.

    Tom Forsyth has a great overview of shadowing techniques:  http://home.comcast.net/~tom_forsyth/papers/Tom_Forsyth_Practical_Shadows.ppt.zip


    flimflam:
    I don't suppose fxc.exe can be redistributed with your own programs so that I can pass the resulting byte code to the Effect constructor?


    The native DXSDK FXC tool does not produce the same format compiled code used by XNA Game Studio, so that won't work.

    I'm curious why you need to compile shaders on the fly at runtime?

    Many game engines include an option to do this in debug builds, as it can be very useful for iterating and prototyping shader code. The usual approach is to #ifdef out this code when building the final release game, though, at which point the final set of shaders is known so there is no more need for dynamic compilation.  This is the approach taken by most commercial Xbox games, for instance.
  • 10/12/2010 2:11 AM In reply to

    Re: Tips for shadow mapping in the Reach profile?

    Thanks for the quick response, Shawn. I don't have powerpoint or the viewer at the moment (will install one soon so I may view the link), does that link you've provided explain this ID based shadow map system in detail? To be honest, this is the first I've actually heard of it, and google searching seems to be a bit sparse except for really complicated looking papers on the subject. I'm really new to concepts like shadow mapping, so I need my hand held to a certain extent. To elaborate on my intended use for this shadow system, it's for shadowing terrain that isn't just a heightmap. I think self-shadowing might be a requirement for this.

    As for my needs for dynamic shaders, that's a shame that fxc wouldn't work. I didn't know they were actually different formats.

    The reason I needed to be able to compile shaders at runtime is for the editor portion of my project. I realize an editor is something you could reasonably expect that a development environment would be present on, but I was planning to integrate the editor into the game itself, and this editor is part of the game, not just a development tool. I wanted the shaders for various things to be customizable to a certain extent from within the editor. I suppose I will just need to supply a wide arrangement of shaders with plenty of changeable parameters.

    Curiously, if there's seemingly no way to get the correct byte code for XNA shaders outside of the content pipeline, what's the purpose of the overloaded constructor that takes a byte array? Is it just remnants that wasn't removed? Is it solely for feeding in content pipeline compiled code?
  • 10/12/2010 4:09 AM In reply to

    Re: Tips for shadow mapping in the Reach profile?

    flimflam:
    I think self-shadowing might be a requirement for this.


    Yes, for terrain it probably is.

    I'm curious how dynamic your terrain and lighting is? Can the terrain be deformed, or the light source move, on the fly?

    If not it might be worth considering a precomputed lightmap as opposed to realtime lighting. Many (I hesitate to say most, but suspect it might actually be most) terrain engines go with precomputed lightmaps, which not only makes the runtime drawing code far more efficient, but also enables much higher quality lighting (cool things like soft shadows become feasible).

    flimflam:
    I suppose I will just need to supply a wide arrangement of shaders with plenty of changeable parameters.


    I think that's how I'd tackle this.

    flimflam:
    what's the purpose of the overloaded constructor that takes a byte array? Is it solely for feeding in content pipeline compiled code?


    Exactly. Without that constructor, we would have had no way to implement the Content Pipeline type reader! This can also be useful for developers who compile their shaders using EffectProcessor, but then deploy the resulting bits some other way than via .xnb files (for instance, see the Stock Effects utility on this site once the education catalog comes back up after the site upgrade)
  • 10/12/2010 6:45 AM In reply to

    Re: Tips for shadow mapping in the Reach profile?

    Unfortunately, my terrain is completely deformable. I'm actually generating my terrain based on voxel information. It's a primitive setup; I'm simply using cubes at the moment, but it's not something I could really generate lightmaps for. 

    The camera is a birds eye view similar to what you'd see in a 2D RPG however, so the rendered area isn't actually very large.
  • 10/12/2010 8:31 AM In reply to

    Re: Tips for shadow mapping in the Reach profile?

    Did you get any more info about ID shadow mapping.  I also have not come across this.   I had got my shadows working nicely in XNA 3.1 but the HLSL instruction slot limit in XNA 4 has reduced the quality to poor/rubbish.

    I did not solve the problem of artifacts on self shadowing of moving objects and had almost abandoned that idea anyway.

    Any more links would be welcome.

    Thanks
  • 10/12/2010 2:40 PM In reply to

    Re: Tips for shadow mapping in the Reach profile?

    Tom has a good overview in his shadowing techniques paper.

    The basic idea is to give each object in the scene a unique ID, and write this ID out to a color buffer instead of the object depth, then when applying the shadows, instead of testing (current depth < recorded depth) you test (current ID != recorded ID).
  • 10/12/2010 3:51 PM In reply to

    Re: Tips for shadow mapping in the Reach profile?

    Or better yet compress the depth as a color and use that :

    float4 FloatToFloat4( float rawValue )
    {   
        const float4 packFactors = float4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);
        const float4 bitMask = float4(1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);

        float4 packedValue = float4(frac(packFactors*rawValue));
        packedValue -= packedValue.xxyz * bitMask;
        return packedValue;
    }

    Decompress it where you need it :

    float Float4ToFloat(float4 encodedValue)
    {
        const float4 unpackFactors = float4( 1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0 );

        return dot(encodedValue,unpackFactors);
    }

    Float buffers are expensive and in most cases not worth it.

    http://communistgames.blogspot.com/
  • 10/12/2010 7:17 PM In reply to

    Re: Tips for shadow mapping in the Reach profile?

    Here is a link on what I'm talking about, you can download an example from there that is using that tehnique:

    http://communistgames.blogspot.com/2010/10/xna-40-reach-and-shadowmaping.html


    http://communistgames.blogspot.com/
Page 1 of 1 (9 posts) Previous Discussion Next Discussion
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG