mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Implement a global shader parameter passing system and useful shaders
This commit is contained in:
parent
22e6fb7056
commit
27373919f4
15 changed files with 241 additions and 90 deletions
52
src/game.cpp
52
src/game.cpp
|
@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <IGUIButton.h>
|
||||
#include <IGUIStaticText.h>
|
||||
#include <IGUIFont.h>
|
||||
#include <IMaterialRendererServices.h>
|
||||
#include "client.h"
|
||||
#include "server.h"
|
||||
#include "guiPauseMenu.h"
|
||||
|
@ -835,6 +836,49 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class GameGlobalShaderConstantSetter : public IShaderConstantSetter
|
||||
{
|
||||
Sky *m_sky;
|
||||
bool *m_force_fog_off;
|
||||
f32 *m_fog_range;
|
||||
|
||||
public:
|
||||
GameGlobalShaderConstantSetter(Sky *sky, bool *force_fog_off,
|
||||
f32 *fog_range):
|
||||
m_sky(sky),
|
||||
m_force_fog_off(force_fog_off),
|
||||
m_fog_range(fog_range)
|
||||
{}
|
||||
~GameGlobalShaderConstantSetter() {}
|
||||
|
||||
virtual void onSetConstants(video::IMaterialRendererServices *services,
|
||||
bool is_highlevel)
|
||||
{
|
||||
if(!is_highlevel)
|
||||
return;
|
||||
|
||||
// Background color
|
||||
video::SColor bgcolor = m_sky->getBgColor();
|
||||
video::SColorf bgcolorf(bgcolor);
|
||||
float bgcolorfa[4] = {
|
||||
bgcolorf.r,
|
||||
bgcolorf.g,
|
||||
bgcolorf.b,
|
||||
bgcolorf.a,
|
||||
};
|
||||
services->setPixelShaderConstant("skyBgColor", bgcolorfa, 4);
|
||||
|
||||
// Fog distance
|
||||
float fog_distance = *m_fog_range;
|
||||
if(*m_force_fog_off)
|
||||
fog_distance = 10000*BS;
|
||||
services->setPixelShaderConstant("fogDistance", &fog_distance, 1);
|
||||
}
|
||||
|
||||
private:
|
||||
IrrlichtDevice *m_device;
|
||||
};
|
||||
|
||||
void the_game(
|
||||
bool &kill,
|
||||
bool random_input,
|
||||
|
@ -1250,6 +1294,7 @@ void the_game(
|
|||
bool show_hud = true;
|
||||
bool show_chat = true;
|
||||
bool force_fog_off = false;
|
||||
f32 fog_range = 100*BS;
|
||||
bool disable_camera_update = false;
|
||||
bool show_debug = g_settings->getBool("show_debug");
|
||||
bool show_profiler_graph = false;
|
||||
|
@ -1259,6 +1304,12 @@ void the_game(
|
|||
float time_of_day = 0;
|
||||
float time_of_day_smooth = 0;
|
||||
|
||||
/*
|
||||
Shader constants
|
||||
*/
|
||||
shsrc->addGlobalConstantSetter(
|
||||
new GameGlobalShaderConstantSetter(sky, &force_fog_off, &fog_range));
|
||||
|
||||
/*
|
||||
Main loop
|
||||
*/
|
||||
|
@ -2434,7 +2485,6 @@ void the_game(
|
|||
Fog range
|
||||
*/
|
||||
|
||||
f32 fog_range;
|
||||
if(farmesh)
|
||||
{
|
||||
fog_range = BS*farmesh_range;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue