AtmosphereTestScene.cpp 22.2 KB
Newer Older
Dario Seyb's avatar
Dario Seyb committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <engine/scene/scenes/AtmosphereTestScene.hpp>

#include <engine/ui/UISystem.hpp>

#include <ACGL/ACGL.hh>

#include <ACGL/OpenGL/Objects.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/Math/Math.hh>
#include <ACGL/OpenGL/Data/TextureLoadStore.hh>
#include <ACGL/OpenGL/Managers.hh>

#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
#include <ACGL/OpenGL/Creator/VertexArrayObjectCreator.hh>
#include <ACGL/OpenGL/Creator/Texture2DCreator.hh>

#include <engine/scene/Transform.hpp>
#include <engine/scene/Drawable.hpp>
#include <engine/scene/Planet.hpp>

#include <engine/events/MouseEvent.hpp>
#include <engine/events/KeyboardEvent.hpp>

#include <engine/graphics/BloomPostFX.hpp>

Dario Seyb's avatar
Dario Seyb committed
26

Dario Seyb's avatar
Dario Seyb committed
27 28 29 30
using namespace ACGL::OpenGL;
using namespace ACGL::Base;
using namespace ACGL::Utils;

Dario Seyb's avatar
Dario Seyb committed
31 32 33 34 35 36 37 38 39 40 41 42
void AtmosphereTestScene::switchConsole() {
  if (isInterpolatingCamera) return;
  m_player->setHasControl(false);

  if (isFocusedOnConsole) {
    camStartPos = m_player->getCockpitPosition();
    camTargetPos = { 0, 0 , 0 };
    camStartRot = glm::quat_cast(m_player->getRotation());
    camTargetRot = glm::quat();
    m_console.pause();
    m_renderer->setRenderPassActive("Main"_sh, true);
    m_renderer->setRenderPassActive("Skybox"_sh, true);
David Gilbert's avatar
David Gilbert committed
43
    m_renderer->setRenderPassActive("Minimap"_sh, true);
Dario Seyb's avatar
Dario Seyb committed
44
    cockpitSoundSource->setVolume(0);
Dario Seyb's avatar
Dario Seyb committed
45
    cockpitSoundSource->play(-1);
Dario Seyb's avatar
Dario Seyb committed
46 47
    m_renderer->setRenderPassActive("Console"_sh, false);

Dario Seyb's avatar
Dario Seyb committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  } else {
    // TODO: Fix returning to console!
    return;
    camStartPos = m_player->getCockpitPosition();
    camTargetPos = CAM_CONSOLE_POS;
    camStartRot = glm::quat_cast(m_player->getRotation());
    camTargetRot = glm::quat_cast(CAM_CONSOLE_ROT);
    m_console.play();
  }

  isFocusedOnConsole = !isFocusedOnConsole;
  interpolationTime = 0;
  totalInterpolationTime = 4;
  isInterpolatingCamera = true;
}

