mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Improved block picking
This commit is contained in:
parent
62b59de95a
commit
30619771af
@ -50,7 +50,7 @@ void main() {
|
|||||||
|
|
||||||
// Select glowing
|
// Select glowing
|
||||||
if (select_pos.w > 0 && select_pos.xyz == floor(sprite_pos)) {
|
if (select_pos.w > 0 && select_pos.xyz == floor(sprite_pos)) {
|
||||||
f_col = f_col * 8.0;
|
f_col *= 8.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
f_light = 1.0;
|
f_light = 1.0;
|
||||||
|
@ -21,6 +21,10 @@ out vec4 tgt_color;
|
|||||||
#include <sky.glsl>
|
#include <sky.glsl>
|
||||||
#include <light.glsl>
|
#include <light.glsl>
|
||||||
|
|
||||||
|
float vmax(vec3 v) {
|
||||||
|
return max(v.x, max(v.y, v.z));
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// First 3 normals are negative, next 3 are positive
|
// First 3 normals are negative, next 3 are positive
|
||||||
vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1));
|
vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1));
|
||||||
@ -46,6 +50,14 @@ void main() {
|
|||||||
diffuse_light += point_light * ao;
|
diffuse_light += point_light * ao;
|
||||||
|
|
||||||
vec3 col = f_col + hash(vec4(floor(f_chunk_pos * 3.0 - f_norm * 0.5), 0)) * 0.02; // Small-scale noise
|
vec3 col = f_col + hash(vec4(floor(f_chunk_pos * 3.0 - f_norm * 0.5), 0)) * 0.02; // Small-scale noise
|
||||||
|
|
||||||
|
// Select glowing
|
||||||
|
if (select_pos.w > 0 && select_pos.xyz == floor(f_pos - f_norm * 0.01)) {
|
||||||
|
if (vmax(abs(mod(f_pos - f_norm * 0.5, 1.0) - 0.5)) > 0.45) {
|
||||||
|
col *= 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vec3 surf_color = illuminate(srgb_to_linear(col), light, diffuse_light, ambient_light);
|
vec3 surf_color = illuminate(srgb_to_linear(col), light, diffuse_light, ambient_light);
|
||||||
|
|
||||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||||
|
@ -256,6 +256,13 @@ impl PlayState for SessionState {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let can_build = self.client
|
||||||
|
.borrow()
|
||||||
|
.state()
|
||||||
|
.read_storage::<comp::CanBuild>()
|
||||||
|
.get(self.client.borrow().entity())
|
||||||
|
.is_some();
|
||||||
|
|
||||||
// Only highlight collectables
|
// Only highlight collectables
|
||||||
self.scene.set_select_pos(select_pos.filter(|sp| {
|
self.scene.set_select_pos(select_pos.filter(|sp| {
|
||||||
self.client
|
self.client
|
||||||
@ -263,7 +270,7 @@ impl PlayState for SessionState {
|
|||||||
.state()
|
.state()
|
||||||
.terrain()
|
.terrain()
|
||||||
.get(*sp)
|
.get(*sp)
|
||||||
.map(|b| b.is_collectible())
|
.map(|b| b.is_collectible() || can_build)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -279,16 +286,9 @@ impl PlayState for SessionState {
|
|||||||
return PlayStateResult::Shutdown;
|
return PlayStateResult::Shutdown;
|
||||||
},
|
},
|
||||||
Event::InputUpdate(GameInput::Primary, state) => {
|
Event::InputUpdate(GameInput::Primary, state) => {
|
||||||
// Check the existence of CanBuild component. If it's here, use LMB to
|
// If we can build, use LMB to break blocks, if not, use it to attack
|
||||||
// break blocks, if not, use it to attack
|
|
||||||
let mut client = self.client.borrow_mut();
|
let mut client = self.client.borrow_mut();
|
||||||
if state
|
if state && can_build {
|
||||||
&& client
|
|
||||||
.state()
|
|
||||||
.read_storage::<comp::CanBuild>()
|
|
||||||
.get(client.entity())
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
if let Some(select_pos) = select_pos {
|
if let Some(select_pos) = select_pos {
|
||||||
client.remove_block(select_pos);
|
client.remove_block(select_pos);
|
||||||
}
|
}
|
||||||
@ -302,13 +302,7 @@ impl PlayState for SessionState {
|
|||||||
|
|
||||||
let mut client = self.client.borrow_mut();
|
let mut client = self.client.borrow_mut();
|
||||||
|
|
||||||
if state
|
if state && can_build {
|
||||||
&& client
|
|
||||||
.state()
|
|
||||||
.read_storage::<comp::CanBuild>()
|
|
||||||
.get(client.entity())
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
if let Some(build_pos) = build_pos {
|
if let Some(build_pos) = build_pos {
|
||||||
client.place_block(build_pos, self.selected_block);
|
client.place_block(build_pos, self.selected_block);
|
||||||
}
|
}
|
||||||
@ -319,12 +313,7 @@ impl PlayState for SessionState {
|
|||||||
|
|
||||||
Event::InputUpdate(GameInput::Roll, state) => {
|
Event::InputUpdate(GameInput::Roll, state) => {
|
||||||
let client = self.client.borrow();
|
let client = self.client.borrow();
|
||||||
if client
|
if can_build {
|
||||||
.state()
|
|
||||||
.read_storage::<comp::CanBuild>()
|
|
||||||
.get(client.entity())
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
if state {
|
if state {
|
||||||
if let Some(block) = select_pos
|
if let Some(block) = select_pos
|
||||||
.and_then(|sp| client.state().terrain().get(sp).ok().copied())
|
.and_then(|sp| client.state().terrain().get(sp).ok().copied())
|
||||||
|
Loading…
Reference in New Issue
Block a user