Episode 2
This commit is contained in:
parent
2b5b5dcb94
commit
ad910a47f1
@ -71,20 +71,20 @@
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>C:\dev\C++\ScuffedMinecraft\Dependencies\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\dev\C++\ScuffedMinecraft\Dependencies\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)Dependencies\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)Dependencies\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>C:\dev\C++\ScuffedMinecraft\Dependencies\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\dev\C++\ScuffedMinecraft\Dependencies\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)Dependencies\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)Dependencies\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IncludePath>C:\dev\C++\ScuffedMinecraft\Dependencies\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\dev\C++\ScuffedMinecraft\Dependencies\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)Dependencies\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)Dependencies\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>C:\dev\C++\ScuffedMinecraft\Dependencies\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\dev\C++\ScuffedMinecraft\Dependencies\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)Dependencies\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)Dependencies\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@ -155,6 +155,7 @@
|
||||
<ClCompile Include="src\Block.cpp" />
|
||||
<ClCompile Include="src\Camera.cpp" />
|
||||
<ClCompile Include="src\Chunk.cpp" />
|
||||
<ClCompile Include="src\NoiseSettings.cpp" />
|
||||
<ClCompile Include="src\Planet.cpp" />
|
||||
<ClCompile Include="src\Shader.cpp" />
|
||||
<ClCompile Include="src\TupleHash.h" />
|
||||
@ -174,6 +175,7 @@
|
||||
<ClInclude Include="src\Blocks.h" />
|
||||
<ClInclude Include="src\Camera.h" />
|
||||
<ClInclude Include="src\Chunk.h" />
|
||||
<ClInclude Include="src\NoiseSettings.h" />
|
||||
<ClInclude Include="src\Planet.h" />
|
||||
<ClInclude Include="src\Shader.h" />
|
||||
<ClInclude Include="vendor\imgui\imconfig.h" />
|
||||
|
@ -66,6 +66,9 @@
|
||||
<ClCompile Include="vendor\imgui\imgui_widgets.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\NoiseSettings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\Shader.h">
|
||||
@ -119,6 +122,9 @@
|
||||
<ClInclude Include="vendor\imgui\imstb_truetype.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\NoiseSettings.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="assets\shaders\vertex_shader.glsl" />
|
||||
|
@ -1,12 +1,23 @@
|
||||
#version 330 core
|
||||
|
||||
in vec2 TexCoord;
|
||||
in vec3 Normal;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
vec3 ambient = vec3(.5);
|
||||
vec3 lightDirection = vec3(0.8, 1, 0.7);
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(tex, TexCoord);
|
||||
vec3 lightDir = normalize(-lightDirection);
|
||||
|
||||
float diff = max(dot(Normal, lightDir), 0.0);
|
||||
vec3 diffuse = diff * vec3(1);
|
||||
|
||||
vec4 result = vec4(ambient + diffuse, 1.0);
|
||||
|
||||
FragColor = texture(tex, TexCoord) * result;
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
#version 330 core
|
||||
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoord;
|
||||
layout (location = 2) in int aDirection;
|
||||
|
||||
out vec2 TexCoord;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform float texMultiplier;
|
||||
|
||||
@ -11,8 +14,20 @@ uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
// Array of possible normals based on direction
|
||||
const vec3 normals[6] = vec3[6](
|
||||
vec3(0, 0, 1), // 0
|
||||
vec3(0, 0, -1), // 1
|
||||
vec3(1, 0, 0), // 2
|
||||
vec3(-1, 0, 0), // 3
|
||||
vec3(0, 1, 0), // 4
|
||||
vec3(0, -1, 0) // 5
|
||||
);
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
TexCoord = aTexCoord * texMultiplier;
|
||||
|
||||
Normal = normals[aDirection];
|
||||
}
|
@ -52,8 +52,8 @@ int main()
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
// Create window
|
||||
GLFWwindow* window = glfwCreateWindow(windowX, windowY, "Scuffed Minecraft", NULL, NULL);
|
||||
if (window == NULL)
|
||||
GLFWwindow* window = glfwCreateWindow(windowX, windowY, "Scuffed Minecraft", nullptr, nullptr);
|
||||
if (window == nullptr)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window\n";
|
||||
glfwTerminate();
|
||||
|
@ -44,12 +44,6 @@ void Chunk::GenerateChunk()
|
||||
WorldGen::GenerateChunkData(chunkPos.x - 1, chunkPos.y, chunkPos.z, chunkSize, &westData);
|
||||
WorldGen::GenerateChunkData(chunkPos.x, chunkPos.y + 1, chunkPos.z, chunkSize, &upData);
|
||||
WorldGen::GenerateChunkData(chunkPos.x, chunkPos.y - 1, chunkPos.z, chunkSize, &downData);
|
||||
//auto northData = Planet::planet->GetChunkData(chunkPos.x, chunkPos.y, chunkPos.z - 1);
|
||||
//auto southData = Planet::planet->GetChunkData(chunkPos.x, chunkPos.y, chunkPos.z + 1);
|
||||
//auto eastData = Planet::planet->GetChunkData(chunkPos.x + 1, chunkPos.y, chunkPos.z);
|
||||
//auto westData = Planet::planet->GetChunkData(chunkPos.x - 1, chunkPos.y, chunkPos.z);
|
||||
//auto upData = Planet::planet->GetChunkData(chunkPos.x, chunkPos.y + 1, chunkPos.z);
|
||||
//auto downData = Planet::planet->GetChunkData(chunkPos.x, chunkPos.y - 1, chunkPos.z);
|
||||
|
||||
//std::cout << "Got chunk data in thread: " << std::this_thread::get_id() << '\n';
|
||||
|
||||
@ -82,10 +76,10 @@ void Chunk::GenerateChunk()
|
||||
|
||||
if (northBlock == 0)
|
||||
{
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 0, block->sideMinX, block->sideMinY));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 0, block->sideMaxX, block->sideMinY));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 0, block->sideMinX, block->sideMaxY));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 0, block->sideMaxX, block->sideMaxY));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 0, block->sideMinX, block->sideMinY, 0));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 0, block->sideMaxX, block->sideMinY, 0));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 0, block->sideMinX, block->sideMaxY, 0));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 0, block->sideMaxX, block->sideMaxY, 0));
|
||||
|
||||
indices.push_back(currentVertex + 0);
|
||||
indices.push_back(currentVertex + 3);
|
||||
@ -112,10 +106,10 @@ void Chunk::GenerateChunk()
|
||||
}
|
||||
if (southBlock == 0)
|
||||
{
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 1, block->sideMinX, block->sideMinY));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 1, block->sideMaxX, block->sideMinY));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 1, block->sideMinX, block->sideMaxY));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 1, block->sideMaxX, block->sideMaxY));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 1, block->sideMinX, block->sideMinY, 1));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 1, block->sideMaxX, block->sideMinY, 1));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 1, block->sideMinX, block->sideMaxY, 1));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 1, block->sideMaxX, block->sideMaxY, 1));
|
||||
|
||||
indices.push_back(currentVertex + 0);
|
||||
indices.push_back(currentVertex + 3);
|
||||
@ -142,10 +136,10 @@ void Chunk::GenerateChunk()
|
||||
}
|
||||
if (westBlock == 0)
|
||||
{
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 0, block->sideMinX, block->sideMinY));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 1, block->sideMaxX, block->sideMinY));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 0, block->sideMinX, block->sideMaxY));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 1, block->sideMaxX, block->sideMaxY));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 0, block->sideMinX, block->sideMinY, 2));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 1, block->sideMaxX, block->sideMinY, 2));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 0, block->sideMinX, block->sideMaxY, 2));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 1, block->sideMaxX, block->sideMaxY, 2));
|
||||
|
||||
indices.push_back(currentVertex + 0);
|
||||
indices.push_back(currentVertex + 3);
|
||||
@ -172,10 +166,10 @@ void Chunk::GenerateChunk()
|
||||
}
|
||||
if (eastBlock == 0)
|
||||
{
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 1, block->sideMinX, block->sideMinY));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 0, block->sideMaxX, block->sideMinY));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 1, block->sideMinX, block->sideMaxY));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 0, block->sideMaxX, block->sideMaxY));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 1, block->sideMinX, block->sideMinY, 3));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 0, block->sideMaxX, block->sideMinY, 3));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 1, block->sideMinX, block->sideMaxY, 3));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 0, block->sideMaxX, block->sideMaxY, 3));
|
||||
|
||||
indices.push_back(currentVertex + 0);
|
||||
indices.push_back(currentVertex + 3);
|
||||
@ -202,10 +196,10 @@ void Chunk::GenerateChunk()
|
||||
}
|
||||
if (bottomBlock == 0)
|
||||
{
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 1, block->bottomMinX, block->bottomMinY));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 1, block->bottomMaxX, block->bottomMinY));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 0, block->bottomMinX, block->bottomMaxY));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 0, block->bottomMaxX, block->bottomMaxY));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 1, block->bottomMinX, block->bottomMinY, 4));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 1, block->bottomMaxX, block->bottomMinY, 4));
|
||||
vertices.push_back(Vertex(x + 1, y + 0, z + 0, block->bottomMinX, block->bottomMaxY, 4));
|
||||
vertices.push_back(Vertex(x + 0, y + 0, z + 0, block->bottomMaxX, block->bottomMaxY, 4));
|
||||
|
||||
indices.push_back(currentVertex + 0);
|
||||
indices.push_back(currentVertex + 3);
|
||||
@ -232,10 +226,10 @@ void Chunk::GenerateChunk()
|
||||
}
|
||||
if (topBlock == 0)
|
||||
{
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 1, block->topMinX, block->topMinY));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 1, block->topMaxX, block->topMinY));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 0, block->topMinX, block->topMaxY));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 0, block->topMaxX, block->topMaxY));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 1, block->topMinX, block->topMinY, 5));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 1, block->topMaxX, block->topMinY, 5));
|
||||
vertices.push_back(Vertex(x + 0, y + 1, z + 0, block->topMinX, block->topMaxY, 5));
|
||||
vertices.push_back(Vertex(x + 1, y + 1, z + 0, block->topMaxX, block->topMaxY, 5));
|
||||
|
||||
indices.push_back(currentVertex + 0);
|
||||
indices.push_back(currentVertex + 3);
|
||||
@ -276,6 +270,8 @@ void Chunk::Render(unsigned int modelLoc)
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(1, 2, GL_BYTE, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texGridX));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribIPointer(2, 1, GL_BYTE, sizeof(Vertex), (void*)offsetof(Vertex, direction));
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
glGenBuffers(1, &ebo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
||||
|
@ -8,8 +8,9 @@ struct Vertex
|
||||
{
|
||||
char posX, posY, posZ;
|
||||
char texGridX, texGridY;
|
||||
char direction;
|
||||
|
||||
Vertex(char _posX, char _posY, char _posZ, char _texGridX, char _texGridY)
|
||||
Vertex(char _posX, char _posY, char _posZ, char _texGridX, char _texGridY, char _direction)
|
||||
{
|
||||
posX = _posX;
|
||||
posY = _posY;
|
||||
@ -17,6 +18,8 @@ struct Vertex
|
||||
|
||||
texGridX = _texGridX;
|
||||
texGridY = _texGridY;
|
||||
|
||||
direction = _direction;
|
||||
}
|
||||
};
|
||||
|
||||
|
18
ScuffedMinecraft/src/NoiseSettings.cpp
Normal file
18
ScuffedMinecraft/src/NoiseSettings.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "NoiseSettings.h"
|
||||
|
||||
NoiseSettings::NoiseSettings(float _frequency, float _amplitude, float _offset)
|
||||
: frequency(_frequency), amplitude(_amplitude), offset(_offset), chance(0), block(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NoiseSettings::NoiseSettings(float _frequency, float _amplitude, float _offset, float _chance, unsigned int _block, int _maxHeight)
|
||||
: frequency(_frequency), amplitude(_amplitude), offset(_offset), chance(_chance), block(_block), maxHeight(_maxHeight)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NoiseSettings::~NoiseSettings()
|
||||
{
|
||||
|
||||
}
|
17
ScuffedMinecraft/src/NoiseSettings.h
Normal file
17
ScuffedMinecraft/src/NoiseSettings.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
struct NoiseSettings
|
||||
{
|
||||
public:
|
||||
float amplitude;
|
||||
float frequency;
|
||||
float offset;
|
||||
|
||||
float chance;
|
||||
unsigned int block;
|
||||
int maxHeight;
|
||||
|
||||
NoiseSettings(float _frequency, float _amplitude, float _offset);
|
||||
NoiseSettings(float _frequency, float _amplitude, float _offset, float _chance, unsigned int _block, int _maxHeight);
|
||||
~NoiseSettings();
|
||||
};
|
@ -55,17 +55,17 @@ void Planet::Update(float camX, float camY, float camZ, unsigned int modelLoc)
|
||||
// Add middle chunks
|
||||
for (int y = 0; y <= renderHeight; y++)
|
||||
{
|
||||
chunkQueue.push({ camChunkX, y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + r, y, camChunkZ });
|
||||
chunkQueue.push({ camChunkX, y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - r, y, camChunkZ });
|
||||
chunkQueue.push({ camChunkX, camChunkY + y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY + y, camChunkZ });
|
||||
chunkQueue.push({ camChunkX, camChunkY + y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY + y, camChunkZ });
|
||||
|
||||
if (y > 0)
|
||||
{
|
||||
chunkQueue.push({ camChunkX, -y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + r, -y, camChunkZ });
|
||||
chunkQueue.push({ camChunkX, -y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - r, -y, camChunkZ });
|
||||
chunkQueue.push({ camChunkX, camChunkY - y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY - y, camChunkZ });
|
||||
chunkQueue.push({ camChunkX, camChunkY - y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY - y, camChunkZ });
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,31 +74,31 @@ void Planet::Update(float camX, float camY, float camZ, unsigned int modelLoc)
|
||||
{
|
||||
for (int y = 0; y <= renderHeight; y++)
|
||||
{
|
||||
chunkQueue.push({ camChunkX + e, y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX - e, y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + e, camChunkY + y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX - e, camChunkY + y, camChunkZ + r });
|
||||
|
||||
chunkQueue.push({ camChunkX + r, y, camChunkZ + e });
|
||||
chunkQueue.push({ camChunkX + r, y, camChunkZ - e });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY + y, camChunkZ + e });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY + y, camChunkZ - e });
|
||||
|
||||
chunkQueue.push({ camChunkX + e, y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - e, y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX + e, camChunkY + y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - e, camChunkY + y, camChunkZ - r });
|
||||
|
||||
chunkQueue.push({ camChunkX - r, y, camChunkZ + e });
|
||||
chunkQueue.push({ camChunkX - r, y, camChunkZ - e });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY + y, camChunkZ + e });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY + y, camChunkZ - e });
|
||||
|
||||
if (y > 0)
|
||||
{
|
||||
chunkQueue.push({ camChunkX + e, -y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX - e, -y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + e, camChunkY - y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX - e, camChunkY - y, camChunkZ + r });
|
||||
|
||||
chunkQueue.push({ camChunkX + r, -y, camChunkZ + e });
|
||||
chunkQueue.push({ camChunkX + r, -y, camChunkZ - e });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY - y, camChunkZ + e });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY - y, camChunkZ - e });
|
||||
|
||||
chunkQueue.push({ camChunkX + e, -y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - e, -y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX + e, camChunkY - y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - e, camChunkY - y, camChunkZ - r });
|
||||
|
||||
chunkQueue.push({ camChunkX - r, -y, camChunkZ + e });
|
||||
chunkQueue.push({ camChunkX - r, -y, camChunkZ - e });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY - y, camChunkZ + e });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY - y, camChunkZ - e });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,17 +106,17 @@ void Planet::Update(float camX, float camY, float camZ, unsigned int modelLoc)
|
||||
// Add corners
|
||||
for (int y = 0; y <= renderHeight; y++)
|
||||
{
|
||||
chunkQueue.push({ camChunkX + r, y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + r, y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - r, y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX - r, y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY + y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY + y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY + y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY + y, camChunkZ - r });
|
||||
|
||||
if (y > 0)
|
||||
{
|
||||
chunkQueue.push({ camChunkX + r, -y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + r, -y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - r, -y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX - r, -y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY - y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX + r, camChunkY - y, camChunkZ - r });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY - y, camChunkZ + r });
|
||||
chunkQueue.push({ camChunkX - r, camChunkY - y, camChunkZ - r });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,25 +46,25 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath)
|
||||
|
||||
// vertex shader
|
||||
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex, 1, &vShaderCode, NULL);
|
||||
glShaderSource(vertex, 1, &vShaderCode, nullptr);
|
||||
glCompileShader(vertex);
|
||||
// print compile errors if any
|
||||
glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
|
||||
glGetShaderInfoLog(vertex, 512, nullptr, infoLog);
|
||||
std::cout << "Error compiling vertex shader!\n" << infoLog << '\n';
|
||||
}
|
||||
|
||||
// fragment shader
|
||||
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||
glShaderSource(fragment, 1, &fShaderCode, nullptr);
|
||||
glCompileShader(fragment);
|
||||
// print compile errors if any
|
||||
glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(fragment, 512, NULL, infoLog);
|
||||
glGetShaderInfoLog(fragment, 512, nullptr, infoLog);
|
||||
std::cout << "Error compiling fragment shader!\n" << infoLog << '\n';
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath)
|
||||
glGetProgramiv(ID, GL_LINK_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetProgramInfoLog(ID, 512, NULL, infoLog);
|
||||
glGetProgramInfoLog(ID, 512, nullptr, infoLog);
|
||||
std::cout << "Error linking shader program!\n" << infoLog << '\n';
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,37 @@
|
||||
#include "WorldGen.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <OpenSimplexNoise.hh>
|
||||
|
||||
#include "Blocks.h"
|
||||
|
||||
void WorldGen::GenerateChunkData(int chunkX, int chunkY, int chunkZ, int chunkSize, std::vector<unsigned int>* chunkData)
|
||||
{
|
||||
// Init noise
|
||||
OSN::Noise<2> noise2D;
|
||||
OSN::Noise<3> noise3D;
|
||||
|
||||
// Init noise settings
|
||||
NoiseSettings surfaceSettings[] {
|
||||
{ 0.01f, 20.0f, 0 },
|
||||
{ 0.1f, 3.0f, 0 }
|
||||
};
|
||||
int surfaceSettingsLength = sizeof(surfaceSettings) / sizeof(*surfaceSettings);
|
||||
|
||||
NoiseSettings caveSettings[] {
|
||||
{ 0.05f, 1.0f, 0, .5f, 0, 100 }
|
||||
};
|
||||
int caveSettingsLength = sizeof(caveSettings) / sizeof(*caveSettings);
|
||||
|
||||
NoiseSettings oreSettings[] {
|
||||
{ 0.075f, 1.0f, 8.54f, .75f, 1, 0 }
|
||||
};
|
||||
int oreSettingsLength = sizeof(oreSettings) / sizeof(*oreSettings);
|
||||
|
||||
// Set vector size
|
||||
chunkData->reserve(chunkSize * chunkSize * chunkSize);
|
||||
|
||||
OSN::Noise<2> surfaceNoise;
|
||||
OSN::Noise<3> caveNoise;
|
||||
// Account for chunk position
|
||||
int startX = chunkX * chunkSize;
|
||||
int startY = chunkY * chunkSize;
|
||||
int startZ = chunkZ * chunkSize;
|
||||
@ -18,36 +40,78 @@ void WorldGen::GenerateChunkData(int chunkX, int chunkY, int chunkZ, int chunkSi
|
||||
{
|
||||
for (int z = 0; z < chunkSize; z++)
|
||||
{
|
||||
int noiseY = (surfaceNoise.eval((float)(x + startX) * .1f, (float)(z + startZ) * .1f) * 3.0f) + 20;
|
||||
// Surface noise
|
||||
int noiseY = 20;
|
||||
for (int i = 0; i < surfaceSettingsLength; i++)
|
||||
{
|
||||
noiseY += noise2D.eval(
|
||||
(float)((x + startX) * surfaceSettings[i].frequency) + surfaceSettings[i].offset,
|
||||
(float)((z + startZ) * surfaceSettings[i].frequency) + surfaceSettings[i].offset)
|
||||
* surfaceSettings[i].amplitude;
|
||||
}
|
||||
|
||||
for (int y = 0; y < chunkSize; y++)
|
||||
{
|
||||
//chunkData.push_back(0); // Empty
|
||||
//chunkData.push_back(1); // Full
|
||||
//chunkData.push_back(((x + y + z) % 2 == 0) ? 1 : 0); // Checkerboard
|
||||
/*chunkData.push_back( // Edges
|
||||
(x == 0 || x == chunkSize - 1) ||
|
||||
(y == 0 || y == chunkSize - 1) ||
|
||||
(z == 0 || z == chunkSize - 1)
|
||||
? 1 : 0
|
||||
);*/
|
||||
// Cave noise
|
||||
bool cave = false;
|
||||
for (int i = 0; i < caveSettingsLength; i++)
|
||||
{
|
||||
if (y + startY > caveSettings[i].maxHeight)
|
||||
continue;
|
||||
|
||||
float noiseCaves = caveNoise.eval(
|
||||
(float)(x + startX) * .1f,
|
||||
(float)(y + startY) * .1f,
|
||||
(float)(z + startZ) * .1f);
|
||||
float noiseCaves = noise3D.eval(
|
||||
(float)((x + startX) * caveSettings[i].frequency) + caveSettings[i].offset,
|
||||
(float)((y + startY) * caveSettings[i].frequency) + caveSettings[i].offset,
|
||||
(float)((z + startZ) * caveSettings[i].frequency) + caveSettings[i].offset)
|
||||
* caveSettings[i].amplitude;
|
||||
|
||||
if (noiseCaves > caveSettings[i].chance)
|
||||
{
|
||||
cave = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 1: Terrain Shape (surface and caves) and Ores
|
||||
|
||||
// Sky and Caves
|
||||
if (y + startY > noiseY)
|
||||
chunkData->push_back(0);
|
||||
else if (noiseCaves > .5f)
|
||||
else if (cave)
|
||||
chunkData->push_back(0);
|
||||
// Ground
|
||||
else if (y + startY == noiseY)
|
||||
chunkData->push_back(Blocks::GRASS_BLOCK);
|
||||
else if (y + startY > 10)
|
||||
chunkData->push_back(Blocks::DIRT_BLOCK);
|
||||
else
|
||||
chunkData->push_back(Blocks::STONE_BLOCK);
|
||||
{
|
||||
bool blockSet = false;
|
||||
for (int i = 0; i < oreSettingsLength; i++)
|
||||
{
|
||||
if (y + startY > oreSettings[i].maxHeight)
|
||||
continue;
|
||||
|
||||
float noiseOre = noise3D.eval(
|
||||
(float)((x + startX) * oreSettings[i].frequency) + oreSettings[i].offset,
|
||||
(float)((y + startY) * oreSettings[i].frequency) + oreSettings[i].offset,
|
||||
(float)((z + startZ) * oreSettings[i].frequency) + oreSettings[i].offset)
|
||||
* oreSettings[i].amplitude;
|
||||
|
||||
if (noiseOre > oreSettings[i].chance)
|
||||
{
|
||||
chunkData->push_back(oreSettings[i].block);
|
||||
blockSet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!blockSet)
|
||||
{
|
||||
if (y + startY == noiseY)
|
||||
chunkData->push_back(Blocks::GRASS_BLOCK);
|
||||
else if (y + startY > 10)
|
||||
chunkData->push_back(Blocks::DIRT_BLOCK);
|
||||
else
|
||||
chunkData->push_back(Blocks::STONE_BLOCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "NoiseSettings.h"
|
||||
|
||||
namespace WorldGen
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user