Commit 77a29210 authored by Dario Seyb's avatar Dario Seyb

look around in the cockpit using the arrow keys

parent d4d2890a
......@@ -5,6 +5,10 @@ in vec2 teTexCoord;
in vec3 tePosition;
uniform sampler2D uTexture;
uniform bool uHasNormalMap;
uniform sampler2D uNormalMap;
uniform vec4 uEmissiveColor;
uniform vec4 uTintColor;
uniform float uTime;
......@@ -40,7 +44,7 @@ void main()
vec4 prevPosition = uPrevViewProjectionMatrix * uPrevModelMatrix * inverse(uModelMatrix) * vec4(tePosition, 1);
vec3 prevFragCoord = prevPosition.xyz/prevPosition.w;
vec3 thisFragCoord = thisPosition.xyz/thisPosition.w;
vec3 thisFragCoord = thisPosition.xyz/thisPosition.w;
oMotion = (thisFragCoord-prevFragCoord)*0.5;
oMotion.z = thisPosition.z;
......
......@@ -25,9 +25,7 @@ uniform mat4 uViewProjectionInverseMatrix;
in vec2 vTexCoord;
out vec4 oColor;
vec3 unpackNormal(vec4 norm) {
return norm.xyz; //(norm.xyz * 2) - vec3(1, 1, 1);
}
#pragma import "Utils.glsl"
float linearizeDepth(float depth) {
return (2.0 * uNear) / (uFar + uNear - depth * (uFar - uNear)); // convert to linear values
......@@ -73,7 +71,7 @@ void main()
{
vec4 color = texture(uSamplerColor, vTexCoord);
vec4 emissive = texture(uSamplerEmissive, vTexCoord);
vec3 normal = unpackNormal(texture(uSamplerNormal, vTexCoord));
vec3 normal = texture(uSamplerNormal, vTexCoord).rgb;
float depth = unpackDepth(texture(uSamplerDepth, vTexCoord).r);
......
#pragma import "CommonDeferredFrag.glsl"
#pragma import "Utils.glsl"
vec4 color() {
return texture(uTexture, teTexCoord).rgba * uTintColor;
......@@ -9,5 +10,9 @@ vec4 emissive() {
}
vec3 normal() {
if(uHasNormalMap) {
vec3 tangentNormal = unpackNormal(texture(uNormalMap, teTexCoord));
return tangentNormal;
}
return teNormal;
}
vec3 unpackNormal(vec4 norm) {
return norm.xyz * 2 - vec3(1, 1, 1);
}
......@@ -7,7 +7,7 @@
struct Camera : Component<Camera> {
explicit Camera() : fov(75), near(0.1f), far(100), worldUp(glm::dvec3(0, 1, 0)), isMain(false), renderPassIndex(std::numeric_limits<uint32_t>::max()) {}
explicit Camera(float fov, float near, float far, glm::dvec3 up = glm::dvec3(0, 1, 0), bool isMain = false, bool passIndex = std::numeric_limits<uint32_t>::max())
explicit Camera(float fov, float near, float far, glm::dvec3 up = glm::dvec3(0, 1, 0), bool isMain = false, uint32_t passIndex = std::numeric_limits<uint32_t>::max())
: fov(fov), near(near), far(far), worldUp(up), isMain(isMain), renderPassIndex(passIndex) { }
float fov;
float near;
......
......@@ -10,6 +10,7 @@ struct Material {
glm::vec4 tintColor;
glm::vec4 emissiveColor;
SharedTexture2D mainTexture;
SharedTexture2D normalTexture;
SharedShaderProgram prog;
bool castShadow;
RenderQueue queue;
......
......@@ -33,6 +33,7 @@ private:
Entity parentEntity;
Transform::Handle cameraTransform;
Transform::Handle cockpitCamTransform;
Camera::Handle camera;
......
......@@ -324,6 +324,14 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
drawCall.material.prog->use();
drawCall.material.prog->setTexture("uTexture", drawCall.material.mainTexture, 0);
if (drawCall.material.normalTexture) {
drawCall.material.prog->setTexture("uNormalMap", drawCall.material.normalTexture, 1);
drawCall.material.prog->setUniform("uHasNormalMap", true);
} else {
drawCall.material.prog->setUniform("uHasNormalMap", false);
}
drawCall.material.prog->setUniform("uFar", cam->far);
drawCall.material.prog->setUniform("uTime", (float)totalTime);
drawCall.material.prog->setUniform("uTintColor", drawCall.material.tintColor);
......
......@@ -60,13 +60,13 @@ bool OrbitalSimulationSystem::startup() {
.fragmentDataLocations(m_renderer->getGBufferLocations()));
planetMat = { glm::vec4(1, 1, 1, 1), glm::vec4(0, 0, 0, 1), texture, dispMappingShader, 1, RenderQueue::OPAQUE };
planetMat = { glm::vec4(1, 1, 1, 1), glm::vec4(0, 0, 0, 1), texture, nullptr, dispMappingShader, 1, RenderQueue::OPAQUE };
trajectoryMat = { glm::vec4(1, 1, 1, 1), glm::vec4(1, 0, 0, 1), texture, testShader, 0, RenderQueue::OPAQUE };
trajectoryMat = { glm::vec4(1, 1, 1, 1), glm::vec4(1, 0, 0, 1), texture, nullptr, testShader, 0, RenderQueue::OPAQUE };
atmosphereMat = { glm::vec4(0, 0, 1, 0.9f), glm::vec4(0, 0, .2, 1), texture, atmosphereShader, 0, RenderQueue::TRANSPARENT };
atmosphereMat = { glm::vec4(0, 0, 1, 0.9f), glm::vec4(0, 0, .2, 1), texture, nullptr, atmosphereShader, 0, RenderQueue::TRANSPARENT };
waterMat = { glm::vec4(0, 0.2, 0.8, 1), glm::vec4(0, 0, .2, 1), texture, waterShader, 0, RenderQueue::OPAQUE };
waterMat = { glm::vec4(0, 0.2, 0.8, 1), glm::vec4(0, 0, .2, 1), texture, nullptr, waterShader, 0, RenderQueue::OPAQUE };
return true;
}
......
......@@ -191,12 +191,13 @@ bool PlayerSystem::startup() {
// Create an entity that is used to position the camera in the scene
m_mainCamera = m_scene->create();
cameraTransform = m_mainCamera.assign<Transform>();
camera = m_mainCamera.assign<Camera>(75, 1, 20000000);
camera = m_mainCamera.assign<Camera>(50, 1, 20000000);
camera->isMain = true;
cameraTransform->position = glm::dvec3(0, 0, 1000);
m_cockpitCamera = m_scene->create();
m_cockpitCamera.assign<Transform>()->position = glm::dvec3(0, 0, 0);
cockpitCamTransform = m_cockpitCamera.assign<Transform>();
cockpitCamTransform->position = glm::dvec3(0, 0, 0);
m_cockpitCamera.assign<Camera>(50, 0.01f, 50);
m_renderer->addRenderPass(m_mainCamera);
......@@ -322,9 +323,13 @@ void PlayerSystem::update(float dt) {
if (m_keyState[SDL_SCANCODE_UP]) rotDir += glm::dvec2(0, 1);
if (m_keyState[SDL_SCANCODE_DOWN]) rotDir -= glm::dvec2(0, 1);
auto up = rotate(glm::dvec3(0, 1, 0), glm::inverse(cockpitCamTransform->rotation));
cockpitCamTransform->rotation = glm::rotate(cockpitCamTransform->rotation, rotDir.x * 0.05, up);
cockpitCamTransform->rotation = glm::rotate(cockpitCamTransform->rotation, rotDir.y * 0.05, glm::dvec3(1, 0, 0));
// Rotate the camera based on the mouse movement
auto up = rotate(camera->worldUp, glm::inverse(cameraTransform->rotation));
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, rotDir.x * 0.05, glm::dvec3(0, 1, 0));
//up = rotate(camera->worldUp, glm::inverse(cameraTransform->rotation));
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, rotDir.x * 0.05, up);
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, rotDir.y * 0.05, glm::dvec3(1, 0, 0));
if (moveDir.x != 0 || moveDir.y || moveDir.z != 0 ) {
......
......@@ -52,7 +52,7 @@ bool AtmosphereTestScene::startup() {
geom1.vao->setMode(GL_PATCHES);
// Create a material that uses the loaded shader program
Material sunMaterial = { glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 2, 2, 1, 20 }, checkboardTexture, sunShader, false, RenderQueue::OPAQUE };
Material sunMaterial = { glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 2, 2, 1, 20 }, checkboardTexture, nullptr, sunShader, false, RenderQueue::OPAQUE };
// Let's create a placeholder sun
sun = m_sceneGraph->create();
......@@ -76,7 +76,13 @@ bool AtmosphereTestScene::startup() {
.attributeLocations(vaoCockpit->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations()).create();
Material cockpitMaterial{ glm::vec4{0.4, 0.4, 0.4, 1}, glm::vec4{0, 0, 0, 1}, checkboardTexture, cockpitShader, true, RenderQueue::OPAQUE };
Material cockpitMaterial{ glm::vec4{0.4, 0.4, 0.4, 1}, glm::vec4{0, 0, 0, 1},
checkboardTexture,
Texture2DFileManager::the()->get(Texture2DCreator("cockpit/DefaultMaterial_Normal_OpenGL.png")),
cockpitShader,
true,
RenderQueue::OPAQUE };
Geometry cockpitGeom{ vaoCockpit };
cockpitGeom.vao->setMode(GL_PATCHES);
cockpit = m_sceneGraph->create();
......@@ -85,7 +91,7 @@ bool AtmosphereTestScene::startup() {
cockpitTransform->position = glm::dvec3(0, 0, 0);
cockpitDrawable->renderPassIndex = 1;
cockpitDrawable->visible = true;
auto cockpitLight = cockpit.assign<Light>(glm::vec4(1, 1, 1, 0.2), glm::vec3(1, 0, 0), false, LightType::POINT, 1);
auto cockpitLight = cockpit.assign<Light>(glm::vec4(1, 1, 1, 0.5), glm::vec3(1, 0, 0), false, LightType::POINT, 1);
auto blinkButton = m_sceneGraph->create();
blinkButton.assign<Light>(glm::vec4(1, 0.2, 0.2, 2), glm::vec3(1, 0, 0), false, LightType::POINT, 1);
......
......@@ -60,8 +60,8 @@ bool OrbitsScene::startup() {
Geometry geom2 = { vaoTeapot };
// Create a material that uses the loaded shader program
Material sunMaterial = { glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 2, 2, 1, 1 }, checkboardTexture, pbrShader, false, RenderQueue::OPAQUE };
Material transparentMat = { glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 0, 0, 0, 1 }, testTransparencyTexture, pbrShader, false, RenderQueue::TRANSPARENT };
Material sunMaterial = { glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 2, 2, 1, 1 }, checkboardTexture, nullptr, pbrShader, false, RenderQueue::OPAQUE };
Material transparentMat = { glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 0, 0, 0, 1 }, testTransparencyTexture, nullptr, pbrShader, false, RenderQueue::TRANSPARENT };
// Let's create a placeholder sun
auto scene = m_sceneGraph->create();
......
......@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
// If you try to initialize a system before it's dependencies you'll get an error message in the console
Context context;
WindowSystem window(&context, 1280, 720);
SettingsSystem settings(&context, "data/", "geometry/", "geometry/", "shader/", "sound/");
SettingsSystem settings(&context, "data/", "textures/", "geometry/", "shader/", "sound/");
EventSystem events(&context);
RendererSystem renderer(&context);
SceneGraphSystem sceneGraph(&context);
......
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