Skip to content

Commit

Permalink
alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Jan 16, 2025
1 parent 0e978a3 commit bbbef71
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
33 changes: 19 additions & 14 deletions src/client/content_cao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,17 @@ static void setColorParam(scene::ISceneNode *node, video::SColor color)
node->getMaterial(i).ColorParam = color;
}

static scene::SMesh *generateNodeMesh(const NodeDefManager *ndef, MapNode n,
static scene::SMesh *generateNodeMesh(Client *client, MapNode n,
std::vector<MeshAnimationInfo> &animation)
{
n.setParam1(0xff);
auto *ndef = client->ndef();
auto *shdsrc = client->getShaderSource();

MeshCollector collector(v3f(0), v3f());
{
MeshMakeData mmd(ndef, 1, MeshGrid{1});
mmd.fillSingleNode(n, MapNode(CONTENT_AIR, 0xff));
n.setParam1(0xff);
mmd.fillSingleNode(n);
MapblockMeshGenerator(&mmd, &collector).generate();
}

Expand All @@ -214,12 +216,15 @@ static scene::SMesh *generateNodeMesh(const NodeDefManager *ndef, MapNode n,
&p.indices[0], p.indices.size());

// Set up material
buf->Material.setTexture(0, p.layer.texture);
auto &mat = buf->Material;
mat.setTexture(0, p.layer.texture);
u32 shader_id = shdsrc->getShader("object_shader", p.layer.material_type, NDT_NORMAL);
mat.MaterialType = shdsrc->getShaderInfo(shader_id).material;
if (layer == 1) {
buf->Material.PolygonOffsetSlopeScale = -1;
buf->Material.PolygonOffsetDepthBias = -1;
mat.PolygonOffsetSlopeScale = -1;
mat.PolygonOffsetDepthBias = -1;
}
p.layer.applyMaterialOptions(buf->Material);
p.layer.applyMaterialOptionsWithShaders(mat);

mesh->addMeshBuffer(buf.get());
}
Expand Down Expand Up @@ -652,8 +657,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)

infostream << "GenericCAO::addToScene(): " << m_prop.visual << std::endl;

m_material_type_param = 0.5f; // May cut off alpha < 128 depending on m_material_type

if (m_prop.visual != "node" && m_prop.visual != "wielditem" && m_prop.visual != "item")
{
IShaderSource *shader_source = m_client->getShaderSource();
MaterialType material_type;
Expand All @@ -667,13 +671,17 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)

u32 shader_id = shader_source->getShader("object_shader", material_type, NDT_NORMAL);
m_material_type = shader_source->getShaderInfo(shader_id).material;
} else {
// Not used, so make sure it's not valid
m_material_type = EMT_INVALID;
}

m_matrixnode = m_smgr->addDummyTransformationSceneNode();
m_matrixnode->grab();

auto setMaterial = [this] (video::SMaterial &mat) {
mat.MaterialType = m_material_type;
if (m_material_type != EMT_INVALID)
mat.MaterialType = m_material_type;
mat.FogEnable = true;
mat.forEachTexture([] (auto &tex) {
tex.MinFilter = video::ETMINF_NEAREST_MIPMAP_NEAREST;
Expand Down Expand Up @@ -809,7 +817,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
n.setContent(m_client->ndef()->getId(m_prop.textures.at(0)));
if (m_prop.textures.size() > 1)
n.setParam2(stoi(m_prop.textures[1], 0, 255));
auto *mesh = generateNodeMesh(m_client->ndef(), n, m_meshnode_animation);
auto *mesh = generateNodeMesh(m_client, n, m_meshnode_animation);

m_meshnode = m_smgr->addMeshSceneNode(mesh, m_matrixnode);
m_meshnode->setSharedMaterials(true);
Expand Down Expand Up @@ -1379,7 +1387,6 @@ void GenericCAO::updateTextures(std::string mod)

video::SMaterial &material = m_spritenode->getMaterial(0);
material.MaterialType = m_material_type;
material.MaterialTypeParam = m_material_type_param;
material.setTexture(0, tsrc->getTextureForMesh(texturestring));

material.forEachTexture([=] (auto &tex) {
Expand Down Expand Up @@ -1408,7 +1415,6 @@ void GenericCAO::updateTextures(std::string mod)
// Set material flags and texture
video::SMaterial &material = m_animated_meshnode->getMaterial(i);
material.MaterialType = m_material_type;
material.MaterialTypeParam = m_material_type_param;
material.TextureLayers[0].Texture = texture;
material.BackfaceCulling = m_prop.backface_culling;

Expand Down Expand Up @@ -1440,7 +1446,6 @@ void GenericCAO::updateTextures(std::string mod)
// Set material flags and texture
video::SMaterial &material = m_meshnode->getMaterial(i);
material.MaterialType = m_material_type;
material.MaterialTypeParam = m_material_type_param;
material.setTexture(0, tsrc->getTextureForMesh(texturestring));
material.getTextureMatrix(0).makeIdentity();

Expand Down
5 changes: 3 additions & 2 deletions src/client/content_cao.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ struct MeshAnimationInfo {
class GenericCAO : public ClientActiveObject
{
private:
static constexpr auto EMT_INVALID = video::EMT_FORCE_32BIT;

// Only set at initialization
std::string m_name = "";
bool m_is_player = false;
Expand All @@ -100,8 +102,7 @@ class GenericCAO : public ClientActiveObject
std::vector<MeshAnimationInfo> m_meshnode_animation;

// Material
video::E_MATERIAL_TYPE m_material_type;
f32 m_material_type_param;
video::E_MATERIAL_TYPE m_material_type = EMT_INVALID;

// Movement
v3f m_position = v3f(0.0f, 10.0f * BS, 0);
Expand Down
7 changes: 4 additions & 3 deletions src/client/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>
#include <SMaterial.h>

enum MaterialType{
enum MaterialType : u8 {
TILE_MATERIAL_BASIC,
TILE_MATERIAL_ALPHA,
TILE_MATERIAL_LIQUID_TRANSPARENT,
Expand Down Expand Up @@ -98,8 +98,9 @@ struct TileLayer
case TILE_MATERIAL_LIQUID_TRANSPARENT:
case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT:
return true;
default:
return false;
}
return false;
}

// Ordered for size, please do not reorder
Expand All @@ -113,7 +114,7 @@ struct TileLayer
u16 animation_frame_length_ms = 0;
u16 animation_frame_count = 1;

u8 material_type = TILE_MATERIAL_BASIC;
MaterialType material_type = TILE_MATERIAL_BASIC;
u8 material_flags =
//0 // <- DEBUG, Use the one below
MATERIAL_FLAG_BACKFACE_CULLING |
Expand Down
2 changes: 1 addition & 1 deletion src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ void ContentFeatures::deSerialize(std::istream &is, u16 protocol_version)
#if CHECK_CLIENT_BUILD()
static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer,
const TileSpec &tile, const TileDef &tiledef, video::SColor color,
u8 material_type, u32 shader_id, bool backface_culling,
MaterialType material_type, u32 shader_id, bool backface_culling,
const TextureSettings &tsettings)
{
layer->shader_id = shader_id;
Expand Down

0 comments on commit bbbef71

Please sign in to comment.