summaryrefslogtreecommitdiffstats
path: root/cwd/assets/altcraft
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-12-06 01:39:15 +0100
committerLaG1924 <lag1924@gmail.com>2021-12-07 12:37:47 +0100
commitaa591c73c818d7f26caa15bc567929e2d404dcf2 (patch)
tree2514facee211ef5eb16812658caae91d1ee078d6 /cwd/assets/altcraft
parentMinor shader optimization (diff)
downloadAltCraft-aa591c73c818d7f26caa15bc567929e2d404dcf2.tar
AltCraft-aa591c73c818d7f26caa15bc567929e2d404dcf2.tar.gz
AltCraft-aa591c73c818d7f26caa15bc567929e2d404dcf2.tar.bz2
AltCraft-aa591c73c818d7f26caa15bc567929e2d404dcf2.tar.lz
AltCraft-aa591c73c818d7f26caa15bc567929e2d404dcf2.tar.xz
AltCraft-aa591c73c818d7f26caa15bc567929e2d404dcf2.tar.zst
AltCraft-aa591c73c818d7f26caa15bc567929e2d404dcf2.zip
Diffstat (limited to 'cwd/assets/altcraft')
-rw-r--r--cwd/assets/altcraft/scripts/ui.lua1
-rw-r--r--cwd/assets/altcraft/shaders/frag/fwd_entity.fs11
-rw-r--r--cwd/assets/altcraft/shaders/frag/fwd_face.fs38
-rw-r--r--cwd/assets/altcraft/shaders/frag/fwd_sky.fs65
-rw-r--r--cwd/assets/altcraft/ui/options.rml6
5 files changed, 121 insertions, 0 deletions
diff --git a/cwd/assets/altcraft/scripts/ui.lua b/cwd/assets/altcraft/scripts/ui.lua
index 938088f..bc04626 100644
--- a/cwd/assets/altcraft/scripts/ui.lua
+++ b/cwd/assets/altcraft/scripts/ui.lua
@@ -1,5 +1,6 @@
local options = {
gamma = 2.2,
+ deffered = false,
flight = false,
mouseSensetivity = 0.1,
renderDistance = 2,
diff --git a/cwd/assets/altcraft/shaders/frag/fwd_entity.fs b/cwd/assets/altcraft/shaders/frag/fwd_entity.fs
new file mode 100644
index 0000000..094aaf2
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/fwd_entity.fs
@@ -0,0 +1,11 @@
+#version 330 core
+
+in vec4 entityWorldPos;
+
+out vec4 fragColor;
+
+uniform vec3 entityColor;
+
+void main() {
+ fragColor = vec4(entityColor, 1.0f);
+}
diff --git a/cwd/assets/altcraft/shaders/frag/fwd_face.fs b/cwd/assets/altcraft/shaders/frag/fwd_face.fs
new file mode 100644
index 0000000..deb8341
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/fwd_face.fs
@@ -0,0 +1,38 @@
+#version 330 core
+
+in vec4 faceWorldPos;
+in vec3 faceTextureUv;
+in vec3 faceAddColor;
+in vec3 faceNormal;
+in vec2 faceLight;
+
+out vec4 fragColor;
+
+uniform sampler2DArray textureAtlas;
+
+layout (std140) uniform Globals {
+ mat4 projView;
+ mat4 proj;
+ mat4 view;
+ uvec2 viewportSize;
+ vec4 ssaoKernels[64];
+ float globalTime;
+ float dayTime;
+ float gamma;
+};
+
+void main() {
+ vec4 col = texture(textureAtlas, faceTextureUv);
+ if (col.a < 0.3f)
+ discard;
+
+ float localLight = faceLight.r / 15.0f;
+ float skyLight = faceLight.g / 15.0f;
+ float lightLevel = clamp(localLight + skyLight * dayTime, 0.01f, 1.0f);
+ lightLevel = pow(lightLevel, 3);
+ lightLevel = clamp(lightLevel, 0.005f, 1.0f);
+
+ fragColor = vec4(col.rgb * faceAddColor.rgb * lightLevel, 1.0f);
+
+ fragColor.rgb = pow(fragColor.rgb, vec3(1.0f / gamma));
+}
diff --git a/cwd/assets/altcraft/shaders/frag/fwd_sky.fs b/cwd/assets/altcraft/shaders/frag/fwd_sky.fs
new file mode 100644
index 0000000..b6185fd
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/fwd_sky.fs
@@ -0,0 +1,65 @@
+#version 330 core
+
+in vec3 facePos;
+
+out vec4 fragColor;
+
+layout (std140) uniform Globals {
+ mat4 projView;
+ mat4 proj;
+ mat4 view;
+ uvec2 viewportSize;
+ vec4 ssaoKernels[64];
+ float globalTime;
+ float dayTime;
+ float gamma;
+};
+
+uniform sampler2DArray textureAtlas;
+uniform vec4 sunTexture;
+uniform float sunTextureLayer;
+uniform vec4 moonTexture;
+uniform float moonTextureLayer;
+
+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;
+ float w = TextureAtlasCoords.z;
+ float h = TextureAtlasCoords.w;
+ vec2 A = vec2(x, 1 - y - h);
+ vec2 B = vec2(x + w, 1 - y);
+ vec2 transformed = A + UvCoords * (B - A);
+ return vec3(transformed.x, transformed.y, Layer);
+}
+
+vec4 Sun() {
+ 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));
+ return sun;
+}
+
+vec4 Moon() {
+ 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));
+ return moon;
+}
+
+void main() {
+ fragColor = vec4(mix(NightSkyColor, DaySkyColor, dayTime).rgb, 1.0f);
+ fragColor += vec4(Sun().rgb, 1.0f);
+ fragColor += vec4(Moon().rgb, 1.0f);
+
+ fragColor.rgb = pow(fragColor.rgb, vec3(1.0f / gamma));
+}
diff --git a/cwd/assets/altcraft/ui/options.rml b/cwd/assets/altcraft/ui/options.rml
index 9aa4624..ea7c39e 100644
--- a/cwd/assets/altcraft/ui/options.rml
+++ b/cwd/assets/altcraft/ui/options.rml
@@ -14,6 +14,12 @@
</div>
<div class="option">
+ <label>Deffered shading</label>
+ <input type="checkbox" id="deffered" />
+ <span id="deffered-val"></span>
+ </div>
+
+ <div class="option">
<label>Flight</label>
<input type="checkbox" id="flight" />
<span id="flight-val"></span>