Minor refactor

This commit is contained in:
MihailRis 2023-11-15 13:38:42 +03:00
parent aa88fcd7f9
commit be980b2aa6
7 changed files with 21 additions and 17 deletions

View File

@ -22,12 +22,15 @@ void main(){
vec2 pos2d = (u_model * vec4(v_position, 1.0)).xz-u_cameraPos.xz;
vec4 modelpos = u_model * vec4(v_position+vec3(0,pow(length(pos2d)*0.0, 3.0),0), 1.0);
vec4 viewmodelpos = u_view * modelpos;
vec3 light = v_light.rgb;
vec3 light = v_light.rgb * 1.6;
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance);
light += torchlight * u_torchlightColor;
a_color = vec4(pow(light, vec3(u_gamma)),1.0f);
a_texCoord = v_texCoord;
a_color.rgb += u_skyLightColor * v_light.a;
a_color.r = min(a_color.r, 1.1);
a_color.g = min(a_color.g, 1.1);
a_color.b = min(a_color.b, 1.1);
a_distance = length(viewmodelpos);
gl_Position = u_proj * viewmodelpos;
}

View File

@ -15,7 +15,7 @@ void setup_definitions() {
block->skyLightPassing = true;
block->obstacle = false;
block->selectable = false;
block->model = 0;
block->model = BlockModel::none;
Block::blocks[block->id] = block;
block = new Block(BLOCK_DIRT, 2);
@ -71,7 +71,7 @@ void setup_definitions() {
block->drawGroup = 5;
block->lightPassing = true;
block->obstacle = false;
block->model = 2;
block->model = BlockModel::xsprite;
block->hitboxScale = 0.5f;
Block::blocks[block->id] = block;
@ -79,7 +79,7 @@ void setup_definitions() {
block->drawGroup = 5;
block->lightPassing = true;
block->obstacle = false;
block->model = 2;
block->model = BlockModel::xsprite;
Block::blocks[block->id] = block;
block = new Block(BLOCK_BRICK, 17);

View File

@ -206,9 +206,9 @@ void HudRenderer::drawInventory(Player* player) {
tint = vec4(1.0f);
}
if (cblock->model == BLOCK_MODEL_CUBE){
if (cblock->model == BlockModel::block){
batch->blockSprite(x, y, size, size, 16, cblock->textureFaces, tint);
} else if (cblock->model == BLOCK_MODEL_X_SPRITE){
} else if (cblock->model == BlockModel::xsprite){
batch->sprite(x, y, size, size, 16, cblock->textureFaces[3], tint);
}
}
@ -265,9 +265,9 @@ void HudRenderer::draw(){
{
Block* cblock = Block::blocks[player->choosenBlock];
if (cblock->model == BLOCK_MODEL_CUBE){
if (cblock->model == BlockModel::block){
batch->blockSprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
} else if (cblock->model == BLOCK_MODEL_X_SPRITE){
} else if (cblock->model == BlockModel::xsprite){
batch->sprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
}
}

View File

@ -136,9 +136,9 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
linesShader->use();
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
glLineWidth(2.0f);
if (selectedBlock->model == 1){
if (selectedBlock->model == BlockModel::block){
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 == BlockModel::xsprite){
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();

View File

@ -313,7 +313,7 @@ void BlocksRenderer::render(const voxel* voxels, int atlas_size) {
uvfor(def, 2, atlas_size), uvfor(def, 3, atlas_size),
uvfor(def, 4, atlas_size), uvfor(def, 5, atlas_size) };
switch (def.model) {
case BLOCK_MODEL_CUBE:
case BlockModel::block:
if (*((light_t*)&def.emission)) {
blockCube(x, y, z, vec3(1, 1, 1), texfaces, def.drawGroup);
}
@ -321,7 +321,7 @@ void BlocksRenderer::render(const voxel* voxels, int atlas_size) {
blockCubeShaded(x, y, z, vec3(1, 1, 1), texfaces, &def, vox.states);
}
break;
case BLOCK_MODEL_X_SPRITE: {
case BlockModel::xsprite: {
blockXSprite(x, y, z, vec3(1, 1, 1), texfaces[FACE_MX], texfaces[FACE_MZ], 1.0f);
break;
}

View File

@ -243,7 +243,7 @@ void PlayerController::updateInteraction(){
lighting->onBlockSet(x,y,z, 0);
}
if (Events::jclicked(mousecode::BUTTON_2)){
if (block->model != BLOCK_MODEL_X_SPRITE){
if (block->model != BlockModel::xsprite){
x = (int)(iend.x)+(int)(norm.x);
y = (int)(iend.y)+(int)(norm.y);
z = (int)(iend.z)+(int)(norm.z);

View File

@ -1,9 +1,6 @@
#ifndef VOXELS_BLOCK_H_
#define VOXELS_BLOCK_H_
#define BLOCK_MODEL_CUBE 1
#define BLOCK_MODEL_X_SPRITE 2
#define FACE_MX 0
#define FACE_PX 1
#define FACE_MY 2
@ -11,6 +8,10 @@
#define FACE_MZ 4
#define FACE_PZ 5
enum class BlockModel {
none, block, xsprite
};
class Block {
public:
static Block* blocks[256];
@ -20,7 +21,7 @@ public:
int textureFaces[6]; // -x,x, -y,y, -z,z
unsigned char emission[3];
unsigned char drawGroup = 0;
unsigned char model = 1; // 0:None 1:Block 2:XSprite
BlockModel model = BlockModel::block;
bool lightPassing = false;
bool skyLightPassing = false;
bool obstacle = true;