Dario Seyb's avatar
Dario Seyb committed
64 65 66 67 68 69 70 71 72
bool AtmosphereTestScene::startup() {
  if (!Scene::startup()) {
    return false;
  }

  RESOLVE_DEPENDENCY(m_player);
  RESOLVE_DEPENDENCY(m_orbitals);

  m_renderer->addEffect<BloomPostFX>();
Dario Seyb's avatar
Dario Seyb committed
73

Dario Seyb's avatar
Dario Seyb committed
74 75 76 77
  consoleCamera = m_sceneGraph->create();
  consoleCamera.assign<Transform>();
  consoleCamera.assign<Camera>(50, 0.1, 50);

Dario Seyb's avatar
Dario Seyb committed
78 79 80 81
  m_audio->setListener(consoleCamera);

  m_renderer->setRenderPassActive("Main"_sh, false);
  m_renderer->setRenderPassActive("Skybox"_sh, false);
David Gilbert's avatar
David Gilbert committed
82
  m_renderer->setRenderPassActive("Minimap"_sh, false);
Dario Seyb's avatar
Dario Seyb committed
83

84
  m_renderer->setRenderPassSSAO("Cockpit"_sh, m_settings->getQualitySetting() == QualitySetting::High && m_settings->ssaoEnabled());
Dario Seyb's avatar
Dario Seyb committed
85

Dario Seyb's avatar
Dario Seyb committed
86
  m_renderer->addRenderPass(consoleCamera, "Console"_sh, ScreenSpaceSize::HALF);
Dario Seyb's avatar
Dario Seyb committed
87

Dario Seyb's avatar
Dario Seyb committed
88 89 90 91 92 93
  planetViewCam = m_sceneGraph->create();
  planetViewCam.assign<Transform>();
  planetViewCam.assign<Camera>(50, 0.1, 50);
  m_renderer->addRenderPass(planetViewCam, "PlanetView"_sh, ScreenSpaceSize::HALF);
  m_renderer->setRenderPassOnlyTexture("PlanetView"_sh, true);

Dario Seyb's avatar
Dario Seyb committed
94 95 96
  m_renderer->addRenderPass(planetViewCam, "LogoView"_sh, ScreenSpaceSize::HALF);
  m_renderer->setRenderPassOnlyTexture("LogoView"_sh, true);

97 98 99 100 101
  m_console.m_events = m_events;
  m_console.m_renderer = m_renderer;
  m_console.m_sceneGraph = m_sceneGraph;
  m_console.m_audio = m_audio;

Dario Seyb's avatar
Dario Seyb committed
102 103 104 105 106 107 108 109 110 111 112 113
  auto textTexture =
    Texture2DFileManager::the()->get(Texture2DCreator("none.png"));
  auto textGeom = Geometry{ VertexArrayObjectCreator("loading_text.obj").create() };

  auto textShader =
    ShaderProgramFileManager::the()->get(ShaderProgramCreator("console/Title")
      .attributeLocations(textGeom.vao->getAttributeLocations())
      .fragmentDataLocations(m_renderer->getGBufferLocations()));

  loadingText = m_sceneGraph->create();
  loadingText.assign<Drawable>(textGeom,
    Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 } * 10,
114
    textTexture, nullptr, nullptr, nullptr, textShader,
Dario Seyb's avatar
Dario Seyb committed
115 116 117 118 119 120 121
    false, RenderQueue::OPAQUE, GL_BACK },
    0, m_renderer->getRenderPassId("Console"_sh));

  auto textTransform = loadingText.assign<Transform>();
  textTransform->position = { 0, -3, -11 };
  loadingText.assign<Light>(glm::vec4(0, 0.2, 1.0, 5), glm::vec3(1, 0, 0),
    false, LightType::POINT, m_renderer->getRenderPassId("Console"_sh));
