XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

How to create a cloudshadoweffect in a 2D RTS game

Last post 6/27/2009 3:12 PM by RvdVeer. 5 replies.
  • 6/23/2009 9:48 AM

    How to create a cloudshadoweffect in a 2D RTS game

    Hello experts!

    It's a bit hard to explain what I would like to create with XNA, but I'll give it a shot anyway.
    I'm currently working on a kind of 2D RTS game, with characters and a tile engine where the camera
    is positioned above the 'world'. Since this is for educational purposes (namely myself) I used a lot from great tutorials from some of you and those found
    on the world wide web...

    To make the game a little bit more realistic, I would like to have weather situations. To start with clouds (in fact the shadow they drop when
    a cloud passes the sun).
    I was thinking about the following (you may correct me if I'm thinking the wrong way, since I'm quite new to game developing):

    I was thinking about creating a huge bitmap with an alpha channel.
    To prevent enourmous loading times, I was thinking about clipping a part from this bitmap (texture) to the size of the playfield (currently 800*600 for testing
    purposes) and render this to a Render2DTarget, within this Rendertarget, I could use some simple math functions (sin, cos) to make the clouds move a bit, before
    I render them with my spriteBatch.

    Next I need to mix it with my currently drawn world (using spritebatches).

    Am I thinking the right way? Are there tuturials about this subject? I must admit, I haven't looked that thourougly yet...

    I've read about shaders too, but are they useable in 2D games? Since what I've read about them is that they are far more commenly used in 3D games or simulations.

    I can use all advice, in the meantime I will try to program this out, but I feel this 'solution' I had in mind would significantly decrease the overall performance of the game. Thus I'm curious on how this would work in a more appropriate way.

    Thank you for your time and effort thus far.

    Robert.

  • 6/23/2009 1:01 PM In reply to

    Re: How to create a cloudshadoweffect in a 2D RTS game

    Hello,

    Shaders are indeed useable in 2D games (2D in XNA is still a 3D Direct3D environment but drawn flat with a 2D projection and no perspective). Everything in XNA is rendered with shader, even spritebatch calls.

    But it would be a kind of an overkill to use it for your purpose. To draw simple cloud shadows, I would just draw clouds on above your world with a black color and an alpha value. If you'r also drawing clouds, just draw your shadows first, with a little offset so that the shadows are not right under them, giving a cool effect of perspective, then draw the clouds without the offset.

    Shaders would be great in your case if all of your tile graphics had normal maps, you could have been able to cast shadows on mountains etc. But I think it is out of the scope of your XNA learning and I didn't saw anywhere tilesets with normal values. Shaders, in 2D Games, are more commonly used to do some postprocessing (bloom/blur, color variation) or stuff like refraction (for cool explosion effects).

    Using a RenderTarget could decrease the performance, it depends on what you'll be doing with it, and how (avoid the GetData method). But you shouldn't bother about performance as long as it runs fine on your PC and/or the Xbox.
    http://helmut.dev-blog.fr/
  • 6/23/2009 6:34 PM In reply to

    Re: How to create a cloudshadoweffect in a 2D RTS game

    Thank you for your reply Helmut,

    I was thinking the same way about the texture with an alpha value, and like I suggested, I could use some math to make the shadows move psuedo-randomly.
    Although I'm new to XNA, I'm not new to C# programming and I must admit that XNA is far more easy to understand (I call it the learnrate) in comparison with the Java3D API.

    However I thought that RenderTargets could increase the time, since you don't render them to your screen but in memory only. I might have misunderstood that then, so I will drop that idea for now.

    I'll post my findings here soon.
    Anyway, thanks again for the time (and that wonderful refraction link )!

    Regards,

    Robert
  • 6/24/2009 5:45 PM In reply to

    Re: How to create a cloudshadoweffect in a 2D RTS game

    Thanks again Helmut,

    Your advice helped me alot. I figured out how it worked and it was even more simple as I thought (hence I would not have asked my queston). In fact I feel quite stupid :)

    Next is how to create sunbeams, I hope that is just as easy.

  • 6/26/2009 7:47 AM In reply to

    Re: How to create a cloudshadoweffect in a 2D RTS game

    Answer
    Reply Quote
    There is nothing stupid in learning :).

    Sunbeams, do you mean lens flare or god rays ?
    Lens flare wouldn't look quite natural with a RTS-like top-down view, since the sun would be in your back (no visible ligth source = no visible lens flare). God rays would be nice, you may simply have some cloud sprite with rays directly in the cloud graphics (don't know if you see what I mean) and then render random cloud, some with rays, some without.
    http://helmut.dev-blog.fr/
  • 6/27/2009 3:12 PM In reply to

    Re: How to create a cloudshadoweffect in a 2D RTS game

    Well I mean god-rays ;)

    However I tried to visualize your idea with a little help of photoshop, but I'm not that great in art work especially not in drawing rays...

    I managed to take a few screenshots from my current try-out RTS game to show you how I tricked my clouds.

    I use a rather big texture (2048x2048 pixels) which I render twice.
    First I render it with AlphaBlending enabled, centered on screen, and with a black color modulation (like you said).
    Second I render it again, however I use a small offset and I use a white color modulation (no tinting).

    The results are (like you also said) fairly easy to implement, judging from the screenshots screenshot 1 and screenshot 2.
    It would be nice to draw some rays down, but since the clouds are moving, the rays should fade in and out as well, as I will position the sun at a set coordinate.
    Perhaps later the sun can move, but not for now.

    What I really would like to do is that the shadow cast by clouds is of effect of our 'hero' which has a light aura. Since I only use
    spritebatches and no camara 2d engine of my own, I wonder if this can be done that easily. I'm not sure if I'm thinking about the same idea you had in mind.

    Anyway, I'm not yet out of thoughts, perhaps it would be better to convert it all to 3D, as I have the idea that lighting and stuff is a bit easier to do...



Page 1 of 1 (6 items) Previous Next