Skip to content

Commit

Permalink
Clip posteffect color to respective nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Dec 13, 2024
1 parent ac7406c commit 4f1cb53
Show file tree
Hide file tree
Showing 21 changed files with 882 additions and 104 deletions.
1 change: 1 addition & 0 deletions client/shaders/nodes_shader/opengl_vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void main(void)
// Generate waves with Perlin-type noise.
// The constants are calibrated such that they roughly
// correspond to the old sine waves.
// Note: The same thing is implemented in clientmap.cpp. Keep them consistent!
vec3 wavePos = (mWorld * pos).xyz + cameraOffset;
// The waves are slightly compressed along the z-axis to get
// wave-fronts along the x-axis.
Expand Down
10 changes: 10 additions & 0 deletions client/shaders/object_shader/opengl_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ uniform lowp vec4 fogColor;
uniform float fogDistance;
uniform float fogShadingParameter;

// Only used for the wieldhand. 0 otherwise.
uniform vec4 wield_posteffect_color;

// The cameraOffset is the current center of the visible world.
uniform highp vec3 cameraOffset;
uniform float animationTimer;
Expand Down Expand Up @@ -458,5 +461,12 @@ void main(void)
col = mix(fogColor * pow(fogColor / fogColorMax, vec4(2.0 * clarity)), col, clarity);
col = vec4(col.rgb, base.a);

// Apply posteffect color for the wieldhand, by blending it above this
// fragment.
// The alpha channel is not blended. The posteffect geometry behind the
// wieldhand already makes the image less transparent.
// wield_posteffect_color.rgb is premultiplied.
col.rgb = col.rgb * (1.0 - wield_posteffect_color.a) + wield_posteffect_color.rgb;

gl_FragData[0] = col;
}
5 changes: 4 additions & 1 deletion src/client/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,8 @@ void Camera::wield(const ItemStack &item)
}
}

void Camera::drawWieldedTool(irr::core::matrix4* translation)
void Camera::drawWieldedTool(irr::core::matrix4* translation,
const video::SColorf &post_color)
{
// Clear Z buffer so that the wielded tool stays in front of world geometry
m_wieldmgr->getVideoDriver()->clearBuffers(video::ECBF_DEPTH);
Expand All @@ -624,7 +625,9 @@ void Camera::drawWieldedTool(irr::core::matrix4* translation)
cam->updateAbsolutePosition();
cam->setTarget(focusPoint);
}
m_client->setWieldPostEffectColor(post_color);
m_wieldmgr->drawAll();
m_client->setWieldPostEffectColor(video::SColorf(0.0f,0.0f,0.0f,0.0f));
}

void Camera::drawNametags()
Expand Down
3 changes: 2 additions & 1 deletion src/client/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class Camera
// Draw the wielded tool.
// This has to happen *after* the main scene is drawn.
// Warning: This clears the Z buffer.
void drawWieldedTool(irr::core::matrix4* translation=NULL);
void drawWieldedTool(irr::core::matrix4* translation = nullptr,
const video::SColorf &post_color = video::SColorf(0.0f,0.0f,0.0f,0.0f));

// Toggle the current camera mode
void toggleCameraMode() {
Expand Down
12 changes: 12 additions & 0 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,16 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
return m_mesh_grid;
}

video::SColorf getWieldPostEffectColor() const
{
return m_wield_posteffect_color;
}

void setWieldPostEffectColor(video::SColorf color)
{
m_wield_posteffect_color = color;
}

bool inhibit_inventory_revert = false;

private:
Expand Down Expand Up @@ -596,4 +606,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

// The number of blocks the client will combine for mesh generation.
MeshGrid m_mesh_grid;

video::SColorf m_wield_posteffect_color{0};
};
Loading

0 comments on commit 4f1cb53

Please sign in to comment.