1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Initial refactoring on shader usage and generation

`IShaderSource` was designed with the idea that if you want a shader,
you must want it for a node. So it depends heavily on being given a tile
material and the node drawtype. But this doesn't make sense neither in theory
nor in practice.
This commit takes a small step towards removing the incorrect abstraction.
This commit is contained in:
sfan5 2024-12-13 16:11:21 +01:00
parent eb8beb335e
commit a6293b9861
14 changed files with 81 additions and 53 deletions

View file

@ -271,7 +271,7 @@ public:
The id 0 points to a null shader. Its material is EMT_SOLID.
*/
u32 getShaderIdDirect(const std::string &name,
MaterialType material_type, NodeDrawType drawtype) override;
MaterialType material_type, NodeDrawType drawtype);
/*
If shader specified by the name pointed by the id doesn't
@ -281,10 +281,18 @@ public:
and not found in cache, the call is queued to the main thread
for processing.
*/
u32 getShader(const std::string &name,
MaterialType material_type, NodeDrawType drawtype) override;
u32 getShaderRaw(const std::string &name, bool blendAlpha) override
{
// TODO: the shader system should be refactored to be much more generic.
// Just let callers pass arbitrary constants, this would also deal with
// runtime changes cleanly.
return getShader(name, blendAlpha ? TILE_MATERIAL_ALPHA : TILE_MATERIAL_BASIC,
NodeDrawType_END);
}
ShaderInfo getShaderInfo(u32 id) override;
// Processes queued shader requests from other threads.
@ -607,11 +615,17 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
#define textureFlags texture2
)";
/* Define constants for node and object shaders */
const bool node_shader = drawtype != NodeDrawType_END;
if (node_shader) {
bool use_discard = fully_programmable;
// For renderers that should use discard instead of GL_ALPHA_TEST
const char *renderer = reinterpret_cast<const char*>(GL.GetString(GL.RENDERER));
if (strstr(renderer, "GC7000"))
use_discard = true;
if (!use_discard) {
// workaround for a certain OpenGL implementation lacking GL_ALPHA_TEST
const char *renderer = reinterpret_cast<const char*>(GL.GetString(GL.RENDERER));
if (strstr(renderer, "GC7000"))
use_discard = true;
}
if (use_discard) {
if (shaderinfo.base_material == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
shaders_header << "#define USE_DISCARD 1\n";
@ -664,9 +678,25 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
shaders_header << "#define WATER_WAVE_LENGTH " << g_settings->getFloat("water_wave_length") << "\n";
shaders_header << "#define WATER_WAVE_SPEED " << g_settings->getFloat("water_wave_speed") << "\n";
}
switch (material_type) {
case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT:
case TILE_MATERIAL_WAVING_LIQUID_OPAQUE:
case TILE_MATERIAL_WAVING_LIQUID_BASIC:
case TILE_MATERIAL_LIQUID_TRANSPARENT:
shaders_header << "#define MATERIAL_WAVING_LIQUID 1\n";
break;
default:
shaders_header << "#define MATERIAL_WAVING_LIQUID 0\n";
break;
}
shaders_header << "#define ENABLE_WAVING_LEAVES " << g_settings->getBool("enable_waving_leaves") << "\n";
shaders_header << "#define ENABLE_WAVING_PLANTS " << g_settings->getBool("enable_waving_plants") << "\n";
}
/* Other constants */
shaders_header << "#define ENABLE_TONE_MAPPING " << g_settings->getBool("tone_mapping") << "\n";
if (g_settings->getBool("enable_dynamic_shadows")) {