summaryrefslogtreecommitdiff
path: root/earth.glsl
diff options
context:
space:
mode:
authorMathias Froehlich <Mathias.Froehlich@web.de>2012-02-11 12:07:19 +0100
committerMathias Froehlich <Mathias.Froehlich@web.de>2012-02-11 12:41:42 +0100
commit9a0b81e67419bab8402914bc3f30483d8cb89dfc (patch)
treeebcbc7deae61539c3b3fac144522f806f676f472 /earth.glsl
parent960e917686e4ef367d0ce4ae6b34338a3a9bea87 (diff)
cleanup ieeeHEADmaster
Diffstat (limited to 'earth.glsl')
-rw-r--r--earth.glsl50
1 files changed, 28 insertions, 22 deletions
diff --git a/earth.glsl b/earth.glsl
index 2b37122..908601d 100644
--- a/earth.glsl
+++ b/earth.glsl
@@ -64,13 +64,15 @@ vec3 inscatter(inout vec3 x, inout float t, vec3 v, vec3 s, out float r, out flo
vec3 result;
r = length(x);
mu = dot(x, v) / r;
- float d = -r * mu - ieeesqrt(r * r * (mu * mu - 1.0) + Rt * Rt);
- if (d > 0.0) { // if x in space and ray intersects atmosphere
+ if ((r * r * (mu * mu - 1.0) + Rt * Rt) >= 0.0) {
+ float d = -r * mu - sqrt(r * r * (mu * mu - 1.0) + Rt * Rt);
+ if (d > 0.0) { // if x in space and ray intersects atmosphere
// move x to nearest intersection of ray with top atmosphere boundary
x += d * v;
t -= d;
mu = (r * mu + d) / Rt;
r = Rt;
+ }
}
if (r <= Rt) { // if ray intersects atmosphere
float nu = dot(v, s);
@@ -96,19 +98,19 @@ vec3 inscatter(inout vec3 x, inout float t, vec3 v, vec3 s, out float r, out flo
#ifdef FIX
// avoids imprecision problems near horizon by interpolating between two points above and below horizon
const float EPS = 0.004;
- float muHoriz = -ieeesqrt(1.0 - (Rg / r) * (Rg / r));
+ float muHoriz = -sqrt(max(0.0, 1.0 - (Rg / r) * (Rg / r)));
if (abs(mu - muHoriz) < EPS) {
float a = ((mu - muHoriz) + EPS) / (2.0 * EPS);
mu = muHoriz - EPS;
- r0 = ieeesqrt(r * r + t * t + 2.0 * r * t * mu);
+ r0 = sqrt(r * r + t * t + 2.0 * r * t * mu);
mu0 = (r * mu + t) / r0;
vec4 inScatter0 = texture4D(inscatterSampler, r, mu, muS, nu);
vec4 inScatter1 = texture4D(inscatterSampler, r0, mu0, muS0, nu);
vec4 inScatterA = max(inScatter0 - attenuation.rgbr * inScatter1, 0.0);
mu = muHoriz + EPS;
- r0 = ieeesqrt(r * r + t * t + 2.0 * r * t * mu);
+ r0 = sqrt(r * r + t * t + 2.0 * r * t * mu);
mu0 = (r * mu + t) / r0;
inScatter0 = texture4D(inscatterSampler, r, mu, muS, nu);
inScatter1 = texture4D(inscatterSampler, r0, mu0, muS0, nu);
@@ -159,8 +161,8 @@ vec3 groundColor(vec3 x, float t, vec3 v, vec3 s, float r, float mu, vec3 attenu
// water specular color due to sunLight
if (reflectance.w > 0.0) {
vec3 h = normalize(s - v);
- float fresnel = 0.02 + 0.98 * ieeepow(1.0 - dot(-v, h), 5.0);
- float waterBrdf = fresnel * ieeepow(max(dot(h, n), 0.0), 150.0);
+ float fresnel = 0.02 + 0.98 * pow(1.0 - dot(-v, h), 5.0);
+ float waterBrdf = fresnel * pow(max(dot(h, n), 0.0), 150.0);
groundColor += reflectance.w * max(waterBrdf, 0.0) * sunLight * ISun;
}
@@ -184,9 +186,9 @@ vec3 sunColor(vec3 x, float t, vec3 v, vec3 s, float r, float mu) {
vec3 HDR(vec3 L) {
L = L * exposure;
- L.r = L.r < 1.413 ? ieeepow(L.r * 0.38317, 1.0 / 2.2) : 1.0 - exp(-L.r);
- L.g = L.g < 1.413 ? ieeepow(L.g * 0.38317, 1.0 / 2.2) : 1.0 - exp(-L.g);
- L.b = L.b < 1.413 ? ieeepow(L.b * 0.38317, 1.0 / 2.2) : 1.0 - exp(-L.b);
+ L.r = L.r < 1.413 ? pow(L.r * 0.38317, 1.0 / 2.2) : 1.0 - exp(-L.r);
+ L.g = L.g < 1.413 ? pow(L.g * 0.38317, 1.0 / 2.2) : 1.0 - exp(-L.g);
+ L.b = L.b < 1.413 ? pow(L.b * 0.38317, 1.0 / 2.2) : 1.0 - exp(-L.b);
return L;
}
@@ -196,21 +198,25 @@ void main() {
float r = length(x);
float mu = dot(x, v) / r;
- float t = -r * mu - ieeesqrt(r * r * (mu * mu - 1.0) + Rg * Rg);
-
- vec3 g = x - vec3(0.0, 0.0, Rg + 10.0);
- float a = v.x * v.x + v.y * v.y - v.z * v.z;
- float b = 2.0 * (g.x * v.x + g.y * v.y - g.z * v.z);
- float c = g.x * g.x + g.y * g.y - g.z * g.z;
- float d = -(b + ieeesqrt(b * b - 4.0 * a * c)) / (2.0 * a);
- bool cone = d > 0.0 && abs(x.z + d * v.z - Rg) <= 10.0;
-
- if (t > 0.0) {
+ float t = -r * mu - sqrt(r * r * (mu * mu - 1.0) + Rg * Rg);
+
+ if ((r * r * (mu * mu - 1.0) + Rg * Rg) >= 0.0) {
+ vec3 g = x - vec3(0.0, 0.0, Rg + 10.0);
+ float a = v.x * v.x + v.y * v.y - v.z * v.z;
+ float b = 2.0 * (g.x * v.x + g.y * v.y - g.z * v.z);
+ float c = g.x * g.x + g.y * g.y - g.z * g.z;
+ float d = -(b + ieeesqrt(b * b - 4.0 * a * c)) / (2.0 * a);
+ bool cone = d > 0.0 && abs(x.z + d * v.z - Rg) <= 10.0;
+
+ if (t > 0.0) {
if (cone && d < t) {
- t = d;
+ t = d;
}
- } else if (cone) {
+ } else if (cone) {
t = d;
+ }
+ } else {
+ t = 0.0;
}
vec3 attenuation;