Commit ce940255 authored by Dario Seyb's avatar Dario Seyb

first version of the intro

parent 71a6dbb9
This diff is collapsed.
This diff is collapsed.
# Blender v2.71 (sub 0) OBJ File: ''
# www.blender.org
v -1.000000 -1.000000 -0.000001
v 1.000000 -1.000000 -0.000001
v -1.000000 1.000000 0.000001
v 1.000000 1.000000 0.000001
vt 0.999900 0.000100
vt 0.999900 0.999900
vt 0.000100 0.999900
vt 0.000100 0.000100
vn 0.000000 -0.000000 1.000000
s off
f 2/1/1 4/2/1 3/3/1
f 1/4/1 2/1/1 3/3/1
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4,6 +4,7 @@ uniform mat4 uModelMatrix;
uniform mat4 uViewProjectionMatrix;
uniform float uFar;
uniform float uTime;
in vec3 aNormal;
in vec3 aPosition;
......
#define LAST_SHADER TESSELATION
#pragma import "../CommonDeferredFrag.glsl"
#pragma import "../Utils.glsl"
vec4 color() {
return vec4(0, 0, 0, 1);
}
vec4 emissive() {
vec2 texCoord = teTexCoord;
if(uTime > 7.5) {
float time = (uTime - 7.5);
texCoord.x += time * 0.2 * min(time, 1);
}
float middle = pow(abs(texCoord.y-0.5), 0.5);
float octave01 = sin(texCoord.x * 100 + uTime) * 0.02;
float octave02 = sin(texCoord.x * 200 + 2 + uTime * 3) * 0.01;
float period = mod( abs(texCoord.x-0.5) + uTime * 0.2 + middle + octave01 + octave02, 0.4 );
vec4 res = vec4(2, 3 + sin(uTime * 0.6), 3 + cos(uTime*0.6), 1) * (0.1 + 0.6 * period) * 0.2;
res.a = 1;
return res * uEmissiveColor;
}
vec3 normal() {
return teNormal;
}
vec4 specularSmoothness() {
return vec4(0, 0, 0, 0);
}
#version 410 core
layout(vertices = 3) out;
in vec3 vPosition[];
in vec2 vTexCoord[];
in vec3 vNormal[];
out vec3 tNormal[];
out vec2 tTexCoord[];
out vec3 tPosition[];
//patch out vec3 tPosition;
//patch out vec3 tNormal;
//patch out vec2 tTexCoord;
#define ID gl_InvocationID
void main(){
tNormal[ID] = vNormal[ID];
tTexCoord[ID] = vTexCoord[ID];
tPosition[ID] = vPosition[ID];
if (ID == 0) {
gl_TessLevelInner[0] = 1;
gl_TessLevelOuter[0] = 1;
gl_TessLevelOuter[1] = 1;
gl_TessLevelOuter[2] = 1;
}
}
#version 410 core
layout(triangles, equal_spacing, ccw) in;
in vec2 tTexCoord[];
in vec3 tNormal[];
in vec3 tPosition[];
out vec3 teNormal;
out vec2 teTexCoord;
out vec3 tePosition;
uniform mat4 uViewProjectionMatrix;
uniform mat4 uModelMatrix;
vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2){
return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2;
}
vec3 interpolate3D(vec3 v0, vec3 v1, vec3 v2){
return vec3(gl_TessCoord.x) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2;
}
void main(){
teNormal = interpolate3D(tNormal[0], tNormal[1], tNormal[2]);
teNormal = normalize(teNormal);
teTexCoord = interpolate2D(tTexCoord[0], tTexCoord[1], tTexCoord[2]);
tePosition = interpolate3D(tPosition[0], tPosition[1], tPosition[2]);
gl_Position = uViewProjectionMatrix * vec4(tePosition, 1.0);
}
#pragma import "../CommonDeferredVert.glsl"
vec3 normal() {
return aNormal;
}
vec2 texCoord() {
return aTexCoord;
}
vec3 position() {
vec4 modelPos = vec4(aPosition, 1.0) ;
vec4 worldPosition = uModelMatrix * modelPos;
return worldPosition.xyz;
}
#define LAST_SHADER TESSELATION
#pragma import "../CommonDeferredFrag.glsl"
#pragma import "../Utils.glsl"
vec4 color() {
return vec4(0, 0, 0, 1);
}
vec4 emissive() {
vec4 res = vec4(0.6 + 0.5 * teTexCoord.x, 0.2 + 0.4 * teTexCoord.y, 0.2, 1) * (sin(uTime * 20) * cos(uTime * 2) * 0.5 + 1.4) * min(uTime/10 + 0.1, 1);
res.a = 1;
return res * uEmissiveColor;
}
vec3 normal() {
return teNormal;
}
vec4 specularSmoothness() {
return vec4(0, 0, 0, 0);
}
#version 410 core
layout(vertices = 3) out;
in vec3 vPosition[];
in vec2 vTexCoord[];
in vec3 vNormal[];
out vec3 tNormal[];
out vec2 tTexCoord[];
out vec3 tPosition[];
//patch out vec3 tPosition;
//patch out vec3 tNormal;
//patch out vec2 tTexCoord;
#define ID gl_InvocationID
void main(){
tNormal[ID] = vNormal[ID];
tTexCoord[ID] = vTexCoord[ID];
tPosition[ID] = vPosition[ID];
if (ID == 0) {
gl_TessLevelInner[0] = 1;
gl_TessLevelOuter[0] = 1;
gl_TessLevelOuter[1] = 1;
gl_TessLevelOuter[2] = 1;
}
}
#version 410 core
layout(triangles, equal_spacing, ccw) in;
in vec2 tTexCoord[];
in vec3 tNormal[];
in vec3 tPosition[];
out vec3 teNormal;
out vec2 teTexCoord;
out vec3 tePosition;
uniform mat4 uViewProjectionMatrix;
uniform mat4 uModelMatrix;
vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2){
return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2;
}
vec3 interpolate3D(vec3 v0, vec3 v1, vec3 v2){
return vec3(gl_TessCoord.x) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2;
}
void main(){
teNormal = interpolate3D(tNormal[0], tNormal[1], tNormal[2]);
teNormal = normalize(teNormal);
teTexCoord = interpolate2D(tTexCoord[0], tTexCoord[1], tTexCoord[2]);
tePosition = interpolate3D(tPosition[0], tPosition[1], tPosition[2]);
gl_Position = uViewProjectionMatrix * vec4(tePosition, 1.0);
}
#pragma import "../CommonDeferredVert.glsl"
vec3 normal() {
return aNormal;
}
vec2 texCoord() {
return aTexCoord;
}
vec3 position() {
vec4 modelPos = vec4(aPosition, 1.0) ;
vec4 worldPosition = uModelMatrix * modelPos;
return worldPosition.xyz;
}
......@@ -83,6 +83,8 @@ public:
return cameraTransform->position;
}
const bool* getKeyTable() { return m_keyState; };
std::string getParentName() {
if (parentEntity.valid() && parentEntity.has_component<Planet>()){
return parentEntity.component<Planet>()->name;
......
......@@ -17,6 +17,8 @@ private:
Entity sun;
Entity skybox;
Entity loadingText;
Entity earth;
Entity cockpit;
Entity cockpitSun;
......@@ -24,6 +26,7 @@ private:
Entity consoleCamera;
SoundSource::Handle consoleSoundSource;
SoundSource::Handle cockpitSoundSource;
Material cockpitMaterial, sunMaterial, skyboxMaterial;
Geometry cockpitGeometry, sunGeometry, skyboxGeometry;
......@@ -44,11 +47,16 @@ private:
bool isFocusedOnConsole = true;
bool didOneFrame = false;
public:
CONSTRUCT_SCENE(AtmosphereTestScene) { };
void switchToMainScene();
void loadMainSceneResources();
void switchConsole();
bool startup() override;
void shutdown() override;
};
\ No newline at end of file
#include <engine/scene/Scene.hpp>
#include <engine/scene/Transform.hpp>
#include <engine/scene/Drawable.hpp>
#include <engine/audio/SoundSource.hpp>
class Console {
private:
Entity cube;
enum class State {
FadingIn,
FadingTextOut,
MovingA,
Playing
};
State state = State::FadingIn;
float timer = 0;
const float FADE_IN_TIME = 3.0f;
const float FADE_OUT_TIME = 5.5f;
const float MOVE_A_TIME = 7.5f;
Entity text;
Entity background;
Entity letterW;
Entity soundSource;
Drawable::Handle textDrawable;
Drawable::Handle letterADrawable;
Drawable::Handle backgroundDrawable;
Transform::Handle letterATransform;
SoundSource::Handle soundSourceAudio;
Transform::Handle soundSourceTransform;
glm::dvec3 aStartPos;
glm::dvec3 aTargetPos;
glm::quat aStartRot;
glm::quat aTargetRot;
glm::dvec3 playerSpeed;
public:
EventSystem* m_events;
RendererSystem* m_renderer;
......@@ -10,7 +54,7 @@ public:
AudioSystem* m_audio;
void startup();
void update(const SimulateEvent& e);
bool update(const SimulateEvent& e, const bool* keyTable);
void pause();
void play();
};
\ No newline at end of file
......@@ -302,11 +302,6 @@ bool PlayerSystem::startup() {
}
void PlayerSystem::handleKeyboard(KeyboardEvent e) {
if (!m_hasControl) {
return;
}
if (e.originalEvent.key.repeat != 0) {
return;
}
......
......@@ -28,6 +28,36 @@ using namespace ACGL::OpenGL;
using namespace ACGL::Base;
using namespace ACGL::Utils;
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);
cockpitSoundSource->setVolume(0);
cockpitSoundSource->play();
} 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;
}
bool AtmosphereTestScene::startup() {
if (!Scene::startup()) {
return false;
......@@ -42,19 +72,40 @@ bool AtmosphereTestScene::startup() {
consoleCamera.assign<Transform>();
consoleCamera.assign<Camera>(50, 0.1, 50);
m_audio->setListener(consoleCamera);
m_renderer->setRenderPassActive("Main"_sh, false);
m_renderer->setRenderPassActive("Skybox"_sh, false);
m_renderer->addRenderPass(consoleCamera, "Console"_sh);
m_renderer->setRenderPassOnlyTexture("Console"_sh, true);
m_console.m_events = m_events;
m_console.m_renderer = m_renderer;
m_console.m_sceneGraph = m_sceneGraph;
m_console.m_audio = m_audio;
m_console.startup();
auto textTexture =
Texture2DFileManager::the()->get(Texture2DCreator("none.png"));
auto textGeom = Geometry{ VertexArrayObjectCreator("loading_text.obj").create() };
textGeom.vao->setMode(GL_PATCHES);
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,
textTexture, nullptr, nullptr, textShader,
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));
loadMainSceneResources();
switchToMainScene();
mainSceneRunning = true;
SDL_SetRelativeMouseMode(SDL_TRUE);
m_player->setHasControl(false);
......@@ -62,11 +113,30 @@ bool AtmosphereTestScene::startup() {
m_player->setRotation(CAM_CONSOLE_ROT);
m_events->subscribe<SimulateEvent>([this](const SimulateEvent &e) {
if (didOneFrame && !resourceLoadingFinished) {
loadMainSceneResources();
switchToMainScene();
m_renderer->setRenderPassOnlyTexture("Console"_sh, true);
m_console.startup();
}
didOneFrame = true;
if (!resourceLoadingFinished) {
return;
}
sunLight->dir = -glm::normalize(m_player->getWorldPosition());
cockpitSunLight->dir =
glm::vec3(glm::dvec4(sunLight->dir, 0) * m_player->getRotation());
m_console.update(e);
if (isFocusedOnConsole) {
if (m_console.update(e, m_player->getKeyTable())) {
switchConsole();
}
}
if (isInterpolatingCamera) {
double interpolationPercent = 1.0 - glm::pow(1 - interpolationTime / totalInterpolationTime, 2);
......@@ -74,7 +144,8 @@ bool AtmosphereTestScene::startup() {
interpolationPercent = 1.0 - glm::pow(1 - interpolationTime / totalInterpolationTime, 5);
consoleSoundSource->setVolume(1.0f - interpolationTime / totalInterpolationTime);
consoleSoundSource->setVolume((1.0f - interpolationTime / totalInterpolationTime) * 0.5);
cockpitSoundSource->setVolume(interpolationTime / totalInterpolationTime);
glm::quat rot = glm::slerp(camStartRot, camTargetRot, (float)interpolationPercent);
m_player->setRotation(glm::mat4_cast(rot));
......@@ -84,7 +155,9 @@ bool AtmosphereTestScene::startup() {
m_player->setRotation(glm::mat4_cast(camTargetRot));
isInterpolatingCamera = false;
m_player->setHasControl(true);
m_renderer->setRenderPassActive("Console"_sh, false);
consoleSoundSource->setVolume(0);
cockpitSoundSource->setVolume(1);
}
}
});
......@@ -99,32 +172,13 @@ bool AtmosphereTestScene::startup() {
m_player->setRotation(glm::mat4());
}
break;
case SDL_SCANCODE_SPACE:
case SDL_SCANCODE_RETURN:
if (e.originalEvent.key.type == SDL_KEYDOWN) {
if (isInterpolatingCamera) break;
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();
} else {
// TODO: Fix returning to console!
break;
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;
switchConsole();
}
case SDL_SCANCODE_R:
if (e.originalEvent.key.type == SDL_KEYDOWN) {
ShaderProgramFileManager::the()->updateAll();
}
default:
break;
......@@ -194,6 +248,10 @@ void AtmosphereTestScene::switchToMainScene() {
earth = m_orbitals->addPlanet(sunTransform, "Earth", 0.000002988,
0.009153735632184, 0.016713, 1.000000,
0.0000000, 0.00000, 4.93533, 0);
m_player->attachToParent(earth);
double r = earth.component<Transform>()->scale.x;
m_player->setPosition(glm::dvec3(0, 0, r * 1.2));
}
{
......@@ -208,6 +266,10 @@ void AtmosphereTestScene::switchToMainScene() {
cockpit.assign<Light>(glm::vec4(1, 1, 1, 0.2), glm::vec3(1, 0, 0),
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);
cockpitSun = m_sceneGraph->create();
cockpitSun.assign<Transform>();
cockpitSunLight =
......@@ -239,10 +301,14 @@ void AtmosphereTestScene::switchToMainScene() {
0, cockpitPassId);
console.assign<Transform>();
auto soundTrack = m_audio->createSound("chipzel - Spectra - 01 Spectra.mp3", SoundMode::MODE_2D);
soundTrack = m_audio->createSound("chipzel - Spectra - 01 Spectra.mp3", SoundMode::MODE_2D);
consoleSoundSource = console.assign<SoundSource>(soundTrack);
consoleSoundSource->setVolume(0.5);
consoleSoundSource->play();
}
loadingText.component<Drawable>()->visible = false;
loadingText.destroy();
}
void AtmosphereTestScene::loadMainSceneResources() {
......
......@@ -12,9 +12,6 @@
#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>
......@@ -23,33 +20,175 @@
void Console::startup() {
auto consolePassId = m_renderer->getRenderPassId("Console"_sh);
auto cubeTexture =
Texture2DFileManager::the()->get(Texture2DCreator("checkerboard.png"));
auto cubeGeom = Geometry{ VertexArrayObjectCreator("cube.obj").create() };
cubeGeom.vao->setMode(GL_PATCHES);
auto cubeShader =
ShaderProgramCreator("PBR")
.attributeLocations(cubeGeom.vao->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations())
.create();
auto wallHitSound = m_audio->createSound("wallHit.wav", SoundMode::MODE_3D);
auto cube = m_sceneGraph->create();
cube.assign<Drawable>(cubeGeom,
soundSource = m_sceneGraph->create();
soundSourceTransform = soundSource.assign<Transform>();
soundSourceAudio = soundSource.assign<SoundSource>(wallHitSound);
soundSourceAudio->setVolume(3);
auto textTexture =