Skip to content

Commit ccbf802

Browse files
authoredDec 19, 2020
Cleanup shader generation code (#10663)
Shader generation is a mess. This commit cleans some parts up, including dropping remains of HLSL support which was never actually implemented.
1 parent 664f5ce commit ccbf802

File tree

11 files changed

+164
-384
lines changed

11 files changed

+164
-384
lines changed
 

‎client/shaders/nodes_shader/opengl_fragment.glsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ varying vec3 eyeVec;
2222
const float fogStart = FOG_START;
2323
const float fogShadingParameter = 1.0 / ( 1.0 - fogStart);
2424

25-
#ifdef ENABLE_TONE_MAPPING
25+
#if ENABLE_TONE_MAPPING
Has conversations. Original line has conversations.
2626

2727
/* Hable's UC2 Tone mapping parameters
2828
A = 0.22;
@@ -73,7 +73,7 @@ void main(void)
7373

7474
vec4 col = vec4(color.rgb * varColor.rgb, 1.0);
7575

76-
#ifdef ENABLE_TONE_MAPPING
76+
#if ENABLE_TONE_MAPPING
7777
col = applyToneMapping(col);
7878
#endif
7979

‎client/shaders/object_shader/opengl_fragment.glsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const float BS = 10.0;
1919
const float fogStart = FOG_START;
2020
const float fogShadingParameter = 1.0 / (1.0 - fogStart);
2121

22-
#ifdef ENABLE_TONE_MAPPING
22+
#if ENABLE_TONE_MAPPING
2323

2424
/* Hable's UC2 Tone mapping parameters
2525
A = 0.22;
@@ -75,7 +75,7 @@ void main(void)
7575

7676
col.rgb *= emissiveColor.rgb * vIDiff;
7777

78-
#ifdef ENABLE_TONE_MAPPING
78+
#if ENABLE_TONE_MAPPING
7979
col = applyToneMapping(col);
8080
#endif
8181

‎src/client/clientenvironment.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ class CAOShaderConstantSetter : public IShaderConstantSetter
5151

5252
~CAOShaderConstantSetter() override = default;
5353

54-
void onSetConstants(video::IMaterialRendererServices *services,
55-
bool is_highlevel) override
54+
void onSetConstants(video::IMaterialRendererServices *services) override
5655
{
57-
if (!is_highlevel)
58-
return;
59-
6056
// Ambient color
6157
video::SColorf emissive_color(m_emissive_color);
6258

‎src/client/game.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,8 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
475475
g_settings->deregisterChangedCallback("enable_fog", settingsCallback, this);
476476
}
477477

478-
virtual void onSetConstants(video::IMaterialRendererServices *services,
479-
bool is_highlevel)
478+
void onSetConstants(video::IMaterialRendererServices *services) override
480479
{
481-
if (!is_highlevel)
482-
return;
483-
484480
// Background color
485481
video::SColor bgcolor = m_sky->getBgColor();
486482
video::SColorf bgcolorf(bgcolor);

‎src/client/hud.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
100100
if (g_settings->getBool("enable_shaders")) {
101101
IShaderSource *shdrsrc = client->getShaderSource();
102102
u16 shader_id = shdrsrc->getShader(
103-
m_mode == HIGHLIGHT_HALO ? "selection_shader" : "default_shader", 1, 1);
103+
m_mode == HIGHLIGHT_HALO ? "selection_shader" : "default_shader", TILE_MATERIAL_ALPHA);
104104
m_selection_material.MaterialType = shdrsrc->getShaderInfo(shader_id).material;
105105
} else {
106106
m_selection_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;

‎src/client/minimap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ void Minimap::drawMinimap(core::rect<s32> rect) {
612612
material.TextureLayer[1].Texture = data->heightmap_texture;
613613

614614
if (m_enable_shaders && data->mode.type == MINIMAP_TYPE_SURFACE) {
615-
u16 sid = m_shdrsrc->getShader("minimap_shader", 1, 1);
615+
u16 sid = m_shdrsrc->getShader("minimap_shader", TILE_MATERIAL_ALPHA);
616616
material.MaterialType = m_shdrsrc->getShaderInfo(sid).material;
617617
} else {
618618
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;

‎src/client/render/interlaced.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void RenderingCoreInterlaced::initMaterial()
3636
mat.UseMipMaps = false;
3737
mat.ZBuffer = false;
3838
mat.ZWriteEnable = false;
39-
u32 shader = s->getShader("3d_interlaced_merge", TILE_MATERIAL_BASIC, 0);
39+
u32 shader = s->getShader("3d_interlaced_merge", TILE_MATERIAL_BASIC);
4040
mat.MaterialType = s->getShaderInfo(shader).material;
4141
for (int k = 0; k < 3; ++k) {
4242
mat.TextureLayer[k].AnisotropicFilter = false;

‎src/client/shader.cpp

+142-351
Large diffs are not rendered by default.

‎src/client/shader.h

+9-12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include <IMaterialRendererServices.h>
2424
#include "irrlichttypes_bloated.h"
2525
#include <string>
26+
#include "tile.h"
27+
#include "nodedef.h"
2628

2729
class IGameDef;
2830

@@ -46,8 +48,8 @@ struct ShaderInfo {
4648
std::string name = "";
4749
video::E_MATERIAL_TYPE base_material = video::EMT_SOLID;
4850
video::E_MATERIAL_TYPE material = video::EMT_SOLID;
49-
u8 drawtype = 0;
50-
u8 material_type = 0;
51+
NodeDrawType drawtype = NDT_NORMAL;
52+
MaterialType material_type = TILE_MATERIAL_BASIC;
5153

5254
ShaderInfo() = default;
5355
virtual ~ShaderInfo() = default;
@@ -65,8 +67,7 @@ namespace irr { namespace video {
6567
class IShaderConstantSetter {
6668
public:
6769
virtual ~IShaderConstantSetter() = default;
68-
virtual void onSetConstants(video::IMaterialRendererServices *services,
69-
bool is_highlevel) = 0;
70+
virtual void onSetConstants(video::IMaterialRendererServices *services) = 0;
7071
virtual void onSetMaterial(const video::SMaterial& material)
7172
{ }
7273
};
@@ -128,27 +129,23 @@ class IShaderSource {
128129
virtual ~IShaderSource() = default;
129130

130131
virtual u32 getShaderIdDirect(const std::string &name,
131-
const u8 material_type, const u8 drawtype){return 0;}
132+
MaterialType material_type, NodeDrawType drawtype = NDT_NORMAL){return 0;}
132133
virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
133134
virtual u32 getShader(const std::string &name,
134-
const u8 material_type, const u8 drawtype){return 0;}
135+
MaterialType material_type, NodeDrawType drawtype = NDT_NORMAL){return 0;}
135136
};
136137

137138
class IWritableShaderSource : public IShaderSource {
138139
public:
139140
IWritableShaderSource() = default;
140141
virtual ~IWritableShaderSource() = default;
141142

142-
virtual u32 getShaderIdDirect(const std::string &name,
143-
const u8 material_type, const u8 drawtype){return 0;}
144-
virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
145-
virtual u32 getShader(const std::string &name,
146-
const u8 material_type, const u8 drawtype){return 0;}
147-
148143
virtual void processQueue()=0;
149144
virtual void insertSourceShader(const std::string &name_of_shader,
150145
const std::string &filename, const std::string &program)=0;
151146
virtual void rebuildShaders()=0;
147+
148+
/// @note Takes ownership of @p setter.
152149
virtual void addShaderConstantSetterFactory(IShaderConstantSetterFactory *setter) = 0;
153150
};
154151

‎src/client/sky.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) :
6565
// Create materials
6666

6767
m_materials[0] = baseMaterial();
68-
m_materials[0].MaterialType = ssrc->getShaderInfo(ssrc->getShader("stars_shader", TILE_MATERIAL_ALPHA, 0)).material;
68+
m_materials[0].MaterialType = ssrc->getShaderInfo(ssrc->getShader("stars_shader", TILE_MATERIAL_ALPHA)).material;
6969
m_materials[0].Lighting = true;
7070
m_materials[0].ColorMaterial = video::ECM_NONE;
7171

‎src/nodedef.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
774774

775775
bool is_liquid = false;
776776

777-
u8 material_type = (alpha == 255) ?
777+
MaterialType material_type = (alpha == 255) ?
778778
TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA;
779779

780780
switch (drawtype) {
@@ -892,7 +892,7 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
892892

893893
u32 tile_shader = shdsrc->getShader("nodes_shader", material_type, drawtype);
894894

895-
u8 overlay_material = material_type;
895+
MaterialType overlay_material = material_type;
896896
if (overlay_material == TILE_MATERIAL_OPAQUE)
897897
overlay_material = TILE_MATERIAL_BASIC;
898898
else if (overlay_material == TILE_MATERIAL_LIQUID_OPAQUE)
@@ -913,7 +913,7 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
913913
tdef[j].backface_culling, tsettings);
914914
}
915915

916-
u8 special_material = material_type;
916+
MaterialType special_material = material_type;
917917
if (drawtype == NDT_PLANTLIKE_ROOTED) {
918918
if (waving == 1)
919919
special_material = TILE_MATERIAL_WAVING_PLANTS;

0 commit comments

Comments
 (0)
Please sign in to comment.