Skip to content

Commit 3a6dfda

Browse files
authored
Make shading of CAOs optional (#10033)
1 parent 0a1181f commit 3a6dfda

File tree

10 files changed

+47
-7
lines changed

10 files changed

+47
-7
lines changed

client/shaders/object_shader/opengl_vertex.glsl

+4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ void main(void)
3939
lightVec = sunPosition - worldPosition;
4040
eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz;
4141

42+
#if (MATERIAL_TYPE == TILE_MATERIAL_PLAIN) || (MATERIAL_TYPE == TILE_MATERIAL_PLAIN_ALPHA)
43+
vIDiff = 1.0;
44+
#else
4245
// This is intentional comparison with zero without any margin.
4346
// If normal is not equal to zero exactly, then we assume it's a valid, just not normalized vector
4447
vIDiff = length(gl_Normal) == 0.0
4548
? 1.0
4649
: directional_ambient(normalize(gl_Normal));
50+
#endif
4751

4852
gl_FrontColor = gl_BackColor = gl_Color;
4953
}

doc/lua_api.txt

+3
Original file line numberDiff line numberDiff line change
@@ -6644,6 +6644,9 @@ Player properties need to be saved manually.
66446644

66456645
damage_texture_modifier = "^[brighten",
66466646
-- Texture modifier to be applied for a short duration when object is hit
6647+
6648+
shaded = true,
6649+
-- Setting this to 'false' disables diffuse lighting of entity
66476650
}
66486651

66496652
Entity definition

games/devtest/mods/testentities/visuals.lua

+11-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ minetest.register_entity("testentities:mesh", {
5555
},
5656
})
5757

58+
minetest.register_entity("testentities:mesh_unshaded", {
59+
initial_properties = {
60+
visual = "mesh",
61+
mesh = "testnodes_pyramid.obj",
62+
textures = {
63+
"testnodes_mesh_stripes2.png"
64+
},
65+
shaded = false,
66+
},
67+
})
68+
5869
-- Advanced visual tests
5970

6071
-- A test entity for testing animated and yaw-modulated sprites
@@ -71,4 +82,3 @@ minetest.register_entity("testentities:yawsprite", {
7182
self.object:set_sprite({x=0, y=0}, 1, 0, true)
7283
end,
7384
})
74-

src/client/content_cao.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,16 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
577577

578578
if (m_enable_shaders) {
579579
IShaderSource *shader_source = m_client->getShaderSource();
580-
u32 shader_id = shader_source->getShader(
581-
"object_shader",
582-
(m_prop.use_texture_alpha) ? TILE_MATERIAL_ALPHA : TILE_MATERIAL_BASIC,
583-
NDT_NORMAL);
580+
MaterialType material_type;
581+
582+
if (m_prop.shaded && m_prop.glow == 0)
583+
material_type = (m_prop.use_texture_alpha) ?
584+
TILE_MATERIAL_ALPHA : TILE_MATERIAL_BASIC;
585+
else
586+
material_type = (m_prop.use_texture_alpha) ?
587+
TILE_MATERIAL_PLAIN_ALPHA : TILE_MATERIAL_PLAIN;
588+
589+
u32 shader_id = shader_source->getShader("object_shader", material_type, NDT_NORMAL);
584590
m_material_type = shader_source->getShaderInfo(shader_id).material;
585591
} else {
586592
m_material_type = (m_prop.use_texture_alpha) ?
@@ -1504,6 +1510,7 @@ bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const
15041510
return old.backface_culling != new_.backface_culling ||
15051511
old.is_visible != new_.is_visible ||
15061512
old.mesh != new_.mesh ||
1513+
old.shaded != new_.shaded ||
15071514
old.use_texture_alpha != new_.use_texture_alpha ||
15081515
old.visual != new_.visual ||
15091516
old.visual_size != new_.visual_size ||

src/client/mesh.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ bool checkMeshNormals(scene::IMesh *mesh)
341341
// hurting the performance and covering only really weird broken models.
342342
f32 length = buffer->getNormal(0).getLength();
343343

344-
if (!std::isfinite(length) || std::fabs(length) < 1e-10f)
344+
if (!std::isfinite(length) || length < 1e-10f)
345345
return false;
346346
}
347347

