Refactor, shader fix
This commit is contained in:
parent
6965bbe809
commit
fbce36a05c
@ -7,11 +7,14 @@ out vec4 f_color;
|
|||||||
|
|
||||||
uniform sampler2D u_texture0;
|
uniform sampler2D u_texture0;
|
||||||
uniform vec3 u_fogColor;
|
uniform vec3 u_fogColor;
|
||||||
|
uniform float u_fogFactor;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
vec4 tex_color = texture(u_texture0, a_texCoord);
|
vec4 tex_color = texture(u_texture0, a_texCoord);
|
||||||
//if (tex_color.a < 0.5)
|
//if (tex_color.a < 0.5)
|
||||||
// discard;
|
// discard;
|
||||||
float depth = (a_distance/256.0)*(a_distance/256.0)*256.0/6;
|
float depth = (a_distance/256.0)*(a_distance/256.0)*256.0/6;
|
||||||
f_color = mix(a_color * tex_color, vec4(u_fogColor,1.0), min(1.0, depth/256.0/1.0f));
|
float alpha = a_color.a * tex_color.a;
|
||||||
|
f_color = mix(a_color * tex_color, vec4(u_fogColor,1.0), min(1.0, depth*u_fogFactor));
|
||||||
|
f_color.a = alpha;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,18 +78,12 @@ void write_world(World* world, Level* level){
|
|||||||
world->wfile->writePlayer(level->player);
|
world->wfile->writePlayer(level->player);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_level(World* world, Level* level, vec3 position, float delta, long frame, VoxelRenderer* renderer, PlayerController* playerController){
|
void update_level(World* world, Level* level, float delta, long frame, VoxelRenderer* renderer){
|
||||||
playerController->update_controls(delta);
|
level->playerController->update_controls(delta);
|
||||||
playerController->update_interaction();
|
level->playerController->update_interaction();
|
||||||
|
|
||||||
|
vec3 position = level->player->hitbox->position;
|
||||||
level->chunks->setCenter(world->wfile, position.x, 0, position.z);
|
level->chunks->setCenter(world->wfile, position.x, 0, position.z);
|
||||||
int freeLoaders = level->chunksController->countFreeLoaders();
|
|
||||||
for (int i = 0; i < freeLoaders; i++)
|
|
||||||
level->chunksController->_buildMeshes(renderer, frame);
|
|
||||||
|
|
||||||
freeLoaders = level->chunksController->countFreeLoaders();
|
|
||||||
for (int i = 0; i < freeLoaders; i++)
|
|
||||||
level->chunksController->loadVisible(world->wfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Level* load_level(World* world, Player* player) {
|
Level* load_level(World* world, Player* player) {
|
||||||
@ -137,7 +131,6 @@ int main() {
|
|||||||
std::cout << "-- preparing systems" << std::endl;
|
std::cout << "-- preparing systems" << std::endl;
|
||||||
HudRenderer hud;
|
HudRenderer hud;
|
||||||
WorldRenderer worldRenderer(level);
|
WorldRenderer worldRenderer(level);
|
||||||
PlayerController playerController(level);
|
|
||||||
|
|
||||||
float lastTime = glfwGetTime();
|
float lastTime = glfwGetTime();
|
||||||
float delta = 0.0f;
|
float delta = 0.0f;
|
||||||
@ -162,12 +155,19 @@ int main() {
|
|||||||
devdata = !devdata;
|
devdata = !devdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_level(world, level, camera->position, delta, frame, worldRenderer.renderer, &playerController);
|
update_level(world, level, delta, frame, worldRenderer.renderer);
|
||||||
|
int freeLoaders = level->chunksController->countFreeLoaders();
|
||||||
|
for (int i = 0; i < freeLoaders; i++)
|
||||||
|
level->chunksController->_buildMeshes(worldRenderer.renderer, frame);
|
||||||
|
freeLoaders = level->chunksController->countFreeLoaders();
|
||||||
|
for (int i = 0; i < freeLoaders; i++)
|
||||||
|
level->chunksController->loadVisible(world->wfile);
|
||||||
|
|
||||||
worldRenderer.draw(world, camera, assets, occlusion);
|
worldRenderer.draw(world, camera, assets, occlusion);
|
||||||
if (playerController.selectedBlockId != -1){
|
if (level->playerController->selectedBlockId != -1){
|
||||||
Block* selectedBlock = Block::blocks[playerController.selectedBlockId];
|
Block* selectedBlock = Block::blocks[level->playerController->selectedBlockId];
|
||||||
LineBatch* lineBatch = worldRenderer.lineBatch;
|
LineBatch* lineBatch = worldRenderer.lineBatch;
|
||||||
vec3 pos = playerController.selectedBlockPosition;
|
vec3 pos = level->playerController->selectedBlockPosition;
|
||||||
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){
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "Level.h"
|
#include "Level.h"
|
||||||
#include "../lighting/Lighting.h"
|
#include "../lighting/Lighting.h"
|
||||||
#include "../voxels/ChunksController.h"
|
#include "../voxels/ChunksController.h"
|
||||||
|
#include "../player_control.h"
|
||||||
|
|
||||||
Level::Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics) :
|
Level::Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics) :
|
||||||
player(player),
|
player(player),
|
||||||
@ -8,6 +9,7 @@ Level::Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physic
|
|||||||
physics(physics) {
|
physics(physics) {
|
||||||
lighting = new Lighting(chunks);
|
lighting = new Lighting(chunks);
|
||||||
chunksController = new ChunksController(world, chunks, lighting);
|
chunksController = new ChunksController(world, chunks, lighting);
|
||||||
|
playerController = new PlayerController(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Level::~Level(){
|
Level::~Level(){
|
||||||
@ -16,4 +18,5 @@ Level::~Level(){
|
|||||||
delete player;
|
delete player;
|
||||||
delete lighting;
|
delete lighting;
|
||||||
delete chunksController;
|
delete chunksController;
|
||||||
|
delete playerController;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ class Chunks;
|
|||||||
class Lighting;
|
class Lighting;
|
||||||
class PhysicsSolver;
|
class PhysicsSolver;
|
||||||
class ChunksController;
|
class ChunksController;
|
||||||
|
class PlayerController;
|
||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
public:
|
public:
|
||||||
@ -15,6 +16,7 @@ public:
|
|||||||
PhysicsSolver* physics;
|
PhysicsSolver* physics;
|
||||||
Lighting* lighting;
|
Lighting* lighting;
|
||||||
ChunksController* chunksController;
|
ChunksController* chunksController;
|
||||||
|
PlayerController* playerController;
|
||||||
Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics);
|
Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics);
|
||||||
~Level();
|
~Level();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -112,7 +112,8 @@ void WorldRenderer::draw(World* world, Camera* camera, Assets* assets, bool occl
|
|||||||
shader->uniformMatrix("u_view", camera->getView());
|
shader->uniformMatrix("u_view", camera->getView());
|
||||||
shader->uniform1f("u_gamma", 1.6f);
|
shader->uniform1f("u_gamma", 1.6f);
|
||||||
shader->uniform3f("u_skyLightColor", 2.2f,2.2f,2.2f);
|
shader->uniform3f("u_skyLightColor", 2.2f,2.2f,2.2f);
|
||||||
shader->uniform3f("u_fogColor", 0.7f,0.71f,0.73f);
|
shader->uniform3f("u_fogColor", 0.7f,0.81f,1.0f);
|
||||||
|
shader->uniform1f("u_fogFactor", 0.03f);
|
||||||
shader->uniform3f("u_cameraPos", camera->position.x,camera->position.y,camera->position.z);
|
shader->uniform3f("u_cameraPos", camera->position.x,camera->position.y,camera->position.z);
|
||||||
texture->bind();
|
texture->bind();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user