Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ varying vec3 tsLightVec;
bool normalTexturePresent = false;

const float e = 2.718281828459;
const float BS = 10.0;

float intensity (vec3 color){
return (color.r + color.g + color.b) / 3.0;
Expand Down Expand Up @@ -94,17 +95,34 @@ vec4 base = texture2D(baseTexture, uv).rgba;
color = base.rgb;
#endif

vec4 col = vec4(color.rgb, base.a);
#if MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE
float alpha = gl_Color.a;
vec4 col = vec4(color.rgb, alpha);
col *= gl_Color;
col = col * col; // SRGB -> Linear
col *= 1.8;
col.r = 1.0 - exp(1.0 - col.r) / e;
col.g = 1.0 - exp(1.0 - col.g) / e;
col.b = 1.0 - exp(1.0 - col.b) / e;
col = sqrt(col); // Linear -> SRGB
if(fogDistance != 0.0){
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
alpha = mix(alpha, 0.0, d);
}
gl_FragColor = vec4(col.rgb, alpha);
#else
vec4 col = vec4(color.rgb, base.a);
col *= gl_Color;
col = col * col; // SRGB -> Linear
col *= 1.8;
col.r = 1.0 - exp(1.0 - col.r) / e;
col.g = 1.0 - exp(1.0 - col.g) / e;
col.b = 1.0 - exp(1.0 - col.b) / e;
col = sqrt(col); // Linear -> SRGB
if(fogDistance != 0.0){
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
col = mix(col, skyBgColor, d);
}
gl_FragColor = vec4(col.rgb, base.a);
gl_FragColor = vec4(col.rgb, base.a);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,60 @@ uniform mat4 mTransWorld;
uniform mat4 mWorld;

uniform float dayNightRatio;
uniform float animationTimer;

uniform vec3 eyePosition;
uniform float animationTimer;

varying vec3 vPosition;
varying vec3 worldPosition;

varying vec3 eyeVec;
varying vec3 lightVec;

varying vec3 tsEyeVec;
varying vec3 tsLightVec;

const float e = 2.718281828459;
const float BS = 10.0;

float smoothCurve( float x ) {
return x * x *( 3.0 - 2.0 * x );
}
float triangleWave( float x ) {
return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
}
float smoothTriangleWave( float x ) {
return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;
}

void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;

#ifdef ENABLE_WAVING_WATER
vec4 pos2 = gl_Vertex;
pos2.y -= 2.0;
pos2.y -= sin (pos2.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) * WATER_WAVE_HEIGHT
+ sin ((pos2.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) / 7.0) * WATER_WAVE_HEIGHT;
gl_Position = mWorldViewProj * pos2;
vPosition = gl_Position.xyz;
gl_TexCoord[0] = gl_MultiTexCoord0;

#if (MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) && ENABLE_WAVING_WATER
vec4 pos = gl_Vertex;
pos.y -= 2.0;
pos.y -= sin (pos.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) * WATER_WAVE_HEIGHT
+ sin ((pos.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) / 7.0) * WATER_WAVE_HEIGHT;
gl_Position = mWorldViewProj * pos;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
vec4 pos = gl_Vertex;
vec4 pos2 = mWorld * gl_Vertex;
pos.x += (smoothTriangleWave(animationTimer*10.0 + pos2.x * 0.01 + pos2.z * 0.01) * 2.0 - 1.0) * 0.4;
pos.y += (smoothTriangleWave(animationTimer*15.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.2;
pos.z += (smoothTriangleWave(animationTimer*10.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.4;
gl_Position = mWorldViewProj * pos;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
vec4 pos = gl_Vertex;
vec4 pos2 = mWorld * gl_Vertex;
if (gl_TexCoord[0].y < 0.05) {
pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;
pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;
}
gl_Position = mWorldViewProj * pos;
#else
gl_Position = mWorldViewProj * gl_Vertex;
vPosition = gl_Position.xyz;
#endif

vPosition = gl_Position.xyz;
worldPosition = (mWorld * gl_Vertex).xyz;
vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0);

Expand Down Expand Up @@ -85,7 +108,7 @@ void main(void)

// Moonlight is blue
b += (day - night) / 13.0;
rg -= (day - night) / 13.0;
rg -= (day - night) / 23.0;

// Emphase blue a bit in darker places
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
Expand All @@ -99,12 +122,14 @@ void main(void)
color.g = clamp(rg,0.0,1.0);
color.b = clamp(b,0.0,1.0);

#if !(MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE)
// Make sides and bottom darker than the top
color = color * color; // SRGB -> Linear
if(gl_Normal.y <= 0.5)
color *= 0.6;
color = sqrt(color); // Linear -> SRGB
color.a = gl_Color.a;
#endif

color.a = gl_Color.a;
gl_FrontColor = gl_BackColor = color;
}
1 change: 0 additions & 1 deletion client/shaders/plants_shader/base.txt

This file was deleted.

94 changes: 0 additions & 94 deletions client/shaders/plants_shader/opengl_fragment.glsl

This file was deleted.

93 changes: 0 additions & 93 deletions client/shaders/plants_shader/opengl_vertex.glsl

This file was deleted.

1 change: 0 additions & 1 deletion client/shaders/solids_shader/base.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ varying vec3 tsEyeVec;
varying vec3 lightVec;
varying vec3 tsLightVec;

bool normalTexturePresent = false;
bool normalTexturePresent = false;

const float e = 2.718281828459;

const float BS = 10.0;

float intensity (vec3 color){
return (color.r + color.g + color.b) / 3.0;
}
Expand All @@ -39,7 +40,7 @@ void main (void)
vec4 bump;
vec2 uv = gl_TexCoord[0].st;
bool use_normalmap = false;

#ifdef USE_NORMALMAPS
if (texture2D(useNormalmap,vec2(1.0,1.0)).r > 0.0){
normalTexturePresent = true;
Expand Down Expand Up @@ -94,17 +95,34 @@ vec4 base = texture2D(baseTexture, uv).rgba;
color = base.rgb;
#endif

vec4 col = vec4(color.rgb, base.a);
#if MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE
float alpha = gl_Color.a;
vec4 col = vec4(color.rgb, alpha);
col *= gl_Color;
col = col * col; // SRGB -> Linear
col *= 1.8;
col.r = 1.0 - exp(1.0 - col.r) / e;
col.g = 1.0 - exp(1.0 - col.g) / e;
col.b = 1.0 - exp(1.0 - col.b) / e;
col = sqrt(col); // Linear -> SRGB
if(fogDistance != 0.0){
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
alpha = mix(alpha, 0.0, d);
}
gl_FragColor = vec4(col.rgb, alpha);
#else
vec4 col = vec4(color.rgb, base.a);
col *= gl_Color;
col = col * col; // SRGB -> Linear
col *= 1.8;
col.r = 1.0 - exp(1.0 - col.r) / e;
col.g = 1.0 - exp(1.0 - col.g) / e;
col.b = 1.0 - exp(1.0 - col.b) / e;
col = sqrt(col); // Linear -> SRGB
if(fogDistance != 0.0){
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
col = mix(col, skyBgColor, d);
}
gl_FragColor = vec4(col.rgb, base.a);
gl_FragColor = vec4(col.rgb, base.a);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,59 @@ uniform mat4 mTransWorld;
uniform mat4 mWorld;

uniform float dayNightRatio;

uniform vec3 eyePosition;
uniform float animationTimer;

varying vec3 vPosition;
varying vec3 worldPosition;

varying vec3 eyeVec;
varying vec3 lightVec;

varying vec3 tsEyeVec;
varying vec3 tsLightVec;

const float e = 2.718281828459;
const float BS = 10.0;

float smoothCurve( float x ) {
return x * x *( 3.0 - 2.0 * x );
}
float triangleWave( float x ) {
return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
}
float smoothTriangleWave( float x ) {
return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;
}

void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;

#if (MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) && ENABLE_WAVING_WATER
vec4 pos = gl_Vertex;
pos.y -= 2.0;
pos.y -= sin (pos.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) * WATER_WAVE_HEIGHT
+ sin ((pos.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) / 7.0) * WATER_WAVE_HEIGHT;
gl_Position = mWorldViewProj * pos;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
vec4 pos = gl_Vertex;
vec4 pos2 = mWorld * gl_Vertex;
pos.x += (smoothTriangleWave(animationTimer*10.0 + pos2.x * 0.01 + pos2.z * 0.01) * 2.0 - 1.0) * 0.4;
pos.y += (smoothTriangleWave(animationTimer*15.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.2;
pos.z += (smoothTriangleWave(animationTimer*10.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.4;
gl_Position = mWorldViewProj * pos;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
vec4 pos = gl_Vertex;
vec4 pos2 = mWorld * gl_Vertex;
if (gl_TexCoord[0].y < 0.05) {
pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;
pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;
}
gl_Position = mWorldViewProj * pos;
#else
gl_Position = mWorldViewProj * gl_Vertex;
#endif

vPosition = gl_Position.xyz;
worldPosition = (mWorld * gl_Vertex).xyz;
vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0);
Expand Down Expand Up @@ -73,7 +108,7 @@ void main(void)

// Moonlight is blue
b += (day - night) / 13.0;
rg -= (day - night) / 13.0;
rg -= (day - night) / 23.0;

// Emphase blue a bit in darker places
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
Expand All @@ -87,12 +122,14 @@ void main(void)
color.g = clamp(rg,0.0,1.0);
color.b = clamp(b,0.0,1.0);

#if !(MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE)
// Make sides and bottom darker than the top
color = color * color; // SRGB -> Linear
if(gl_Normal.y <= 0.5)
color *= 0.6;
color = sqrt(color); // Linear -> SRGB
color.a = gl_Color.a;
#endif

color.a = gl_Color.a;
gl_FrontColor = gl_BackColor = color;
}
4 changes: 2 additions & 2 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2670,9 +2670,9 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
infostream<<"- Updating node aliases"<<std::endl;
m_nodedef->updateAliases(m_itemdef);

// Update node textures
// Update node textures and assign shaders to each tile
infostream<<"- Updating node textures"<<std::endl;
m_nodedef->updateTextures(m_tsrc);
m_nodedef->updateTextures(m_tsrc, m_shsrc);

// Preload item textures and meshes if configured to
if(g_settings->getBool("preload_item_visuals"))
Expand Down
33 changes: 11 additions & 22 deletions src/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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")){
Expand All @@ -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);
}
Expand Down Expand Up @@ -1360,16 +1346,18 @@ 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);
os<<tsrc->getTextureName(tile.texture_id);
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"));
Expand All @@ -1388,6 +1376,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
}
}
}
}
}

