opengl: Added missing irradiance from sky

This commit is contained in:
Michaël Lemaire 2015-12-18 00:59:50 +01:00
parent 351a58f69b
commit 366ac4a6c9
2 changed files with 16 additions and 0 deletions

View file

@ -68,6 +68,7 @@ void OpenGLSkybox::update() {
(SoftwareBrunetonAtmosphereRenderer *)renderer->getAtmosphereRenderer(); (SoftwareBrunetonAtmosphereRenderer *)renderer->getAtmosphereRenderer();
renderer->getSharedState()->set("transmittanceTexture", bruneton->getModel()->getTextureTransmittance()); renderer->getSharedState()->set("transmittanceTexture", bruneton->getModel()->getTextureTransmittance());
renderer->getSharedState()->set("inscatterTexture", bruneton->getModel()->getTextureInscatter()); renderer->getSharedState()->set("inscatterTexture", bruneton->getModel()->getTextureInscatter());
renderer->getSharedState()->set("irradianceTexture", bruneton->getModel()->getTextureIrradiance());
} }
void OpenGLSkybox::render() { void OpenGLSkybox::render() {

View file

@ -32,6 +32,7 @@ uniform float sunRadius;
in vec3 unprojected; in vec3 unprojected;
uniform sampler2D transmittanceTexture; uniform sampler2D transmittanceTexture;
uniform sampler2D irradianceTexture;
uniform sampler3D inscatterTexture; uniform sampler3D inscatterTexture;
vec4 texture4D(sampler3D tex, float r, float mu, float muS, float nu) 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) */ 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) { float phaseFunctionR(float mu) {
return (3.0 / (16.0 * M_PI)) * (1.0 + mu * 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; return result;
} }