Thread: Rayleigh scattering shader

  1. #16
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Hmm, makes sense. I calculate the angle as a dot product of the view and light vectors:

    Code:
    vec4 wPos = mWorld*gl_Vertex; //world matrix * "in" vertex position
    vec3 lPos = vec3(0.0, 10000.0, 5000.0);
    
    vec3 V = normalize(wPos.xyz - eyePosition);
    vec3 L = normalize(lPos - eyePosition);
    
    float theta = dot(L, V);
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  2. #17
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    But that is not what the formula needs. You are only calculating the cosine of the angle not the actual angle. The formula, according to what I see, needs the actual angle - IE: the arccosine(dot(L,V))

    Note that for:

    cos(theta) and cos^2(theta) you can do:

    dot(L,V) and dot(L,V) * dot(L,V) respectively.

  3. #18
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Sorry for the slow replying. I'm running out of free time these days (I'm done working weekends now though...hopefully that'll give me a bit more play time ).

    I tried:
    Code:
    float theta = dot(L, V);
    float acosTheta = acos(theta);
    float acosTheta2 = acosTheta*acosTheta;
    Using acosTheta in place of theta in the formulas, the the overall result is the same - no colour changes (using acos did require me to remove the coefficient multipliers, as with them the sky was too dark).

    There's something here somewhere, that I'm (frustratingly) just not getting. Mathematically, everything looks like it should do what it's supposed to.

    Could it be affected by sky sphere tessellation? Not likely, but it's just a thought.
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  4. #19
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    No idea- this is actually the part of the formula I had trouble with as well. Regardless of the sun position I could not get sunset skies without significantly altering mie and rayleigh along with the sun position. It was almost as if Rayleigh and Mie were different during the day as opposed to sunset which is not how I understood the system according to the GDC document. If Rayleigh and Mie change over time then how do they change and based on what mathematical formula? If Rayleigh and Mie can stay constant then why do we not see the orange and reds like the demo shows?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shaders and parameters
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 12-06-2006, 07:33 AM
  2. Sky scattering shader
    By VirtualAce in forum Game Programming
    Replies: 9
    Last Post: 08-24-2006, 12:51 PM
  3. Shader hell
    By VirtualAce in forum Game Programming
    Replies: 4
    Last Post: 08-18-2006, 09:21 PM
  4. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  5. Replies: 6
    Last Post: 11-12-2005, 11:57 AM