Commit 7fad2e2f authored by Dario Seyb's avatar Dario Seyb

shared pointers are evil, yo

parent 7f8adae3
......@@ -39,6 +39,10 @@ private:
Material cockpitMaterial, sunMaterial, skyboxMaterial, windshieldMaterial;
Geometry cockpitGeometry, sunGeometry, skyboxGeometry;
Geometry consoleGeom, consoleFrontLeftGeom, consoleFrontRightGeom, consoleBackLeftGeom, consoleBackRightGeom, consoleMiddleLeftGeom, consoleMiddleRightGeom, windShieldGeom;
std::shared_ptr<Sound> soundTrackIntro, soundTrackMain;
bool resourceLoadingFinished = false;
bool mainSceneRunning = false;
......
......@@ -347,11 +347,10 @@ SharedTextureData computeTransmittanceTexture(double atmosphereRadius,
const int INSCATTERING_INTEGRAL_SAMPLES = 50;
glm::dvec3 sampleTransmittance(SharedTextureData transmittance, double r,
glm::dvec3 sampleTransmittance(GLubyte* transmittance, double r,
double mu, double Rg, double Rt) {
auto data = transmittance->getData();
int h = transmittance->getHeight();
int w = transmittance->getWidth();
int h = 56;
int w = 256;
double uR = sqrt((r - Rg) / (Rt - Rg));
......@@ -363,7 +362,7 @@ glm::dvec3 sampleTransmittance(SharedTextureData transmittance, double r,
x = glm::clamp(x, 0, w - 1);
y = glm::clamp(y, 0, h - 1);
auto pixel = data + (x + y * w) * 4;
auto pixel = transmittance + (x + y * w) * 4;
return{ double(pixel[0]) / 255, double(pixel[1]) / 255, double(pixel[2]) / 255 };
}
......@@ -371,7 +370,7 @@ glm::dvec3 sampleTransmittance(SharedTextureData transmittance, double r,
// transmittance(=transparency) of atmosphere between x and x0
// assume segment x,x0 not intersecting ground
// r=||x||, mu=cos(zenith angle of [x,x0) ray at x), v=unit direction vector of [x,x0) ray
glm::vec3 sampleTransmittance(SharedTextureData transmittance, double r,
glm::vec3 sampleTransmittance(GLubyte* transmittance, double r,
double mu, glm::vec3 v, glm::vec3 x0, double Rg, double Rt) {
glm::vec3 result;
float r1 = glm::length(x0);
......@@ -401,7 +400,7 @@ double limit(double r, double mu, double Rg, double RL) {
// transmittance(=transparency) of atmosphere between x and x0
// assume segment x,x0 not intersecting ground
// d = distance between x and x0, mu=cos(zenith angle of [x,x0) ray at x)
glm::dvec3 sampleTransmittance(SharedTextureData transmittance, double r, double mu, double d, double Rg, double Rt) {
glm::dvec3 sampleTransmittance(GLubyte* transmittance, double r, double mu, double d, double Rg, double Rt) {
glm::dvec3 result;
double r1 = glm::sqrt(r * r + d * d + 2.0 * r * mu * d);
double mu1 = (r * mu + d) / r1;
......@@ -413,7 +412,7 @@ glm::dvec3 sampleTransmittance(SharedTextureData transmittance, double r, double
return result;
}
void integrand(SharedTextureData transmittance, double r, double mu, double muS, double nu, double t, double Rg, double Rt, double HR, double HM, glm::dvec3& ray, glm::dvec3& mie) {
void integrand(GLubyte* transmittance, double r, double mu, double muS, double nu, double t, double Rg, double Rt, double HR, double HM, glm::dvec3& ray, glm::dvec3& mie) {
ray = glm::dvec3(0.0);
mie = glm::dvec3(0.0);
......@@ -427,7 +426,7 @@ void integrand(SharedTextureData transmittance, double r, double mu, double muS,
}
}
glm::dvec4 inscatter(SharedTextureData transmittance, float r, float mu, float muS, float nu, double Rg, double Rt, double RL, double HR, double HM, glm::dvec3 betaR, double betaM) {
glm::dvec4 inscatter(GLubyte* transmittance, float r, float mu, float muS, float nu, double Rg, double Rt, double RL, double HR, double HM, glm::dvec3 betaR, double betaM) {
glm::dvec3 ray = glm::dvec3(0.0);
glm::dvec3 mie = glm::dvec3(0.0);
double dx = limit(r, mu, Rg, RL) / double(INSCATTERING_INTEGRAL_SAMPLES);
......@@ -451,7 +450,7 @@ glm::dvec4 inscatter(SharedTextureData transmittance, float r, float mu, float m
SharedTextureData
computeInscatteringTexture(SharedTextureData transmittance,
computeInscatteringTexture(GLubyte* transmittance,
double atmosphereRadius, double planetRadius,
glm::dvec3 constBetaRayleigh, double constBetaMie,
double g) {
......@@ -571,7 +570,7 @@ void precomputeAtmosphereLookupTextures(double molecularNumberDensity,
auto inscatteringCompute = std::thread([&]() {
inscattering =
computeInscatteringTexture(transmittance, atmosphereRadius, planetRadius,
computeInscatteringTexture(transmittance->getData(), atmosphereRadius, planetRadius,
constBetaRayleigh, constBetaMie, g);
});
......
......@@ -281,8 +281,6 @@ void AtmosphereTestScene::switchToMainScene() {
{
auto cockpitPassId = m_renderer->getRenderPassId("Cockpit"_sh);
cockpit = m_sceneGraph->create();
auto cockpitDrawable = cockpit.assign<Drawable>(
cockpitGeometry, cockpitMaterial, 0, cockpitPassId);
......@@ -294,8 +292,7 @@ void AtmosphereTestScene::switchToMainScene() {
false, LightType::POINT, cockpitPassId);
auto soundTrack = m_audio->createSound("chipzel - Spectra - 04 Formed in the Clouds (Interlude).mp3", SoundMode::MODE_2D);
cockpitSoundSource = cockpit.assign<SoundSource>(soundTrack);
cockpitSoundSource = cockpit.assign<SoundSource>(soundTrackIntro);
cockpitSun = m_sceneGraph->create();
cockpitSun.assign<Transform>();
......@@ -303,22 +300,7 @@ void AtmosphereTestScene::switchToMainScene() {
cockpitSun.assign<Light>(glm::vec4(1, 1, 1, 3), glm::vec3(1, 0, 0),
true, LightType::DIRECTIONAL, cockpitPassId);
/*auto blinkButton = m_sceneGraph->create();
blinkButton.assign<Light>(glm::vec4(0.2, 0.2, 0.6, 5), glm::vec3(1, 0, 0),
false, LightType::POINT, cockpitPassId);
auto transform = blinkButton.assign<Transform>();
transform->parent = cockpitTransform;
transform->position = {0.7655, -0.4545, -1.643};
blinkButton = m_sceneGraph->create();
blinkButton.assign<Light>(glm::vec4(0.1, 0.7, 0.2, 5), glm::vec3(1, 0, 0),
false, LightType::POINT, cockpitPassId);
transform = blinkButton.assign<Transform>();
transform->parent = cockpitTransform;
transform->position = {-0.7655, -0.4545, -1.643};*/
auto console = m_sceneGraph->create();
auto consoleGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_maindisplay.obj").create() };
console.assign<Drawable>(
consoleGeom,
Material{glm::vec4{1, 1, 1, 1}, glm::vec4{1, 1, 1, 1},
......@@ -327,16 +309,13 @@ void AtmosphereTestScene::switchToMainScene() {
0, cockpitPassId);
auto consoleTransform = console.assign<Transform>();
soundTrack = m_audio->createSound("chipzel - Spectra - 01 Spectra.mp3", SoundMode::MODE_2D);
consoleSoundSource = console.assign<SoundSource>(soundTrack);
consoleSoundSource = console.assign<SoundSource>(soundTrackMain);
consoleSoundSource->setVolume(0.5);
consoleSoundSource->play();
auto consoleFrontLeft = m_sceneGraph->create();
consoleGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_front_left.obj").create() };
consoleFrontLeft.assign<Drawable>(
consoleGeom,
consoleFrontLeftGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
nullptr, nullptr, nullptr,
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
......@@ -344,9 +323,8 @@ void AtmosphereTestScene::switchToMainScene() {
consoleFrontLeft.assign<Transform>();
auto consoleFrontRight = m_sceneGraph->create();
consoleGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_front_right.obj").create() };
consoleFrontRight.assign<Drawable>(
consoleGeom,
consoleFrontRightGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
nullptr, nullptr, nullptr,
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
......@@ -354,9 +332,8 @@ void AtmosphereTestScene::switchToMainScene() {
consoleFrontRight.assign<Transform>();
auto consoleBackLeft = m_sceneGraph->create();
consoleGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_back_left.obj").create() };
consoleBackLeft.assign<Drawable>(
consoleGeom,
consoleBackLeftGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
m_renderer->getRenderPassTarget("Minimap"_sh), nullptr, nullptr,
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
......@@ -364,9 +341,8 @@ void AtmosphereTestScene::switchToMainScene() {
consoleBackLeft.assign<Transform>();
auto consoleBackRight = m_sceneGraph->create();
consoleGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_back_right.obj").create() };
consoleBackRight.assign<Drawable>(
consoleGeom,
consoleBackRightGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
nullptr, nullptr, nullptr,
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
......@@ -375,9 +351,8 @@ void AtmosphereTestScene::switchToMainScene() {
auto consoleMiddleLeft= m_sceneGraph->create();
consoleGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_middle_left.obj").create() };
consoleMiddleLeft.assign<Drawable>(
consoleGeom,
consoleMiddleLeftGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
nullptr, nullptr, nullptr,
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
......@@ -385,9 +360,8 @@ void AtmosphereTestScene::switchToMainScene() {
consoleMiddleLeft.assign<Transform>();
auto consoleMiddleRight = m_sceneGraph->create();
consoleGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_middle_right.obj").create() };
consoleMiddleRight.assign<Drawable>(
consoleGeom,
consoleMiddleRightGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
nullptr, nullptr, nullptr,
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
......@@ -395,14 +369,11 @@ void AtmosphereTestScene::switchToMainScene() {
consoleMiddleRight.assign<Transform>();
auto windShield = m_sceneGraph->create();
auto windShieldGeom = Geometry{
VertexArrayObjectCreator("cockpit/cockpit_v2_windshield.obj").create() };
windShield.assign<Drawable>(
windShieldGeom,
windshieldMaterial,
0, cockpitPassId);
windShield.assign<Transform>();
}
loadingText.component<Drawable>()->visible = false;
......@@ -480,6 +451,19 @@ void AtmosphereTestScene::loadMainSceneResources() {
"windshield_DefaultMaterial_AlbedoTransparency.png")),
nullptr, nullptr, cockpitShader, false,
RenderQueue::OPAQUE, GL_NONE };
consoleGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_maindisplay.obj").create() };
consoleFrontLeftGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_front_left.obj").create() };
consoleFrontRightGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_front_right.obj").create() };
consoleBackLeftGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_back_left.obj").create() };
consoleBackRightGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_back_right.obj").create() };
consoleMiddleLeftGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_middle_left.obj").create() };
consoleMiddleRightGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_console_middle_right.obj").create() };
windShieldGeom = Geometry{ VertexArrayObjectCreator("cockpit/cockpit_v2_windshield.obj").create() };
soundTrackIntro = m_audio->createSound("chipzel - Spectra - 04 Formed in the Clouds (Interlude).mp3", SoundMode::MODE_2D);
soundTrackMain = m_audio->createSound("chipzel - Spectra - 01 Spectra.mp3", SoundMode::MODE_2D);
}
resourceLoadingFinished = true;
......
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