Home Technical Talk

Shader - Simple Atmospheric Scattering - Any Helpsies?

polycounter lvl 12
Offline / Send Message
Ace-Angel polycounter lvl 12
Heya to all you stallion peeps of PC,

Question, does any one know where I could find the code (or maybe some tips) about creating an Atmospheric Scatter shader which isn't accurate, but emulates the simplicity of the said formula in a much more manageable format?

For example, I would like it so when the sun rises, the sky color 'hue rotates' from a black to orange, to Blue, in theory this is all easy to implement with some Rotators, clamping, increase in brightness and etc, but for the life of me, I cannot find 'hints' on how I could use the Light Vector to calculate this.

Also, bonus question, is there a way to create a 'zenith' spread from my Light vector?

Software I'm using are UDK and Max, and both of them are having issues with the 'real' atmos-scatter, (as in they show me a glow orb of light) which is why I'm looking for a 'lite' solution.

Cheers all the handsome peeps, and ciao!

EDIT: Almost forgot, if you peeps know of any communities that might better help my endevour, please do direct me to them.

Replies

  • Brice Vandemoortele
    Offline / Send Message
    Brice Vandemoortele polycounter lvl 19
    If we're talking 'color of the sky dome', using a texture look-up is one way to go. You could 'paint' it, or use a more elaborate (computationally intensive) solution to bake it.
    Being usually 2-dimensional, textures are limited since you're very likely to use one dimension for time (say, the width of the 2D texture). So this leaves you with just one dimension (height) to map to whatever you might choose: nadir to zenith, or sun-facing to shadow, etc. If you want to map more dimension you could use a 3D texture, or more easily; do two or more samples and blend/add them in some way.
    There's a bunch of papers available freely on the subject but I don't know how math-savvy you are or what style you're aiming for.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Yep, that's the idea, skydome kinda deal.

    Well, I read the papers which have the HLSL code in them, the only problem is all of them have for a lack of better terms, alot of extra math which I don't need.

    As you said, alot of the blending can be done easily from with a texture (or in some cases, using your Texture Coordinates as your mask if you want to go proc.) which makes it light, but the issues I'm having is I'm unable to figure out the core parts of the math behind it (the part where the light vector, pending on position, will change the colors automatically).

    An example of what I mean in Lambert terms is if I have a Lerp with my Light Vector being the Alpha mask, I can tell my Lambert what the color of the direct hit can be and the backscatter be.

    As for if I'm math savvy, a little, but I'm much better at HLSL read-up.
  • LoTekK
    Offline / Send Message
    LoTekK polycounter lvl 17
    the issues I'm having is I'm unable to figure out the core parts of the math behind it (the part where the light vector, pending on position, will change the colors automatically).
    Are you doing this for a space-perspective planet shader? Or a planetary surface-level effect? From the wording of your first post, I'd guess at surface-level.

    In which case, for something simple that you're going for, I'd imagine dotting the light vector against the horizon vector would be the bulk of it? The horizon vector would, I suppose, be some arbitrary angle from the camera/player's viewpoint to account for planetary curve; and if you've got a flat world, then your horizon vector would be flat (offhand maybe normalize((lightpos - playerpos) * vector3(1,0,1)) assuming y-up.

    That way your normalized (0-1) dot product could be your lookup.

    atmo.jpg

    Might be oversimplifying, mind. Just some initial thoughts. I might have a play with this myself tonight, if I can find a bit of time.
  • Farfarer
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    LoTekK wrote: »
    Are you doing this for a space-perspective planet shader? Or a planetary surface-level effect? From the wording of your first post, I'd guess at surface-level.

    In which case, for something simple that you're going for, I'd imagine dotting the light vector against the horizon vector would be the bulk of it? The horizon vector would, I suppose, be some arbitrary angle from the camera/player's viewpoint to account for planetary curve; and if you've got a flat world, then your horizon vector would be flat (offhand maybe normalize((lightpos - playerpos) * vector3(1,0,1)) assuming y-up.

    That way your normalized (0-1) dot product could be your lookup.

    atmo.jpg

    Might be oversimplifying, mind. Just some initial thoughts. I might have a play with this myself tonight, if I can find a bit of time.

    Oh, very nice, that's makes sense, although if I may ask, are the two scattering effects different in this part of the math, or about the same?

    I figured if I could get an answer about the Skydome from Surface level, the Planet level would be easy enough to reverse, or is there more?

    Cheers anyhow for the write-down, will take a look ASAP.
    Talon wrote: »

    That's the issue, almost everything I did, I used the GPU Gems math/HLSL and most other sites followed this one too, but for some reason, my entire Dome lights up like a fireball.
Sign In or Register to comment.