Crepuscular Rays with XNA

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
7,345
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Apr 26, 2009

I got several requests regarding my last light shaft video which I deleted because it was so crappy. What you see here is the application I am going to explain in my next tutorial on how to implement volumetric lighting aka crepuscular rays aka light shafts aka god rays.

The scene consists of three cascaded cogs I created with Cinema4D. The crepuscular ray shader is taken from GPU Gems III from the article by Mitchel. One BIG disadvantage of this approach is, that the light source has to be visible (in this case, placed right behind the cogs). There has been an interesting paper on Eurographics 2009 which avoids this problem by ray casting the shadow map.

The application is coded with Visual Studio 2008 and XNA Gamestudio 3.0. The rendering is done as follows:

1. Draw the background
2. Draw all objects in black over the background
3. Perform the crepuscular ray shader on that masked texture

Basically, you then additively render the original scene over the result, but I apply some additional filtering steps:

4. Extract luminance values greater than 1.0
5. Apply gaussian blur on high luminance values
6. Combine crepuscular rays, gaussian blur and colored cogs

Done. More details in my tutorial.
4.

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (starvald)

  • Thank you for this. You tutorial was very helpful. I did it(my fourth shader) from your explanations only, which was very clear to me.

    Though one question, I can get the lightposition in screen.

    ScreenLightPos.y is working but ScreenLightPos.x has no effect.

    And what is this for:

    float Len = length( DeltaTexCoord );

    I didn't see it in rest of the code.

    Thanks again.

  • you are right! the line of code you mentioned isn't required in the rest of the shader and can be removed. thank you for that hint.

    concerning the second problem: the 2d position of the light is found at the top of the game.cs:

    private Vector2 _LightMapPosition = new Vector2( 0.7f, 0.44f );

    I altered both values and it worked! did you change these parameters?

    nicolas

  • I fixed it sort of. I was doing this as a mod for an old game title 'Morrowind'(2001, but with a very much alive community).

    A utility lets us to write post-process shaders for it.

    Currently DoF, SSAO and godrays(thanks to you) are working. If anybody is interested visit Morrowind modding forums on Bethsoft.

    PS. Yeah, I love that game. :)

  • I am glad that I could help you. Best luck for modding your game and thanks for your interest in my shader!

see all

All Comments (6)

Sign In or Sign Up now to post a comment!
  • Nice work I'm gonna give this a shot

  • I am not using the c codes but only the hlsl part. I am very new to this.

    ScreenlightPos is the only thing I can alter for light position. I was assuming they were x,y coordinates on ranged between 0 and 1.

    In my tests I couldn't make it shine from top- right ever!

    It is confusing(vectors).

    PS. I have a sunvec vector which I want to bind to ScreenLightPos. (and an eyevec if helps.)

  • Yes, nice job, I am still yet to have a play with these,looks very cool, just hope I can run them on my hardware, should be fine on the 360 though :)

  • Hi starvald,

    Great job on the crepuscular ray. The old one is also impressive, not crappy like you said.

    I read in the description "More details in my tutorial", does this mean you gonna put up one about this at your homepage?

    Also, if you have time, please send me the update soure code of the XNA sun that has crepuscular ray. Thanks a lot and great job.

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more