55 ScaleOverScaleDepth = Scale / ScaleDepth;
142 return uScaleDepth *
Ogre::Math::Exp(-0.00287 +
x*(0.459 +
x*(3.83 +
x*(-6.80 +
x*5.25))));
155 ScaleOverScaleDepth = Scale / ScaleDepth,
164 v3Pos = Direction.normalisedCopy(),
166 uInvWaveLength = Ogre::Vector3(
173 Ogre::Vector3 v3Ray = v3Pos - uCameraPos;
174 double fFar = v3Ray.length();
178 Ogre::Vector3 v3Start = uCameraPos;
179 double fHeight = uCameraPos.y,
180 fStartAngle = v3Ray.dotProduct(v3Start) / fHeight,
182 fStartOffset = fDepth *
_scale(fStartAngle, ScaleDepth);
186 fScaledLength = fSampleLength * Scale,
187 fHeight_, fDepth_, fLightAngle, fCameraAngle, fScatter;
188 Ogre::Vector3 v3SampleRay = v3Ray * fSampleLength,
189 v3SamplePoint = v3Start + v3SampleRay * 0.5f,
190 color = Ogre::Vector3(0,0,0), v3Attenuate;
195 fHeight_ = v3SamplePoint.length();
198 fLightAngle = uLightDir.dotProduct(v3SamplePoint) / fHeight_;
199 fCameraAngle = v3Ray.dotProduct(v3SamplePoint) / fHeight_;
201 fScatter = (fStartOffset + fDepth*(
_scale(fLightAngle, ScaleDepth) -
_scale(fCameraAngle, ScaleDepth)));
203 v3Attenuate = Ogre::Vector3(
209 v3Attenuate *= (fDepth_ * fScaledLength);
210 color += v3Attenuate;
213 v3SamplePoint += v3SampleRay;
217 Ogre::Vector3 oRayleighColor = color * (uInvWaveLength * KrESun),
218 oMieColor = color * KmESun,
219 oDirection = uCameraPos - v3Pos;
224 double cos = uLightDir.dotProduct(oDirection) / oDirection.length(),
226 rayleighPhase = 0.75 * (1.0 + 0.5*cos2),
228 miePhase = 1.5f * ((1.0f - g2) / (2.0f + g2)) *
229 (1.0f + cos2) / Ogre::Math::Pow(1.0f + g2 - 2.0f *
mOptions.
G * cos, 1.5f);
231 Ogre::Vector3 oColor;
235 oColor = Ogre::Vector3(
241 oColor += Ogre::Math::Clamp<Ogre::Real>(((1 - std::max(oColor.x, std::max(oColor.y, oColor.z))*10)), 0, 1)
242 * (Ogre::Vector3(0.05, 0.05, 0.1)
243 * (2-0.75f*Ogre::Math::Clamp<Ogre::Real>(-uLightDir.y, 0, 1)) * Ogre::Math::Pow(1-Direction.y, 3));
247 oColor =
mOptions.
Exposure * (rayleighPhase * oRayleighColor + miePhase * oMieColor);
249 Ogre::Real nightmult = Ogre::Math::Clamp<Ogre::Real>(((1 - std::max(oColor.x, std::max(oColor.y, oColor.z))*10)), 0, 1);
252 Ogre::Vector3 nightCol = Ogre::Vector3(0.05, 0.05, 0.1) * (2-0.75f*Ogre::Math::Clamp<Ogre::Real>(-uLightDir.y, 0, 1)) * Ogre::Math::Pow(1-Direction.y, 3);
253 nightCol.x = Ogre::Math::Pow(nightCol.x, 2.2);
254 nightCol.y = Ogre::Math::Pow(nightCol.y, 2.2);
255 nightCol.z = Ogre::Math::Pow(nightCol.z, 2.2);
257 oColor += nightmult*nightCol;