summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRealBadAngel <mk@realbadangel.pl>2013-12-09 13:25:43 +0100
committerRealBadAngel <mk@realbadangel.pl>2013-12-09 13:28:50 +0100
commitdae03382bf1e3abfcc33417c611b9194c7783b3f (patch)
treec74773f8136d4d9db008b9092a11d3d084182d08 /src
parent50b0e9f7a4916044b1938d461c9c4029b30569da (diff)
downloadminetest-dae03382bf1e3abfcc33417c611b9194c7783b3f.tar.gz
minetest-dae03382bf1e3abfcc33417c611b9194c7783b3f.tar.bz2
minetest-dae03382bf1e3abfcc33417c611b9194c7783b3f.zip
Optimize shaders code. Add settings at compile time.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp38
-rw-r--r--src/mapblock_mesh.cpp8
-rw-r--r--src/shader.cpp52
3 files changed, 49 insertions, 49 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 68bd12b97..b67602f5a 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -815,44 +815,6 @@ public:
services->setPixelShaderConstant("eyePosition", (irr::f32*)&eye_position, 3);
services->setVertexShaderConstant("eyePosition", (irr::f32*)&eye_position, 3);
- float enable_bumpmapping = 0;
- if (g_settings->getBool("enable_bumpmapping"))
- enable_bumpmapping = 1;
- services->setPixelShaderConstant("enableBumpmapping", &enable_bumpmapping, 1);
-
- float enable_parallax_occlusion = 0;
- if (g_settings->getBool("enable_parallax_occlusion")) {
- enable_parallax_occlusion = 1;
- float parallax_occlusion_scale = g_settings->getFloat("parallax_occlusion_scale");
- services->setPixelShaderConstant("parallaxOcclusionScale", &parallax_occlusion_scale, 1);
- float parallax_occlusion_bias = g_settings->getFloat("parallax_occlusion_bias");
- services->setPixelShaderConstant("parallaxOcclusionBias", &parallax_occlusion_bias, 1);
- }
- services->setPixelShaderConstant("enableParallaxOcclusion", &enable_parallax_occlusion, 1);
-
- float enable_waving_water = 0;
- if (g_settings->getBool("enable_waving_water")){
- enable_waving_water = 1;
- float water_wave_height_f = g_settings->getFloat("water_wave_height");
- services->setVertexShaderConstant("waterWaveHeight", &water_wave_height_f, 1);
- float water_wave_length_f = g_settings->getFloat("water_wave_length");
- services->setVertexShaderConstant("waterWaveLength", &water_wave_length_f, 1);
- float water_wave_speed_f = g_settings->getFloat("water_wave_speed");
- services->setVertexShaderConstant("waterWaveSpeed", &water_wave_speed_f, 1);
- }
- services->setVertexShaderConstant("enableWavingWater", &enable_waving_water, 1);
-
- float enable_waving_leaves = 0;
- if (g_settings->getBool("enable_waving_leaves"))
- enable_waving_leaves = 1;
- services->setVertexShaderConstant("enableWavingLeaves", &enable_waving_leaves, 1);
-
- float enable_waving_plants = 0;
- if (g_settings->getBool("enable_waving_plants"))
- enable_waving_plants = 1;
- services->setVertexShaderConstant("enableWavingPlants", &enable_waving_plants, 1);
-
-
// Normal map texture layer
int layer1 = 1;
int layer2 = 2;
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index 81aac72d7..afea3dcce 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -1111,6 +1111,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
*/
bool enable_shaders = g_settings->getBool("enable_shaders");
bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
+ bool enable_parallax_occlusion = g_settings->getBool("enable_parallax_occlusion");
video::E_MATERIAL_TYPE shadermat1, shadermat2, shadermat3,
shadermat4, shadermat5;
@@ -1210,7 +1211,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
if (enable_shaders) {
ITextureSource *tsrc = data->m_gamedef->tsrc();
material.setTexture(2, tsrc->getTexture("disable_img.png"));
- if (enable_bumpmapping) {
+ if (enable_bumpmapping || enable_parallax_occlusion) {
std::string fname_base = tsrc->getTextureName(p.tile.texture_id);
std::string normal_ext = "_normal.png";
size_t pos = fname_base.find(".");
@@ -1292,7 +1293,8 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
{
bool enable_shaders = g_settings->getBool("enable_shaders");
bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
-
+ bool enable_parallax_occlusion = g_settings->getBool("enable_parallax_occlusion");
+
if(!m_has_animation)
{
m_animation_force_timer = 100000;
@@ -1362,7 +1364,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
// Set the texture
buf->getMaterial().setTexture(0, tsrc->getTexture(os.str()));
buf->getMaterial().setTexture(2, tsrc->getTexture("disable_img.png"));
- if (enable_shaders && enable_bumpmapping)
+ if (enable_shaders && (enable_bumpmapping || enable_parallax_occlusion))
{
std::string fname_base,fname_normal;
fname_base = tsrc->getTextureName(tile.texture_id);
diff --git a/src/shader.cpp b/src/shader.cpp
index 76af23686..39296f6a3 100644
--- a/src/shader.cpp
+++ b/src/shader.cpp
@@ -673,15 +673,51 @@ ShaderInfo generate_shader(std::string name, IrrlichtDevice *device,
if(vertex_program == "" && pixel_program == "" && geometry_program == "")
return shaderinfo;
- if (g_settings->getBool("enable_bumpmapping") || g_settings->getBool("enable_parallax_occlusion")) {
- if(vertex_program != "")
- vertex_program = "#define NORMALS\n" + vertex_program;
- if(pixel_program != "")
- pixel_program = "#define NORMALS\n" + pixel_program;
- if(geometry_program != "")
- geometry_program = "#define NORMALS\n" + geometry_program;
- }
+ // Create shaders header
+ std::string shaders_header = "#version 120\n";
+ if (g_settings->getBool("enable_bumpmapping"))
+ shaders_header += "#define ENABLE_BUMPMAPPING\n";
+
+ if (g_settings->getBool("enable_parallax_occlusion")){
+ shaders_header += "#define ENABLE_PARALLAX_OCCLUSION\n";
+ shaders_header += "#define PARALLAX_OCCLUSION_SCALE ";
+ shaders_header += ftos(g_settings->getFloat("parallax_occlusion_scale"));
+ shaders_header += "\n";
+ shaders_header += "#define PARALLAX_OCCLUSION_BIAS ";
+ shaders_header += ftos(g_settings->getFloat("parallax_occlusion_bias"));
+ shaders_header += "\n";
+ }
+
+ if (g_settings->getBool("enable_bumpmapping") || g_settings->getBool("enable_parallax_occlusion"))
+ shaders_header += "#define USE_NORMALMAPS\n";
+
+ if (g_settings->getBool("enable_waving_water")){
+ shaders_header += "#define ENABLE_WAVING_WATER\n";
+ shaders_header += "#define WATER_WAVE_HEIGHT ";
+ shaders_header += ftos(g_settings->getFloat("water_wave_height"));
+ shaders_header += "\n";
+ shaders_header += "#define WATER_WAVE_LENGTH ";
+ shaders_header += ftos(g_settings->getFloat("water_wave_length"));
+ shaders_header += "\n";
+ shaders_header += "#define WATER_WAVE_SPEED ";
+ shaders_header += ftos(g_settings->getFloat("water_wave_speed"));
+ shaders_header += "\n";
+ }
+
+ if (g_settings->getBool("enable_waving_leaves"))
+ shaders_header += "#define ENABLE_WAVING_LEAVES\n";
+
+ if (g_settings->getBool("enable_waving_plants"))
+ shaders_header += "#define ENABLE_WAVING_PLANTS\n";
+
+ if(pixel_program != "")
+ pixel_program = shaders_header + pixel_program;
+ if(vertex_program != "")
+ vertex_program = shaders_header + vertex_program;
+ if(geometry_program != "")
+ geometry_program = shaders_header + geometry_program;
+
// Call addHighLevelShaderMaterial() or addShaderMaterial()
const c8* vertex_program_ptr = 0;
const c8* pixel_program_ptr = 0;