mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
Merge pull request #1015 from MihailRis/lights-fixes
Lights fixes and upgrades
This commit is contained in:
commit
891446bccb
12 changed files with 69 additions and 45 deletions
|
|
@ -3,22 +3,27 @@
|
|||
|
||||
#define CLOUDS_FOG_FACTOR_MUL 0.3f
|
||||
#define CLOUDS_FOG_CURVE_MUL 0.4f
|
||||
#define COLOR_TEMPERATURE_COMPENSATION 1.12f
|
||||
#define COLOR_TEMPERATURE_COMPENSATION 1.14f
|
||||
|
||||
vec4 effect() {
|
||||
vec4 pos = texture(u_position, v_uv);
|
||||
float light = 1.0;
|
||||
|
||||
#ifdef ENABLE_SSAO
|
||||
light = 0.0;
|
||||
float z = pos.z;
|
||||
for (int y = -2; y <= 2; y++) {
|
||||
for (int x = -2; x <= 2; x++) {
|
||||
vec2 offset = vec2(x, y) / u_screenSize;
|
||||
light += texture(u_ssao, v_uv + offset * 2.0).r;
|
||||
vec2 texel = 2.0 / u_screenSize;
|
||||
float centerZ = pos.z;
|
||||
float sum = 0.0;
|
||||
float wsum = 0.0;
|
||||
for (int y = -2; y < 2; y++) {
|
||||
for (int x = -2; x < 2; x++) {
|
||||
vec2 uv = v_uv + vec2(x, y) * texel;
|
||||
float z = texture(u_position, uv).z;
|
||||
float w = exp(-abs(centerZ - z) / (abs(centerZ) * 0.05 + 0.001));
|
||||
sum += texture(u_ssao, uv).r * w;
|
||||
wsum += w;
|
||||
}
|
||||
}
|
||||
light /= 24.0;
|
||||
light = sum / wsum;
|
||||
#endif // ENABLE_SSAO
|
||||
|
||||
vec4 modelpos = u_inverseView * pos;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
#define CURVATURE_FACTOR 0.002
|
||||
|
||||
// lighting
|
||||
#define SKY_LIGHT_MUL 2.5
|
||||
#define SKY_LIGHT_TINT (vec3(1.0, 0.75, 0.6) * 2.0)
|
||||
#define SKY_LIGHT_MUL 4.0
|
||||
#define SKY_LIGHT_TINT (vec3(1.0, 0.2, 0.2) * 2.0)
|
||||
|
||||
// fog
|
||||
#define FOG_POS_SCALE vec3(1.0, 0.2, 1.0)
|
||||
|
|
|
|||
|
|
@ -19,24 +19,22 @@ float calc_shadow(
|
|||
float bias
|
||||
) {
|
||||
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;
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
projCoords.z -= 0.00001 / u_shadowsRes + bias;
|
||||
|
||||
float shadow = 0.0;
|
||||
if (dot(realnormal, u_sunDir) < 0.0) {
|
||||
// 3x3 kernel
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.8) * step * 1.0 * u_shadowsSoftness;
|
||||
shadow += texture(shadowsMap, projCoords + offset);
|
||||
}
|
||||
// 3x3 kernel
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.1) * step * 1.0 * u_shadowsSoftness;
|
||||
shadow += texture(shadowsMap, projCoords + offset);
|
||||
}
|
||||
shadow /= 9.0;
|
||||
} else {
|
||||
shadow = 0.0;
|
||||
}
|
||||
shadow /= 9.0;
|
||||
|
||||
shadow *= max(0.0, sqrt(-dot(realnormal, u_sunDir)));
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <constants>
|
||||
|
||||
vec3 pick_sky_color(samplerCube cubemap, float dayTime, vec3 minSkyLight) {
|
||||
float elevation = sin(dayTime * PI2) * 0.2;
|
||||
float elevation = -sin(dayTime * PI2) * 0.1;
|
||||
vec3 skyLightColor = texture(cubemap, vec3(0.0f, elevation, -0.4f)).rgb;
|
||||
skyLightColor *= SKY_LIGHT_TINT;
|
||||
skyLightColor = min(vec3(1.0f), skyLightColor * SKY_LIGHT_MUL);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ SOFTWARE.
|
|||
#define ABSORPTION_BETA vec3(2.04e-5, 4.97e-5, 1.95e-6) /* what color gets absorbed by the atmosphere (Due to things like ozone) */
|
||||
#define G 0.9 /* mie scattering direction, or how big the blob around the sun is */
|
||||
// and the heights (how far to go up before the scattering has no effect)
|
||||
#define HEIGHT_RAY 8e3 /* rayleigh height */
|
||||
#define HEIGHT_RAY 12e3 /* rayleigh height */
|
||||
#define HEIGHT_MIE 1.2e3 /* and mie */
|
||||
#define HEIGHT_ABSORPTION 30e3 /* at what height the absorption is at it's maximum */
|
||||
#define ABSORPTION_FALLOFF 4e3 /* how much the absorption decreases the further away it gets from the maximum height */
|
||||
|
|
|
|||
|
|
@ -85,8 +85,12 @@ LevelScreen::LevelScreen(
|
|||
};
|
||||
keepAlive(settings.graphics.backlight.observe(resetChunks));
|
||||
keepAlive(settings.graphics.softLighting.observe(resetChunks));
|
||||
keepAlive(settings.graphics.denseRender.observe([=](bool flag) {
|
||||
resetChunks(flag);
|
||||
keepAlive(settings.graphics.denseRender.observe([=](bool) {
|
||||
resetChunks(false);
|
||||
frontend->getContentGfxCache().refresh();
|
||||
}));
|
||||
keepAlive(settings.graphics.shadowsQuality.observe([=](int quality) {
|
||||
resetChunks(false);
|
||||
frontend->getContentGfxCache().refresh();
|
||||
}));
|
||||
keepAlive(settings.camera.fov.observe([=](double value) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ static debug::Logger logger("gl-gbuffer");
|
|||
|
||||
// TODO: REFACTOR
|
||||
|
||||
uint GBuffer::getSSAODownsample() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
void GBuffer::createColorBuffer() {
|
||||
if (colorBuffer == 0)
|
||||
glGenTextures(1, &colorBuffer);
|
||||
|
|
@ -117,15 +121,17 @@ void GBuffer::createDepthBuffer() {
|
|||
}
|
||||
|
||||
void GBuffer::createSSAOBuffer() {
|
||||
if (ssaoBuffer == 0)
|
||||
if (ssaoBuffer == 0) {
|
||||
glGenTextures(1, &ssaoBuffer);
|
||||
}
|
||||
uint ssaoDownsample = getSSAODownsample();
|
||||
glBindTexture(GL_TEXTURE_2D, ssaoBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_R16F,
|
||||
width,
|
||||
height,
|
||||
width / ssaoDownsample,
|
||||
height / ssaoDownsample,
|
||||
0,
|
||||
GL_RED,
|
||||
GL_FLOAT,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ public:
|
|||
uint getHeight() const;
|
||||
|
||||
std::unique_ptr<ImageData> toImage() const;
|
||||
|
||||
uint getSSAODownsample() const;
|
||||
private:
|
||||
uint width;
|
||||
uint height;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ PostProcessing::PostProcessing(size_t effectSlotsCount)
|
|||
quadMesh = std::make_unique<Mesh<PostProcessingVertex>>(meshData, 6);
|
||||
|
||||
std::vector<glm::vec3> ssaoNoise;
|
||||
for (unsigned int i = 0; i < 16; i++)
|
||||
int res = 4;
|
||||
for (unsigned int i = 0; i < res*res; i++)
|
||||
{
|
||||
glm::vec3 noise(
|
||||
(rand() / static_cast<float>(RAND_MAX)) * 2.0 - 1.0,
|
||||
|
|
@ -41,7 +42,7 @@ PostProcessing::PostProcessing(size_t effectSlotsCount)
|
|||
}
|
||||
glGenTextures(1, &noiseTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, noiseTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 4, 4, 0, GL_RGB, GL_FLOAT, ssaoNoise.data());
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, res, res, 0, GL_RGB, GL_FLOAT, ssaoNoise.data());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
|
|
@ -89,7 +90,8 @@ void PostProcessing::configureEffect(
|
|||
PostEffect& effect,
|
||||
Shader& shader,
|
||||
float timer,
|
||||
const Camera& camera
|
||||
const Camera& camera,
|
||||
unsigned int downsample
|
||||
) {
|
||||
const auto& viewport = context.getViewport();
|
||||
shader.uniform1i("u_screen", TARGET_COLOR);
|
||||
|
|
@ -101,7 +103,7 @@ void PostProcessing::configureEffect(
|
|||
}
|
||||
shader.uniform1i("u_noise", TARGET_SSAO); // used in SSAO pass
|
||||
shader.uniform1i("u_ssao", TARGET_SSAO);
|
||||
shader.uniform2i("u_screenSize", viewport);
|
||||
shader.uniform2i("u_screenSize", viewport / downsample);
|
||||
shader.uniform3f("u_cameraPos", camera.position);
|
||||
shader.uniform1f("u_timer", timer);
|
||||
shader.uniformMatrix("u_projection", camera.getProjection());
|
||||
|
|
@ -128,15 +130,14 @@ void PostProcessing::renderDeferredShading(
|
|||
|
||||
auto& ssaoEffect = assets.require<PostEffect>("ssao");
|
||||
auto& shader = ssaoEffect.use();
|
||||
configureEffect(
|
||||
context,
|
||||
ssaoEffect,
|
||||
shader,
|
||||
timer,
|
||||
camera
|
||||
);
|
||||
uint ssaoDownscale = gbuffer->getSSAODownsample();
|
||||
configureEffect(context, ssaoEffect, shader, timer, camera, ssaoDownscale);
|
||||
gbuffer->bindSSAO();
|
||||
quadMesh->draw();
|
||||
{
|
||||
auto ssaoContext = context.sub();
|
||||
ssaoContext.setViewport(context.getViewport() / ssaoDownscale);
|
||||
quadMesh->draw();
|
||||
}
|
||||
gbuffer->unbind();
|
||||
|
||||
{
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ private:
|
|||
PostEffect& effect,
|
||||
Shader& shader,
|
||||
float timer,
|
||||
const Camera& camera
|
||||
const Camera& camera,
|
||||
unsigned downsample = 1U
|
||||
);
|
||||
|
||||
void refreshFbos(uint width, uint height);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
#include "frontend/ContentGfxCache.hpp"
|
||||
|
||||
const glm::vec3 BlocksRenderer::SUN_VECTOR(0.528265, 0.833149, -0.163704);
|
||||
constexpr float DIRECTIONAL_LIGHT_FACTOR = 0.3f;
|
||||
|
||||
BlocksRenderer::BlocksRenderer(
|
||||
size_t capacity,
|
||||
|
|
@ -128,7 +127,7 @@ void BlocksRenderer::faceAO(
|
|||
float s = 0.5f;
|
||||
if (lights) {
|
||||
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 axisY = glm::normalize(Y);
|
||||
|
|
@ -167,7 +166,7 @@ void BlocksRenderer::face(
|
|||
float s = 0.5f;
|
||||
if (lights) {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
d = (1.0f - DIRECTIONAL_LIGHT_FACTOR) + d * DIRECTIONAL_LIGHT_FACTOR;
|
||||
d = (1.0f - directionalLightFactor) + d * directionalLightFactor;
|
||||
glm::vec3 t = glm::cross(r, n);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
|
@ -692,6 +691,10 @@ SortingMeshData BlocksRenderer::renderTranslucent(
|
|||
void BlocksRenderer::build(
|
||||
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));
|
||||
this->chunk = chunk;
|
||||
this->voxelsBuffer = &volume;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ struct UVRegion;
|
|||
|
||||
class BlocksRenderer final {
|
||||
public:
|
||||
static constexpr float DEFAULT_DIRECTIONAL_LIGHT_FACTOR = 0.3f;
|
||||
|
||||
BlocksRenderer(
|
||||
size_t capacity,
|
||||
const Block* const* blockDefs,
|
||||
|
|
@ -56,6 +58,8 @@ private:
|
|||
bool cancelled = false;
|
||||
bool densePass = false;
|
||||
bool denseRender = false;
|
||||
float directionalLightFactor = 0.0f;
|
||||
|
||||
AABB meshAABB {};
|
||||
const Chunk* chunk = nullptr;
|
||||
const VoxelsRenderVolume* voxelsBuffer = nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue