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

Change shaders to be defined by input constants rather than drawtype/material type

This commit is contained in:
sfan5 2025-04-17 23:48:08 +02:00
parent baa4c7cd21
commit f3c2bbfb48
2 changed files with 127 additions and 89 deletions

View file

@ -28,17 +28,6 @@
std::string getShaderPath(const std::string &name_of_shader,
const std::string &filename);
struct ShaderInfo {
std::string name = "";
video::E_MATERIAL_TYPE base_material = video::EMT_SOLID;
video::E_MATERIAL_TYPE material = video::EMT_SOLID;
NodeDrawType drawtype = NDT_NORMAL;
MaterialType material_type = TILE_MATERIAL_BASIC;
ShaderInfo() = default;
virtual ~ShaderInfo() = default;
};
/*
Abstraction for pushing constants (or what we pretend is) into
shaders. These end up as `#define` prepended to the shader source.
@ -218,7 +207,18 @@ using CachedStructPixelShaderSetting = CachedStructShaderSetting<T, count, cache
A "shader" could more precisely be called a "shader material" and comprises
a vertex, fragment and optional geometry shader.
It is uniquely identified by a name, base material and the input constants.
*/
struct ShaderInfo {
std::string name;
video::E_MATERIAL_TYPE base_material = video::EMT_SOLID;
// Material ID the shader has received from Irrlicht
video::E_MATERIAL_TYPE material = video::EMT_SOLID;
// Input constants
ShaderConstants input_constants;
};
class IShaderSource {
public:
IShaderSource() = default;
@ -229,19 +229,38 @@ public:
*
* Use this to get the material ID to plug into `video::SMaterial`.
*/
virtual ShaderInfo getShaderInfo(u32 id) = 0;
/// @brief Generates or gets a shader suitable for nodes and entities
virtual u32 getShader(const std::string &name,
MaterialType material_type, NodeDrawType drawtype = NDT_NORMAL) = 0;
virtual const ShaderInfo &getShaderInfo(u32 id) = 0;
/**
* Generates or gets a shader for general use.
* Generates or gets a shader.
*
* Note that the input constants are not for passing the entire world into
* the shader. Use `IShaderConstantSetter` to handle user settings.
* @param name name of the shader (directory on disk)
* @param input_const primary key constants for this shader
* @param base_mat base material to use
* @return shader ID
* @note `base_material` only controls alpha behavior
*/
virtual u32 getShader(const std::string &name,
const ShaderConstants &input_const, video::E_MATERIAL_TYPE base_mat) = 0;
/// @brief Helper: Generates or gets a shader suitable for nodes and entities
u32 getShader(const std::string &name,
MaterialType material_type, NodeDrawType drawtype = NDT_NORMAL);
/**
* Helper: Generates or gets a shader for common, general use.
* @param name name of the shader
* @param blendAlpha enable alpha blending for this material?
* @return shader ID
*/
virtual u32 getShaderRaw(const std::string &name, bool blendAlpha = false) = 0;
inline u32 getShaderRaw(const std::string &name, bool blendAlpha = false)
{
auto base_mat = blendAlpha ? video::EMT_TRANSPARENT_ALPHA_CHANNEL :
video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
return getShader(name, ShaderConstants(), base_mat);
}
};
class IWritableShaderSource : public IShaderSource {