// Day-night transition
Expand Down
24 changes: 20 additions & 4 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ class CNodeDefManager: public IWritableNodeDefManager
}
}
}
virtual void updateTextures(ITextureSource *tsrc)
virtual void updateTextures(ITextureSource *tsrc,
IShaderSource *shdsrc)
{
#ifndef SERVER
infostream<<"CNodeDefManager::updateTextures(): Updating "
Expand All @@ -621,6 +622,8 @@ class CNodeDefManager: public IWritableNodeDefManager
}

bool is_liquid = false;
bool is_water_surface = false;

u8 material_type;
material_type = (f->alpha == 255) ? TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA;

Expand Down Expand Up @@ -676,13 +679,13 @@ class CNodeDefManager: public IWritableNodeDefManager
}
}
if (f->waving == 1)
material_type = TILE_MATERIAL_LEAVES;
material_type = TILE_MATERIAL_WAVING_LEAVES;
break;
case NDT_PLANTLIKE:
f->solidness = 0;
f->backface_culling = false;
if (f->waving == 1)
material_type = TILE_MATERIAL_PLANTS;
material_type = TILE_MATERIAL_WAVING_PLANTS;
break;
case NDT_TORCHLIKE:
case NDT_SIGNLIKE:
Expand All @@ -693,11 +696,22 @@ class CNodeDefManager: public IWritableNodeDefManager
break;
}

