Skip to content

Commit

Permalink
Move phase to function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-Pain committed Jan 11, 2024
1 parent 15d5b6a commit 604e4d9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions data/shaders/opengl/planetrings.frag
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ in vec4 varyingEyepos;

out vec4 frag_color;

float phaseFunction(const float g, const float mu)
{
/*
* Use Mie phase function:
* https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/simulating-sky/simulating-colors-of-the-sky.html
*/
return 3.f / (8.f * 3.141592) * ((1.f - g * g) * (1.f + mu * mu)) / ((2.f + g * g) * pow(1.f + g * g - 2.f * g * mu, 1.5f));
}

void main(void)
{
// Bits of ring in shadow!
Expand All @@ -28,11 +37,11 @@ void main(void)

// second term: diffuse mie (scattering through ring)
float g = 0.76f;
float phaseThrough = 3.f / (8.f * 3.141592) * ((1.f - g * g) * (1.f + mu * mu)) / ((2.f + g * g) * pow(1.f + g * g - 2.f * g * mu, 1.5f));
float phaseThrough = phaseFunction(g, mu);

// third term: reflect mie (imitate albedo >= 1.0)
float muRev = dot(-normalize(vec3(uLight[i].position)), eyenorm);
float phaseReflect = 3.f / (8.f * 3.141592) * ((1.f - g * g) * (1.f + muRev * muRev)) / ((2.f + g * g) * pow(1.f + g * g - 2.f * g * muRev, 1.5f));
float phaseReflect = phaseFunction(g, muRev);

col = col + texCol * (diffuse + phaseThrough + phaseReflect) * uLight[i].diffuse;
}
Expand Down

0 comments on commit 604e4d9

Please sign in to comment.