Commit da111aed authored by Dario Seyb's avatar Dario Seyb

added basic cockpit

parent defc1419
This diff is collapsed.
#version 330
uniform sampler2D uSamplerColor;
in vec2 vTexCoord;
out vec4 oColor;
void main()
{
oColor = texture(uSamplerColor, vTexCoord);
}
#version 330
out vec2 vTexCoord;
const vec2 quad[4] = vec2[] (
vec2(-1.0, 1.0),
vec2(-1.0,-1.0),
vec2( 1.0, 1.0),
vec2( 1.0,-1.0)
);
void main()
{
vec2 p = quad[ gl_VertexID ];
vTexCoord = p * vec2(0.5, 0.5) + vec2(0.5, 0.5);
gl_Position = vec4(p, 0.0, 1.0);
}
......@@ -29,18 +29,18 @@ void main()
vec2 samplePos = vTexCoord-motion.xy;
vec3 history = texture(uSamplerHistory, vTexCoord).rgb;
vec4 history = texture(uSamplerHistory, vTexCoord);
float factor = 0.75;
vec3 current = texture(uSamplerColor, vTexCoord).rgb;
vec4 current = texture(uSamplerColor, vTexCoord);
vec3 minNeighbour = current;
vec3 maxNeighbour = current;
vec4 minNeighbour = current;
vec4 maxNeighbour = current;
for(int x = -1; x <= 1; x++) {
for(int y = -1; y <= 1; y++) {
vec3 sample = texture(uSamplerColor, vTexCoord + vec2(x, y)/vec2(1280, 720)).rgb;
vec4 sample = texture(uSamplerColor, vTexCoord + vec2(x, y)/vec2(1280, 720));
minNeighbour = min(minNeighbour, sample);
maxNeighbour = max(maxNeighbour, sample);
}
......@@ -48,5 +48,5 @@ void main()
history = clamp(history, minNeighbour, maxNeighbour);
oColor = vec4(mix(current, history, factor), 1);
oColor = mix(current, history, factor);
}
......@@ -13,5 +13,6 @@ struct Camera : Component<Camera> {
float far;
glm::dvec3 worldUp;
bool isMain;
uint32_t renderPassIndex;
};
......@@ -33,6 +33,8 @@ struct RenderPass {
Stack<DrawCall> submittedDrawCallsOpaque;
Stack<DrawCall> submittedDrawCallsTransparent;
Stack<LightData> submittedLights;
ACGL::OpenGL::SharedFrameBufferObject compositingTarget;
ACGL::OpenGL::SharedFrameBufferObject txaaHistory;
Entity camera;
};
......@@ -77,6 +79,7 @@ private:
SharedShaderProgram m_deferredCombineProgram;
SharedShaderProgram m_blitProgram;
SharedShaderProgram m_passBlitProgram;
SharedShaderProgram m_shadowMapProg;
SharedShaderProgram m_pbrProg;
......@@ -105,7 +108,20 @@ public:
void shutdown() override;
void addRenderPass(Entity cam) {
m_passes.push_back({ kilobytes(4), kilobytes(4), kilobytes(4), cam });
cam.component<Camera>()->renderPassIndex = m_passes.size();
auto target = SharedFrameBufferObject(new FrameBufferObject());
target->attachColorTexture("oColor", createScreenspaceTexture(ScreenSpaceSize::FULL, GL_RGBA32F));
target->validate();
auto txaa = SharedFrameBufferObject(new FrameBufferObject());
txaa->attachColorTexture("oColor", createScreenspaceTexture(ScreenSpaceSize::FULL, GL_RGBA32F));
txaa->validate();
m_passes.push_back({ kilobytes(4), kilobytes(4), kilobytes(4), target, txaa, cam });
}
inline size_t getNumPasses() {
return m_passes.size();
}
inline void submit(DrawCall drawCall, RenderQueue queue, uint32_t passIndex = 0) {
......
......@@ -12,6 +12,7 @@ private:
Light::Handle sunLight;
Entity sun;
Entity earth;
Entity cockpit;
public:
CONSTRUCT_SCENE(AtmosphereTestScene) { };
......
......@@ -78,6 +78,7 @@ void BloomPostFX::apply(ACGL::OpenGL::ConstSharedTextureBase inputBuffer, ACGL::
m_extractProgram->setTexture("uSamplerColor", inputBuffer, 0);
m_extractProgram->setUniform("uThreshold", 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glGetError();
std::array<glm::vec2, 15> offsets;
......@@ -93,6 +94,7 @@ void BloomPostFX::apply(ACGL::OpenGL::ConstSharedTextureBase inputBuffer, ACGL::
}
m_blurProgram->setUniform("uSampleOffsets", offsets.size(), offsets.data());
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glGetError();
// Blur vertically
m_extractBuffer->bind();
......@@ -104,6 +106,7 @@ void BloomPostFX::apply(ACGL::OpenGL::ConstSharedTextureBase inputBuffer, ACGL::
}
m_blurProgram->setUniform("uSampleOffsets", offsets.size(), offsets.data());
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glGetError();
// Mix with input
......
......@@ -121,10 +121,9 @@ bool RendererSystem::startup() {
m_deferredCombineProgram = ShaderProgramFileManager::the()->get(ShaderProgramCreator("DeferredCombine"));
m_blitProgram = ShaderProgramFileManager::the()->get(ShaderProgramCreator("Blit"));
m_passBlitProgram = ShaderProgramFileManager::the()->get(ShaderProgramCreator("PassBlit"));
m_shadowMapProg = ShaderProgramFileManager::the()->get(ShaderProgramCreator("ShadowMap"));
m_txaaProg = ShaderProgramFileManager::the()->get(ShaderProgramCreator("TXAA").fragmentDataLocations(m_postfxTargetBuffer->getAttachmentLocations()));
m_txaaProg = ShaderProgramFileManager::the()->get(ShaderProgramCreator("TXAA").fragmentDataLocations(m_primaryCompositingBuffer->getAttachmentLocations()));
m_tfShaderProg = ShaderProgramFileManager::the()->get(ShaderProgramCreator("TerrainTransformFeedback"));
......@@ -249,6 +248,7 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
currentOffset.x /= gBufferRes.x;
currentOffset.y /= gBufferRes.y;
currentOffset.z = 0;
aaProj = glm::perspectiveFov<float>(glm::radians(cam->fov), windowSize.x, windowSize.y, cam->near, cam->far);
glm::mat4 viewProjectionMatrix = glm::translate(currentOffset) * aaProj * glm::inverse(camTransform);
......@@ -264,7 +264,7 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
// First pass - render to the transform feedback buffer:
//glEnable(GL_RASTERIZER_DISCARD);
PrimitiveQuery *q = new PrimitiveQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
//PrimitiveQuery *q = new PrimitiveQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
for (size_t i = 0; i < pass.submittedDrawCallsOpaque.size(); i++) {
......@@ -400,14 +400,16 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
counterStart = SDL_GetPerformanceCounter();
// Deferred lighting (accumulation)
m_primaryCompositingBuffer->bind();
pass.compositingTarget->setClearColor(glm::vec4{ 0, 0, 0, 0 });
pass.compositingTarget->bind();
pass.compositingTarget->clearBuffers();
glDisable(GL_DEPTH_TEST);
//glDepthMask(GL_FALSE);
glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);
glCullFace(GL_BACK);
auto compositingRes = glm::vec2(m_primaryCompositingBuffer->getSize());
auto compositingRes = glm::vec2(pass.compositingTarget->getSize());
glViewport(0, 0, compositingRes.x, compositingRes.y);
m_deferredCombineProgram->use();
......@@ -503,6 +505,41 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
glDisable(GL_DEPTH_TEST);
glCullFace(GL_BACK);
// TXAA
glDisable(GL_BLEND);
pass.compositingTarget->bind();
m_txaaProg->use();
m_txaaProg->setTexture(
"uSamplerColor", pass.compositingTarget->getColorAttachments()[0].texture,
0);
m_txaaProg->setTexture(
"uSamplerHistory", pass.txaaHistory->getColorAttachments()[0].texture,
1);
m_txaaProg->setTexture("uSamplerMotion", m_motionBuffer, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // create 2 triangles (defined in shader) with no attributes
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
m_primaryCompositingBuffer->bind();
m_passBlitProgram->use();
m_passBlitProgram->setTexture(
"uSamplerColor", pass.compositingTarget->getColorAttachments()[0].texture,
0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // create 2 triangles (defined in shader) with no attributes
// Swap TAA buffers
auto temp = pass.compositingTarget;
pass.compositingTarget = pass.txaaHistory;
pass.txaaHistory = temp;
trans->lastRenderTransform = camTransform;
pass.submittedDrawCallsOpaque.reset();
......@@ -518,6 +555,7 @@ void RendererSystem::frame(double interp, double totalTime) {
for (auto& pass : m_passes) {
render(pass, interp, totalTime);
glGetError();
}
m_totalLightCount = 0;
......@@ -528,33 +566,8 @@ void RendererSystem::frame(double interp, double totalTime) {
Uint64 counterStart = SDL_GetPerformanceCounter();
// TXAA
glBlendFunc(GL_ONE, GL_ONE);
m_postfxTargetBuffer->setClearColor(glm::vec4{ 0, 0, 0, 0 });
m_postfxTargetBuffer->bind();
m_postfxTargetBuffer->clearBuffers();
glDisable(GL_BLEND);
m_txaaProg->use();
m_txaaProg->setTexture(
"uSamplerColor", m_primaryCompositingBuffer->getColorAttachments()[0].texture,
0);
m_txaaProg->setTexture(
"uSamplerHistory", m_txaaHistoryBuffer->getColorAttachments()[0].texture,
1);
m_txaaProg->setTexture("uSamplerMotion", m_motionBuffer, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // create 2 triangles (defined in shader) with no attributes
// Swap TAA buffers
auto temp = m_txaaHistoryBuffer;
m_txaaHistoryBuffer = m_postfxTargetBuffer;
m_postfxTargetBuffer = temp;
for (auto& fx : m_effects) {
fx->apply(m_postfxTargetBuffer->getColorAttachments()[0].texture, m_primaryCompositingBuffer);
fx->apply(m_primaryCompositingBuffer->getColorAttachments()[0].texture, m_postfxTargetBuffer);
auto temp = m_primaryCompositingBuffer;
m_primaryCompositingBuffer = m_postfxTargetBuffer;
......@@ -566,7 +579,7 @@ void RendererSystem::frame(double interp, double totalTime) {
m_blitProgram->use();
m_blitProgram->setTexture(
"uSamplerColor", m_postfxTargetBuffer->getColorAttachments()[0].texture,
"uSamplerColor", m_primaryCompositingBuffer->getColorAttachments()[0].texture,
0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // create 2 triangles (defined in shader) with no attributes
......
......@@ -196,8 +196,8 @@ bool PlayerSystem::startup() {
cameraTransform->position = glm::dvec3(0, 0, 1000);
m_cockpitCamera = m_scene->create();
m_cockpitCamera.assign<Transform>();
m_cockpitCamera.assign<Camera>(75, 0.1f, 200000000);
m_cockpitCamera.assign<Transform>()->position = glm::dvec3(0, 0, 0);
m_cockpitCamera.assign<Camera>(50, 0.01f, 50);
m_renderer->addRenderPass(m_mainCamera);
m_renderer->addRenderPass(m_cockpitCamera);
......
......@@ -74,19 +74,16 @@ void SceneGraphSystem::prepareDraw(double interp) {
auto drawableEntities = m_entityManager.entities_with_components<Drawable, Transform>();
// Only works if we have just ONE camera
auto cameras = m_entityManager.entities_with_components<Camera>();
glm::dvec3 cam;
std::vector<glm::dvec3> cams(m_renderer->getNumPasses());
for (auto e : cameras) {
if (e.component<Camera>()->isMain) {
cam = e.component<Transform>()->thisGlobalTransform.pos;
}
cams[e.component<Camera>()->renderPassIndex] = e.component<Transform>()->thisGlobalTransform.pos;
}
Drawable::Handle drawable;
for (auto e : drawableEntities) {
e.unpack<Drawable, Transform>(drawable, transform);
auto thisRenderTransform = interpolate(transform->lastGlobalTransform, transform->thisGlobalTransform, interp, cam);
auto thisRenderTransform = interpolate(transform->lastGlobalTransform, transform->thisGlobalTransform, interp, cams[drawable->renderPassIndex]);
if (drawable->visible) {
m_renderer->submit({ drawable->material, drawable->geometry, transform->lastRenderTransform, thisRenderTransform, drawable->recursionDepth }, drawable->material.queue, drawable->renderPassIndex);
}
......
......@@ -43,7 +43,7 @@ bool AtmosphereTestScene::startup() {
auto checkboardTexture = Texture2DFileManager::the()->get(Texture2DCreator("checkerboard.png"));
// look up all shader files starting with 'PBR' and build a ShaderProgram from it:
auto pbrShader = ShaderProgramCreator("PBR")
auto sunShader = ShaderProgramCreator("PBR")
.attributeLocations(vaoSun->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations()).create();
......@@ -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, 1 }, checkboardTexture, pbrShader, false, RenderQueue::OPAQUE };
Material sunMaterial = { glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 2, 2, 1, 1 }, checkboardTexture, sunShader, false, RenderQueue::OPAQUE };
// Let's create a placeholder sun
sun = m_sceneGraph->create();
......@@ -69,6 +69,24 @@ bool AtmosphereTestScene::startup() {
// mass radius e a i N w
earth = m_orbitals->addPlanet(sunTransform, "Earth", 0.000002988, 0.009153735632184, 0.016713, 1.000000, 0.0000000, 0.00000, 4.93533, 0);
// create cockpit
auto vaoCockpit = VertexArrayObjectCreator("cockpit.obj").create();
auto cockpitShader = ShaderProgramCreator("PBR")
.attributeLocations(vaoCockpit->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations()).create();
Material cockpitMaterial{ glm::vec4{1, 1, 1, 1}, glm::vec4{0.05, 0.05, 0.05, 1}, checkboardTexture, cockpitShader, true, RenderQueue::OPAQUE };
Geometry cockpitGeom{ vaoCockpit };
cockpitGeom.vao->setMode(GL_PATCHES);
cockpit = m_sceneGraph->create();
auto cockpitDrawable = cockpit.assign<Drawable>(cockpitGeom, cockpitMaterial);
auto cockpitTransform = cockpit.assign<Transform>();
cockpitTransform->position = glm::dvec3(0, 0, 0);
cockpitDrawable->renderPassIndex = 1;
cockpitDrawable->visible = true;
auto cockpitLight = cockpit.assign<Light>(glm::vec4(1, 1, 1, 1), glm::vec3(1, 0, 0), false, LightType::POINT, 1);
m_events->subscribe<SimulateEvent>([this](const SimulateEvent& e) {
sunLight->dir = -glm::normalize(m_player->getWorldPosition());
});
......
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