Skip to content
Permalink
Browse files

Cleanup selection mesh code, add shaders for halo and selection boxes

  • Loading branch information
RealBadAngel authored and kwolekr committed Feb 8, 2016
1 parent 4301953 commit b44da4916aa09b27155ce6675cccbcc128b5a66c
@@ -279,6 +279,9 @@ enable_clouds (Clouds) bool true
# Use 3D cloud look instead of flat.
enable_3d_clouds (3D clouds) bool true

# Method used to highlight selected object.
node_highlighting (Node highlighting) enum box box,halo

[***Filtering]

# Use mip mapping to scale textures. May slightly increase performance.
@@ -482,9 +485,6 @@ desynchronize_mapblock_texture_animation (Desynchronize block animation) bool tr
# Useful if there's something to be displayed right or left of hotbar.
hud_hotbar_max_width (Maximum hotbar width) float 1.0

# Enable selection highlighting for nodes (disables selectionbox).
enable_node_highlighting (Node highlighting) bool false

# Enables caching of facedir rotated meshes.
enable_mesh_cache (Mesh cache) bool false

@@ -0,0 +1,4 @@
void main(void)
{
gl_FragColor = gl_Color;
}
@@ -0,0 +1,9 @@
uniform mat4 mWorldViewProj;

void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = mWorldViewProj * gl_Vertex;

gl_FrontColor = gl_BackColor = gl_Color;
}
@@ -0,0 +1,9 @@
uniform sampler2D baseTexture;

void main(void)
{
vec2 uv = gl_TexCoord[0].st;
vec4 color = texture2D(baseTexture, uv);
color.rgb *= gl_Color.rgb;
gl_FragColor = color;
}
@@ -0,0 +1,9 @@
uniform mat4 mWorldViewProj;

void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = mWorldViewProj * gl_Vertex;

gl_FrontColor = gl_BackColor = gl_Color;
}
@@ -555,9 +555,9 @@
# type: float
# hud_hotbar_max_width = 1.0

# Enable selection highlighting for nodes (disables selectionbox).
# type: bool
# enable_node_highlighting = false
# Selection highlighting method (box or halo)
# type: string
# node_highlighting = box

# Enables caching of facedir rotated meshes.
# type: bool
@@ -235,11 +235,9 @@ Client::Client(
m_inventory_updated(false),
m_inventory_from_server(NULL),
m_inventory_from_server_age(0.0),
m_show_highlighted(false),
m_animation_time(0),
m_crack_level(-1),
m_crack_pos(0,0,0),
m_highlighted_pos(0,0,0),
m_map_seed(0),
m_password(password),
m_chosen_auth_mech(AUTH_MECHANISM_NONE),
@@ -1508,15 +1506,6 @@ int Client::getCrackLevel()
return m_crack_level;
}

void Client::setHighlighted(v3s16 pos, bool show_highlighted)
{
m_show_highlighted = show_highlighted;
v3s16 old_highlighted_pos = m_highlighted_pos;
m_highlighted_pos = pos;
addUpdateMeshTaskForNode(old_highlighted_pos, false, true);
addUpdateMeshTaskForNode(m_highlighted_pos, false, true);
}

void Client::setCrack(int level, v3s16 pos)
{
int old_crack_level = m_crack_level;
@@ -1601,7 +1590,6 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)
// Debug: 1-6ms, avg=2ms
data->fill(b);
data->setCrack(m_crack_level, m_crack_pos);
data->setHighlighted(m_highlighted_pos, m_show_highlighted);
data->setSmoothLighting(m_cache_smooth_lighting);
}

@@ -456,9 +456,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
int getCrackLevel();
void setCrack(int level, v3s16 pos);

void setHighlighted(v3s16 pos, bool show_higlighted);
v3s16 getHighlighted(){ return m_highlighted_pos; }

u16 getHP();
u16 getBreath();

@@ -609,12 +606,10 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
Inventory *m_inventory_from_server;
float m_inventory_from_server_age;
PacketCounter m_packetcounter;
bool m_show_highlighted;
// Block mesh animation parameters
float m_animation_time;
int m_crack_level;
v3s16 m_crack_pos;
v3s16 m_highlighted_pos;
// 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT
//s32 m_daynight_i;
//u32 m_daynight_ratio;
@@ -171,7 +171,6 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
MeshCollector &collector)
{
INodeDefManager *nodedef = data->m_gamedef->ndef();
ITextureSource *tsrc = data->m_gamedef->tsrc();
scene::ISceneManager* smgr = data->m_gamedef->getSceneManager();
scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();

@@ -1615,55 +1614,5 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
break;}
}
}

/*
Caused by incorrect alpha blending, selection mesh needs to be created as
last element to ensure it gets blended correct over nodes with alpha channel
*/
// Create selection mesh
v3s16 p = data->m_highlighted_pos_relative;
if (data->m_show_hud &&
(p.X >= 0) && (p.X < MAP_BLOCKSIZE) &&
(p.Y >= 0) && (p.Y < MAP_BLOCKSIZE) &&
(p.Z >= 0) && (p.Z < MAP_BLOCKSIZE)) {

MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
if(n.getContent() != CONTENT_AIR) {
// Get selection mesh light level
static const v3s16 dirs[7] = {
v3s16( 0, 0, 0),
v3s16( 0, 1, 0),
v3s16( 0,-1, 0),
v3s16( 1, 0, 0),
v3s16(-1, 0, 0),
v3s16( 0, 0, 1),
v3s16( 0, 0,-1)
};

u16 l = 0;
u16 l1 = 0;
for (u8 i = 0; i < 7; i++) {
MapNode n1 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dirs[i]);
l1 = getInteriorLight(n1, -4, nodedef);
if (l1 > l)
l = l1;
}
video::SColor c = MapBlock_LightColor(255, l, 0);
data->m_highlight_mesh_color = c;
std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
TileSpec h_tile;
h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;
h_tile.texture = tsrc->getTextureForMesh("halo.png",&h_tile.texture_id);
v3f pos = intToFloat(p, BS);
f32 d = 0.05 * BS;
for (std::vector<aabb3f>::iterator i = boxes.begin();
i != boxes.end(); ++i) {
aabb3f box = *i;
box.MinEdge += v3f(-d, -d, -d) + pos;
box.MaxEdge += v3f(d, d, d) + pos;
makeCuboid(&collector, box, &h_tile, 1, c, NULL);
}
}
}
}

@@ -137,8 +137,9 @@ void set_default_settings(Settings *settings)
settings->setDefault("console_color", "(0,0,0)");
settings->setDefault("console_alpha", "200");
settings->setDefault("selectionbox_color", "(0,0,0)");
settings->setDefault("enable_node_highlighting", "false");
settings->setDefault("selectionbox_width", "2");
settings->setDefault("inventory_items_animations", "false");
settings->setDefault("node_highlighting", "box");
settings->setDefault("crosshair_color", "(255,255,255)");
settings->setDefault("crosshair_alpha", "255");
settings->setDefault("hud_scaling", "1.0");
@@ -149,8 +150,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("enable_sound", "true");
settings->setDefault("sound_volume", "0.8");
settings->setDefault("desynchronize_mapblock_texture_animation", "true");
settings->setDefault("selectionbox_width","2");
settings->setDefault("hud_hotbar_max_width","1.0");
settings->setDefault("hud_hotbar_max_width", "1.0");
settings->setDefault("enable_local_map_saving", "false");

settings->setDefault("mip_map", "false");

0 comments on commit b44da49

Please sign in to comment.
You can’t perform that action at this time.