добавленно частичное сглаживание
This commit is contained in:
parent
fea123bc5f
commit
f04bac6b43
Binary file not shown.
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 16 KiB |
BIN
res/block.png.old.old
Normal file
BIN
res/block.png.old.old
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
@ -210,7 +210,7 @@ void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int
|
|||||||
float vu = 1.0f - ((index[3] / atlasRes) * scale) - scale;
|
float vu = 1.0f - ((index[3] / atlasRes) * scale) - scale;
|
||||||
float uf = (index[0] % atlasRes) * scale;
|
float uf = (index[0] % atlasRes) * scale;
|
||||||
float vf = 1.0f - ((index[0] / atlasRes) * scale) - scale;
|
float vf = 1.0f - ((index[0] / atlasRes) * scale) - scale;
|
||||||
if (this->index + 18*VERTEX_SIZE >= capacity)
|
// if (this->index + 18*VERTEX_SIZE >= capacity)
|
||||||
render();
|
render();
|
||||||
|
|
||||||
float ar = 0.88f;
|
float ar = 0.88f;
|
||||||
@ -258,6 +258,10 @@ void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int
|
|||||||
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
|
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
|
||||||
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
|
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
|
||||||
vertex(points[1], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
|
vertex(points[1], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
|
||||||
|
|
||||||
|
glDisable(GL_MULTISAMPLE);
|
||||||
|
render();
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch2D::rect(float x, float y, float w, float h,
|
void Batch2D::rect(float x, float y, float w, float h,
|
||||||
|
|||||||
@ -65,7 +65,7 @@ void HudRenderer::drawDebug(Level* level, Assets* assets, int fps, bool occlusio
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HudRenderer::draw(Level* level, Assets* assets){
|
void HudRenderer::draw(Level* level, Assets* assets, bool devdata){
|
||||||
uicamera->fov = Window::height;
|
uicamera->fov = Window::height;
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
@ -210,11 +210,12 @@ void HudRenderer::draw(Level* level, Assets* assets){
|
|||||||
|
|
||||||
batch->render();
|
batch->render();
|
||||||
|
|
||||||
if (Events::_cursor_locked){
|
if (Events::_cursor_locked && !devdata){
|
||||||
Shader* crosshairShader = assets->getShader("crosshair");
|
Shader* crosshairShader = assets->getShader("crosshair");
|
||||||
crosshairShader->use();
|
crosshairShader->use();
|
||||||
crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
|
crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
|
||||||
crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
|
crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
|
||||||
|
glLineWidth(2.0f);
|
||||||
crosshair->draw(GL_LINES);
|
crosshair->draw(GL_LINES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class HudRenderer {
|
|||||||
public:
|
public:
|
||||||
HudRenderer();
|
HudRenderer();
|
||||||
~HudRenderer();
|
~HudRenderer();
|
||||||
void draw(Level* level, Assets* assets);
|
void draw(Level* level, Assets* assets, bool devdata);
|
||||||
void drawDebug(Level* level, Assets* assets, int fps, bool occlusion);
|
void drawDebug(Level* level, Assets* assets, int fps, bool occlusion);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -159,8 +159,8 @@ void mainloop(Level* level, Assets* assets) {
|
|||||||
for (int i = 0; i < freeLoaders; i++)
|
for (int i = 0; i < freeLoaders; i++)
|
||||||
level->chunksController->loadVisible(world->wfile);
|
level->chunksController->loadVisible(world->wfile);
|
||||||
|
|
||||||
worldRenderer.draw(world, camera, occlusion);
|
worldRenderer.draw(world, camera, occlusion, devdata);
|
||||||
hud.draw(level, assets);
|
hud.draw(level, assets, devdata);
|
||||||
if (devdata) {
|
if (devdata) {
|
||||||
hud.drawDebug(level, assets, fps, occlusion);
|
hud.drawDebug(level, assets, fps, occlusion);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setSeed(int number){
|
void setSeed(int number){
|
||||||
seed = ((unsigned short)number+23729 xor (unsigned short)number+16786);
|
seed = ((unsigned short)(number*23729) xor (unsigned short)(number+16786));
|
||||||
|
rand();
|
||||||
|
}
|
||||||
|
void setSeed(int number1,int number2){
|
||||||
|
seed = (((unsigned short)(number1*23729) or (unsigned short)(number2%16786)) xor (unsigned short)(number2*number1));
|
||||||
rand();
|
rand();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -70,27 +74,28 @@ float calc_height_faster(fnl_state *noise, int real_x, int real_z){
|
|||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
int generate_tree(fnl_state *noise, PseudoRandom* random, const float* heights, int real_x, int real_y, int real_z, int tileSize){
|
int generate_tree(fnl_state *noise, PseudoRandom* random, float* heights, int real_x, int real_y, int real_z, int tileSize){
|
||||||
const int tileX = floor((double)real_x/(double)tileSize);
|
const int tileX = floor((double)real_x/(double)tileSize);
|
||||||
const int tileY = floor((double)real_z/(double)tileSize);
|
const int tileZ = floor((double)real_z/(double)tileSize);
|
||||||
random->setSeed(tileX*4325261+tileY*12160951+tileSize*9431111);
|
random->setSeed(tileX*4325261+tileZ*12160951+tileSize*9431111);
|
||||||
|
|
||||||
bool gentree = fnlGetNoise3D(noise, tileX*3.0f+633, 0.0, tileY*3.0f) > -0.1f && (random->rand() % 10) < 7;
|
bool gentree = fnlGetNoise3D(noise, tileX*3.0f+633, 0.0, tileZ*3.0f) > -0.1f && (random->rand() % 10) < 7;
|
||||||
if (!gentree)
|
if (!gentree)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const int randomX = (random->rand() % (tileSize/2)) - tileSize/4;
|
const int randomX = (random->rand() % (tileSize/2)) - tileSize/4;
|
||||||
const int randomZ = (random->rand() % (tileSize/2)) - tileSize/4;
|
const int randomZ = (random->rand() % (tileSize/2)) - tileSize/4;
|
||||||
int centerX = tileX * tileSize + tileSize/2 + randomX;
|
int centerX = tileX * tileSize + tileSize/2 + randomX;
|
||||||
int centerY = tileY * tileSize + tileSize/2 + randomZ;
|
int centerZ = tileZ * tileSize + tileSize/2 + randomZ;
|
||||||
int height = (int)calc_height_faster(noise, centerX, centerY);
|
// int height = (int)(heights[centerX*CHUNK_W+centerZ]);
|
||||||
if ((height < 57) || (fnlGetNoise3D(noise, real_x*0.025f,real_z*0.025f, 0.0f)*0.5f > 0.5))
|
int height = (int)calc_height_faster(noise, centerX, centerZ);
|
||||||
|
if ((height < 57)/* || (fnlGetNoise3D(noise, real_x*0.025f,real_z*0.025f, 0.0f)*0.5f > 0.5)*/)
|
||||||
return 0;
|
return 0;
|
||||||
int lx = real_x - centerX;
|
int lx = real_x - centerX;
|
||||||
int radius = random->rand() % 4 + 3;
|
int radius = random->rand() % 4 + 2;
|
||||||
int ly = real_y - height - 3 * radius;
|
int ly = real_y - height - 3 * radius;
|
||||||
int lz = real_z - centerY;
|
int lz = real_z - centerZ;
|
||||||
if (lx == 0 && lz == 0 && real_y - height < 4*radius)
|
if (lx == 0 && lz == 0 && real_y - height < (3*radius + radius/2))
|
||||||
return 6;
|
return 6;
|
||||||
if (lx*lx+ly*ly/2+lz*lz < radius*radius)
|
if (lx*lx+ly*ly/2+lz*lz < radius*radius)
|
||||||
return 7;
|
return 7;
|
||||||
@ -102,6 +107,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
|
noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
|
||||||
noise.seed = seed * 60617077 % 25896307;
|
noise.seed = seed * 60617077 % 25896307;
|
||||||
PseudoRandom randomtree;
|
PseudoRandom randomtree;
|
||||||
|
PseudoRandom randomgrass;
|
||||||
|
|
||||||
float heights[CHUNK_VOL];
|
float heights[CHUNK_VOL];
|
||||||
|
|
||||||
@ -123,6 +129,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
for (int y = 0; y < CHUNK_H; y++){
|
for (int y = 0; y < CHUNK_H; y++){
|
||||||
int real_y = y;
|
int real_y = y;
|
||||||
int id = real_y < 55 ? BLOCK_WATER : BLOCK_AIR;
|
int id = real_y < 55 ? BLOCK_WATER : BLOCK_AIR;
|
||||||
|
int states = 0;
|
||||||
if ((real_y == (int)height) && (54 < real_y)) {
|
if ((real_y == (int)height) && (54 < real_y)) {
|
||||||
id = BLOCK_GRASS_BLOCK;
|
id = BLOCK_GRASS_BLOCK;
|
||||||
} else if (real_y < (height - 6)){
|
} else if (real_y < (height - 6)){
|
||||||
@ -130,13 +137,14 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
} else if (real_y < height){
|
} else if (real_y < height){
|
||||||
id = BLOCK_DIRT;
|
id = BLOCK_DIRT;
|
||||||
} else {
|
} else {
|
||||||
int tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 16);
|
int tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23);
|
||||||
if (tree) {
|
if (tree) {
|
||||||
id = tree;
|
id = tree;
|
||||||
} else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 19))){
|
states = 0x32;
|
||||||
id = tree;
|
// } else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 19))){
|
||||||
} else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23))){
|
// id = tree;
|
||||||
id = tree;
|
// } else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23))){
|
||||||
|
// id = tree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ((height - (1.5 - 0.2 * pow(height - 54, 4))) < real_y) && (real_y < height)){
|
if ( ((height - (1.5 - 0.2 * pow(height - 54, 4))) < real_y) && (real_y < height)){
|
||||||
@ -144,14 +152,20 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
}
|
}
|
||||||
if (real_y <= 2)
|
if (real_y <= 2)
|
||||||
id = BLOCK_BEDROCK;
|
id = BLOCK_BEDROCK;
|
||||||
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)random() > 56000)){
|
|
||||||
|
randomgrass.setSeed(real_x,real_z);
|
||||||
|
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 56000)){
|
||||||
id = BLOCK_GRASS;
|
id = BLOCK_GRASS;
|
||||||
}
|
}
|
||||||
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)random() > 64000)){
|
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 65000)){
|
||||||
id = BLOCK_FLOWER;
|
id = BLOCK_FLOWER;
|
||||||
}
|
}
|
||||||
|
if ((height > 56) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 65533)){
|
||||||
|
id = BLOCK_WOOD;
|
||||||
|
states = 0x32;
|
||||||
|
}
|
||||||
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;
|
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;
|
||||||
voxels[(y * CHUNK_D + z) * CHUNK_W + x].states = 0x32;
|
voxels[(y * CHUNK_D + z) * CHUNK_W + x].states = states;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ int Window::initialize(int width, int height, const char* title){
|
|||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
|
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
|
||||||
//glfwWindowHint(GLFW_SAMPLES, 2);
|
glfwWindowHint(GLFW_SAMPLES, 16);
|
||||||
|
|
||||||
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
||||||
if (window == nullptr){
|
if (window == nullptr){
|
||||||
@ -34,6 +34,8 @@ int Window::initialize(int width, int height, const char* title){
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
// glDisable(GL_MULTISAMPLE);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
Window::width = width;
|
Window::width = width;
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "graphics/VoxelRenderer.h"
|
#include "graphics/VoxelRenderer.h"
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#include "window/Window.h"
|
#include "window/Window.h"
|
||||||
#include "window/Camera.h"
|
#include "window/Camera.h"
|
||||||
@ -63,15 +64,16 @@ bool WorldRenderer::drawChunk(size_t index, Camera* camera, Shader* shader, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 model = glm::translate(mat4(1.0f), vec3(chunk->x*CHUNK_W+0.5f, 0.5f, chunk->z*CHUNK_D+0.5f));
|
mat4 model = glm::translate(mat4(1.0f), vec3(chunk->x*CHUNK_W+0.5f, 0.5f, chunk->z*CHUNK_D+0.5f));
|
||||||
shader->uniformMatrix("u_model", model);
|
shader->uniformMatrix("u_model", model);
|
||||||
|
glDisable(GL_MULTISAMPLE);
|
||||||
mesh->draw(GL_TRIANGLES);
|
mesh->draw(GL_TRIANGLES);
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WorldRenderer::draw(World* world, Camera* camera, bool occlusion){
|
void WorldRenderer::draw(World* world, Camera* camera, bool occlusion, bool devdata){
|
||||||
Chunks* chunks = level->chunks;
|
Chunks* chunks = level->chunks;
|
||||||
|
|
||||||
vec4 skyColor(0.7f, 0.81f, 1.0f, 1.0f);
|
vec4 skyColor(0.7f, 0.81f, 1.0f, 1.0f);
|
||||||
@ -133,21 +135,54 @@ void WorldRenderer::draw(World* world, Camera* camera, bool occlusion){
|
|||||||
// draw 3D stuff here
|
// draw 3D stuff here
|
||||||
batch3d->render();
|
batch3d->render();
|
||||||
|
|
||||||
linesShader->use();
|
if (devdata) {
|
||||||
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
|
linesShader->use();
|
||||||
glLineWidth(2.0f);
|
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
|
||||||
lineBatch->line(camera->position.x, camera->position.y-0.1f, camera->position.z, camera->position.x+0.01f, camera->position.y-0.1f, camera->position.z, 1, 0, 0, 1);
|
|
||||||
lineBatch->line(camera->position.x, camera->position.y-0.1f, camera->position.z, camera->position.x, camera->position.y-0.1f, camera->position.z+0.01f, 0, 0, 1, 1);
|
vec3 point = vec3(camera->position.x+camera->front.x/1,
|
||||||
lineBatch->line(camera->position.x, camera->position.y-0.1f, camera->position.z, camera->position.x, camera->position.y-0.1f+0.01f, camera->position.z, 0, 1, 0, 1);
|
camera->position.y+camera->front.y/1,
|
||||||
lineBatch->render();
|
camera->position.z+camera->front.z/1);
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
glLineWidth(3.0f);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x+0.1f, point.y, point.z,
|
||||||
|
0, 0, 0, 1);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x, point.y, point.z+0.1f,
|
||||||
|
0, 0, 0, 1);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x, point.y+0.1f, point.z,
|
||||||
|
0, 0, 0, 1);
|
||||||
|
lineBatch->render();
|
||||||
|
|
||||||
|
glLineWidth(1.0f);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x+0.1f, point.y, point.z,
|
||||||
|
1, 0, 0, 1);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x, point.y, point.z+0.1f,
|
||||||
|
0, 0, 1, 1);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x, point.y+0.1f, point.z,
|
||||||
|
0, 1, 0, 1);
|
||||||
|
lineBatch->render();
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
if (level->playerController->selectedBlockId != -1){
|
if (level->playerController->selectedBlockId != -1){
|
||||||
Block* selectedBlock = Block::blocks[level->playerController->selectedBlockId];
|
Block* selectedBlock = Block::blocks[level->playerController->selectedBlockId];
|
||||||
vec3 pos = level->playerController->selectedBlockPosition;
|
vec3 pos = level->playerController->selectedBlockPosition;
|
||||||
|
linesShader->use();
|
||||||
|
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
|
||||||
|
glLineWidth(2.0f);
|
||||||
if (selectedBlock->model == 1){
|
if (selectedBlock->model == 1){
|
||||||
lineBatch->box(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f, 1.005f,1.005f,1.005f, 0,0,0,0.5f);
|
lineBatch->box(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f, 1.005f,1.005f,1.005f, 0,0,0,0.5f);
|
||||||
} else if (selectedBlock->model == 2){
|
} else if (selectedBlock->model == 2){
|
||||||
lineBatch->box(pos.x+0.5f, pos.y+0.35f, pos.z+0.5f, 0.805f,0.705f,0.805f, 0,0,0,0.5f);
|
lineBatch->box(pos.x+0.5f, pos.y+0.35f, pos.z+0.5f, 0.805f,0.705f,0.805f, 0,0,0,0.5f);
|
||||||
}
|
}
|
||||||
|
lineBatch->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public:
|
|||||||
WorldRenderer(Level* level, Assets* assets);
|
WorldRenderer(Level* level, Assets* assets);
|
||||||
~WorldRenderer();
|
~WorldRenderer();
|
||||||
|
|
||||||
void draw(World* world, Camera* camera, bool occlusion);
|
void draw(World* world, Camera* camera, bool occlusion, bool devdata);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user