diff --git a/src/render/opengl/OpenGLSkybox.cpp b/src/render/opengl/OpenGLSkybox.cpp index d9bd0f1..674a325 100644 --- a/src/render/opengl/OpenGLSkybox.cpp +++ b/src/render/opengl/OpenGLSkybox.cpp @@ -68,6 +68,7 @@ void OpenGLSkybox::update() { (SoftwareBrunetonAtmosphereRenderer *)renderer->getAtmosphereRenderer(); renderer->getSharedState()->set("transmittanceTexture", bruneton->getModel()->getTextureTransmittance()); renderer->getSharedState()->set("inscatterTexture", bruneton->getModel()->getTextureInscatter()); + renderer->getSharedState()->set("irradianceTexture", bruneton->getModel()->getTextureIrradiance()); } void OpenGLSkybox::render() { diff --git a/src/render/opengl/shaders/atmosphere.frag b/src/render/opengl/shaders/atmosphere.frag index 18ab5d8..c0f6ff6 100644 --- a/src/render/opengl/shaders/atmosphere.frag +++ b/src/render/opengl/shaders/atmosphere.frag @@ -32,6 +32,7 @@ uniform float sunRadius; in vec3 unprojected; uniform sampler2D transmittanceTexture; +uniform sampler2D irradianceTexture; uniform sampler3D inscatterTexture; vec4 texture4D(sampler3D tex, float r, float mu, float muS, float nu) @@ -98,6 +99,17 @@ vec4 _sunTransmittance(vec3 v, vec3 s, float r, float mu, float radius) return transmittance; /* Eq (9) */ } +void _getIrradianceUV(float r, float muS, out float uMuS, out float uR) { + uR = (r - Rg) / (Rt - Rg); + uMuS = (muS + 0.2) / (1.0 + 0.2); +} + +vec4 _irradiance(float r, float muS) { + float u, v; + _getIrradianceUV(r, muS, u, v); + return texture(irradianceTexture, vec2(u, v)); +} + float phaseFunctionR(float mu) { return (3.0 / (16.0 * M_PI)) * (1.0 + mu * mu); } @@ -328,5 +340,8 @@ vec4 applyLighting(vec3 location, vec3 normal, vec4 color, float reflection, flo } } + /* global irradiance from sky */ + result += dot(vec3(0.0, -1.0, 0.0), normal) * _irradiance(r0, muS); + return result; }