summaryrefslogtreecommitdiff
path: root/src/mapblock_mesh.cpp
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@o2.pl>2014-05-14 23:19:31 +0200
committerRealBadAngel <maciej.kasatkin@o2.pl>2014-06-15 05:40:33 +0200
commit6c98fd6658fcf7c0c676ee88f03e364c852e9f1b (patch)
tree01a6a17c00730bd2744a2394f36950ba83b10107 /src/mapblock_mesh.cpp
parent9ffa88b558498a139488679ef2ed8767c8540471 (diff)
downloadminetest-6c98fd6658fcf7c0c676ee88f03e364c852e9f1b.tar.gz
minetest-6c98fd6658fcf7c0c676ee88f03e364c852e9f1b.tar.bz2
minetest-6c98fd6658fcf7c0c676ee88f03e364c852e9f1b.zip
Unite nodes shaders.
Pass drawtype and material type to shaders. Move shaders generation to startup only. Allow assign shaders per tile. Initial code to support water surface shader.
Diffstat (limited to 'src/mapblock_mesh.cpp')
-rw-r--r--src/mapblock_mesh.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index 73f69c247..bf62fe8b4 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -1106,24 +1106,13 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
/*
Convert MeshCollector to SMesh
*/
+ ITextureSource *tsrc = m_gamedef->tsrc();
+ IShaderSource *shdrsrc = m_gamedef->getShaderSource();
+
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;
- shadermat1 = shadermat2 = shadermat3 = shadermat4 = shadermat5 =
- video::EMT_SOLID;
-
- if (enable_shaders) {
- IShaderSource *shdrsrc = m_gamedef->getShaderSource();
- shadermat1 = shdrsrc->getShader("solids_shader").material;
- shadermat2 = shdrsrc->getShader("liquids_shader").material;
- shadermat3 = shdrsrc->getShader("alpha_shader").material;
- shadermat4 = shdrsrc->getShader("leaves_shader").material;
- shadermat5 = shdrsrc->getShader("plants_shader").material;
- }
-
for(u32 i = 0; i < collector.prebuffers.size(); i++)
{
PreMeshBuffer &p = collector.prebuffers[i];
@@ -1135,7 +1124,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
// - Cracks
if(p.tile.material_flags & MATERIAL_FLAG_CRACK)
{
- ITextureSource *tsrc = data->m_gamedef->tsrc();
// Find the texture name plus ^[crack:N:
std::ostringstream os(std::ios::binary);
os<<tsrc->getTextureName(p.tile.texture_id)<<"^[crack";
@@ -1151,7 +1139,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
// - Texture animation
if(p.tile.material_flags & MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
{
- ITextureSource *tsrc = data->m_gamedef->tsrc();
// Add to MapBlockMesh in order to animate these tiles
m_animation_tiles[i] = p.tile;
m_animation_frames[i] = 0;
@@ -1206,7 +1193,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
material.setTexture(0, p.tile.texture);
if (enable_shaders) {
- ITextureSource *tsrc = data->m_gamedef->tsrc();
+ material.MaterialType = shdrsrc->getShaderInfo(p.tile.shader_id).material;
+ p.tile.applyMaterialOptionsWithShaders(material);
material.setTexture(2, tsrc->getTexture("disable_img.png"));
if (enable_bumpmapping || enable_parallax_occlusion) {
if (tsrc->isKnownSourceImage("override_normal.png")){
@@ -1230,8 +1218,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
}
}
}
- p.tile.applyMaterialOptionsWithShaders(material,
- shadermat1, shadermat2, shadermat3, shadermat4, shadermat5);
} else {
p.tile.applyMaterialOptions(material);
}
@@ -1360,6 +1346,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
ITextureSource *tsrc = m_gamedef->getTextureSource();
+ IShaderSource *shdrsrc = m_gamedef->getShaderSource();
// Create new texture name from original
std::ostringstream os(std::ios::binary);
@@ -1367,9 +1354,10 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
os<<"^[verticalframe:"<<(int)tile.animation_frame_count<<":"<<frame;
// 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 || enable_parallax_occlusion))
- {
+ if (enable_shaders){
+ buf->getMaterial().setTexture(2, tsrc->getTexture("disable_img.png"));
+ buf->getMaterial().MaterialType = shdrsrc->getShaderInfo(tile.shader_id).material;
+ if (enable_bumpmapping || enable_parallax_occlusion){
if (tsrc->isKnownSourceImage("override_normal.png")){
buf->getMaterial().setTexture(1, tsrc->getTexture("override_normal.png"));
buf->getMaterial().setTexture(2, tsrc->getTexture("enable_img.png"));
@@ -1388,6 +1376,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
}
}
}
+ }
}
// Day-night transition