Dario Seyb's avatar
Dario Seyb committed
122 123 124 125 126 127 128 129


  SDL_SetRelativeMouseMode(SDL_TRUE);
  m_player->setHasControl(false);
  m_player->setCockpitPosition(CAM_CONSOLE_POS);
  m_player->setRotation(CAM_CONSOLE_ROT);

  m_events->subscribe<SimulateEvent>([this](const SimulateEvent &e) {
Dario Seyb's avatar
Dario Seyb committed
130 131 132 133 134

    if (didOneFrame && !resourceLoadingFinished) {
      loadMainSceneResources();
      switchToMainScene();
      m_renderer->setRenderPassOnlyTexture("Console"_sh, true);
David Gilbert's avatar
David Gilbert committed
135
      m_console.startup();      
Dario Seyb's avatar
Dario Seyb committed
136 137 138 139 140 141 142 143
    }

    didOneFrame = true;

    if (!resourceLoadingFinished) {
      return;
    }

144 145
    sunLight->dir = -glm::normalize(m_player->getWorldPosition());
    cockpitSunLight->dir =
Dario Seyb's avatar
Dario Seyb committed
146
      glm::vec3(glm::dvec4(sunLight->dir, 0) * m_player->getShipRotation());
147

Dario Seyb's avatar
Dario Seyb committed
148 149 150 151 152
    if (isFocusedOnConsole) {
      if (m_console.update(e, m_player->getKeyTable())) {
        switchConsole();
      }
    }
Dario Seyb's avatar
Dario Seyb committed
153 154 155 156 157 158 159

    if (isInterpolatingCamera) {
      double interpolationPercent = 1.0 - glm::pow(1 - interpolationTime / totalInterpolationTime, 2);
      m_player->setCockpitPosition(camStartPos + (camTargetPos-camStartPos)*interpolationPercent);

      interpolationPercent = 1.0 - glm::pow(1 - interpolationTime / totalInterpolationTime, 5);

Dario Seyb's avatar
Dario Seyb committed
160 161
      consoleSoundSource->setVolume((1.0f - interpolationTime / totalInterpolationTime) * 0.5);
      cockpitSoundSource->setVolume(interpolationTime / totalInterpolationTime);
162

Dario Seyb's avatar
Dario Seyb committed
163 164 165 166 167 168 169 170
      glm::quat rot = glm::slerp(camStartRot, camTargetRot, (float)interpolationPercent);
      m_player->setRotation(glm::mat4_cast(rot));
      interpolationTime += e.dt;
      if (interpolationTime >= totalInterpolationTime) {
        m_player->setCockpitPosition(camTargetPos);
        m_player->setRotation(glm::mat4_cast(camTargetRot));
        isInterpolatingCamera = false;
        m_player->setHasControl(true);
171
        consoleSoundSource->setVolume(0);
Dario Seyb's avatar
Dario Seyb committed
172
        cockpitSoundSource->setVolume(1);
Dario Seyb's avatar
Dario Seyb committed
173 174
      }
    }
Dario Seyb's avatar
Dario Seyb committed
175 176 177 178 179 180 181 182

    double rotationSpeedFactor = (1.0 - exp(-glm::abs(m_player->getVelocity()) * 0.001)) * 3  * glm::sign(m_player->getVelocity());

    planetRotationSpeed += rotationSpeedFactor * e.dt;
    planetRotationSpeed = glm::sign(planetRotationSpeed) * glm::min(glm::abs(planetRotationSpeed), 3.0);
    planetRotationSpeed -= planetRotationSpeed * e.dt * 0.3;

    planetViewTransform->rotation = glm::rotate<double>(planetViewTransform->rotation, planetRotationSpeed * e.dt, glm::dvec3{ 0.0, 1.0, 0.0 });
Dario Seyb's avatar
Dario Seyb committed
183 184 185

    logoViewTransform->rotation = glm::inverse(m_player->getShipRotation()); // glm::rotate<double>(logoViewTransform->rotation, 1.0 * e.dt, glm::dvec3{ 0.0, 1.0, 0.0 });

Dario Seyb's avatar
Dario Seyb committed
186 187 188 189 190 191 192 193
  });

  m_events->subscribe<KeyboardEvent>([this](const KeyboardEvent &e) {
    switch (e.originalEvent.key.keysym.scancode) {
    case SDL_SCANCODE_TAB:
        if (e.originalEvent.key.type == SDL_KEYDOWN) {
          m_player->attachToParent(earth);
          float r = earth.component<Transform>()->scale.x;
Dario Seyb's avatar
Dario Seyb committed
194
          m_player->setPosition(glm::vec3(0, 0, r * 3.5));
Dario Seyb's avatar
Dario Seyb committed
195 196 197
          m_player->setRotation(glm::mat4());
        }
      break;
Dario Seyb's avatar
Dario Seyb committed
198
    case SDL_SCANCODE_RETURN:
Dario Seyb's avatar
Dario Seyb committed
199
      if (e.originalEvent.key.type == SDL_KEYDOWN) {
Dario Seyb's avatar
Dario Seyb committed
200 201
        switchConsole();
      }
Dario Seyb's avatar
Dario Seyb committed
202
      break;
Dario Seyb's avatar
Dario Seyb committed
203 204 205
    case SDL_SCANCODE_R:
      if (e.originalEvent.key.type == SDL_KEYDOWN) {
        ShaderProgramFileManager::the()->updateAll();
Dario Seyb's avatar
Dario Seyb committed
206
        Texture2DFileManager::the()->updateAll();
Dario Seyb's avatar
Dario Seyb committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
      }
    default:
      break;
    }
  });

  // Subscribe to the UI drawing event.
  // This is called once per frame
  m_events->subscribe<"DrawUI"_sh>([this]() {

    ImGui::Begin("Camera Control", 0,
                 ImGuiWindowFlags_::ImGuiWindowFlags_AlwaysAutoResize);

    float r;
    if (ImGui::Button("Sun/Global", glm::vec2(100, 20))) {
      // Reset the camera to sun coords
      m_player->attachToParent(sun);
      r = sun.component<Transform>()->scale.x;
      m_player->setPosition(glm::dvec3(0, 0, r * 1.2));
      m_player->setRotation(glm::dmat4());
    }

    if (ImGui::Button("Earth", glm::vec2(100, 20))) {
      m_player->attachToParent(earth);
      r = earth.component<Transform>()->scale.x;
      m_player->setPosition(glm::dvec3(0, 0, r * 1.2));
      m_player->setRotation(glm::dmat4());
    }
Dario Seyb's avatar
Dario Seyb committed
235

Dario Seyb's avatar
Dario Seyb committed
236 237
    ImGui::End();
  });
Dario Seyb's avatar
Dario Seyb committed
238

Dario Seyb's avatar
Dario Seyb committed
239 240 241 242
  return true;
}

