uniform float daylight;
uniform float ambientLight;
uniform vec3 lightDir;
+uniform float depthOffset;
void main()
{
vec4 worldSpace = model * vec4(vertexPosition, 1.0);
gl_Position = VP * worldSpace;
+ if (gl_Position.z > -1.0)
+ gl_Position.z = max(-1.0, gl_Position.z - depthOffset);
fragmentPosition = worldSpace.xyz;
fragmentTextureCoordinates = vertexPosition;
uniform float daylight;
uniform float ambientLight;
uniform vec3 lightDir;
+uniform float depthOffset;
void main()
{
vec4 worldSpace = model * vec4(vertexPosition, 1.0);
gl_Position = VP * worldSpace;
+ if (gl_Position.z > -1.0)
+ gl_Position.z = max(-1.0, gl_Position.z - depthOffset);
fragmentPosition = worldSpace.xyz;
fragmentColor = vertexColor;
static GLuint shader_prog;
static GLint loc_VP;
+static GLint loc_depthOffset;
static LightShader light_shader;
static Map entities;
static List nametagged;
free(shader_defs);
loc_VP = glGetUniformLocation(shader_prog, "VP"); GL_DEBUG
+ loc_depthOffset = glGetUniformLocation(shader_prog, "depthOffset"); GL_DEBUG
EntityVertex vertices[6][6];
for (int f = 0; f < 6; f++) {
light_shader.prog = shader_prog;
light_shader_locate(&light_shader);
+ client_entity_depth_offset(0.0f);
+
return true;
}
pthread_mutex_unlock(&mtx_nametagged);
}
+void client_entity_depth_offset(f32 offset)
+{
+ glProgramUniform1f(shader_prog, loc_depthOffset, offset);
+}
+
ClientEntity *client_entity_grab(u64 id)
{
return id ? map_get(&entities, &id, &cmp_entity, &refcount_grb) : NULL;
bool client_entity_gfx_init();
void client_entity_gfx_deinit();
void client_entity_gfx_update();
+void client_entity_depth_offset(f32 offset);
ClientEntity *client_entity_grab(u64 id);
void client_entity_drop(ClientEntity *entity);
static GLuint _3d_shader_prog;
static GLint _3d_loc_VP;
+static GLint _3d_loc_depthOffset;
static ModelShader _3d_model_shader;
static LightShader _3d_light_shader;
free(_3d_shader_defs);
_3d_loc_VP = glGetUniformLocation(_3d_shader_prog, "VP");
+ _3d_loc_depthOffset = glGetUniformLocation(_3d_shader_prog, "depthOffset");
_3d_model_shader.prog = _3d_shader_prog;
_3d_model_shader.loc_transform = glGetUniformLocation(_3d_shader_prog, "model"); GL_DEBUG
_3d_light_shader.prog = _3d_shader_prog;
light_shader_locate(&_3d_light_shader);
+ client_inventory_depth_offset(0.0f);
+
return true;
}
light_shader_update(&_3d_light_shader);
}
+void client_inventory_depth_offset(f32 offset)
+{
+ glProgramUniform1f(_3d_shader_prog, _3d_loc_depthOffset, offset);
+}
+
static void wield_init(ModelNode *hand)
{
if (hand)
void client_inventory_deinit();
void client_inventory_update();
+void client_inventory_depth_offset(f32 offset);
void client_inventory_init_player(ClientEntity *entity);
void client_inventory_deinit_player(ClientEntity *entity);
void client_inventory_update_player(void *peer, ToClientPlayerInventory *pkt);
// entity callbacks
+static void local_on_model_before_render(__attribute__((unused)) Model *model)
+{
+ client_entity_depth_offset(0.2f);
+ client_inventory_depth_offset(0.2f);
+}
+
+static void local_on_model_after_render(__attribute__((unused)) Model *model)
+{
+ client_entity_depth_offset(0.0f);
+ client_inventory_depth_offset(0.0f);}
+
static void on_add(ClientEntity *entity)
{
entity->model = model_clone(player_model);
}
on_add(entity);
+ entity->model->callbacks.before_render = &local_on_model_before_render;
+ entity->model->callbacks.after_render = &local_on_model_after_render;
player_entity = refcount_grb(&entity->rc);
recv_pos_rot();
}
}
-static void __attribute__((unused)) on_model_step(Model *model, __attribute__((unused)) f64 dtime)
-{
- ClientPlayerData *data = ((ClientEntity *) model->extra)->extra;
- (void) data; // ToDo: animations
-}
-
static void on_model_delete(Model *model)
{
if (model->extra)
RESSOURCE_PATH "models/player.txt", RESSOURCE_PATH "textures/models/player",
&client_entity_cube, &client_entity_shader);
- player_model->callbacks.step = &on_model_step;
player_model->callbacks.delete = &on_model_delete;
}
static void render_model(Model *model)
{
- if (model->flags.wireframe) {
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); GL_DEBUG
- }
+ if (model->callbacks.before_render)
+ model->callbacks.before_render(model);
render_node(model->root);
- if (model->flags.wireframe) {
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); GL_DEBUG
- }
+ if (model->callbacks.after_render)
+ model->callbacks.after_render(model);
}
// step model help im stuck
static void model_step(Model *model, Tree *transparent, f64 dtime)
{
+ if (model->callbacks.step)
+ model->callbacks.step(model, dtime);
+
if (client_config.view_distance < (model->distance = sqrt(
pow(model->root->pos.x - camera.eye[0], 2) +
pow(model->root->pos.y - camera.eye[1], 2) +
pow(model->root->pos.z - camera.eye[2], 2))))
return;
- if (model->callbacks.step)
- model->callbacks.step(model, dtime);
-
if (!model->root->visible)
return;
model->replace = NULL;
model->callbacks.step = NULL;
+ model->callbacks.before_render = NULL;
+ model->callbacks.after_render = NULL;
model->callbacks.delete = NULL;
model->flags.delete =
- model->flags.wireframe =
model->flags.frustum_culling =
model->flags.transparent = 0;
struct Model *replace;
struct {
void (*step)(struct Model *model, f64 dtime);
+ void (*before_render)(struct Model *model);
+ void (*after_render)(struct Model *model);
void (*delete)(struct Model *model);
} callbacks;
struct {
unsigned int delete: 1;
- unsigned int wireframe: 1;
unsigned int frustum_culling: 1;
unsigned int transparent: 1;
} flags;