Commit 18207b30 authored by Dario Seyb's avatar Dario Seyb

drawing atmosphere for all planets

parent 71a08394
......@@ -191,8 +191,9 @@ vec4 color() {
float depth = texture(uSamplerDepth, screenTexCoord).r;
vec3 viewDir = normalize(vPosition - uCameraPosition);
float planetRadius = 6360;
float atmosphereRadius = 6778;
float planetRadius = uEmissiveColor.r; //6360;
float atmosphereRadius = uEmissiveColor.g; //6778;
vec3 camSpaceWorldPos = depth != 1 ?
unpackWorldPosition(depth) - uCameraPosition :
intersectSphereMax(uCameraPosition, viewDir, uObjectPosition, atmosphereRadius) - uCameraPosition;
......
#version 410 core
#pragma import "Utils.glsl"
uniform bool uHasAlbedoMap;
uniform sampler2D uTexture;
......
......@@ -4,7 +4,6 @@
vec3 unpackNormal(vec4 normalMotion) {
vec2 ang = normalMotion.xy;
vec2 scth = vec2(sin(ang.x * M_PI), cos(ang.x * M_PI));
//sincos(ang.x * M_PI, scth.x, scth.y);
vec2 scphi = vec2(sqrt(1.0 - ang.y*ang.y), ang.y);
return vec3(scth.y*scphi.x, scth.x*scphi.x, scphi.y);
}
\ No newline at end of file
......@@ -564,7 +564,6 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // create 2 triangles (defined in shader) with no attributes
#if 1
// Transparent rendering
//glBlendFuncSeparate(GL_ONE, GL_ONE, GL_SRC_ALPHA, GL_ONE);
glCullFace(GL_FRONT);
......@@ -616,7 +615,6 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
drawCall.geometry.vao->render();
}
glCullFace(GL_BACK);
#endif
glEnable(GL_BLEND);
auto temp = m_primaryCompositingBuffer;
......
......@@ -338,7 +338,7 @@ SharedTextureData computeTransmittanceTexture(double atmosphereRadius,
result->setFormat(GL_RGBA);
result->setType(GL_UNSIGNED_BYTE);
stbi_write_png("transmittance.png", WIDTH, HEIGHT, 4, transmittance, 0);
//stbi_write_png("transmittance.png", WIDTH, HEIGHT, 4, transmittance, 0);
return result;
}
......@@ -521,7 +521,7 @@ computeInscatteringTexture(SharedTextureData transmittance,
}
}
stbi_write_png(("inscattering_" + std::to_string(z) + ".png").c_str(), WIDTH, HEIGHT, 4, inscattering + z * WIDTH * HEIGHT * 4, 0);
//stbi_write_png(("inscattering_" + std::to_string(z) + ".png").c_str(), WIDTH, HEIGHT, 4, inscattering + z * WIDTH * HEIGHT * 4, 0);
}
return inscatteringData;
......@@ -587,25 +587,28 @@ Entity OrbitalSimulationSystem::addPlanet(Transform::Handle sun, std::string n,
// Add an atmosphere to the planet
if (generateAtmosphereLookups) {
SharedTexture2D transmittance;
SharedTexture3D inscattering;
double Rg = planetTransform->scale.x;
double Rt = planetTransform->scale.x * 1.05;
static SharedTexture2D transmittance;
static SharedTexture3D inscattering;
if (transmittance == nullptr) {
precomputeAtmosphereLookupTextures(2.55 * glm::pow(10.0, -11.0), // premultiply by nm^4 => 25 - 4*9
1.000206102, glm::dvec3{ 680, 550, 440 }, // in nm
6360000, 6420000, 8000, 0.76, transmittance, inscattering);
atmosphereMat.mainTexture = transmittance;
atmosphereMat.specularSmoothnessTexture = inscattering;
} else {
atmosphereMat.mainTexture = nullptr;
atmosphereMat.specularSmoothnessTexture = nullptr;
}
atmosphereMat.mainTexture = transmittance;
atmosphereMat.specularSmoothnessTexture = inscattering;
atmosphereMat.emissiveColor = { Rg - 10, Rt + 80, 0, 0 };
auto atmosphere = m_scene->create();
auto atmosphereTransform = atmosphere.assign<Transform>();
atmosphereTransform->parent = planetTransform;
atmosphere.assign<Drawable>(atmosphereGeom, atmosphereMat, 0, m_renderer->getRenderPassId("Main"_sh));
atmosphereTransform->scale = planetTransform->scale * 1.05;
atmosphereTransform->scale = glm::dvec3(Rt);
// 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