void AtmosphereTestScene::switchToMainScene() {
David Gilbert's avatar
David Gilbert committed
243 244


Dario Seyb's avatar
Dario Seyb committed
245 246
  {
    auto skyboxPassId = m_renderer->getRenderPassId("Skybox"_sh);
Dario Seyb's avatar
Dario Seyb committed
247

Dario Seyb's avatar
Dario Seyb committed
248 249
    skybox = m_sceneGraph->create();
    skybox.assign<Transform>();
Dario Seyb's avatar
Dario Seyb committed
250 251 252
    skybox.assign<Drawable>(skyboxGeometry, skyboxMaterial, 0, skyboxPassId);
    skybox.assign<Light>(glm::vec4(1, 1, 1, 1), glm::vec3(1, 0, 0), false,
                         LightType::POINT, skyboxPassId);
Dario Seyb's avatar
Dario Seyb committed
253
  }
Dario Seyb's avatar
Dario Seyb committed
254

Dario Seyb's avatar
Dario Seyb committed
255 256 257 258 259 260 261 262
  {
    auto mainPassId = m_renderer->getRenderPassId("Main"_sh);

    // Let's create a placeholder sun
    sun = m_sceneGraph->create();
    // Add a transform component to it so we are able to position it in space
    auto sunTransform = sun.assign<Transform>();
    // Add a Drawable component to it so the renderer has something to draw
David Gilbert's avatar
David Gilbert committed
263
    sun.assign<Drawable>(sunGeometry, sunMaterial, 0, m_renderer->getRenderPassId("Main"_sh));
Dario Seyb's avatar
Dario Seyb committed
264 265
    float scale = m_orbitals->solarRadius * m_orbitals->scaleFactor * 0.1;
    sunTransform->scale = glm::dvec3(scale);
Dario Seyb's avatar
Dario Seyb committed
266
    sunLight = sun.assign<Light>(glm::vec4(1, 1, 1, 1.5), glm::vec3(1, 0, 0),
David Gilbert's avatar
David Gilbert committed
267 268 269 270 271 272
                                 false, LightType::DIRECTIONAL, m_renderer->getRenderPassId("Main"_sh));

    // Let's create a placeholder sun
    sun2 = m_sceneGraph->create();
    // Add a transform component to it so we are able to position it in space
    auto sunTransform2 = sun2.assign<Transform>();
Dario Seyb's avatar
Dario Seyb committed
273
    sunMaterial.emissiveColor.a = 3.0;
David Gilbert's avatar
David Gilbert committed
274 275 276
    // Add a Drawable component to it so the renderer has something to draw
    sun2.assign<Drawable>(sunGeometry, sunMaterial, 0, m_renderer->getRenderPassId("Minimap"_sh));
    //float scale2 = m_orbitals->solarRadius * m_orbitals->scaleFactor * 0.1;
Dario Seyb's avatar
Dario Seyb committed
277
    sunTransform2->scale = glm::dvec3(0.4, 0.4, 0.4);
David Gilbert's avatar
David Gilbert committed
278 279 280 281
    sunTransform2->position = glm::dvec3(0, 0, -70);
    sunLight2 = sun2.assign<Light>(glm::vec4(1, 1, 1, 1), glm::vec3(1, 0, 0),
      false, LightType::POINT, m_renderer->getRenderPassId("Minimap"_sh));

Dario Seyb's avatar
Dario Seyb committed
282 283 284 285 286 287 288

    // create a planet!
    // Mass in solar masses, Radius in solar radii, Eccentricity, Semimajor
    // axis, Inclination, Ascending Node, Arg. of Periapsis, time at perihelion
    //																mass              radius
    //e
    // a        i          N          w
Dario Seyb's avatar
Dario Seyb committed
289

Dario Seyb's avatar
Dario Seyb committed
290 291 292 293 294 295 296 297
    mercury = m_orbitals->addPlanet(sunTransform, "Mercury", 0.000000165956, 0.003505316091954, 0.205633, 0.387098, 0.1222500, 0.84153, 0.50768, 0, "earth");
    venus = m_orbitals->addPlanet(sunTransform, "Venus", 0.00000243522, 0.008695402298851, 0.006778, 0.723330, 0.0592500, 1.33679, 0.95717, 0, "mars");
    earth = m_orbitals->addPlanet(sunTransform, "Earth", 0.000002988, 0.009153735632184, 0.016713, 1.000000, 0.0000000, 0.00000, 4.93533, 0, m_settings->getDefaultPlanetType());
    mars = m_orbitals->addPlanet(sunTransform, "Mars", 0.000000319716, 0.004870689655172, 0.093396, 1.523688, 0.0322851, 0.02333, 4.99858, 0, "mars");
    jupiter = m_orbitals->addPlanet(sunTransform, "Jupiter", 0.000954265748, 0.1004468390805, 0.048482, 5.202560, 0.0227500, 1.75150, 4.77905, 0, "jupiter");
    saturn = m_orbitals->addPlanet(sunTransform, "Saturn", 0.00028386, 0.08366666666667, 0.055580, 9.554750, 0.0434412, 1.98230, 5.92169, 0, "jupiter");
    uranus = m_orbitals->addPlanet(sunTransform, "Uranus", 0.00004344552, 0.03643965517241, 0.047292, 19.18176, 0.0134948, 1.29060, 1.68516, 0, "jupiter");
    neptune = m_orbitals->addPlanet(sunTransform, "Neptune", 0.0000512442, 0.03537643678161, 0.008598, 30.05814, 0.0002355, 2.29810, 4.76243, 0, "jupiter");
Dario Seyb's avatar
Dario Seyb committed
298

Dario Seyb's avatar
Dario Seyb committed
299 300 301

    m_player->attachToParent(earth);
    double r = earth.component<Transform>()->scale.x;
Dario Seyb's avatar
Dario Seyb committed
302
    m_player->setPosition(glm::dvec3(-r * 0.5, 0, r * 2.5));
Dario Seyb's avatar
Dario Seyb committed
303
  }
Dario Seyb's avatar
Dario Seyb committed
304

Dario Seyb's avatar
Dario Seyb committed
305
  {
Dario Seyb's avatar
Dario Seyb committed
306
    auto cockpitPassId = m_renderer->getRenderPassId("Cockpit"_sh);
Dario Seyb's avatar
Dario Seyb committed
307

Dario Seyb's avatar
Dario Seyb committed
308
    cockpit = m_sceneGraph->create();
Dario Seyb's avatar
Dario Seyb committed
309 310
    auto cockpitDrawable = cockpit.assign<Drawable>(
        cockpitGeometry, cockpitMaterial, 0, cockpitPassId);
Dario Seyb's avatar
Dario Seyb committed
311 312 313
    auto cockpitTransform = cockpit.assign<Transform>();
    cockpitTransform->position = glm::dvec3(0, 0, 0);
    cockpitDrawable->visible = true;
Dario Seyb's avatar
Dario Seyb committed
314
    auto cockpitLight =
Dario Seyb's avatar
Dario Seyb committed
315
        cockpit.assign<Light>(glm::vec4(1, 1, 1, 0.0), glm::vec3(1, 0, 0),
Dario Seyb's avatar
Dario Seyb committed
316
                              false, LightType::POINT, cockpitPassId);
Dario Seyb's avatar
Dario Seyb committed
317

Dario Seyb's avatar
Dario Seyb committed
318

Dario Seyb's avatar
Dario Seyb committed
319
    cockpitSoundSource = cockpit.assign<SoundSource>(soundTrackIntro);
Dario Seyb's avatar
Dario Seyb committed
320

Dario Seyb's avatar
merged  
Dario Seyb committed
321 322
    cockpitSun = m_sceneGraph->create();
    cockpitSun.assign<Transform>();
Dario Seyb's avatar
Dario Seyb committed
323 324 325
    cockpitSunLight =
        cockpitSun.assign<Light>(glm::vec4(1, 1, 1, 3), glm::vec3(1, 0, 0),
                                 true, LightType::DIRECTIONAL, cockpitPassId);
Dario Seyb's avatar
merged  
Dario Seyb committed
326

Dario Seyb's avatar
Dario Seyb committed
327 328 329 330 331 332 333 334 335

    auto lightLeft = m_sceneGraph->create();
    lightLeft.assign<Transform>()->position = { -0.6, 0.6, -2.34 };
    lightLeft.assign<Light>(glm::vec4(1.0, 0.5, 0.3, 0.5), glm::vec3(1, 0, 0), false, LightType::POINT, cockpitPassId);

    auto lightRight= m_sceneGraph->create();
    lightRight.assign<Transform>()->position = { 0.6, 0.6, -2.34 };
    lightRight.assign<Light>(glm::vec4(0.3, 1.0, 0.4, 0.5), glm::vec3(1, 0, 0), false, LightType::POINT, cockpitPassId);

Dario Seyb's avatar
Dario Seyb committed
336 337 338 339
    auto console = m_sceneGraph->create();
    console.assign<Drawable>(
        consoleGeom,
        Material{glm::vec4{1, 1, 1, 1}, glm::vec4{1, 1, 1, 1},
340
                 m_renderer->getRenderPassTarget("Console"_sh), nullptr, nullptr, nullptr,
Dario Seyb's avatar
Dario Seyb committed
341
                 skyboxMaterial.prog, false, RenderQueue::OPAQUE, GL_NONE},
Dario Seyb's avatar
Dario Seyb committed
342
        0, cockpitPassId);
343
    auto consoleTransform = console.assign<Transform>();
344

Dario Seyb's avatar
Dario Seyb committed
345
    consoleSoundSource = console.assign<SoundSource>(soundTrackMain);
Dario Seyb's avatar
Dario Seyb committed
346
    consoleSoundSource->setVolume(0.5);
Dario Seyb's avatar
Dario Seyb committed
347
    consoleSoundSource->play(-1);
Dario Seyb's avatar
Dario Seyb committed
348

Dario Seyb's avatar
Dario Seyb committed
349 350
    auto consoleFrontLeft = m_sceneGraph->create();
    consoleFrontLeft.assign<Drawable>(
Dario Seyb's avatar
Dario Seyb committed
351
      consoleFrontLeftGeom,
Dario Seyb's avatar
Dario Seyb committed
352 353 354
      Material{ glm::vec4{ 0.2, 0.2, 0.2, 1 }, glm::vec4{ 1, 1, 1, 1 },
      nullptr, nullptr, nullptr, m_renderer->getRenderPassTarget("LogoView"_sh),
      defaultPbrProg, true, RenderQueue::OPAQUE, GL_NONE },
Dario Seyb's avatar
Dario Seyb committed
355
      0, cockpitPassId);
Dario Seyb's avatar
Dario Seyb committed
356
    consoleFrontLeft.assign<Transform>();
Dario Seyb's avatar
Dario Seyb committed
357

Dario Seyb's avatar
Dario Seyb committed
358 359
    auto consoleFrontRight = m_sceneGraph->create();
    consoleFrontRight.assign<Drawable>(
Dario Seyb's avatar
Dario Seyb committed
360
      consoleFrontRightGeom,
Dario Seyb's avatar
Dario Seyb committed
361
      Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
Dario Seyb's avatar
Dario Seyb committed
362
      m_renderer->getRenderPassTarget("PlanetView"_sh), nullptr, nullptr, nullptr,
Dario Seyb's avatar
Dario Seyb committed
363 364 365 366 367 368
      skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
      0, cockpitPassId);
    consoleFrontRight.assign<Transform>();

    auto consoleBackLeft = m_sceneGraph->create();
    consoleBackLeft.assign<Drawable>(
Dario Seyb's avatar
Dario Seyb committed
369
      consoleBackLeftGeom,
Dario Seyb's avatar
Dario Seyb committed
370
      Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
371
      m_renderer->getRenderPassTarget("Minimap"_sh), nullptr, nullptr, nullptr,
Dario Seyb's avatar
Dario Seyb committed
372
      skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
Dario Seyb's avatar
Dario Seyb committed
373
      0, cockpitPassId);
Dario Seyb's avatar
Dario Seyb committed
374 375 376 377
    consoleBackLeft.assign<Transform>();

    auto consoleBackRight = m_sceneGraph->create();
    consoleBackRight.assign<Drawable>(
Dario Seyb's avatar
Dario Seyb committed
378
      consoleBackRightGeom,
Dario Seyb's avatar
Dario Seyb committed
379
      Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
380
      outOfOrderTexture, nullptr, nullptr, nullptr,
Dario Seyb's avatar
Dario Seyb committed
381 382 383 384 385 386 387
      skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
      0, cockpitPassId);
    consoleBackRight.assign<Transform>();


    auto consoleMiddleLeft= m_sceneGraph->create();
    consoleMiddleLeft.assign<Drawable>(
Dario Seyb's avatar
Dario Seyb committed
388
      consoleMiddleLeftGeom,
Dario Seyb's avatar
Dario Seyb committed
389
      Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
390
      outOfOrderTexture, nullptr, nullptr, nullptr,
Dario Seyb's avatar
Dario Seyb committed
391 392
      skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
      0, cockpitPassId);
Dario Seyb's avatar
POLISH  
Dario Seyb committed
393
    consoleMiddleLeft.assign<Transform>()->scale = { -1, 1, 1 };
Dario Seyb's avatar
Dario Seyb committed
394

Dario Seyb's avatar
Dario Seyb committed
395 396
    auto consoleMiddleRight = m_sceneGraph->create();
    consoleMiddleRight.assign<Drawable>(
Dario Seyb's avatar
Dario Seyb committed
397
      consoleMiddleRightGeom,
Dario Seyb's avatar
Dario Seyb committed
398
      Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
399
      outOfOrderTexture, nullptr, nullptr, nullptr,
Dario Seyb's avatar
Dario Seyb committed
400
      skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
Dario Seyb's avatar
Dario Seyb committed
401
      0, cockpitPassId);
Dario Seyb's avatar
POLISH  
Dario Seyb committed
402
    consoleMiddleRight.assign<Transform>()->scale = { -1, 1, 1 };
Dario Seyb's avatar
Dario Seyb committed
403

Dario Seyb's avatar
Dario Seyb committed
404 405 406 407 408 409
    auto windShield = m_sceneGraph->create();
    windShield.assign<Drawable>(
      windShieldGeom,
      windshieldMaterial,
      0, cockpitPassId);
    windShield.assign<Transform>();
Dario Seyb's avatar
Dario Seyb committed
410
  }
Dario Seyb's avatar
Dario Seyb committed
411

Dario Seyb's avatar
Dario Seyb committed
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
  {
    auto planetViewPassId = m_renderer->getRenderPassId("PlanetView"_sh);
    auto planetView = m_sceneGraph->create();
    planetView.assign<Drawable>(
      planetViewGeom,
      Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 0.3, 1.0, 0.4, 1 },
      nullptr, nullptr, nullptr, nullptr,
      defaultPbrProg, true, RenderQueue::OPAQUE, GL_NONE },
      0, planetViewPassId);
    planetViewTransform = planetView.assign<Transform>();
    planetViewTransform->position = { 0.0, 0.0, -5.0 };;
    planetViewTransform->scale = { 1.5, 1.5, 1.5 };

    planetView.assign<Light>(glm::vec4(1, 1, 1, 0.2), glm::vec3(1, 0, 0),
      false, LightType::POINT, planetViewPassId);
  }

