improve shading & enable disabled elements
This commit is contained in:
@@ -111,6 +111,7 @@ GBuffer::~GBuffer() {
|
||||
|
||||
void GBuffer::bind() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void GBuffer::unbind() {
|
||||
|
||||
@@ -72,17 +72,21 @@ void PostProcessing::use(DrawContext& context, bool gbufferPipeline) {
|
||||
}
|
||||
context.setFramebuffer(gbuffer.get());
|
||||
} else {
|
||||
if (fbo) {
|
||||
fbo->resize(vp.x, vp.y);
|
||||
fboSecond->resize(vp.x, vp.y);
|
||||
} else {
|
||||
fbo = std::make_unique<Framebuffer>(vp.x, vp.y);
|
||||
fboSecond = std::make_unique<Framebuffer>(vp.x, vp.y);
|
||||
}
|
||||
refreshFbos(vp.x, vp.y);
|
||||
context.setFramebuffer(fbo.get());
|
||||
}
|
||||
}
|
||||
|
||||
void PostProcessing::refreshFbos(uint width, uint height) {
|
||||
if (fbo) {
|
||||
fbo->resize(width, height);
|
||||
fboSecond->resize(width, height);
|
||||
} else {
|
||||
fbo = std::make_unique<Framebuffer>(width, height);
|
||||
fboSecond = std::make_unique<Framebuffer>(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void PostProcessing::configureEffect(
|
||||
const DrawContext& context,
|
||||
Shader& shader,
|
||||
@@ -127,6 +131,9 @@ void PostProcessing::render(
|
||||
totalPasses += (effect != nullptr && effect->isActive());
|
||||
}
|
||||
|
||||
const auto& vp = context.getViewport();
|
||||
refreshFbos(vp.x, vp.y);
|
||||
|
||||
if (gbuffer) {
|
||||
gbuffer->bindBuffers();
|
||||
|
||||
@@ -157,7 +164,9 @@ void PostProcessing::render(
|
||||
auto& shader = effect->use();
|
||||
configureEffect(context, shader, timer, camera, shadowMap);
|
||||
|
||||
fbo->getTexture()->bind();
|
||||
if (currentPass > 1) {
|
||||
fbo->getTexture()->bind();
|
||||
}
|
||||
|
||||
if (currentPass < totalPasses) {
|
||||
fboSecond->bind();
|
||||
|
||||
@@ -64,6 +64,8 @@ private:
|
||||
uint shadowMap
|
||||
);
|
||||
|
||||
void refreshFbos(uint width, uint height);
|
||||
|
||||
/// @brief Main framebuffer (lasy field)
|
||||
std::unique_ptr<Framebuffer> fbo;
|
||||
std::unique_ptr<Framebuffer> fboSecond;
|
||||
|
||||
@@ -137,6 +137,8 @@ void WorldRenderer::setupWorldShader(
|
||||
|
||||
if (gbufferPipeline) {
|
||||
shader.uniformMatrix("u_shadowsMatrix", shadowCamera->getProjView());
|
||||
shader.uniform3f("u_sunDir", shadowCamera->front);
|
||||
shader.uniform1i("u_shadowsRes", shadowMap->getResolution());
|
||||
glActiveTexture(GL_TEXTURE4);
|
||||
shader.uniform1i("u_shadows", 4);
|
||||
glBindTexture(GL_TEXTURE_2D, shadowMap->getDepthMap());
|
||||
@@ -373,11 +375,11 @@ void WorldRenderer::draw(
|
||||
auto& shadowsShader = assets.require<Shader>("shadows");
|
||||
|
||||
if (gbufferPipeline) {
|
||||
float shadowMapScale = 0.05f * 2;
|
||||
float shadowMapScale = 0.05f;
|
||||
float shadowMapSize = shadowMap->getResolution() * shadowMapScale;
|
||||
*shadowCamera = Camera(camera.position, shadowMapSize);
|
||||
shadowCamera->near = 0.5f;
|
||||
shadowCamera->far = 600.0f;
|
||||
shadowCamera->near = 0.1f;
|
||||
shadowCamera->far = 800.0f;
|
||||
shadowCamera->perspective = false;
|
||||
shadowCamera->setAspectRatio(1.0f);
|
||||
shadowCamera->rotate(glm::radians(-64.0f), glm::radians(-35.0f), glm::radians(-35.0f));
|
||||
@@ -387,10 +389,10 @@ void WorldRenderer::draw(
|
||||
// );
|
||||
shadowCamera->updateVectors();
|
||||
//shadowCamera->position += camera.dir * shadowMapSize * 0.5f;
|
||||
shadowCamera->position -= shadowCamera->front * 100.0f;
|
||||
shadowCamera->position -= shadowCamera->front * 200.0f;
|
||||
shadowCamera->position -= shadowCamera->right * (shadowMap->getResolution() * shadowMapScale) * 0.5f;
|
||||
shadowCamera->position -= shadowCamera->up * (shadowMap->getResolution() * shadowMapScale) * 0.5f;
|
||||
shadowCamera->position = glm::floor(shadowCamera->position);
|
||||
shadowCamera->position = glm::floor(shadowCamera->position * 0.25f) * 4.0f;
|
||||
{
|
||||
frustumCulling->update(shadowCamera->getProjView());
|
||||
auto sctx = pctx.sub();
|
||||
@@ -419,22 +421,22 @@ void WorldRenderer::draw(
|
||||
ctx.setCullFace(true);
|
||||
renderLevel(ctx, camera, settings, uiDelta, pause, hudVisible);
|
||||
// Debug lines
|
||||
// if (hudVisible) {
|
||||
// if (debug) {
|
||||
// guides->renderDebugLines(
|
||||
// ctx, camera, *lineBatch, linesShader, showChunkBorders
|
||||
// );
|
||||
// }
|
||||
// if (player.currentCamera == player.fpCamera) {
|
||||
// renderHands(camera, delta);
|
||||
// }
|
||||
// }
|
||||
if (hudVisible) {
|
||||
if (debug) {
|
||||
guides->renderDebugLines(
|
||||
ctx, camera, *lineBatch, linesShader, showChunkBorders
|
||||
);
|
||||
}
|
||||
if (player.currentCamera == player.fpCamera) {
|
||||
renderHands(camera, delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
// {
|
||||
// DrawContext ctx = wctx.sub();
|
||||
// texts->render(ctx, camera, settings, hudVisible, true);
|
||||
// }
|
||||
//renderBlockOverlay(wctx);
|
||||
{
|
||||
DrawContext ctx = wctx.sub();
|
||||
texts->render(ctx, camera, settings, hudVisible, true);
|
||||
}
|
||||
renderBlockOverlay(wctx);
|
||||
}
|
||||
|
||||
postProcessing.render(
|
||||
@@ -444,6 +446,7 @@ void WorldRenderer::draw(
|
||||
camera,
|
||||
gbufferPipeline ? shadowMap->getDepthMap() : 0
|
||||
);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void WorldRenderer::renderBlockOverlay(const DrawContext& wctx) {
|
||||
|
||||
Reference in New Issue
Block a user