diff options
author | RealBadAngel <maciej.kasatkin@yahoo.com> | 2014-03-21 01:32:00 +0100 |
---|---|---|
committer | RealBadAngel <maciej.kasatkin@yahoo.com> | 2014-03-21 01:32:00 +0100 |
commit | 0dc1aec50940140e28f434c524296e284e73d623 (patch) | |
tree | b69e282c3b59db2f300e4d017afe67d4ad246a8c /src | |
parent | f3d83a4516eb9c6658a7c3e07bf1b7d4f4996bef (diff) | |
download | minetest-0dc1aec50940140e28f434c524296e284e73d623.tar.gz minetest-0dc1aec50940140e28f434c524296e284e73d623.tar.bz2 minetest-0dc1aec50940140e28f434c524296e284e73d623.zip |
Normal maps generation on the fly.
Parallax mapping with slope information.
Overriding normal maps.
Diffstat (limited to 'src')
-rw-r--r-- | src/defaultsettings.cpp | 7 | ||||
-rw-r--r-- | src/game.cpp | 5 | ||||
-rw-r--r-- | src/mapblock_mesh.cpp | 56 | ||||
-rw-r--r-- | src/shader.cpp | 42 |
4 files changed, 80 insertions, 30 deletions
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 6b291bd2b..b08d79aee 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -130,8 +130,11 @@ void set_default_settings(Settings *settings) settings->setDefault("preload_item_visuals", "true"); settings->setDefault("enable_bumpmapping", "false"); settings->setDefault("enable_parallax_occlusion", "false"); - settings->setDefault("parallax_occlusion_scale", "0.08"); - settings->setDefault("parallax_occlusion_bias", "0.04"); + settings->setDefault("generate_normalmaps", "false"); + settings->setDefault("normalmaps_strength", "0.6"); + settings->setDefault("normalmaps_smooth", "1"); + settings->setDefault("parallax_occlusion_scale", "0.06"); + settings->setDefault("parallax_occlusion_bias", "0.03"); settings->setDefault("enable_waving_water", "false"); settings->setDefault("water_wave_height", "1.0"); settings->setDefault("water_wave_length", "20.0"); diff --git a/src/game.cpp b/src/game.cpp index 0a9dcfdae..761f65f83 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -858,14 +858,17 @@ public: services->setPixelShaderConstant("eyePosition", (irr::f32*)&eye_position, 3); services->setVertexShaderConstant("eyePosition", (irr::f32*)&eye_position, 3); - // Normal map texture layer + // Uniform sampler layers + int layer0 = 0; int layer1 = 1; int layer2 = 2; // before 1.8 there isn't a "integer interface", only float #if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8) + services->setPixelShaderConstant("baseTexture" , (irr::f32*)&layer0, 1); services->setPixelShaderConstant("normalTexture" , (irr::f32*)&layer1, 1); services->setPixelShaderConstant("useNormalmap" , (irr::f32*)&layer2, 1); #else + services->setPixelShaderConstant("baseTexture" , (irr::s32*)&layer0, 1); services->setPixelShaderConstant("normalTexture" , (irr::s32*)&layer1, 1); services->setPixelShaderConstant("useNormalmap" , (irr::s32*)&layer2, 1); #endif diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index ef05acbb7..9cd99fcb7 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -1212,20 +1212,25 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): ITextureSource *tsrc = data->m_gamedef->tsrc(); material.setTexture(2, tsrc->getTexture("disable_img.png")); 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("."); - std::string fname_normal = fname_base.substr(0, pos) + normal_ext; - - if (tsrc->isKnownSourceImage(fname_normal)) { - // look for image extension and replace it - size_t i = 0; - while ((i = fname_base.find(".", i)) != std::string::npos) { - fname_base.replace(i, 4, normal_ext); - i += normal_ext.length(); - } - material.setTexture(1, tsrc->getTexture(fname_base)); + if (tsrc->isKnownSourceImage("override_normal.png")){ + material.setTexture(1, tsrc->getTexture("override_normal.png")); material.setTexture(2, tsrc->getTexture("enable_img.png")); + } else { + std::string fname_base = tsrc->getTextureName(p.tile.texture_id); + std::string normal_ext = "_normal.png"; + size_t pos = fname_base.find("."); + std::string fname_normal = fname_base.substr(0, pos) + normal_ext; + + if (tsrc->isKnownSourceImage(fname_normal)) { + // look for image extension and replace it + size_t i = 0; + while ((i = fname_base.find(".", i)) != std::string::npos) { + fname_base.replace(i, 4, normal_ext); + i += normal_ext.length(); + } + material.setTexture(1, tsrc->getTexture(fname_base)); + material.setTexture(2, tsrc->getTexture("enable_img.png")); + } } } p.tile.applyMaterialOptionsWithShaders(material, @@ -1368,17 +1373,22 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat buf->getMaterial().setTexture(2, tsrc->getTexture("disable_img.png")); if (enable_shaders && (enable_bumpmapping || enable_parallax_occlusion)) { - std::string fname_base,fname_normal; - fname_base = tsrc->getTextureName(tile.texture_id); - unsigned pos; - pos = fname_base.find("."); - fname_normal = fname_base.substr (0, pos); - fname_normal += "_normal.png"; - if (tsrc->isKnownSourceImage(fname_normal)){ - os.str(""); - os<<fname_normal<<"^[verticalframe:"<<(int)tile.animation_frame_count<<":"<<frame; - buf->getMaterial().setTexture(1, tsrc->getTexture(os.str())); + if (tsrc->isKnownSourceImage("override_normal.png")){ + buf->getMaterial().setTexture(1, tsrc->getTexture("override_normal.png")); buf->getMaterial().setTexture(2, tsrc->getTexture("enable_img.png")); + } else { + std::string fname_base,fname_normal; + fname_base = tsrc->getTextureName(tile.texture_id); + unsigned pos; + pos = fname_base.find("."); + fname_normal = fname_base.substr (0, pos); + fname_normal += "_normal.png"; + if (tsrc->isKnownSourceImage(fname_normal)){ + os.str(""); + os<<fname_normal<<"^[verticalframe:"<<(int)tile.animation_frame_count<<":"<<frame; + buf->getMaterial().setTexture(1, tsrc->getTexture(os.str())); + buf->getMaterial().setTexture(2, tsrc->getTexture("enable_img.png")); + } } } } diff --git a/src/shader.cpp b/src/shader.cpp index d29c9d3a7..4006e256f 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -240,12 +240,20 @@ public: services->setVertexShaderConstant(worldViewProj.pointer(), 4, 4); // set transposed world matrix + core::matrix4 transWorld = driver->getTransform(video::ETS_WORLD); + transWorld = transWorld.getTransposed(); + if(is_highlevel) + services->setVertexShaderConstant("mTransWorld", transWorld.pointer(), 16); + else + services->setVertexShaderConstant(transWorld.pointer(), 8, 4); + + // set world matrix core::matrix4 world = driver->getTransform(video::ETS_WORLD); - world = world.getTransposed(); if(is_highlevel) - services->setVertexShaderConstant("mTransWorld", world.pointer(), 16); + services->setVertexShaderConstant("mWorld", world.pointer(), 16); else services->setVertexShaderConstant(world.pointer(), 8, 4); + } private: @@ -673,7 +681,33 @@ ShaderInfo generate_shader(std::string name, IrrlichtDevice *device, // Create shaders header std::string shaders_header = "#version 120\n"; - + + if (g_settings->getBool("generate_normalmaps")){ + shaders_header += "#define GENERATE_NORMALMAPS\n"; + shaders_header += "#define NORMALMAPS_STRENGTH "; + shaders_header += ftos(g_settings->getFloat("normalmaps_strength")); + shaders_header += "\n"; + float sample_step; + int smooth = (int)g_settings->getFloat("normalmaps_smooth"); + switch (smooth){ + case 0: + sample_step = 0.0078125; // 1.0 / 128.0 + break; + case 1: + sample_step = 0.00390625; // 1.0 / 256.0 + break; + case 2: + sample_step = 0.001953125; // 1.0 / 512.0 + break; + default: + sample_step = 0.0078125; + break; + } + shaders_header += "#define SAMPLE_STEP "; + shaders_header += ftos(sample_step); + shaders_header += "\n"; + } + if (g_settings->getBool("enable_bumpmapping")) shaders_header += "#define ENABLE_BUMPMAPPING\n"; @@ -685,7 +719,7 @@ ShaderInfo generate_shader(std::string name, IrrlichtDevice *device, 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"; |