Dario Seyb's avatar
Dario Seyb committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
  {
    auto logoViewPassId = m_renderer->getRenderPassId("LogoView"_sh);
    auto logoView = m_sceneGraph->create();
    logoView.assign<Drawable>(
      logoViewGeom,
      Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1.0, 0.5, 0.3, 1 },
      nullptr, nullptr, nullptr, nullptr,
      defaultPbrProg, true, RenderQueue::OPAQUE, GL_NONE },
      0, logoViewPassId);
    logoViewTransform = logoView.assign<Transform>();
    logoViewTransform->position = { 0.0, 0.0, -5.0 };;
    logoViewTransform->scale = { 0.75, 0.75, 0.75 };

    logoView.assign<Light>(glm::vec4(1, 1, 1, 0.2), glm::vec3(1, 0, 0),
      false, LightType::POINT, logoViewPassId);
  }

Dario Seyb's avatar
Dario Seyb committed
446 447
  loadingText.component<Drawable>()->visible = false;
  loadingText.destroy();
Dario Seyb's avatar
Dario Seyb committed
448
}
Dario Seyb's avatar
Dario Seyb committed
449

Dario Seyb's avatar
Dario Seyb committed
450
void AtmosphereTestScene::loadMainSceneResources() {
Dario Seyb's avatar
Dario Seyb committed
451 452


453
  auto qualitySetting = m_settings->getQualitySetting();
Dario Seyb's avatar
Dario Seyb committed
454 455 456 457 458 459 460
  {
    auto vaoSkybox = VertexArrayObjectCreator("skybox.obj").create();
    auto skyboxShader = ShaderProgramFileManager::the()->get(
        ShaderProgramCreator("Skybox")
            .attributeLocations(vaoSkybox->getAttributeLocations())
            .fragmentDataLocations(m_renderer->getGBufferLocations()));

Dario Seyb's avatar
Dario Seyb committed
461 462 463 464 465
    defaultPbrProg = ShaderProgramFileManager::the()->get(
      ShaderProgramCreator("PBR")
      .attributeLocations(vaoSkybox->getAttributeLocations())
      .fragmentDataLocations(m_renderer->getGBufferLocations()));

466 467 468 469

    auto skyboxTexName = qualitySetting == QualitySetting::High ? "skybox_large.png" : qualitySetting == QualitySetting::Medium ? "skybox_medium.png" : "skybox.png";

    auto skyboxTexture = Texture2DFileManager::the()->get(Texture2DCreator(skyboxTexName));
Dario Seyb's avatar
Dario Seyb committed
470 471 472

    skyboxGeometry = {vaoSkybox};
    skyboxMaterial = {glm::vec4{1, 1, 1, 1},
Dario Seyb's avatar
POLISH  
Dario Seyb committed
473
                      glm::vec4{0.05, 0.05, 0.05, 1},
Dario Seyb's avatar
Dario Seyb committed
474 475 476
                      skyboxTexture,
                      nullptr,
                      nullptr,
477
                      nullptr,
Dario Seyb's avatar
Dario Seyb committed
478 479 480 481 482
                      skyboxShader,
                      false,
                      RenderQueue::OPAQUE,
                      GL_BACK};
  }
Dario Seyb's avatar
Dario Seyb committed
483

Dario Seyb's avatar
Dario Seyb committed
484 485 486 487 488
  {
    auto vaoSun = VertexArrayObjectCreator("uvsphere.obj").create();
    auto checkboardTexture =
        Texture2DFileManager::the()->get(Texture2DCreator("checkerboard.png"));

Dario Seyb's avatar
Dario Seyb committed
489 490 491 492
    auto sunShader = ShaderProgramFileManager::the()->get(
      ShaderProgramCreator("PBR")
      .attributeLocations(vaoSun->getAttributeLocations())
      .fragmentDataLocations(m_renderer->getGBufferLocations()));
Dario Seyb's avatar
Dario Seyb committed
493 494 495 496 497 498 499 500

    sunGeometry = {vaoSun};

    sunMaterial = {glm::vec4{1, 1, 1, 1},
                   glm::vec4{2, 2, 1, 20},
                   checkboardTexture,
                   nullptr,
                   nullptr,
501
                   nullptr,
Dario Seyb's avatar
Dario Seyb committed
502 503 504 505 506
                   sunShader,
                   false,
                   RenderQueue::OPAQUE,
                   GL_BACK};
  }
Dario Seyb's avatar
Dario Seyb committed
507

Dario Seyb's avatar
Dario Seyb committed
508 509
  {
    // create cockpit
Dario Seyb's avatar
Dario Seyb committed
510
    auto vaoCockpit = VertexArrayObjectCreator("cockpit/cockpit_v2_outer.obj").create();
Dario Seyb's avatar
Dario Seyb committed
511 512 513 514
    auto cockpitShader = ShaderProgramFileManager::the()->get(
      ShaderProgramCreator("PBR")
      .attributeLocations(vaoCockpit->getAttributeLocations())
      .fragmentDataLocations(m_renderer->getGBufferLocations()));
Dario Seyb's avatar
Dario Seyb committed
515 516 517 518

    cockpitMaterial = {
        glm::vec4{0.4, 0.4, 0.4, 1}, glm::vec4{0, 0, 0, 1},
        Texture2DFileManager::the()->get(Texture2DCreator(
Dario Seyb's avatar
Dario Seyb committed
519
            "cockpit_v2/cockpit_v2_outer_DefaultMaterial_AlbedoTransparency.png")),
Dario Seyb's avatar
Dario Seyb committed
520
        Texture2DFileManager::the()->get(
Dario Seyb's avatar
Dario Seyb committed
521
            Texture2DCreator("cockpit_v2/cockpit_v2_outer_DefaultMaterial_Normal.png")),
Dario Seyb's avatar
Dario Seyb committed
522
        Texture2DFileManager::the()->get(Texture2DCreator(
Dario Seyb's avatar
Dario Seyb committed
523
            "cockpit_v2/cockpit_v2_outer_DefaultMaterial_SpecularSmoothness.png")),
524 525
        Texture2DFileManager::the()->get(
            Texture2DCreator("cockpit_v2/cockpit_v2_outer_DefaultMaterial_Emission.png")),
Dario Seyb's avatar
Dario Seyb committed
526
        cockpitShader, true, RenderQueue::OPAQUE, GL_NONE };
Dario Seyb's avatar
Dario Seyb committed
527 528

    cockpitGeometry = {vaoCockpit};
Dario Seyb's avatar
Dario Seyb committed
529

Dario Seyb's avatar
POLISH  
Dario Seyb committed
530
    windshieldMaterial = Material{ glm::vec4{ 0.2, 0.3, 1.0, 0.2 }, glm::vec4{ 0.02, 0.03, 0.05, 1 },
Dario Seyb's avatar
Dario Seyb committed
531 532 533
      Texture2DFileManager::the()->get(Texture2DCreator(
        "cockpit_v2/"
        "windshield_DefaultMaterial_AlbedoTransparency.png")),
534
      nullptr, nullptr, nullptr, cockpitShader, false,
Dario Seyb's avatar
Dario Seyb committed
535
      RenderQueue::OPAQUE, GL_NONE };
Dario Seyb's avatar
Dario Seyb committed
536 537 538 539 540 541 542 543 544 545

    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() };

Dario Seyb's avatar
POLISH  
Dario Seyb committed
546 547 548

    outOfOrderTexture = Texture2DFileManager::the()->get(Texture2DCreator("cockpit_v2/outoforder.png"));

Dario Seyb's avatar
Dario Seyb committed
549 550
    soundTrackIntro = m_audio->createSound("GameAmbient.mp3", SoundMode::MODE_2D);
    soundTrackMain = m_audio->createSound("SpaceTheme.mp3", SoundMode::MODE_2D);
Dario Seyb's avatar
Dario Seyb committed
551

Dario Seyb's avatar
Dario Seyb committed
552
  }
Dario Seyb's avatar
Dario Seyb committed
553

Dario Seyb's avatar
Dario Seyb committed
554 555
  {
    planetViewGeom = Geometry{ VertexArrayObjectCreator("planet_wireframe.obj").create() };
Dario Seyb's avatar
Dario Seyb committed
556
    logoViewGeom = Geometry{ VertexArrayObjectCreator("title_text.obj").create() };
Dario Seyb's avatar
Dario Seyb committed
557 558
  }

Dario Seyb's avatar
Dario Seyb committed
559
  resourceLoadingFinished = true;
Dario Seyb's avatar
Dario Seyb committed
560 561
}

Dario Seyb's avatar
Dario Seyb committed
562
void AtmosphereTestScene::shutdown() {}