mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-22 18:39:46 +00:00
update advanced render lighting model
This commit is contained in:
parent
09b427be1e
commit
25cee0284f
4 changed files with 26 additions and 17 deletions
|
|
@ -19,24 +19,22 @@ float calc_shadow(
|
||||||
float bias
|
float bias
|
||||||
) {
|
) {
|
||||||
float step = 1.0 / float(u_shadowsRes);
|
float step = 1.0 / float(u_shadowsRes);
|
||||||
vec4 mpos = shadowMatrix * vec4(modelPos.xyz + normalOffset, 1.0);
|
vec4 mpos = shadowMatrix * vec4(modelPos.xyz + normalOffset * 2.0, 1.0);
|
||||||
vec3 projCoords = mpos.xyz / mpos.w;
|
vec3 projCoords = mpos.xyz / mpos.w;
|
||||||
projCoords = projCoords * 0.5 + 0.5;
|
projCoords = projCoords * 0.5 + 0.5;
|
||||||
projCoords.z -= 0.00001 / u_shadowsRes + bias;
|
projCoords.z -= 0.00001 / u_shadowsRes + bias;
|
||||||
|
|
||||||
float shadow = 0.0;
|
float shadow = 0.0;
|
||||||
if (dot(realnormal, u_sunDir) < 0.0) {
|
// 3x3 kernel
|
||||||
// 3x3 kernel
|
for (int y = -1; y <= 1; y++) {
|
||||||
for (int y = -1; y <= 1; y++) {
|
for (int x = -1; x <= 1; x++) {
|
||||||
for (int x = -1; x <= 1; x++) {
|
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.1) * step * 1.0 * u_shadowsSoftness;
|
||||||
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.8) * step * 1.0 * u_shadowsSoftness;
|
shadow += texture(shadowsMap, projCoords + offset);
|
||||||
shadow += texture(shadowsMap, projCoords + offset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
shadow /= 9.0;
|
|
||||||
} else {
|
|
||||||
shadow = 0.0;
|
|
||||||
}
|
}
|
||||||
|
shadow /= 9.0;
|
||||||
|
|
||||||
|
shadow *= max(0.0, -dot(realnormal, u_sunDir));
|
||||||
return shadow;
|
return shadow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,12 @@ LevelScreen::LevelScreen(
|
||||||
};
|
};
|
||||||
keepAlive(settings.graphics.backlight.observe(resetChunks));
|
keepAlive(settings.graphics.backlight.observe(resetChunks));
|
||||||
keepAlive(settings.graphics.softLighting.observe(resetChunks));
|
keepAlive(settings.graphics.softLighting.observe(resetChunks));
|
||||||
keepAlive(settings.graphics.denseRender.observe([=](bool flag) {
|
keepAlive(settings.graphics.denseRender.observe([=](bool) {
|
||||||
resetChunks(flag);
|
resetChunks(false);
|
||||||
|
frontend->getContentGfxCache().refresh();
|
||||||
|
}));
|
||||||
|
keepAlive(settings.graphics.shadowsQuality.observe([=](int quality) {
|
||||||
|
resetChunks(false);
|
||||||
frontend->getContentGfxCache().refresh();
|
frontend->getContentGfxCache().refresh();
|
||||||
}));
|
}));
|
||||||
keepAlive(settings.camera.fov.observe([=](double value) {
|
keepAlive(settings.camera.fov.observe([=](double value) {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
#include "frontend/ContentGfxCache.hpp"
|
#include "frontend/ContentGfxCache.hpp"
|
||||||
|
|
||||||
const glm::vec3 BlocksRenderer::SUN_VECTOR(0.528265, 0.833149, -0.163704);
|
const glm::vec3 BlocksRenderer::SUN_VECTOR(0.528265, 0.833149, -0.163704);
|
||||||
constexpr float DIRECTIONAL_LIGHT_FACTOR = 0.3f;
|
|
||||||
|
|
||||||
BlocksRenderer::BlocksRenderer(
|
BlocksRenderer::BlocksRenderer(
|
||||||
size_t capacity,
|
size_t capacity,
|
||||||
|
|
@ -128,7 +127,7 @@ void BlocksRenderer::faceAO(
|
||||||
float s = 0.5f;
|
float s = 0.5f;
|
||||||
if (lights) {
|
if (lights) {
|
||||||
float d = glm::dot(glm::normalize(Z), SUN_VECTOR);
|
float d = glm::dot(glm::normalize(Z), SUN_VECTOR);
|
||||||
d = (1.0f - DIRECTIONAL_LIGHT_FACTOR) + d * DIRECTIONAL_LIGHT_FACTOR;
|
d = (1.0f - directionalLightFactor) + d * directionalLightFactor;
|
||||||
|
|
||||||
auto axisX = glm::normalize(X);
|
auto axisX = glm::normalize(X);
|
||||||
auto axisY = glm::normalize(Y);
|
auto axisY = glm::normalize(Y);
|
||||||
|
|
@ -167,7 +166,7 @@ void BlocksRenderer::face(
|
||||||
float s = 0.5f;
|
float s = 0.5f;
|
||||||
if (lights) {
|
if (lights) {
|
||||||
float d = glm::dot(glm::normalize(Z), SUN_VECTOR);
|
float d = glm::dot(glm::normalize(Z), SUN_VECTOR);
|
||||||
d = (1.0f - DIRECTIONAL_LIGHT_FACTOR) + d * DIRECTIONAL_LIGHT_FACTOR;
|
d = (1.0f - directionalLightFactor) + d * directionalLightFactor;
|
||||||
tint *= d;
|
tint *= d;
|
||||||
}
|
}
|
||||||
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, Z, lights ? 0 : 1);
|
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, Z, lights ? 0 : 1);
|
||||||
|
|
@ -349,7 +348,7 @@ void BlocksRenderer::blockCustomModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
float d = glm::dot(n, SUN_VECTOR);
|
float d = glm::dot(n, SUN_VECTOR);
|
||||||
d = (1.0f - DIRECTIONAL_LIGHT_FACTOR) + d * DIRECTIONAL_LIGHT_FACTOR;
|
d = (1.0f - directionalLightFactor) + d * directionalLightFactor;
|
||||||
glm::vec3 t = glm::cross(r, n);
|
glm::vec3 t = glm::cross(r, n);
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
|
@ -692,6 +691,10 @@ SortingMeshData BlocksRenderer::renderTranslucent(
|
||||||
void BlocksRenderer::build(
|
void BlocksRenderer::build(
|
||||||
const Chunk* chunk, const VoxelsRenderVolume& volume
|
const Chunk* chunk, const VoxelsRenderVolume& volume
|
||||||
) {
|
) {
|
||||||
|
directionalLightFactor = settings.graphics.shadowsQuality.get() > 0.0f
|
||||||
|
? 0.0f
|
||||||
|
: DEFAULT_DIRECTIONAL_LIGHT_FACTOR;
|
||||||
|
|
||||||
meshAABB = AABB(glm::vec3(CHUNK_W, CHUNK_H, CHUNK_D));
|
meshAABB = AABB(glm::vec3(CHUNK_W, CHUNK_H, CHUNK_D));
|
||||||
this->chunk = chunk;
|
this->chunk = chunk;
|
||||||
this->voxelsBuffer = &volume;
|
this->voxelsBuffer = &volume;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ struct UVRegion;
|
||||||
|
|
||||||
class BlocksRenderer final {
|
class BlocksRenderer final {
|
||||||
public:
|
public:
|
||||||
|
static constexpr float DEFAULT_DIRECTIONAL_LIGHT_FACTOR = 0.3f;
|
||||||
|
|
||||||
BlocksRenderer(
|
BlocksRenderer(
|
||||||
size_t capacity,
|
size_t capacity,
|
||||||
const Block* const* blockDefs,
|
const Block* const* blockDefs,
|
||||||
|
|
@ -56,6 +58,8 @@ private:
|
||||||
bool cancelled = false;
|
bool cancelled = false;
|
||||||
bool densePass = false;
|
bool densePass = false;
|
||||||
bool denseRender = false;
|
bool denseRender = false;
|
||||||
|
float directionalLightFactor = 0.0f;
|
||||||
|
|
||||||
AABB meshAABB {};
|
AABB meshAABB {};
|
||||||
const Chunk* chunk = nullptr;
|
const Chunk* chunk = nullptr;
|
||||||
const VoxelsRenderVolume* voxelsBuffer = nullptr;
|
const VoxelsRenderVolume* voxelsBuffer = nullptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue