mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-22 18:39:46 +00:00
Merge branch 'main' into dev
This commit is contained in:
commit
35e3d80f35
111 changed files with 935 additions and 664 deletions
|
|
@ -8,149 +8,65 @@ using namespace advanced_pipeline;
|
|||
|
||||
static debug::Logger logger("gl-gbuffer");
|
||||
|
||||
// TODO: REFACTOR
|
||||
|
||||
uint GBuffer::getSSAODownsample() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
void GBuffer::createColorBuffer() {
|
||||
if (colorBuffer == 0)
|
||||
glGenTextures(1, &colorBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGB,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_UNSIGNED_BYTE,
|
||||
nullptr
|
||||
);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBuffer, 0
|
||||
);
|
||||
}
|
||||
|
||||
void GBuffer::createPositionsBuffer() {
|
||||
if (positionsBuffer == 0)
|
||||
glGenTextures(1, &positionsBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, positionsBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA16F,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_FLOAT,
|
||||
nullptr
|
||||
);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, positionsBuffer, 0
|
||||
);
|
||||
}
|
||||
|
||||
void GBuffer::createNormalsBuffer() {
|
||||
if (normalsBuffer == 0)
|
||||
glGenTextures(1, &normalsBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, normalsBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA16F,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_FLOAT,
|
||||
nullptr
|
||||
);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, normalsBuffer, 0
|
||||
);
|
||||
}
|
||||
|
||||
void GBuffer::createEmissionBuffer() {
|
||||
if (emissionBuffer == 0)
|
||||
glGenTextures(1, &emissionBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, emissionBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_R8,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RED,
|
||||
GL_FLOAT,
|
||||
nullptr
|
||||
);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, emissionBuffer, 0
|
||||
);
|
||||
}
|
||||
|
||||
void GBuffer::createDepthBuffer() {
|
||||
if (depthBuffer == 0)
|
||||
glGenRenderbuffers(1, &depthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
||||
glFramebufferRenderbuffer(
|
||||
GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer
|
||||
);
|
||||
}
|
||||
|
||||
void GBuffer::createSSAOBuffer() {
|
||||
if (ssaoBuffer == 0) {
|
||||
glGenTextures(1, &ssaoBuffer);
|
||||
void GBuffer::createBuffer(Buffer& buffer, int downsample) {
|
||||
if (buffer.buffer == 0) {
|
||||
if (&buffer == &depthBuffer)
|
||||
glGenRenderbuffers(1, &depthBuffer.buffer);
|
||||
else
|
||||
glGenTextures(1, &buffer.buffer);
|
||||
}
|
||||
if (&buffer == &depthBuffer){
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer.buffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
||||
glFramebufferRenderbuffer(
|
||||
GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer.buffer
|
||||
);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, buffer.buffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
buffer.internalformat,
|
||||
width / downsample,
|
||||
height / downsample,
|
||||
0,
|
||||
buffer.format,
|
||||
buffer.type,
|
||||
nullptr
|
||||
);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
if (&buffer != &ssaoBuffer)
|
||||
{
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, buffer.attachment, GL_TEXTURE_2D, buffer.buffer, 0
|
||||
);
|
||||
}
|
||||
}
|
||||
uint ssaoDownsample = getSSAODownsample();
|
||||
glBindTexture(GL_TEXTURE_2D, ssaoBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_R16F,
|
||||
width / ssaoDownsample,
|
||||
height / ssaoDownsample,
|
||||
0,
|
||||
GL_RED,
|
||||
GL_FLOAT,
|
||||
nullptr
|
||||
);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
GBuffer::GBuffer(uint width, uint height) : width(width), height(height) {
|
||||
GBuffer::GBuffer(uint width, uint height)
|
||||
: width(width), height(height),
|
||||
colorBuffer {0, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, GL_COLOR_ATTACHMENT0},
|
||||
positionsBuffer {0, GL_RGBA16F, GL_RGBA, GL_FLOAT, GL_COLOR_ATTACHMENT1},
|
||||
normalsBuffer {0, GL_RGBA16F, GL_RGB, GL_FLOAT, GL_COLOR_ATTACHMENT2},
|
||||
emissionBuffer {0, GL_R8, GL_RED, GL_FLOAT, GL_COLOR_ATTACHMENT3},
|
||||
depthBuffer {0, 0, 0, 0, 0},
|
||||
ssaoBuffer {0, GL_R16F, GL_RED, GL_FLOAT, 0}
|
||||
{
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
createColorBuffer();
|
||||
createPositionsBuffer();
|
||||
createNormalsBuffer();
|
||||
createEmissionBuffer();
|
||||
createBuffer(colorBuffer);
|
||||
createBuffer(positionsBuffer);
|
||||
createBuffer(normalsBuffer);
|
||||
createBuffer(emissionBuffer);
|
||||
|
||||
GLenum attachments[4] = {
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
|
|
@ -160,7 +76,7 @@ GBuffer::GBuffer(uint width, uint height) : width(width), height(height) {
|
|||
};
|
||||
glDrawBuffers(4, attachments);
|
||||
|
||||
createDepthBuffer();
|
||||
createBuffer(depthBuffer);
|
||||
|
||||
int status;
|
||||
if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
|
|
@ -170,9 +86,9 @@ GBuffer::GBuffer(uint width, uint height) : width(width), height(height) {
|
|||
|
||||
glGenFramebuffers(1, &ssaoFbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, ssaoFbo);
|
||||
createSSAOBuffer();
|
||||
createBuffer(ssaoBuffer, getSSAODownsample());
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ssaoBuffer, 0
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ssaoBuffer.buffer, 0
|
||||
);
|
||||
GLenum ssaoAttachments[1] = {GL_COLOR_ATTACHMENT0};
|
||||
glDrawBuffers(1, ssaoAttachments);
|
||||
|
|
@ -185,12 +101,12 @@ GBuffer::GBuffer(uint width, uint height) : width(width), height(height) {
|
|||
}
|
||||
|
||||
GBuffer::~GBuffer() {
|
||||
glDeleteTextures(1, &colorBuffer);
|
||||
glDeleteTextures(1, &positionsBuffer);
|
||||
glDeleteTextures(1, &normalsBuffer);
|
||||
glDeleteTextures(1, &emissionBuffer);
|
||||
glDeleteTextures(1, &ssaoBuffer);
|
||||
glDeleteRenderbuffers(1, &depthBuffer);
|
||||
glDeleteTextures(1, &colorBuffer.buffer);
|
||||
glDeleteTextures(1, &positionsBuffer.buffer);
|
||||
glDeleteTextures(1, &normalsBuffer.buffer);
|
||||
glDeleteTextures(1, &emissionBuffer.buffer);
|
||||
glDeleteTextures(1, &ssaoBuffer.buffer);
|
||||
glDeleteRenderbuffers(1, &depthBuffer.buffer);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
glDeleteFramebuffers(1, &ssaoFbo);
|
||||
}
|
||||
|
|
@ -210,23 +126,23 @@ void GBuffer::unbind() const {
|
|||
|
||||
void GBuffer::bindBuffers() const {
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_EMISSION);
|
||||
glBindTexture(GL_TEXTURE_2D, emissionBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, emissionBuffer.buffer);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_NORMALS);
|
||||
glBindTexture(GL_TEXTURE_2D, normalsBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, normalsBuffer.buffer);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_POSITIONS);
|
||||
glBindTexture(GL_TEXTURE_2D, positionsBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, positionsBuffer.buffer);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_COLOR);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffer.buffer);
|
||||
|
||||
if (TARGET_COLOR != 0)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void GBuffer::bindSSAOBuffer() const {
|
||||
glBindTexture(GL_TEXTURE_2D, ssaoBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, ssaoBuffer.buffer);
|
||||
}
|
||||
|
||||
void GBuffer::bindDepthBuffer(int drawFbo) {
|
||||
|
|
@ -245,24 +161,24 @@ void GBuffer::resize(uint width, uint height) {
|
|||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
createDepthBuffer();
|
||||
createColorBuffer();
|
||||
createPositionsBuffer();
|
||||
createNormalsBuffer();
|
||||
createEmissionBuffer();
|
||||
createBuffer(depthBuffer);
|
||||
createBuffer(colorBuffer);
|
||||
createBuffer(positionsBuffer);
|
||||
createBuffer(normalsBuffer);
|
||||
createBuffer(emissionBuffer);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, ssaoFbo);
|
||||
createSSAOBuffer();
|
||||
createBuffer(ssaoBuffer, getSSAODownsample());
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageData> GBuffer::toImage() const {
|
||||
auto data = std::make_unique<ubyte[]>(width * height * 3);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffer.buffer);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data.get());
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
return std::make_unique<ImageData>(
|
||||
|
|
|
|||
|
|
@ -27,22 +27,25 @@ public:
|
|||
|
||||
uint getSSAODownsample() const;
|
||||
private:
|
||||
struct Buffer {
|
||||
uint buffer;
|
||||
const int internalformat;
|
||||
const uint format;
|
||||
const uint type;
|
||||
const uint attachment;
|
||||
};
|
||||
|
||||
uint width;
|
||||
uint height;
|
||||
|
||||
uint fbo;
|
||||
uint colorBuffer = 0;
|
||||
uint positionsBuffer = 0;
|
||||
uint normalsBuffer = 0;
|
||||
uint emissionBuffer = 0;
|
||||
uint depthBuffer = 0;
|
||||
uint ssaoFbo = 0;
|
||||
uint ssaoBuffer = 0;
|
||||
Buffer colorBuffer;
|
||||
Buffer positionsBuffer;
|
||||
Buffer normalsBuffer;
|
||||
Buffer emissionBuffer;
|
||||
Buffer depthBuffer;
|
||||
uint ssaoFbo;
|
||||
Buffer ssaoBuffer;
|
||||
|
||||
void createColorBuffer();
|
||||
void createPositionsBuffer();
|
||||
void createNormalsBuffer();
|
||||
void createEmissionBuffer();
|
||||
void createDepthBuffer();
|
||||
void createSSAOBuffer();
|
||||
void createBuffer(Buffer& buffer, int downsample = 1);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
#include "PostProcessing.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "Mesh.hpp"
|
||||
#include "Shader.hpp"
|
||||
#include "GBuffer.hpp"
|
||||
|
|
@ -18,7 +21,7 @@ using namespace advanced_pipeline;
|
|||
|
||||
PostProcessing::PostProcessing(size_t effectSlotsCount)
|
||||
: effectSlots(effectSlotsCount) {
|
||||
// Fullscreen quad mesh bulding
|
||||
// Fullscreen quad mesh building
|
||||
PostProcessingVertex meshData[] {
|
||||
{{-1.0f, -1.0f}},
|
||||
{{-1.0f, 1.0f}},
|
||||
|
|
@ -37,7 +40,7 @@ PostProcessing::PostProcessing(size_t effectSlotsCount)
|
|||
glm::vec3 noise(
|
||||
(rand() / static_cast<float>(RAND_MAX)) * 2.0 - 1.0,
|
||||
(rand() / static_cast<float>(RAND_MAX)) * 2.0 - 1.0,
|
||||
0.0f);
|
||||
0.0f);
|
||||
ssaoNoise.push_back(noise);
|
||||
}
|
||||
glGenTextures(1, &noiseTexture);
|
||||
|
|
@ -50,7 +53,9 @@ PostProcessing::PostProcessing(size_t effectSlotsCount)
|
|||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
PostProcessing::~PostProcessing() = default;
|
||||
PostProcessing::~PostProcessing() {
|
||||
glDeleteTextures(1, &noiseTexture);
|
||||
}
|
||||
|
||||
void PostProcessing::use(DrawContext& context, bool gbufferPipeline) {
|
||||
const auto& vp = context.getViewport();
|
||||
|
|
@ -107,8 +112,9 @@ void PostProcessing::configureEffect(
|
|||
shader.uniform3f("u_cameraPos", camera.position);
|
||||
shader.uniform1f("u_timer", timer);
|
||||
shader.uniformMatrix("u_projection", camera.getProjection());
|
||||
shader.uniformMatrix("u_view", camera.getView());
|
||||
shader.uniformMatrix("u_inverseView", glm::inverse(camera.getView()));
|
||||
const auto view = camera.getView();
|
||||
shader.uniformMatrix("u_view", view);
|
||||
shader.uniformMatrix("u_inverseView", glm::inverse(view));
|
||||
}
|
||||
|
||||
void PostProcessing::renderDeferredShading(
|
||||
|
|
@ -151,7 +157,7 @@ void PostProcessing::renderDeferredShading(
|
|||
gbuffer->bindSSAOBuffer();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
|
||||
gbuffer->bindBuffers();
|
||||
|
||||
auto& effect = assets.require<PostEffect>("deferred_lighting");
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ struct PostProcessingVertex {
|
|||
};
|
||||
|
||||
/// @brief Framebuffer with blitting with shaders.
|
||||
/// @attention Current implementation does not support multiple render passes
|
||||
/// for multiple effects. Will be implemented in v0.21
|
||||
class PostProcessing {
|
||||
public:
|
||||
PostProcessing(size_t effectSlotsCount);
|
||||
|
|
@ -74,12 +72,12 @@ private:
|
|||
|
||||
void refreshFbos(uint width, uint height);
|
||||
|
||||
/// @brief Main framebuffer (lasy field)
|
||||
/// @brief Main framebuffer (lazy field)
|
||||
std::unique_ptr<Framebuffer> fbo;
|
||||
std::unique_ptr<Framebuffer> fboSecond;
|
||||
/// @brief Fullscreen quad mesh as the post-processing canvas
|
||||
std::unique_ptr<Mesh<PostProcessingVertex>> quadMesh;
|
||||
std::vector<std::shared_ptr<PostEffect>> effectSlots;
|
||||
std::unique_ptr<GBuffer> gbuffer;
|
||||
uint noiseTexture;
|
||||
uint noiseTexture = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,22 @@
|
|||
#include "debug/Logger.hpp"
|
||||
#include "core_defs.hpp"
|
||||
|
||||
inline constexpr uint FACE_WEST = FACE_MX;
|
||||
inline constexpr uint FACE_EAST = FACE_PX;
|
||||
inline constexpr uint FACE_BOTTOM = FACE_MY;
|
||||
inline constexpr uint FACE_TOP = FACE_PY;
|
||||
inline constexpr uint FACE_SOUTH = FACE_MZ;
|
||||
inline constexpr uint FACE_NORTH = FACE_PZ;
|
||||
|
||||
inline constexpr std::array<uint8_t, 6> LEGACY_CUSTOM_MODEL_TEXTURE_ORDER = {
|
||||
FACE_WEST,
|
||||
FACE_EAST,
|
||||
FACE_BOTTOM,
|
||||
FACE_TOP,
|
||||
FACE_SOUTH,
|
||||
FACE_NORTH,
|
||||
};
|
||||
|
||||
static debug::Logger logger("models-generator");
|
||||
|
||||
static void configure_textures(
|
||||
|
|
@ -49,6 +65,21 @@ static inline UVRegion get_region_for(
|
|||
return texreg.region;
|
||||
}
|
||||
|
||||
static inline void map_legacy_box_textures(
|
||||
const std::vector<std::string>& modelTextures,
|
||||
size_t offset,
|
||||
UVRegion (&boxtexfaces)[6],
|
||||
const Assets& assets
|
||||
) {
|
||||
for (size_t i = 0; i < 6; ++i) {
|
||||
const auto legacyFace = LEGACY_CUSTOM_MODEL_TEXTURE_ORDER[i];
|
||||
boxtexfaces[legacyFace] = get_region_for(modelTextures[offset + i], assets);
|
||||
}
|
||||
boxtexfaces[FACE_TOP].scale(glm::vec2(-1, 1));
|
||||
boxtexfaces[FACE_EAST].scale(glm::vec2(-1, 1));
|
||||
boxtexfaces[FACE_NORTH].scale(glm::vec2(-1, 1));
|
||||
}
|
||||
|
||||
void ModelsGenerator::prepareModel(
|
||||
Assets& assets, const Block& def, Variant& variant, uint8_t variantId
|
||||
) {
|
||||
|
|
@ -120,16 +151,8 @@ model::Model ModelsGenerator::fromCustom(
|
|||
for (size_t i = 0; i < modelBoxes.size(); i++) {
|
||||
auto& mesh = model.addMesh("blocks:");
|
||||
mesh.shading = lighting;
|
||||
UVRegion boxtexfaces[6] = {
|
||||
get_region_for(modelTextures[i * 6 + 5], assets),
|
||||
get_region_for(modelTextures[i * 6 + 4], assets),
|
||||
get_region_for(modelTextures[i * 6 + 3], assets),
|
||||
get_region_for(modelTextures[i * 6 + 2], assets),
|
||||
get_region_for(modelTextures[i * 6 + 1], assets),
|
||||
get_region_for(modelTextures[i * 6 + 0], assets)
|
||||
};
|
||||
boxtexfaces[2].scale(glm::vec2(-1));
|
||||
boxtexfaces[5].scale(glm::vec2(-1, 1));
|
||||
UVRegion boxtexfaces[6] = {};
|
||||
map_legacy_box_textures(modelTextures, i * 6, boxtexfaces, assets);
|
||||
|
||||
bool enabled[6] {1,1,1,1,1,1};
|
||||
mesh.addBox(
|
||||
|
|
@ -232,17 +255,14 @@ model::Model ModelsGenerator::loadCustomBlockModel(
|
|||
modelBoxes.push_back(modelbox);
|
||||
|
||||
if (boxarr.size() == 7) {
|
||||
for (uint j = 6; j < 12; j++) {
|
||||
modelTextures.emplace_back(boxarr[6].asString());
|
||||
}
|
||||
const auto texture = boxarr[6].asString();
|
||||
modelTextures.insert(modelTextures.end(), 6, texture);
|
||||
} else if (boxarr.size() == 12) {
|
||||
for (uint j = 6; j < 12; j++) {
|
||||
modelTextures.emplace_back(boxarr[j].asString());
|
||||
}
|
||||
} else {
|
||||
for (uint j = 6; j < 12; j++) {
|
||||
modelTextures.emplace_back("notfound");
|
||||
}
|
||||
modelTextures.insert(modelTextures.end(), 6, "notfound");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -324,11 +324,24 @@ void WorldRenderer::renderInWorldLines(
|
|||
auto ctx = pctx.sub(lineBatch.get());
|
||||
bool culling = engine.getSettings().graphics.frustumCulling.get();
|
||||
level.entities->renderDebug(
|
||||
*lineBatch, culling ? frustumCulling.get() : nullptr, ctx
|
||||
*lineBatch, culling ? frustumCulling.get() : nullptr, ctx,
|
||||
player.currentCamera.get() == player.fpCamera.get() ? player.getEntity() : 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void WorldRenderer::updateEntitiesCulling(const Camera& camera) {
|
||||
bool culling = engine.getSettings().graphics.frustumCulling.get();
|
||||
if (culling) {
|
||||
frustumCulling->update(camera.getProjView());
|
||||
}
|
||||
level.entities->updateCulling(
|
||||
culling ? frustumCulling.get() : nullptr,
|
||||
player.currentCamera.get() == player.fpCamera.get() ? player.getEntity()
|
||||
: 0
|
||||
);
|
||||
}
|
||||
|
||||
void WorldRenderer::update(const Camera& camera, float delta) {
|
||||
timer += delta;
|
||||
chunksRenderer->update();
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ public:
|
|||
~WorldRenderer();
|
||||
|
||||
void update(const Camera& camera, float delta);
|
||||
void updateEntitiesCulling(const Camera& camera);
|
||||
|
||||
void renderFrame(
|
||||
const DrawContext& context,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
#include "GUI.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "assets/Assets.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "elements/Label.hpp"
|
||||
|
|
@ -17,7 +14,6 @@
|
|||
#include "graphics/core/Shader.hpp"
|
||||
#include "graphics/core/Font.hpp"
|
||||
#include "graphics/core/DrawContext.hpp"
|
||||
#include "graphics/core/Shader.hpp"
|
||||
#include "gui_util.hpp"
|
||||
#include "window/Camera.hpp"
|
||||
#include "window/Window.hpp"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue