Commit ff20c3cb authored by Dario Seyb's avatar Dario Seyb

added shadows in the cockpit

parent 3e95f4ba
......@@ -58,6 +58,7 @@ float shadowFactor(vec3 worldPosition) {
if(!uLightHasShadow) return 1;
vec3 shadowCoord = projShadowCoord(worldPosition.xyz);
float x,y;
float shadow = 0;
for (y = -1.5 ; y <=1.5 ; y+=1.0) {
......@@ -68,7 +69,7 @@ float shadowFactor(vec3 worldPosition) {
shadow /= 16.0 ;
return shadow;
return shadow;
}
void main()
......@@ -102,5 +103,5 @@ void main()
float lightNdotL = max(0, dot(lightDir, normal));
vec4 lighting = BRDF (albedo.rgb, specularSmoothness.rgb, oneMinusReflectivity, specularSmoothness.a, normal, viewDir, lightDir, lightNdotL, uLightColor.rgb * uLightColor.a);
oColor = vec4(lighting.rgb + emissive.rgb, uOneOverLightCount * albedo.a);
oColor = vec4(lighting.rgb * shadowFactor(worldPosition) + emissive.rgb, uOneOverLightCount * albedo.a);
}
#version 330 core
#version 410 core
in vec3 vPosition;
in vec2 vTexCoord;
in vec3 tPosition;
in vec2 tTexCoord;
uniform sampler2D uTexture;
uniform vec4 uTintColor;
......@@ -9,17 +10,7 @@ uniform float uTime;
layout(location = 0) out vec4 oDepth;
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main()
{
vec4 color = texture(uTexture, vTexCoord).rgba * uTintColor;
float sample = rand(gl_FragCoord.xy * vPosition.xy + vec2(uTime));
if(sample > color.a) discard;
oDepth = vec4(vec3(gl_FragCoord.z), 1);
}
#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);
}
#version 330 core
#version 410 core
uniform mat4 uModelMatrix;
uniform mat4 uViewProjectionMatrix;
......
......@@ -53,7 +53,7 @@ private:
std::vector<std::shared_ptr<PostFX>> m_effects;
const int SHADOW_MAP_COUNT = 10;
const int SHADOW_MAP_COUNT = 2;
std::vector<ACGL::OpenGL::SharedFrameBufferObject> m_shadowMaps;
ACGL::OpenGL::SharedTexture2D m_dummyShadowMap;
......@@ -180,9 +180,9 @@ public:
if (light.castShadow && m_totalLightCount < m_shadowMaps.size()) {
light.shadowFbo = m_shadowMaps[m_totalLightCount];
light.shadowMap = light.shadowFbo->getDepthAttachment().texture;
m_totalLightCount++;
}
m_totalLightCount++;
m_passes[passIndex].submittedLights.push(light);
}
......
......@@ -19,7 +19,7 @@ using namespace ACGL::OpenGL;
using namespace ACGL::Base;
using namespace ACGL::Utils;
const glm::vec2 SHADOW_MAP_RESOLUTION = {512, 512};
const glm::vec2 SHADOW_MAP_RESOLUTION = { 2048, 2048 };
glm::mat4 interpolate(TransformData a, TransformData b, double t, glm::dvec3 camPos) {
a.pos = a.pos - camPos;
......@@ -418,6 +418,13 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
auto drawCall = pass.submittedDrawCallsOpaque[i];
if (drawCall.material.castShadow) {
if (drawCall.material.cullSide == GL_NONE) {
glDisable(GL_CULL_FACE);
} else {
glEnable(GL_CULL_FACE);
glCullFace(drawCall.material.cullSide);
}
m_shadowMapProg->setUniform("uTintColor", drawCall.material.tintColor);
m_shadowMapProg->setUniform("uModelMatrix", static_cast<glm::mat4>(drawCall.thisRenderTransform));
drawCall.geometry.vao->render();
......@@ -431,7 +438,8 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
// Deferred lighting (accumulation)
m_secondaryCompositingBuffer->setClearColor(glm::vec4{ 0, 0, 0, 0 });
m_secondaryCompositingBuffer->bind();
m_secondaryCompositingBuffer->clearBuffers();
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
//glDepthMask(GL_FALSE);
glBlendFunc(GL_ONE, GL_ONE);
......
......@@ -101,8 +101,8 @@ void SceneGraphSystem::prepareDraw(double interp) {
for (auto e : lightEntities) {
e.unpack<Light, Transform>(light, transform);
auto viewMatrix = glm::mat4(); // glm::lookAt<float>(-light->dir, { 0,0,0 }, glm::vec3(0.0f, 1.0f, 0.0f));
auto lightVP = glm::ortho<double>(-15.0, +15.0, -15.0, 15.0, -15, 15) * static_cast<glm::dmat4>(viewMatrix);
auto viewMatrix = glm::lookAt<double>(glm::dvec3(light->dir), { 0.0, 0.0, 0.0 }, glm::dvec3(0.0, 1.0, 0.0));
auto lightVP = glm::ortho<double>(-10, +10, -10, +10, -10, 10) * static_cast<glm::dmat4>(viewMatrix);
m_renderer->submit({light->color, light->castShadow,light->dir, light->type, transform->lastGlobalTransform, transform->thisGlobalTransform, lightVP, nullptr, nullptr}, light->renderPassIndex);
}
......
......@@ -132,8 +132,6 @@ bool AtmosphereTestScene::startup() {
return;
}
sunLight->dir = -glm::normalize(m_player->getWorldPosition());
cockpitSunLight->dir =
glm::vec3(glm::dvec4(sunLight->dir, 0) * m_player->getShipRotation());
......@@ -327,7 +325,7 @@ void AtmosphereTestScene::switchToMainScene() {
consoleGeom,
Material{glm::vec4{1, 1, 1, 1}, glm::vec4{1, 1, 1, 1},
m_renderer->getRenderPassTarget("Console"_sh), nullptr, nullptr,
skyboxMaterial.prog, false, RenderQueue::OPAQUE, GL_BACK},
skyboxMaterial.prog, false, RenderQueue::OPAQUE, GL_NONE},
0, cockpitPassId);
auto consoleTransform = console.assign<Transform>();
......@@ -344,7 +342,7 @@ void AtmosphereTestScene::switchToMainScene() {
consoleGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
m_renderer->getRenderPassTarget("Console"_sh), nullptr, nullptr,
skyboxMaterial.prog, false, RenderQueue::OPAQUE, GL_BACK },
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
0, cockpitPassId);
consoleFront.assign<Transform>();
......@@ -355,7 +353,7 @@ void AtmosphereTestScene::switchToMainScene() {
consoleGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
m_renderer->getRenderPassTarget("Minimap"_sh), nullptr, nullptr,
skyboxMaterial.prog, false, RenderQueue::OPAQUE, GL_BACK },
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
0, cockpitPassId);
consoleBack.assign<Transform>();
......@@ -366,7 +364,7 @@ void AtmosphereTestScene::switchToMainScene() {
consoleGeom,
Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 1, 1, 1, 1 },
m_renderer->getRenderPassTarget("Console"_sh), nullptr, nullptr,
skyboxMaterial.prog, false, RenderQueue::OPAQUE, GL_BACK },
skyboxMaterial.prog, true, RenderQueue::OPAQUE, GL_NONE },
0, cockpitPassId);
consoleMiddle.assign<Transform>();
......@@ -451,7 +449,7 @@ void AtmosphereTestScene::loadMainSceneResources() {
Texture2DCreator("cockpit_v2/cockpit_v2_outer_DefaultMaterial_Normal.png")),
Texture2DFileManager::the()->get(Texture2DCreator(
"cockpit_v2/cockpit_v2_outer_DefaultMaterial_SpecularSmoothness.png")),
cockpitShader, true, RenderQueue::OPAQUE, GL_BACK};
cockpitShader, true, RenderQueue::OPAQUE, GL_NONE };
cockpitGeometry = {vaoCockpit};
cockpitGeometry.vao->setMode(GL_PATCHES);
......
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