src/client/shader.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,13 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
537537
shaderinfo.base_material = video::EMT_SOLID;
538538
break;
539539
case TILE_MATERIAL_ALPHA:
540+
case TILE_MATERIAL_PLAIN_ALPHA:
540541
case TILE_MATERIAL_LIQUID_TRANSPARENT:
541542
case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT:
542543
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
543544
break;
544545
case TILE_MATERIAL_BASIC:
546+
case TILE_MATERIAL_PLAIN:
545547
case TILE_MATERIAL_WAVING_LEAVES:
546548
case TILE_MATERIAL_WAVING_PLANTS:
547549
case TILE_MATERIAL_WAVING_LIQUID_BASIC:
@@ -644,9 +646,11 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
644646
"TILE_MATERIAL_WAVING_LIQUID_BASIC",
645647
"TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT",
646648
"TILE_MATERIAL_WAVING_LIQUID_OPAQUE",
649+
"TILE_MATERIAL_PLAIN",
650+
"TILE_MATERIAL_PLAIN_ALPHA",
647651
};
648652

649-
for (int i = 0; i < 10; i++){
653+
for (int i = 0; i < 12; i++){
650654
shaders_header += "#define ";
651655
shaders_header += materialTypes[i];
652656
shaders_header += " ";

src/client/tile.h

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ enum MaterialType{
150150
TILE_MATERIAL_WAVING_LIQUID_BASIC,
151151
TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT,
152152
TILE_MATERIAL_WAVING_LIQUID_OPAQUE,
153+
TILE_MATERIAL_PLAIN,
154+
TILE_MATERIAL_PLAIN_ALPHA
153155
};
154156

155157
// Material flags

src/object_properties.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ std::string ObjectProperties::dump()
6969
os << ", zoom_fov=" << zoom_fov;
7070
os << ", use_texture_alpha=" << use_texture_alpha;
7171
os << ", damage_texture_modifier=" << damage_texture_modifier;
72+
os << ", shaded=" << shaded;
7273
return os.str();
7374
}
7475

@@ -116,6 +117,7 @@ void ObjectProperties::serialize(std::ostream &os) const
116117
writeF32(os, zoom_fov);
117118
writeU8(os, use_texture_alpha);
118119
os << serializeString(damage_texture_modifier);
120+
writeU8(os, shaded);
119121

120122
// Add stuff only at the bottom.
121123
// Never remove anything, because we don't want new versions of this
@@ -170,5 +172,9 @@ void ObjectProperties::deSerialize(std::istream &is)
170172
use_texture_alpha = readU8(is);
171173
try {
172174
damage_texture_modifier = deSerializeString(is);
175+
u8 tmp = readU8(is);
176+
if (is.eof())
177+
throw SerializationError("");
178+
shaded = tmp;
173179
} catch (SerializationError &e) {}
174180
}

src/object_properties.h

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct ObjectProperties
6161
float eye_height = 1.625f;
6262
float zoom_fov = 0.0f;
6363
bool use_texture_alpha = false;
64+
bool shaded = true;
6465

6566
ObjectProperties();
6667
std::string dump();

src/script/common/c_content.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ void read_object_properties(lua_State *L, int index,
327327

328328
getfloatfield(L, -1, "zoom_fov", prop->zoom_fov);
329329
getboolfield(L, -1, "use_texture_alpha", prop->use_texture_alpha);
330+
getboolfield(L, -1, "shaded", prop->shaded);
330331

331332
getstringfield(L, -1, "damage_texture_modifier", prop->damage_texture_modifier);
332333
}
@@ -411,6 +412,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
411412
lua_setfield(L, -2, "zoom_fov");
412413
lua_pushboolean(L, prop->use_texture_alpha);
413414
lua_setfield(L, -2, "use_texture_alpha");
415+
lua_pushboolean(L, prop->shaded);
416+
lua_setfield(L, -2, "shaded");
414417
lua_pushlstring(L, prop->damage_texture_modifier.c_str(), prop->damage_texture_modifier.size());
415418
lua_setfield(L, -2, "damage_texture_modifier");
416419
}

0 commit comments

Comments
 (0)