Commit 94c46d3b authored by Dario Seyb's avatar Dario Seyb

some atmosphere fixes

parent eab912f1
......@@ -192,7 +192,7 @@ vec4 color() {
vec3 viewDir = normalize(vPosition - uCameraPosition);
float planetRadius = uEmissiveColor.r; //6360;
float atmosphereRadius = uEmissiveColor.g; //6778;
float atmosphereRadius = uEmissiveColor.g * 1.0115; //6778;
vec3 camSpaceWorldPos = depth != 1 ?
unpackWorldPosition(depth) - uCameraPosition :
......@@ -200,7 +200,7 @@ vec4 color() {
Rg = planetRadius;
Rt = atmosphereRadius;
vec3 worldPos = camSpaceWorldPos - uObjectPosition + uCameraPosition;
vec3 worldPos = camSpaceWorldPos - uObjectPosition + uCameraPosition;
vec3 camSpaceAtmospherePos = intersectSphere(uCameraPosition, viewDir, uObjectPosition, atmosphereRadius) - uCameraPosition;
......@@ -229,77 +229,52 @@ vec4 color() {
float shadowTerm = 0;
if(uHasAlbedoMap) {
vec3 localPos = currentPos - uObjectPosition + uCameraPosition;
vec3 localPos = currentPos - uObjectPosition + uCameraPosition;
vec3 x = localPos;
vec3 v = normalize(viewDir);
vec3 x = localPos;
vec3 v = normalize(viewDir);
float r = length(x);
if(r < Rg) {
localPos = localPos * Rg/r;
r = Rg;
}
float mu = dot(x, v) / r;
float t = length(localPos - worldPos);
//return vec4(t/planetRadius);
float r = length(x);
if(r < Rg) {
localPos = localPos * Rg/r;
r = Rg;
}
//t = -r * mu - sqrt(r * r * (mu * mu - 1.0) + planetRadius * planetRadius);
vec3 g = x - vec3(0.0, 0.0, planetRadius + 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 + sqrt(b * b - 4.0 * a * c)) / (2.0 * a);
bool cone = d > 0.0 && abs(x.z + d * v.z - planetRadius) <= 10.0;
if (t > 0.0) {
if (cone && d < t) {
t = d;
}
} else if (cone) {
t = d;
}
vec3 attenuation = vec3(1.0);
vec3 s = uSunDir;
fogColor = max(vec3(0.0), inscatter(x, worldPos, t, v, s, r, mu, attenuation));
vec3 backgroundColor = texture(uSamplerColor, screenTexCoord).rgb;
fogColor += max(vec3(0.0), attenuation * backgroundColor);
fogAmount = 1.0;
} else {
vec3 Iv = vec3(0);
vec3 Is = vec3(1.0,0.9,0.7);
for(int i = 0; i < steps; i++) {
currentPos += viewDir * distance;
vec3 localPos = currentPos - uObjectPosition + uCameraPosition;
float currentHeight = length(localPos) - planetRadius;
float h = currentHeight/atmosphereThickness;
float cloud = 0; //max(fbm_3d( localPos, 6, 0.0003) + 0.05, 0) * 1000 * (pow8(1-h));
cloud = h > 0.75 ? 0 : cloud;
float atm = 20 * exp(-h/0.25);
float density = ( atm + cloud)/atmosphereRadius;
shadowTerm += getDistance(localPos, uSunDir, planetRadius).x > 0 ? 0 : 1;
totalFog += density * distance;
}
shadowTerm /= steps;
fogAmount = 1.0 - exp(-totalFog);
float mu = dot(x, v) / r;
float t = length(localPos - worldPos);
fogColor = mix( vec3(0.3,0.4,0.9), // bluish
vec3(1.0,0.9,0.7) * 1.2 , // yellowish
pow8(sunAmount* shadowTerm) );
//return vec4(t/planetRadius);
//t = -r * mu - sqrt(r * r * (mu * mu - 1.0) + planetRadius * planetRadius);
vec3 g = x - vec3(0.0, 0.0, planetRadius + 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 + sqrt(b * b - 4.0 * a * c)) / (2.0 * a);
bool cone = d > 0.0 && abs(x.z + d * v.z - planetRadius) <= 10.0;
if (t > 0.0) {
if (cone && d < t) {
t = d;
}
} else if (cone) {
t = d;
}
vec3 attenuation = vec3(1.0);
vec3 s = uSunDir;
fogColor = max(vec3(0.0), inscatter(x, worldPos, t, v, s, r, mu, attenuation));
vec3 backgroundColor = texture(uSamplerColor, screenTexCoord).rgb;
fogColor += max(vec3(0.0), attenuation * backgroundColor);
fogAmount = 1.0;
return vec4(fogColor, fogAmount); //texture(uTexture, teTexCoord).rgba * uTintColor;
}
......
......@@ -632,7 +632,7 @@ Entity OrbitalSimulationSystem::addPlanet(Transform::Handle sun, std::string n,
if (hasAtmosphere) {
atmosphereMat.mainTexture = transmittance;
atmosphereMat.specularSmoothnessTexture = inscattering;
atmosphereMat.emissiveColor = { Rg - 10, Rt + 120, 0, 0 };
atmosphereMat.emissiveColor = { Rg, Rt, 0, 0 };
auto atmosphere = m_scene->create();
auto atmosphereTransform = atmosphere.assign<Transform>();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment