добавленно частичное сглаживание
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 uf = (index[0] % atlasRes) * 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();
|
||||
|
||||
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[6], uvpoints[4], 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,
|
||||
|
||||
@ -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;
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
@ -210,11 +210,12 @@ void HudRenderer::draw(Level* level, Assets* assets){
|
||||
|
||||
batch->render();
|
||||
|
||||
if (Events::_cursor_locked){
|
||||
if (Events::_cursor_locked && !devdata){
|
||||
Shader* crosshairShader = assets->getShader("crosshair");
|
||||
crosshairShader->use();
|
||||
crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
|
||||
crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
|
||||
glLineWidth(2.0f);
|
||||
crosshair->draw(GL_LINES);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ class HudRenderer {
|
||||
public:
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
@ -159,8 +159,8 @@ void mainloop(Level* level, Assets* assets) {
|
||||
for (int i = 0; i < freeLoaders; i++)
|
||||
level->chunksController->loadVisible(world->wfile);
|
||||
|
||||
worldRenderer.draw(world, camera, occlusion);
|
||||
hud.draw(level, assets);
|
||||
worldRenderer.draw(world, camera, occlusion, devdata);
|
||||
hud.draw(level, assets, devdata);
|
||||
if (devdata) {
|
||||
hud.drawDebug(level, assets, fps, occlusion);
|
||||
}
|
||||
|
||||
@ -31,7 +31,11 @@ public:
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
@ -70,27 +74,28 @@ float calc_height_faster(fnl_state *noise, int real_x, int real_z){
|
||||
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 tileY = floor((double)real_z/(double)tileSize);
|
||||
random->setSeed(tileX*4325261+tileY*12160951+tileSize*9431111);
|
||||
const int tileZ = floor((double)real_z/(double)tileSize);
|
||||
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)
|
||||
return 0;
|
||||
|
||||
const int randomX = (random->rand() % (tileSize/2)) - tileSize/4;
|
||||
const int randomZ = (random->rand() % (tileSize/2)) - tileSize/4;
|
||||
int centerX = tileX * tileSize + tileSize/2 + randomX;
|
||||
int centerY = tileY * tileSize + tileSize/2 + randomZ;
|
||||
int height = (int)calc_height_faster(noise, centerX, centerY);
|
||||
if ((height < 57) || (fnlGetNoise3D(noise, real_x*0.025f,real_z*0.025f, 0.0f)*0.5f > 0.5))
|
||||
int centerZ = tileZ * tileSize + tileSize/2 + randomZ;
|
||||
// int height = (int)(heights[centerX*CHUNK_W+centerZ]);
|
||||
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;
|
||||
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 lz = real_z - centerY;
|
||||
if (lx == 0 && lz == 0 && real_y - height < 4*radius)
|
||||
int lz = real_z - centerZ;
|
||||
if (lx == 0 && lz == 0 && real_y - height < (3*radius + radius/2))
|
||||
return 6;
|
||||
if (lx*lx+ly*ly/2+lz*lz < radius*radius)
|
||||
return 7;
|
||||
@ -102,6 +107,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
||||
noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
|
||||
noise.seed = seed * 60617077 % 25896307;
|
||||
PseudoRandom randomtree;
|
||||
PseudoRandom randomgrass;
|
||||
|
||||
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++){
|
||||
int real_y = y;
|
||||
int id = real_y < 55 ? BLOCK_WATER : BLOCK_AIR;
|
||||
int states = 0;
|
||||
if ((real_y == (int)height) && (54 < real_y)) {
|
||||
id = BLOCK_GRASS_BLOCK;
|
||||
} 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){
|
||||
id = BLOCK_DIRT;
|
||||
} 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) {
|
||||
id = tree;
|
||||
} else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 19))){
|
||||
id = tree;
|
||||
} else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23))){
|
||||
id = tree;
|
||||
states = 0x32;
|
||||
// } else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 19))){
|
||||
// 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)){
|
||||
@ -144,14 +152,20 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
||||
}
|
||||
if (real_y <= 2)
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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].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_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
|
||||
//glfwWindowHint(GLFW_SAMPLES, 2);
|
||||
glfwWindowHint(GLFW_SAMPLES, 16);
|
||||
|
||||
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
||||
if (window == nullptr){
|
||||
@ -34,6 +34,8 @@ int Window::initialize(int width, int height, const char* title){
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
// glDisable(GL_MULTISAMPLE);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
Window::width = width;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "graphics/VoxelRenderer.h"
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "window/Window.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));
|
||||
shader->uniformMatrix("u_model", model);
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
mesh->draw(GL_TRIANGLES);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
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;
|
||||
|
||||
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
|
||||
batch3d->render();
|
||||
|
||||
if (devdata) {
|
||||
linesShader->use();
|
||||
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
|
||||
glLineWidth(2.0f);
|
||||
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);
|
||||
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);
|
||||
|
||||
vec3 point = vec3(camera->position.x+camera->front.x/1,
|
||||
camera->position.y+camera->front.y/1,
|
||||
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){
|
||||
Block* selectedBlock = Block::blocks[level->playerController->selectedBlockId];
|
||||
vec3 pos = level->playerController->selectedBlockPosition;
|
||||
linesShader->use();
|
||||
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
|
||||
glLineWidth(2.0f);
|
||||
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);
|
||||
} 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->render();
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public:
|
||||
WorldRenderer(Level* level, Assets* assets);
|
||||
~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