Commit fd666247 authored by Dario Seyb's avatar Dario Seyb

fixed skybox leaking through planet

parent b4fe425c
#pragma import "CommonTransparentFrag.glsl"
#pragma import "noise/noise3d.glsl"
uniform vec3 uObjectPosition;
uniform vec3 uSunDir;
......@@ -24,30 +24,58 @@ vec3 intersectSphere(vec3 o, vec3 l, vec3 c, float r) {
return o + l * max(0, min(a + dsqrt, a - dsqrt));
}
float pow8(float val) {
val = val * val;
val *= val;
val *= val;
return val;
}
vec4 color() {
float depth = texture(uSamplerDepth, gl_FragCoord.xy*uOneOverScreenSize ).r;
float atmosphereRadius = length(tePosition - uObjectPosition);
float planetRadius = 6374.1305775862702;
float atmosphereRadius = planetRadius * 1.025;
vec3 camSpaceWorldPos = unpackWorldPosition(depth) - uCameraPosition;
vec3 viewDir = normalize(tePosition - uCameraPosition);
vec3 camSpaceAtmospherePos = intersectSphere(uCameraPosition, viewDir, uObjectPosition, atmosphereRadius) - uCameraPosition;
if(camSpaceAtmospherePos == -uCameraPosition) discard;
vec3 worldPos = camSpaceWorldPos - uObjectPosition + uCameraPosition;
float planetRadius = length(worldPos);
float atmosphereThickness = atmosphereRadius - planetRadius;
vec3 atmospherePos = camSpaceAtmospherePos - uObjectPosition;
float distance = depth == 1 ? 1000000000.0f : abs(length(camSpaceWorldPos) - length(camSpaceAtmospherePos));
distance = min(distance, length(camSpaceAtmospherePos - tePosition + uCameraPosition));
float fogAmount = 1.0 - exp( -distance*4.0/atmosphereRadius );
vec3 currentPos = camSpaceAtmospherePos;
float totalDistance = depth == 1 ? 1000000000.0f : abs(length(camSpaceWorldPos) - length(camSpaceAtmospherePos));
totalDistance = min(totalDistance, length(camSpaceAtmospherePos - tePosition + uCameraPosition));
int steps = 10;
float sunAmount = max( dot( viewDir, uSunDir ), 0.0 );
vec3 fogColor = mix( vec3(0.5,0.6,0.9), // bluish
vec3(1.0,0.9,0.7), // yellowish
pow(sunAmount,8.0) );
float distance = totalDistance/steps;
float totalFog = 0;
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 = abs((fbm_3d( localPos, 4, 0.00005) * 300 - fbm_3d( localPos, 1, 0.002) * 100))* abs((h - 0.5) * (h-0.5)) * (1.0-h);
float atm = 20 * (1-h) * (1-h)* (1-h);
float density = ( atm + cloud)/atmosphereRadius;
totalFog += density * distance;
}
float fogAmount = 1.0 - exp(-totalFog);
vec3 fogColor = mix( vec3(0.2,0.3,0.9), // bluish
vec3(1.0,0.9,0.7) * 1.2, // yellowish
pow8(sunAmount) );
return vec4(fogColor, fogAmount); //texture(uTexture, teTexCoord).rgba * uTintColor;
}
......@@ -58,4 +86,4 @@ vec4 emissive() {
vec3 normal() {
return teNormal;
}
}
\ No newline at end of file
......@@ -102,5 +102,5 @@ void main()
float lightNdotL = max(0, dot(lightDir, normal));
vec4 lighting = BRDF (albedo.rgb, specularSmoothness.rgb, oneMinusReflectivity, specularSmoothness.a, normal, viewDir, lightDir, lightNdotL, uLightColor.rgb * uLightColor.a);
oColor = vec4(lighting.rgb + emissive.rgb, albedo.a * uOneOverLightCount);
oColor = vec4(lighting.rgb + emissive.rgb, uOneOverLightCount);
}
......@@ -9,4 +9,5 @@ out vec4 oColor;
void main()
{
oColor = texture(uSamplerColor, vTexCoord);
oColor.a = min(1, max(0, oColor.a));
}
......@@ -4,7 +4,9 @@
#pragma import "Utils.glsl"
vec4 color() {
return texture(uTexture, teTexCoord).rgba * uTintColor;
vec4 color = texture(uTexture, teTexCoord).rgba * uTintColor;
color.a = 1;
return color;
}
vec4 emissive() {
......
......@@ -24,10 +24,10 @@ vec4 color() {
vec4 color = texture_getColor(gPosInModelspace, gUpVector_normalized, approxNormal);
float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z);
/*float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z);
float d2 = min(min(gPatchDistance.x, gPatchDistance.y), gPatchDistance.z);
color = amplify(d1, 80, -0.5) * amplify(d2, 120, -0.5) * color;
color.w = 1.0;
color = amplify(d1, 80, -0.5) * amplify(d2, 120, -0.5) * color;*/
color.a = 1.0;
return color;
}
......@@ -40,5 +40,5 @@ vec3 normal() {
}
vec4 specularSmoothness() {
return vec4(0.2, 0.2, 0.2, 0.5);
return vec4(0.2, 0.2, 0.2, 0.1);
}
......@@ -497,7 +497,8 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
// Transparent rendering
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glCullFace(GL_FRONT);
for (size_t i = 0; i < pass.submittedDrawCallsTransparent.size(); i++) {
auto& drawCall = pass.submittedDrawCallsTransparent[i];
......
......@@ -105,7 +105,7 @@ bool OrbitalSimulationSystem::startup() {
RenderQueue::OPAQUE,
GL_BACK };
atmosphereMat = {glm::vec4(0, 0, 1, 0.9f),
atmosphereMat = {glm::vec4(0, 0, 1, 1.0),
glm::vec4(0, 0, .2, 1),
texture,
nullptr,
......@@ -214,6 +214,7 @@ Entity OrbitalSimulationSystem::addPlanet(Transform::Handle sun, std::string n,
glm::dvec3 pos = applyKepler(planetComponent, 0);
pos = glm::dvec3(AUToWorld(pos.x), AUToWorld(pos.y), AUToWorld(pos.z));
planetTransform->scale = glm::dvec3(solarToWorld(r), solarToWorld(r), solarToWorld(r));
planetTransform->position = pos;
......@@ -224,7 +225,7 @@ Entity OrbitalSimulationSystem::addPlanet(Transform::Handle sun, std::string n,
auto atmosphereTransform = atmosphere.assign<Transform>();
atmosphereTransform->parent = planetTransform;
atmosphere.assign<Drawable>(defaultGeom, atmosphereMat, 0, m_renderer->getRenderPassId("Main"_sh));
atmosphereTransform->scale = planetTransform->scale * 1.05;
atmosphereTransform->scale = planetTransform->scale * 1.025;
// Add simple water as well
auto water = m_scene->create();
......
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