/* -------------------------------------------------------------------------------- This source file is part of SkyX. Visit http://www.paradise-studios.net/products/skyx/ Copyright (C) 2009-2012 Xavier Verguín González This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt. -------------------------------------------------------------------------------- */ #ifdef GL_ES precision highp int; precision highp float; #endif // --------------------- SkyX skydome material ------------------------ // ------------------------ GLSL Fragment ----------------------------- #define USE_OGRE_FROM_FUTURE #include SAMPLER2D(uStarfield, 0); OGRE_UNIFORMS( uniform float uTime; uniform vec3 uLightDir; uniform float uG; uniform float uG2; uniform float uExposure; ) MAIN_PARAMETERS IN(vec2 vUV, TEXCOORD0) IN(vec3 vRayleighColor, TEXCOORD1) IN(vec3 vMieColor, TEXCOORD2) IN(vec3 vDirection, TEXCOORD3) IN(float vOpacity, TEXCOORD4) IN(float vHeight, TEXCOORD5) MAIN_DECLARATION { float cos = dot(uLightDir, vDirection) / length(vDirection); float cos2 = cos * cos; float rayleighPhase = 0.75 * (1.0 + 0.5 * cos2); float miePhase = 1.5 * ((1.0 - uG2) / (2.0 + uG2)) * (1.0 + cos2) / pow(1.0 + uG2 - 2.0 * uG * cos, 1.5); #ifdef LDR gl_FragColor = vec4((vec3_splat(1.0) - exp(vec3_splat(-uExposure) * (vec3_splat(rayleighPhase) * vRayleighColor + vec3_splat(miePhase) * vMieColor))), vOpacity); #else // HDR gl_FragColor = vec4(vec3_splat(uExposure) * (vec3_splat(rayleighPhase) * vRayleighColor + vec3_splat(miePhase) * vMieColor), vOpacity); #endif // LDR // For night rendering float nightmult = saturate(1.0 - max(gl_FragColor.x, max(gl_FragColor.y, gl_FragColor.z)) * 10.0); #ifdef STARFIELD #ifdef LDR gl_FragColor.xyz += vec3_splat(nightmult) * (vec3(0.05, 0.05, 0.1) * vec3_splat(2.0 - 0.75 * saturate(-uLightDir.y)) * vec3_splat(pow(vHeight,3.0)) + texture2D(uStarfield, vUV + vec2_splat(uTime)).xyz * vec3_splat(0.35 + saturate(-uLightDir.y * 0.45))); #else // HDR (Linear pipeline -> Gamma correction) gl_FragColor.xyz += vec3_splat(nightmult) * (vec3(0.05, 0.05, 0.1) * vec3_splat(2.0 - 0.75 * saturate(-uLightDir.y)) * vec3_splat(pow(vHeight,3.0)) + texture2D(uStarfield, vUV + vec2_splat(uTime)).xyz * vec3_splat(0.35 + saturate(-uLightDir.y * 0.45))); #endif // LDR #else // NO STARFIELD #ifdef LDR gl_FragColor.xyz += vec3_splat(nightmult) * (vec3(0.05, 0.05, 0.1) * vec3_splat(2.0 - 0.75 * saturate(-uLightDir.y)) * vec3_splat(pow(vHeight, 3.0))); #else // HDR (Linear pipeline -> Gamma correction) gl_FragColor.xyz += vec3_splat(nightmult) * (vec3(0.05, 0.05, 0.1) * vec3_splat(2.0 - 0.75 * saturate(-uLightDir.y)) * vec3_splat(pow(vHeight, 3.0))); #endif // LDR #endif // STARFIELD }