summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-11-21 10:57:57 +0100
committerLaG1924 <lag1924@gmail.com>2021-11-21 10:57:57 +0100
commitf16c897522b6418c399b5699f8378a25c2e5de4f (patch)
tree9fd1490645de30330b6ae84eebd1fe961c3f1e52
parentAdded Gbuffer (diff)
downloadAltCraft-f16c897522b6418c399b5699f8378a25c2e5de4f.tar
AltCraft-f16c897522b6418c399b5699f8378a25c2e5de4f.tar.gz
AltCraft-f16c897522b6418c399b5699f8378a25c2e5de4f.tar.bz2
AltCraft-f16c897522b6418c399b5699f8378a25c2e5de4f.tar.lz
AltCraft-f16c897522b6418c399b5699f8378a25c2e5de4f.tar.xz
AltCraft-f16c897522b6418c399b5699f8378a25c2e5de4f.tar.zst
AltCraft-f16c897522b6418c399b5699f8378a25c2e5de4f.zip
-rw-r--r--cwd/assets/altcraft/shaders/frag/face.fs3
-rw-r--r--cwd/assets/altcraft/shaders/frag/light.fs2
-rw-r--r--cwd/assets/altcraft/shaders/vert/face.vs15
-rw-r--r--src/RendererSectionData.cpp4
-rw-r--r--src/RendererSectionData.hpp19
-rw-r--r--src/RendererWorld.cpp3
6 files changed, 28 insertions, 18 deletions
diff --git a/cwd/assets/altcraft/shaders/frag/face.fs b/cwd/assets/altcraft/shaders/frag/face.fs
index 0eb5a21..2120697 100644
--- a/cwd/assets/altcraft/shaders/frag/face.fs
+++ b/cwd/assets/altcraft/shaders/frag/face.fs
@@ -3,6 +3,7 @@
in VS_OUT {
vec3 Texture;
vec3 Color;
+ vec3 faceNormal;
} fs_in;
layout (location = 0) out vec4 color;
@@ -16,5 +17,5 @@ void main() {
discard;
color = vec4(col.rgb * fs_in.Color, 1.0f);
- normal = vec4(1.0f - color.r, 1.0f - color.b, 1.0f, 1.0f);
+ normal = vec4(fs_in.faceNormal, 1.0f);
}
diff --git a/cwd/assets/altcraft/shaders/frag/light.fs b/cwd/assets/altcraft/shaders/frag/light.fs
index 480e265..73686cc 100644
--- a/cwd/assets/altcraft/shaders/frag/light.fs
+++ b/cwd/assets/altcraft/shaders/frag/light.fs
@@ -12,5 +12,5 @@ void main() {
vec4 c = texture(color, uv);
vec4 n = texture(normal, uv);
float d = texture(depthStencil, uv).r;
- fragColor = vec4(c.r, n.r, d - 0.3f, 1.0f);
+ fragColor = n;
}
diff --git a/cwd/assets/altcraft/shaders/vert/face.vs b/cwd/assets/altcraft/shaders/vert/face.vs
index 93e623d..21f7110 100644
--- a/cwd/assets/altcraft/shaders/vert/face.vs
+++ b/cwd/assets/altcraft/shaders/vert/face.vs
@@ -1,15 +1,17 @@
#version 330 core
-layout (location = 0) in vec3 position[4];
-layout (location = 4) in vec2 uv[4];
-layout (location = 8) in float uvLayer;
-layout (location = 9) in float animation;
-layout (location = 10) in vec3 color;
-layout (location = 11) in vec2 light;
+in vec3 position[4];
+in vec3 normal;
+in vec2 uv[4];
+in float uvLayer;
+in float animation;
+in vec3 color;
+in vec2 light;
out VS_OUT {
vec3 Texture;
vec3 Color;
+ vec3 faceNormal;
} vs_out;
uniform float GlobalTime;
@@ -24,4 +26,5 @@ void main() {
float faceLight = clamp(light.x / 15.0 + (light.y / 15.0) * DayTime, MinLightLevel, 1.0);
vs_out.Color = mix(color.rgb * faceLight, vec3(1,1,1) * faceLight, float(color == vec3(0,0,0)));
+ vs_out.faceNormal = normal;
}
diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp
index 2588fd6..0ac901e 100644
--- a/src/RendererSectionData.cpp
+++ b/src/RendererSectionData.cpp
@@ -26,11 +26,13 @@ glm::vec2 TransformTextureCoord(glm::vec4 TextureAtlasCoords, glm::vec2 UvCoords
void AddFacesByBlockModel(RendererSectionData &data, const BlockFaces &model, const glm::mat4 &transform, bool visibility[FaceDirection::none], BlockLightness light, BlockLightness skyLight) {
for (const auto &face : model.faces) {
+ glm::vec3 normal = {};
glm::vec2 lightness;
lightness.x = _max(light.face[0], light.face[1], light.face[2], light.face[3], light.face[4], light.face[5]);
lightness.y = _max(skyLight.face[0], skyLight.face[1], skyLight.face[2], skyLight.face[3], skyLight.face[4], skyLight.face[5]);
if (face.visibility != FaceDirection::none) {
FaceDirection direction = face.visibility;
+ normal = FaceDirectionVector[direction].glm();
Vector directionVec = model.faceDirectionVector[direction];
FaceDirection faceDirection = FaceDirection::none;
for (int i = 0; i < FaceDirection::none; i++) {
@@ -56,6 +58,8 @@ void AddFacesByBlockModel(RendererSectionData &data, const BlockFaces &model, co
vertexData.positions[2] = transformed * glm::vec4(1, 0, 1, 1);
vertexData.positions[3] = transformed * glm::vec4(1, 0, 0, 1);
+ vertexData.normal = normal;
+
vertexData.uvs[0] = TransformTextureCoord(face.texture, glm::vec2(0, 0), face.frames);
vertexData.uvs[1] = TransformTextureCoord(face.texture, glm::vec2(1, 0), face.frames);
vertexData.uvs[2] = TransformTextureCoord(face.texture, glm::vec2(1, 1), face.frames);
diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp
index edd2992..0a80560 100644
--- a/src/RendererSectionData.hpp
+++ b/src/RendererSectionData.hpp
@@ -31,20 +31,21 @@ struct SectionsData {
};
struct VertexData {
- glm::vec3 positions[4];
- glm::vec2 uvs[4];
- float uvLayers;
- float animations;
- glm::vec3 colors;
- glm::vec2 lights;
- uint8_t padding[20];
+ glm::vec3 positions[4];
+ glm::vec3 normal;
+ glm::vec2 uvs[4];
+ float uvLayers;
+ float animations;
+ glm::vec3 colors;
+ glm::vec2 lights;
+ uint8_t padding[8];
};
struct RendererSectionData {
- std::vector<VertexData> vertices;
+ std::vector<VertexData> vertices;
size_t hash = 0;
Vector sectionPos;
- bool forced = false;
+ bool forced = false;
};
RendererSectionData ParseSection(const SectionsData &sections); \ No newline at end of file
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp
index 561578f..9055729 100644
--- a/src/RendererWorld.cpp
+++ b/src/RendererWorld.cpp
@@ -449,12 +449,13 @@ void RendererWorld::PrepareRender(std::shared_ptr<Gal::Framebuffer> target) {
sectionsPLC->SetPrimitive(Gal::Primitive::TriangleFan);
sectionsBufferBinding = sectionsPLC->BindVertexBuffer({
{"position", Gal::Type::Vec3, 4, 1},
+ {"normal", Gal::Type::Vec3, 1, 1},
{"uv", Gal::Type::Vec2, 4, 1},
{"uvLayer", Gal::Type::Float, 1, 1},
{"animation", Gal::Type::Float, 1, 1},
{"color", Gal::Type::Vec3, 1, 1},
{"light", Gal::Type::Vec2, 1, 1},
- {"", Gal::Type::Uint8, 20, 1}
+ {"", Gal::Type::Uint8, 8, 1}
});
sectionsPipeline = gal->BuildPipeline(sectionsPLC);
sectionsPipeline->SetShaderParameter("MinLightLevel", 0.2f);