Fog and more blocks
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
#version 450
|
||||
|
||||
vec3 SkyColour = vec3(186.0f / 255.0f, 214.0f / 255.0f, 254.0f / 255.0f);
|
||||
|
||||
in vec3 TexCoord;
|
||||
in float Distance;
|
||||
|
||||
out vec4 outColour;
|
||||
|
||||
uniform sampler2DArray tex;
|
||||
|
||||
void main() {
|
||||
outColour = texture(tex, TexCoord);
|
||||
|
||||
outColour = texture(tex, TexCoord);
|
||||
|
||||
if (outColour.w == .0)
|
||||
discard;
|
||||
|
||||
float fogMax = 20000;
|
||||
|
||||
outColour = vec4(mix(outColour.xyz, SkyColour, min(1.0f, Distance / fogMax)), outColour.w);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,23 @@ layout (location = 0) in vec3 position;
|
||||
layout (location = 1) in vec3 texcoord;
|
||||
|
||||
out vec3 TexCoord;
|
||||
out float Distance;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 proj;
|
||||
|
||||
void main() {
|
||||
TexCoord = texcoord;
|
||||
gl_Position = proj * view * model * vec4(position, 1.0);
|
||||
|
||||
TexCoord = texcoord;
|
||||
|
||||
gl_Position = proj * view * model * vec4(position, 1.0);
|
||||
|
||||
// Makes no sense but it works
|
||||
Distance = (
|
||||
gl_Position.x * gl_Position.x +
|
||||
gl_Position.y * gl_Position.y +
|
||||
gl_Position.z * gl_Position.z
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
BIN
resources/textures/bedrock.png
Normal file
BIN
resources/textures/bedrock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 225 B |
BIN
resources/textures/cobblestone.png
Normal file
BIN
resources/textures/cobblestone.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 568 B |
BIN
resources/textures/stone.png
Normal file
BIN
resources/textures/stone.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 223 B |
@@ -92,9 +92,8 @@ void Game::Setup(int w, int h) {
|
||||
Texture texture;
|
||||
m_world->TextureID = texture.LoadTextures(BlockDictionary->Textures);
|
||||
|
||||
|
||||
for (int x = 0; x < 2; x++)
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int y = 0; y < 2; y++) {
|
||||
|
||||
m_world->Chunks.push_back(std::make_shared<Chunk>(x, y));
|
||||
|
||||
@@ -150,7 +149,7 @@ void Game::Run() {
|
||||
|
||||
SDL_Event e;
|
||||
|
||||
const float clear[] = { 0.1f, 0.45f, 0.9f, 1.0f };
|
||||
const float clear[] = { 186.0f / 255.0f, 214.0f / 255.0f, 254.0f / 255.0f };
|
||||
|
||||
m_renderer = std::make_unique<Renderer>();
|
||||
|
||||
|
||||
@@ -13,25 +13,38 @@ Chunk::Chunk(int x, int z) {
|
||||
|
||||
m_model = glm::translate(glm::mat4(1.0f), { x * CHUNK_WIDTH, 0, z * CHUNK_DEPTH });
|
||||
|
||||
std::default_random_engine generator;
|
||||
|
||||
// [x + WIDTH * (y + HEIGHT * z)]
|
||||
for (int x = 0; x < CHUNK_WIDTH; x++)
|
||||
for (int y = 0; y < CHUNK_HEIGHT; y++)
|
||||
for (int z = 0; z < CHUNK_DEPTH; z++) {
|
||||
|
||||
if (y > 15) {
|
||||
if (y > 32) {
|
||||
Voxels.push_back((uint8_t)EBlockType::Air);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::uniform_real_distribution<float> distribution(0, 1);
|
||||
float r = distribution(generator);
|
||||
|
||||
if (r > 0.5f)
|
||||
if (y == 0) {
|
||||
|
||||
Voxels.push_back((uint8_t)EBlockType::Bedrock);
|
||||
|
||||
}
|
||||
else if (y < 28) {
|
||||
|
||||
Voxels.push_back((uint8_t)EBlockType::Stone);
|
||||
|
||||
}
|
||||
else if (y < 32) {
|
||||
|
||||
Voxels.push_back((uint8_t)EBlockType::Dirt);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Voxels.push_back((uint8_t)EBlockType::Grass);
|
||||
else
|
||||
Voxels.push_back((uint8_t)EBlockType::Air);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,20 @@ std::shared_ptr<CBlockDictionary> CBlockDictionary::GetInstance() {
|
||||
|
||||
void CBlockDictionary::Build() {
|
||||
|
||||
RegisterTexture("stone.png");
|
||||
RegisterTexture("dirt.png");
|
||||
RegisterTexture("grass_side.png");
|
||||
RegisterTexture("grass_top.png");
|
||||
RegisterTexture("cobblestone.png");
|
||||
RegisterTexture("bedrock.png");
|
||||
|
||||
// Texture winding order - top, bottom, left, right, front, back
|
||||
RegisterBlock(EBlockType::Air, { });
|
||||
RegisterBlock(EBlockType::Dirt, { EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt });
|
||||
RegisterBlock(EBlockType::Grass, { EFaceTexture::Grass, EFaceTexture::Dirt, EFaceTexture::GrassSide, EFaceTexture::GrassSide, EFaceTexture::GrassSide, EFaceTexture::GrassSide });
|
||||
RegisterBlock(EBlockType::Air, { });
|
||||
RegisterBlock(EBlockType::Stone, { EFaceTexture::Stone, EFaceTexture::Stone, EFaceTexture::Stone, EFaceTexture::Stone, EFaceTexture::Stone, EFaceTexture::Stone });
|
||||
RegisterBlock(EBlockType::Dirt, { EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt });
|
||||
RegisterBlock(EBlockType::Grass, { EFaceTexture::Grass, EFaceTexture::Dirt, EFaceTexture::GrassSide, EFaceTexture::GrassSide, EFaceTexture::GrassSide, EFaceTexture::GrassSide });
|
||||
RegisterBlock(EBlockType::Cobblestone, { EFaceTexture::Cobblestone, EFaceTexture::Cobblestone, EFaceTexture::Cobblestone, EFaceTexture::Cobblestone, EFaceTexture::Cobblestone, EFaceTexture::Cobblestone });
|
||||
RegisterBlock(EBlockType::Bedrock, { EFaceTexture::Bedrock, EFaceTexture::Bedrock, EFaceTexture::Bedrock, EFaceTexture::Bedrock, EFaceTexture::Bedrock, EFaceTexture::Bedrock });
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,12 @@ namespace EBlockType {
|
||||
|
||||
enum Block : uint8_t {
|
||||
|
||||
Air = 0,
|
||||
Dirt = 1,
|
||||
Grass = 2
|
||||
Air = 0,
|
||||
Stone,
|
||||
Grass,
|
||||
Dirt,
|
||||
Cobblestone,
|
||||
Bedrock
|
||||
|
||||
};
|
||||
|
||||
@@ -20,9 +23,12 @@ namespace EFaceTexture {
|
||||
|
||||
enum Texture : uint16_t {
|
||||
|
||||
Dirt = 0,
|
||||
GrassSide = 1,
|
||||
Grass = 2
|
||||
Stone,
|
||||
Dirt,
|
||||
GrassSide,
|
||||
Grass,
|
||||
Cobblestone,
|
||||
Bedrock
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user