if (is_liquid)
if (is_liquid){
material_type = (f->alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
if (f->name == "default:water_source")

This comment has been minimized.

Copy link
@sfan5

sfan5 Jun 15, 2014

Member

This should not be hardcoded...

This comment has been minimized.

Copy link
@paramat

paramat May 5, 2017

Contributor

So true, will remove this.

is_water_surface = true;
}
u32 tile_shader[6];
for(u16 j=0; j<6; j++)
tile_shader[j] = shdsrc->getShader("nodes_shader",material_type, f->drawtype);

if (is_water_surface)
tile_shader[0] = shdsrc->getShader("water_surface_shader",material_type, f->drawtype);

// Tiles (fill in f->tiles[])
for(u16 j=0; j<6; j++){
// Shader
f->tiles[j].shader_id = tile_shader[j];
// Texture
f->tiles[j].texture = tsrc->getTexture(
tiledef[j].name,
Expand Down Expand Up @@ -740,6 +754,8 @@ class CNodeDefManager: public IWritableNodeDefManager
}
// Special tiles (fill in f->special_tiles[])
for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
// Shader
f->special_tiles[j].shader_id = tile_shader[j];
// Texture
f->special_tiles[j].texture = tsrc->getTexture(
f->tiledef_special[j].name,
Expand Down
5 changes: 4 additions & 1 deletion src/nodedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h"
#ifndef SERVER
#include "tile.h"
#include "shader.h"
#endif
#include "itemgroup.h"
#include "sound.h" // SimpleSoundSpec
#include "constants.h" // BS

class IItemDefManager;
class ITextureSource;
class IShaderSource;
class IGameDef;

typedef std::list<std::pair<content_t, int> > GroupItems;
Expand Down Expand Up @@ -323,7 +325,8 @@ class IWritableNodeDefManager : public INodeDefManager
/*
Update tile textures to latest return values of TextueSource.
*/
virtual void updateTextures(ITextureSource *tsrc)=0;
virtual void updateTextures(ITextureSource *tsrc,
IShaderSource *shdsrc)=0;

virtual void serialize(std::ostream &os, u16 protocol_version)=0;
virtual void deSerialize(std::istream &is)=0;
Expand Down
249 changes: 129 additions & 120 deletions src/shader.cpp

Large diffs are not rendered by default.

28 changes: 17 additions & 11 deletions src/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ std::string getShaderPath(const std::string &name_of_shader,
struct ShaderInfo
{
std::string name;
video::E_MATERIAL_TYPE base_material;
video::E_MATERIAL_TYPE material;
u8 drawtype;
u8 material_type;
s32 user_data;

ShaderInfo(): name(""), material(video::EMT_SOLID) {}
ShaderInfo(): name(""), base_material(video::EMT_SOLID),
material(video::EMT_SOLID),
drawtype(0), material_type(0) {}
virtual ~ShaderInfo() {}
};

Expand Down Expand Up @@ -77,23 +83,23 @@ class IShaderSource
public:
IShaderSource(){}
virtual ~IShaderSource(){}
virtual u32 getShaderId(const std::string &name){return 0;}
virtual u32 getShaderIdDirect(const std::string &name){return 0;}
virtual std::string getShaderName(u32 id){return "";}
virtual ShaderInfo getShader(u32 id){return ShaderInfo();}
virtual ShaderInfo getShader(const std::string &name){return ShaderInfo();}
virtual u32 getShaderIdDirect(const std::string &name,
const u8 material_type, const u8 drawtype){return 0;}
virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
virtual u32 getShader(const std::string &name,
const u8 material_type, const u8 drawtype){return 0;}
};

class IWritableShaderSource : public IShaderSource
{
public:
IWritableShaderSource(){}
virtual ~IWritableShaderSource(){}
virtual u32 getShaderId(const std::string &name){return 0;}
virtual u32 getShaderIdDirect(const std::string &name){return 0;}
virtual std::string getShaderName(u32 id){return "";}
virtual ShaderInfo getShader(u32 id){return ShaderInfo();}
virtual ShaderInfo getShader(const std::string &name){return ShaderInfo();}
virtual u32 getShaderIdDirect(const std::string &name,
const u8 material_type, const u8 drawtype){return 0;}
virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
virtual u32 getShader(const std::string &name,
const u8 material_type, const u8 drawtype){return 0;}

virtual void processQueue()=0;
virtual void insertSourceShader(const std::string &name_of_shader,
Expand Down
38 changes: 8 additions & 30 deletions src/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ enum MaterialType{
TILE_MATERIAL_ALPHA,
TILE_MATERIAL_LIQUID_TRANSPARENT,
TILE_MATERIAL_LIQUID_OPAQUE,
TILE_MATERIAL_LEAVES,
TILE_MATERIAL_PLANTS
TILE_MATERIAL_WAVING_LEAVES,
TILE_MATERIAL_WAVING_PLANTS
};

// Material flags
Expand Down Expand Up @@ -167,6 +167,7 @@ struct TileSpec
//0 // <- DEBUG, Use the one below
MATERIAL_FLAG_BACKFACE_CULLING
),
shader_id(0),
animation_frame_count(1),
animation_frame_length_ms(0),
rotation(0)
Expand Down Expand Up @@ -206,42 +207,18 @@ struct TileSpec
case TILE_MATERIAL_LIQUID_OPAQUE:
material.MaterialType = video::EMT_SOLID;
break;
case TILE_MATERIAL_LEAVES:
case TILE_MATERIAL_WAVING_LEAVES:
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
case TILE_MATERIAL_PLANTS:
case TILE_MATERIAL_WAVING_PLANTS:
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
}
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) ? true : false;
}
void applyMaterialOptionsWithShaders(video::SMaterial &material,
const video::E_MATERIAL_TYPE &basic,
const video::E_MATERIAL_TYPE &liquid,
const video::E_MATERIAL_TYPE &alpha,
const video::E_MATERIAL_TYPE &leaves,
const video::E_MATERIAL_TYPE &plants) const

void applyMaterialOptionsWithShaders(video::SMaterial &material) const
{
switch(material_type){
case TILE_MATERIAL_BASIC:
material.MaterialType = basic;
break;
case TILE_MATERIAL_ALPHA:
material.MaterialType = alpha;
break;
case TILE_MATERIAL_LIQUID_TRANSPARENT:
material.MaterialType = liquid;
break;
case TILE_MATERIAL_LIQUID_OPAQUE:
material.MaterialType = liquid;
break;
case TILE_MATERIAL_LEAVES:
material.MaterialType = leaves;
break;
case TILE_MATERIAL_PLANTS:
material.MaterialType = plants;
break;
}
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) ? true : false;
}

Expand All @@ -252,6 +229,7 @@ struct TileSpec
// Material parameters
u8 material_type;
u8 material_flags;
u32 shader_id;
// Animation parameters
u8 animation_frame_count;
u16 animation_frame_length_ms;
Expand Down