summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-11-28 12:16:29 +0100
committerLaG1924 <lag1924@gmail.com>2021-11-28 12:16:29 +0100
commit8286ddda96a5f2925d342d0ce115aa00ae5d94ec (patch)
treeaa46a01fb6230a5c994046c7b4823ae1b35c2c37
parentChanged shaders to use SPB (diff)
downloadAltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.gz
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.bz2
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.lz
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.xz
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.tar.zst
AltCraft-8286ddda96a5f2925d342d0ce115aa00ae5d94ec.zip
-rw-r--r--cwd/assets/altcraft/scripts/ui.lua2
-rw-r--r--cwd/assets/altcraft/shaders/frag/light.fs11
-rw-r--r--cwd/assets/altcraft/shaders/frag/sky.fs14
-rw-r--r--cwd/assets/altcraft/shaders/vert/entity.vs1
-rw-r--r--cwd/assets/altcraft/shaders/vert/face.vs1
-rw-r--r--cwd/assets/altcraft/shaders/vert/fbo.vs1
-rw-r--r--cwd/assets/altcraft/shaders/vert/light.vs1
-rw-r--r--cwd/assets/altcraft/shaders/vert/pp.vs1
-rw-r--r--cwd/assets/altcraft/shaders/vert/rml.vs1
-rw-r--r--cwd/assets/altcraft/shaders/vert/sky.vs1
-rw-r--r--cwd/assets/altcraft/ui/options.rml6
-rw-r--r--src/Gal.hpp3
-rw-r--r--src/GalOgl.cpp29
-rw-r--r--src/Render.cpp6
-rw-r--r--src/RenderConfigs.hpp8
-rw-r--r--src/RendererWorld.cpp4
-rw-r--r--src/TextureAtlas.cpp1
17 files changed, 66 insertions, 25 deletions
diff --git a/cwd/assets/altcraft/scripts/ui.lua b/cwd/assets/altcraft/scripts/ui.lua
index b938737..10791d1 100644
--- a/cwd/assets/altcraft/scripts/ui.lua
+++ b/cwd/assets/altcraft/scripts/ui.lua
@@ -1,5 +1,5 @@
local options = {
- brightness = 0.2,
+ gamma = 2.2,
flight = false,
mouseSensetivity = 0.1,
renderDistance = 2,
diff --git a/cwd/assets/altcraft/shaders/frag/light.fs b/cwd/assets/altcraft/shaders/frag/light.fs
index 07eb3ec..117e0ef 100644
--- a/cwd/assets/altcraft/shaders/frag/light.fs
+++ b/cwd/assets/altcraft/shaders/frag/light.fs
@@ -17,6 +17,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
void main() {
@@ -24,15 +25,19 @@ void main() {
vec4 n = texture(normal, uv);
vec4 ac = texture(addColor, uv);
vec4 l = texture(light, uv);
- float d = 1.0f - texture(depthStencil, uv).r;
+ float d = (1.0f - texture(depthStencil, uv).r) * 16.0f;
float faceLight = l.r;
float skyLight = l.g;
- float lightLevel = clamp(faceLight + skyLight * dayTime, 0.2f, 1.0f);
+ float lightLevel = clamp(faceLight + skyLight * dayTime, 0.01f, 1.0f);
+ lightLevel = pow(lightLevel, 3);
+ lightLevel = clamp(lightLevel, 0.005f, 1.0f);
vec3 faceColor = mix(ac.rgb * lightLevel, vec3(1,1,1) * lightLevel, float(ac.rgb == vec3(0,0,0)));
vec4 finalColor = vec4(c.rgb * faceColor, 1.0f);
+ finalColor.rgb = pow(finalColor.rgb, vec3(1.0f / gamma));
+
switch(renderBuff) {
case 0:
fragColor = finalColor;
@@ -50,7 +55,7 @@ void main() {
fragColor = l;
break;
case 5:
- fragColor = vec4(d, d, d, 1.0f);
+ fragColor = vec4(vec3(d), 1.0f);
break;
}
}
diff --git a/cwd/assets/altcraft/shaders/frag/sky.fs b/cwd/assets/altcraft/shaders/frag/sky.fs
index 32b7da0..1e36dd3 100644
--- a/cwd/assets/altcraft/shaders/frag/sky.fs
+++ b/cwd/assets/altcraft/shaders/frag/sky.fs
@@ -1,6 +1,6 @@
#version 330 core
-in vec3 pos;
+in vec3 facePos;
layout (location = 0) out vec4 color;
layout (location = 1) out vec4 normal;
@@ -12,6 +12,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
uniform sampler2DArray textureAtlas;
@@ -20,12 +21,14 @@ uniform float sunTextureLayer;
uniform vec4 moonTexture;
uniform float moonTextureLayer;
-const vec4 DaySkyColor = vec4(0.49, 0.66, 1, 1);
+const vec4 DaySkyColor = vec4(0.21, 0.4, 1, 1);
const vec3 SunPos = vec3(0, 0.1, 0.5);
const vec3 MoonPos = vec3(0, 0.1, -0.5);
+const vec4 NightSkyColor = vec4(0.0, 0.0008, 0.002, 1.0);
+
vec3 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords, float Layer) {
float x = TextureAtlasCoords.x;
float y = TextureAtlasCoords.y;
@@ -38,7 +41,7 @@ vec3 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords, float Layer)
}
vec4 Sun() {
- vec3 sunDelta = (pos - SunPos) * 3.0f;
+ vec3 sunDelta = (facePos - SunPos) * 3.0f;
float distanceToSun = length(sunDelta);
vec4 sunColor = texture(textureAtlas, TransformTextureCoord(sunTexture, (vec2(sunDelta.xy) + 0.5f), sunTextureLayer));
vec4 sun = mix(vec4(0, 0, 0, 1), sunColor, clamp(1 - distanceToSun * 2.0f, 0, 1));
@@ -46,7 +49,7 @@ vec4 Sun() {
}
vec4 Moon() {
- vec3 moonDelta = (pos - MoonPos) * 4.5f;
+ vec3 moonDelta = (facePos - MoonPos) * 4.5f;
float distanceToMoon = length(moonDelta);
vec4 moonColor = texture(textureAtlas, TransformTextureCoord(moonTexture, (vec2(moonDelta.xy) + 0.5f), moonTextureLayer));
vec4 moon = mix(vec4(0, 0, 0, 1),moonColor, clamp(1 - distanceToMoon * 2.0f, 0, 1));
@@ -54,8 +57,7 @@ vec4 Moon() {
}
void main() {
- vec4 starColor = vec4(0.0f, 0.04f, 0.06f, 1.0f);
- color = vec4(mix(starColor, DaySkyColor, dayTime).rgb, 1.0f);
+ color = vec4(mix(NightSkyColor, DaySkyColor, dayTime).rgb, 1.0f);
color += vec4(Sun().rgb, 1.0f);
color += vec4(Moon().rgb, 1.0f);
normal = vec4(0.0f, 0.0f, 0.0f, 1.0f);
diff --git a/cwd/assets/altcraft/shaders/vert/entity.vs b/cwd/assets/altcraft/shaders/vert/entity.vs
index b2f1db6..4acaa93 100644
--- a/cwd/assets/altcraft/shaders/vert/entity.vs
+++ b/cwd/assets/altcraft/shaders/vert/entity.vs
@@ -9,6 +9,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
void main() {
diff --git a/cwd/assets/altcraft/shaders/vert/face.vs b/cwd/assets/altcraft/shaders/vert/face.vs
index 5fb9357..70c24c8 100644
--- a/cwd/assets/altcraft/shaders/vert/face.vs
+++ b/cwd/assets/altcraft/shaders/vert/face.vs
@@ -18,6 +18,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
void main() {
diff --git a/cwd/assets/altcraft/shaders/vert/fbo.vs b/cwd/assets/altcraft/shaders/vert/fbo.vs
index e490da5..cfde14e 100644
--- a/cwd/assets/altcraft/shaders/vert/fbo.vs
+++ b/cwd/assets/altcraft/shaders/vert/fbo.vs
@@ -10,6 +10,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
void main() {
diff --git a/cwd/assets/altcraft/shaders/vert/light.vs b/cwd/assets/altcraft/shaders/vert/light.vs
index 0033107..4e551f8 100644
--- a/cwd/assets/altcraft/shaders/vert/light.vs
+++ b/cwd/assets/altcraft/shaders/vert/light.vs
@@ -10,6 +10,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
void main() {
diff --git a/cwd/assets/altcraft/shaders/vert/pp.vs b/cwd/assets/altcraft/shaders/vert/pp.vs
index 0033107..4e551f8 100644
--- a/cwd/assets/altcraft/shaders/vert/pp.vs
+++ b/cwd/assets/altcraft/shaders/vert/pp.vs
@@ -10,6 +10,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
void main() {
diff --git a/cwd/assets/altcraft/shaders/vert/rml.vs b/cwd/assets/altcraft/shaders/vert/rml.vs
index d82308e..ea78825 100644
--- a/cwd/assets/altcraft/shaders/vert/rml.vs
+++ b/cwd/assets/altcraft/shaders/vert/rml.vs
@@ -14,6 +14,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
void main() {
diff --git a/cwd/assets/altcraft/shaders/vert/sky.vs b/cwd/assets/altcraft/shaders/vert/sky.vs
index e580843..617caed 100644
--- a/cwd/assets/altcraft/shaders/vert/sky.vs
+++ b/cwd/assets/altcraft/shaders/vert/sky.vs
@@ -11,6 +11,7 @@ layout (std140) uniform Globals {
uvec2 viewportSize;
float globalTime;
float dayTime;
+ float gamma;
};
void main() {
diff --git a/cwd/assets/altcraft/ui/options.rml b/cwd/assets/altcraft/ui/options.rml
index 485dcba..c5758be 100644
--- a/cwd/assets/altcraft/ui/options.rml
+++ b/cwd/assets/altcraft/ui/options.rml
@@ -8,9 +8,9 @@
<body class="body-options">
<form>
<div class="option">
- <label>Brightness</label>
- <input type="range" min="0.0" max="1.0" step="0.01" id="brightness" />
- <span id="brightness-val"></span>
+ <label>Gamma</label>
+ <input type="range" min="1.0" max="3.0" step="0.1" id="gamma" />
+ <span id="gamma-val"></span>
</div>
<div class="option">
diff --git a/src/Gal.hpp b/src/Gal.hpp
index 234e49a..8d7394a 100644
--- a/src/Gal.hpp
+++ b/src/Gal.hpp
@@ -158,6 +158,8 @@ namespace Gal {
virtual void SetWrapping(Wrapping wrapping) = 0;
+ virtual void SetLinear(bool isLinear) = 0;
+
};
struct Texture {
@@ -261,6 +263,7 @@ namespace Gal {
template<typename T>
void Resize() {
Resize(sizeof(T));
+ *Get<T>() = T{};
}
virtual std::byte* GetDataPtr() = 0;
diff --git a/src/GalOgl.cpp b/src/GalOgl.cpp
index 961c6ef..ff43ed8 100644
--- a/src/GalOgl.cpp
+++ b/src/GalOgl.cpp
@@ -321,7 +321,7 @@ size_t GalFormatGetSize(Format format) {
return 0;
}
-GLenum GalFormatGetGlInternalFormat(Format format) {
+GLenum GalFormatGetGlLinearInternalFormat(Format format) {
switch (format) {
case Format::D24S8:
return GL_DEPTH24_STENCIL8;
@@ -335,6 +335,20 @@ GLenum GalFormatGetGlInternalFormat(Format format) {
return 0;
}
+GLenum GalFormatGetGlInternalFormat(Format format) {
+ switch (format) {
+ case Format::D24S8:
+ return GL_DEPTH24_STENCIL8;
+ case Format::R8G8B8:
+ return GL_SRGB;
+ case Format::R8G8B8A8:
+ return GL_SRGB_ALPHA;
+ default:
+ return 0;
+ }
+ return 0;
+}
+
GLenum GalFormatGetGlFormat(Format format) {
switch (format) {
case Format::D24S8:
@@ -580,6 +594,7 @@ struct TextureConfigOgl : public TextureConfig {
Format format;
size_t width = 1, height = 1, depth = 1;
bool interpolateLayers = false;
+ bool linear = true;
GLenum type;
Filtering min = Filtering::Nearest, max = Filtering::Nearest;
@@ -597,6 +612,10 @@ struct TextureConfigOgl : public TextureConfig {
wrap = wrapping;
}
+ virtual void SetLinear(bool isLinear) override {
+ linear = isLinear;
+ }
+
};
struct TextureOgl : public Texture {
@@ -605,12 +624,15 @@ struct TextureOgl : public Texture {
GlResource texture;
Format format;
size_t width, height, depth;
+ bool linear;
virtual void SetData(std::vector<std::byte>&& data, size_t mipLevel = 0) override {
size_t expectedSize = width * height * depth * GalFormatGetSize(format);
if (data.size() != expectedSize && !data.empty())
throw std::logic_error("Size of data is not valid for this texture");
+ GLenum internalFormat = linear ? GalFormatGetGlLinearInternalFormat(format) : GalFormatGetGlInternalFormat(format);
+
oglState.BindTexture(type, texture);
switch (type) {
@@ -630,13 +652,13 @@ struct TextureOgl : public Texture {
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
case GL_PROXY_TEXTURE_CUBE_MAP:
- glTexImage2D(type, mipLevel, GalFormatGetGlInternalFormat(format), width, height, 0, GalFormatGetGlFormat(format), GalFormatGetGlType(format), data.empty() ? nullptr : data.data());
+ glTexImage2D(type, mipLevel, internalFormat, width, height, 0, GalFormatGetGlFormat(format), GalFormatGetGlType(format), data.empty() ? nullptr : data.data());
break;
case GL_TEXTURE_3D:
case GL_PROXY_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
case GL_PROXY_TEXTURE_2D_ARRAY:
- glTexImage3D(type, mipLevel, GalFormatGetGlInternalFormat(format), width, height, depth, 0, GalFormatGetGlFormat(format), GalFormatGetGlType(format), data.empty() ? nullptr : data.data());
+ glTexImage3D(type, mipLevel, internalFormat, width, height, depth, 0, GalFormatGetGlFormat(format), GalFormatGetGlType(format), data.empty() ? nullptr : data.data());
break;
default:
throw std::runtime_error("Unknown texture type");
@@ -1136,6 +1158,7 @@ struct ImplOgl : public Impl {
texture->width = texConfig->width;
texture->height = texConfig->height;
texture->depth = texConfig->depth;
+ texture->linear = texConfig->linear;
GLuint newTex;
glGenTextures(1, &newTex);
diff --git a/src/Render.cpp b/src/Render.cpp
index 682b60a..4fc0616 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -144,6 +144,7 @@ void Render::PrepareToRendering() {
auto gal = Gal::GetImplementation();
gal->GetDefaultFramebuffer()->SetViewport(0, 0, width, height);
+ gal->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->gamma = Settings::ReadDouble("gamma", 2.2);
std::string vertexSource, pixelSource;
{
@@ -503,7 +504,6 @@ void Render::InitEvents() {
renderWorld = true;
SetState(State::Playing);
GetGameState()->GetPlayer()->isFlying = Settings::ReadBool("flight", false);
- PUSH_EVENT("SetMinLightLevel", (float)Settings::ReadDouble("brightness", 0.2f));
});
listener.RegisterHandler("ConnectionFailed", [this](const Event& eventData) {
@@ -597,8 +597,8 @@ void Render::InitEvents() {
else
SDL_GL_SetSwapInterval(0);
- float brightness = Settings::ReadDouble("brightness", 0.2f);
- PUSH_EVENT("SetMinLightLevel", brightness);
+
+ Gal::GetImplementation()->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->gamma = Settings::ReadDouble("gamma", 2.2);
PrepareToRendering();
});
diff --git a/src/RenderConfigs.hpp b/src/RenderConfigs.hpp
index da7fd96..1e6a978 100644
--- a/src/RenderConfigs.hpp
+++ b/src/RenderConfigs.hpp
@@ -5,8 +5,12 @@
struct GlobalShaderParameters {
glm::mat4 projView;
glm::uvec2 viewportSize;
- float globalTime;
- float dayTime;
+ glm::float32 globalTime;
+ glm::float32 dayTime;
+ glm::float32 gamma;
+ glm::uint32 paddingF0 = 0xF0F0F0F0;
+ glm::uint32 paddingF1 = 0xF1F1F1F1;
+ glm::uint32 paddingF2 = 0xF2F2F2F2;
};
std::shared_ptr<Gal::Shader> LoadVertexShader(std::string_view assetPath);
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp
index c6d490a..846788b 100644
--- a/src/RendererWorld.cpp
+++ b/src/RendererWorld.cpp
@@ -256,10 +256,6 @@ RendererWorld::RendererWorld(std::shared_ptr<Gal::Framebuffer> target) {
sections.erase(it);
});
- listener->RegisterHandler("SetMinLightLevel", [this](const Event& eventData) {
-
- });
-
for (int i = 0; i < numOfWorkers; i++)
workers.push_back(std::thread(&RendererWorld::WorkerFunction, this, i));
diff --git a/src/TextureAtlas.cpp b/src/TextureAtlas.cpp
index 7e44a86..9ad018e 100644
--- a/src/TextureAtlas.cpp
+++ b/src/TextureAtlas.cpp
@@ -89,6 +89,7 @@ TextureAtlas::TextureAtlas(std::vector<TextureData> &textures) {
texConfig->SetWrapping(Gal::Wrapping::Clamp);
texConfig->SetMinFilter(Gal::Filtering::Nearest);
texConfig->SetMaxFilter(Gal::Filtering::Nearest);
+ texConfig->SetLinear(false);
texture = gal->BuildTexture(texConfig);