diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg
index 10e03e143c..89238a4bbe 100644
--- a/binaries/data/config/default.cfg
+++ b/binaries/data/config/default.cfg
@@ -58,11 +58,6 @@ renderpath = default
; Prefer GLSL shaders over ARB shaders (not recommended)
preferglsl = false
-; Adjusts how OpenGL calculates mipmap level of detail. 0.0f is the default (blurry) value.
-; Lower values sharpen/extend, and higher values blur/decrease. Clamped at -3.0 to 3.0.
-; -1.0 to -1.5 recommended for good results.
-lodbias = 0
-
; Opt-in online user reporting system
userreport.url = "http://feedback.wildfiregames.com/report/upload/v1/"
diff --git a/binaries/data/mods/public/art/materials/basic_trans.xml b/binaries/data/mods/public/art/materials/basic_trans.xml
index 136f4e7d08..3cc6db6f1f 100644
--- a/binaries/data/mods/public/art/materials/basic_trans.xml
+++ b/binaries/data/mods/public/art/materials/basic_trans.xml
@@ -1,5 +1,6 @@
-
-
-
\ No newline at end of file
+
+
+
+
+
+
diff --git a/binaries/data/mods/public/art/materials/default.xml b/binaries/data/mods/public/art/materials/default.xml
new file mode 100644
index 0000000000..2337fa18e9
--- /dev/null
+++ b/binaries/data/mods/public/art/materials/default.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/binaries/data/mods/public/art/materials/objectcolor.xml b/binaries/data/mods/public/art/materials/objectcolor.xml
index df13fef316..92ebf138c0 100644
--- a/binaries/data/mods/public/art/materials/objectcolor.xml
+++ b/binaries/data/mods/public/art/materials/objectcolor.xml
@@ -1,5 +1,5 @@
-
-
-
\ No newline at end of file
+
+
+
+
+
diff --git a/binaries/data/mods/public/art/materials/player_trans.xml b/binaries/data/mods/public/art/materials/player_trans.xml
index e1d8574139..ca076afbd7 100644
--- a/binaries/data/mods/public/art/materials/player_trans.xml
+++ b/binaries/data/mods/public/art/materials/player_trans.xml
@@ -1,5 +1,5 @@
-
-
-
\ No newline at end of file
+
+
+
+
+
diff --git a/binaries/data/mods/public/shaders/effects/model.xml b/binaries/data/mods/public/shaders/effects/model.xml
new file mode 100644
index 0000000000..d06f6dd25c
--- /dev/null
+++ b/binaries/data/mods/public/shaders/effects/model.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/binaries/data/mods/public/shaders/effects/model_alphablend.xml b/binaries/data/mods/public/shaders/effects/model_alphablend.xml
new file mode 100644
index 0000000000..9387586706
--- /dev/null
+++ b/binaries/data/mods/public/shaders/effects/model_alphablend.xml
@@ -0,0 +1,126 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/binaries/data/mods/public/shaders/effects/model_normal.xml b/binaries/data/mods/public/shaders/effects/model_normal.xml
deleted file mode 100644
index 0d6c4bae21..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_normal.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_normal_instancing.xml b/binaries/data/mods/public/shaders/effects/model_normal_instancing.xml
deleted file mode 100644
index 19e9156cf3..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_normal_instancing.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_solid.xml b/binaries/data/mods/public/shaders/effects/model_solid.xml
deleted file mode 100644
index 134abf20fb..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_solid.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_solid_instancing.xml b/binaries/data/mods/public/shaders/effects/model_solid_instancing.xml
deleted file mode 100644
index 64ef2983ab..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_solid_instancing.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_solid_player.xml b/binaries/data/mods/public/shaders/effects/model_solid_player.xml
deleted file mode 100644
index f597194da5..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_solid_player.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_solid_player_instancing.xml b/binaries/data/mods/public/shaders/effects/model_solid_player_instancing.xml
deleted file mode 100644
index 9a0e7a8a8a..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_solid_player_instancing.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_transparent.xml b/binaries/data/mods/public/shaders/effects/model_transparent.xml
deleted file mode 100644
index 86091dcdd7..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_transparent.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_transparent_blend.xml b/binaries/data/mods/public/shaders/effects/model_transparent_blend.xml
deleted file mode 100644
index 0710e6c13d..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_transparent_blend.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_transparent_opaque.xml b/binaries/data/mods/public/shaders/effects/model_transparent_opaque.xml
deleted file mode 100644
index f36dbd271e..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_transparent_opaque.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/effects/model_transparent_shadow.xml b/binaries/data/mods/public/shaders/effects/model_transparent_shadow.xml
deleted file mode 100644
index d037f3f346..0000000000
--- a/binaries/data/mods/public/shaders/effects/model_transparent_shadow.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/binaries/data/mods/public/shaders/glsl/model_common.fs b/binaries/data/mods/public/shaders/glsl/model_common.fs
index 826017d12f..1003d0f3f8 100644
--- a/binaries/data/mods/public/shaders/glsl/model_common.fs
+++ b/binaries/data/mods/public/shaders/glsl/model_common.fs
@@ -11,7 +11,14 @@ uniform sampler2D losTex;
#endif
#endif
-uniform vec3 objectColor;
+#ifdef USE_OBJECTCOLOR
+ uniform vec3 objectColor;
+#else
+#ifdef USE_PLAYERCOLOR
+ uniform vec3 playerColor;
+#endif
+#endif
+
uniform vec3 shadingColor;
uniform vec3 ambient;
uniform vec4 shadowOffsets1;
@@ -72,9 +79,13 @@ void main()
vec3 color = tex.rgb;
- // Apply player-coloring based on texture alpha
+ // Apply-coloring based on texture alpha
#ifdef USE_OBJECTCOLOR
color *= mix(objectColor, vec3(1.0, 1.0, 1.0), tex.a);
+ #else
+ #ifdef USE_PLAYERCOLOR
+ color *= mix(playerColor, vec3(1.0, 1.0, 1.0), tex.a);
+ #endif
#endif
color *= v_lighting * get_shadow() + ambient;
diff --git a/binaries/data/mods/public/shaders/glsl/terrain_common.vs b/binaries/data/mods/public/shaders/glsl/terrain_common.vs
index 38463cd34a..8a0a570ebc 100644
--- a/binaries/data/mods/public/shaders/glsl/terrain_common.vs
+++ b/binaries/data/mods/public/shaders/glsl/terrain_common.vs
@@ -30,10 +30,12 @@ void main()
float c = textureTransform.x;
float s = -textureTransform.y;
v_tex = vec2(a_vertex.x * c + a_vertex.z * -s, a_vertex.x * -s + a_vertex.z * -c);
-
+
+#ifdef GL_ES
// XXX: Ugly hack to hide some precision issues in GLES
v_tex = mod(v_tex, vec2(9.0, 9.0));
#endif
+#endif
#ifdef BLEND
v_blend = a_uv1;
diff --git a/binaries/data/mods/public/shaders/model_common.fp b/binaries/data/mods/public/shaders/model_common.fp
index f8b72688da..d7cdc4a6ba 100644
--- a/binaries/data/mods/public/shaders/model_common.fp
+++ b/binaries/data/mods/public/shaders/model_common.fp
@@ -15,6 +15,10 @@
#ifdef USE_OBJECTCOLOR
PARAM objectColor = program.local[0];
+#else
+#ifdef USE_PLAYERCOLOR
+ PARAM playerColor = program.local[0];
+#endif
#endif
PARAM shadingColor = program.local[1];
@@ -36,13 +40,18 @@ TEX tex, fragment.texcoord[0], texture[0], 2D;
MOV result.color.a, tex;
#endif
-// Apply player-coloring based on texture alpha
+// Apply coloring based on texture alpha
#ifdef USE_OBJECTCOLOR
LRP temp.rgb, objectColor, 1.0, tex.a;
MUL color.rgb, tex, temp;
+#else
+#ifdef USE_PLAYERCOLOR
+ LRP temp.rgb, playerColor, 1.0, tex.a;
+ MUL color.rgb, tex, temp;
#else
MOV color.rgb, tex;
#endif
+#endif
// Compute color = texture * (ambient + diffuse*shadow)
// (diffuse is 2*fragment.color due to clamp-avoidance in the vertex program)
diff --git a/binaries/data/mods/public/shaders/model_common_arb.xml b/binaries/data/mods/public/shaders/model_common_arb.xml
index a2a86e3c56..e0fef3510b 100644
--- a/binaries/data/mods/public/shaders/model_common_arb.xml
+++ b/binaries/data/mods/public/shaders/model_common_arb.xml
@@ -6,6 +6,7 @@
+
@@ -16,7 +17,8 @@
-
+
+
diff --git a/binaries/data/mods/public/shaders/program.rng b/binaries/data/mods/public/shaders/program.rng
index 10f4bd8beb..c8e59d167f 100644
--- a/binaries/data/mods/public/shaders/program.rng
+++ b/binaries/data/mods/public/shaders/program.rng
@@ -21,6 +21,7 @@
+
@@ -47,6 +48,7 @@
+
@@ -83,6 +85,7 @@
+
@@ -104,6 +107,7 @@
+
pos
@@ -118,4 +122,10 @@
+
+
+
+
+
+
diff --git a/binaries/data/mods/public/shaders/solid.xml b/binaries/data/mods/public/shaders/solid.xml
index 53d668e50d..8e4bd98398 100644
--- a/binaries/data/mods/public/shaders/solid.xml
+++ b/binaries/data/mods/public/shaders/solid.xml
@@ -2,6 +2,7 @@
+
diff --git a/binaries/data/mods/public/shaders/solid_player.xml b/binaries/data/mods/public/shaders/solid_player.xml
index d2d772410d..a196f4d768 100644
--- a/binaries/data/mods/public/shaders/solid_player.xml
+++ b/binaries/data/mods/public/shaders/solid_player.xml
@@ -2,6 +2,7 @@
+
diff --git a/binaries/data/mods/public/shaders/solid_tex.xml b/binaries/data/mods/public/shaders/solid_tex.xml
index c62b3be0d5..4cb11a12b8 100644
--- a/binaries/data/mods/public/shaders/solid_tex.xml
+++ b/binaries/data/mods/public/shaders/solid_tex.xml
@@ -2,6 +2,7 @@
+
diff --git a/source/graphics/LightEnv.cpp b/source/graphics/LightEnv.cpp
index 1ce3f7049f..07234e3013 100644
--- a/source/graphics/LightEnv.cpp
+++ b/source/graphics/LightEnv.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2009 Wildfire Games.
+/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -29,7 +29,6 @@
CLightEnv::CLightEnv()
: m_Elevation(DEGTORAD(45)),
m_Rotation(DEGTORAD(315)),
- m_TerrainShadowTransparency(0.0),
m_LightingModel("standard"),
m_SunColor(1.5, 1.5, 1.5),
m_TerrainAmbientColor(0x50/255.f, 0x60/255.f, 0x85/255.f),
@@ -50,16 +49,11 @@ void CLightEnv::SetRotation(float f)
CalculateSunDirection();
}
-void CLightEnv::SetTerrainShadowTransparency(float f)
-{
- m_TerrainShadowTransparency = f;
-}
-
void CLightEnv::CalculateSunDirection()
{
- m_SunDir.Y=-float(sin(m_Elevation));
- float scale=1+m_SunDir.Y;
- m_SunDir.X=scale*float(sin(m_Rotation));
- m_SunDir.Z=scale*float(cos(m_Rotation));
+ m_SunDir.Y = -sinf(m_Elevation);
+ float scale = 1 + m_SunDir.Y;
+ m_SunDir.X = scale * sinf(m_Rotation);
+ m_SunDir.Z = scale * cosf(m_Rotation);
m_SunDir.Normalize();
}
diff --git a/source/graphics/LightEnv.h b/source/graphics/LightEnv.h
index 4f8e304745..272fa7bf90 100644
--- a/source/graphics/LightEnv.h
+++ b/source/graphics/LightEnv.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Wildfire Games.
+/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -40,13 +40,13 @@ friend class CMapReader;
friend class CXMLReader;
private:
/**
- * m_Elevation: Height of sun above the horizon, in radians.
+ * Height of sun above the horizon, in radians.
* For example, an elevation of M_PI/2 means the sun is straight up.
*/
float m_Elevation;
/**
- * m_Rotation: Direction of sun on the compass, in radians.
+ * Direction of sun on the compass, in radians.
* For example, a rotation of zero means the sun is in the direction (0,0,-1)
* and a rotation of M_PI/2 means the sun is in the direction (1,0,0) (not taking
* elevation into account).
@@ -54,13 +54,9 @@ private:
float m_Rotation;
/**
- * m_TerrainShadowTransparency: Fraction of diffuse light that reaches shadowed terrain.
- * A value of 0.0 means shadowed polygons get only ambient light, while a value of 1.0
- * means shadows don't have any effect at all.
- * TODO: probably delete this, since it's never used and always set to 0.0.
+ * Vector corresponding to m_Elevation and m_Rotation.
+ * Updated by CalculateSunDirection.
*/
- float m_TerrainShadowTransparency;
-
CVector3D m_SunDir;
/**
@@ -80,89 +76,54 @@ public:
float GetElevation() const { return m_Elevation; }
float GetRotation() const { return m_Rotation; }
const CVector3D& GetSunDir() const { return m_SunDir; }
- float GetTerrainShadowTransparency() const { return m_TerrainShadowTransparency; }
const std::string& GetLightingModel() const { return m_LightingModel; }
void SetElevation(float f);
void SetRotation(float f);
- void SetTerrainShadowTransparency(float f);
-
void SetLightingModel(const std::string& model) { m_LightingModel = model; }
/**
- * EvaluateTerrain: Calculate brightness of a point of the terrain with the given normal
- * vector.
+ * Calculate brightness of a point of a unit with the given normal vector,
+ * for rendering with CPU lighting.
* The resulting color contains both ambient and diffuse light.
+ * To cope with sun overbrightness, the color is scaled by 0.5.
*
* @param normal normal vector (must have length 1)
- * @param color resulting color
*/
- void EvaluateTerrain(const CVector3D& normal, RGBColor& color) const
+ RGBColor EvaluateUnitScaled(const CVector3D& normal) const
{
float dot = -normal.Dot(m_SunDir);
- color = m_TerrainAmbientColor;
+ RGBColor color = m_UnitsAmbientColor;
if (dot > 0)
color += m_SunColor * dot;
+
+ return color * 0.5f;
}
/**
- * EvaluateUnit: Calculate brightness of a point of a unit with the given normal
- * vector.
- * The resulting color contains both ambient and diffuse light.
+ * Compute the diffuse sun lighting color on terrain, for rendering with CPU lighting.
+ * To cope with sun overbrightness, the color is scaled by 0.5.
*
* @param normal normal vector (must have length 1)
- * @param color resulting color
*/
- void EvaluateUnit(const CVector3D& normal, RGBColor& color) const
+ SColor4ub EvaluateTerrainDiffuseScaled(const CVector3D& normal) const
{
float dot = -normal.Dot(m_SunDir);
-
- color = m_UnitsAmbientColor;
- if (dot > 0)
- color += m_SunColor * dot;
+ return ConvertRGBColorTo4ub(m_SunColor * dot * 0.5f);
}
/**
- * EvaluateDirect: Like EvaluateTerrain and EvaluateUnit, but return only the direct
- * sunlight term without ambient.
+ * Compute the diffuse sun lighting factor on terrain, for rendering with shader lighting.
*
* @param normal normal vector (must have length 1)
- * @param color resulting color
*/
- void EvaluateDirect(const CVector3D& normal, RGBColor& color) const
+ SColor4ub EvaluateTerrainDiffuseFactor(const CVector3D& normal) const
{
float dot = -normal.Dot(m_SunDir);
-
- if (dot > 0)
- color = m_SunColor * dot;
- else
- color = CVector3D(0,0,0);
- }
-
- /**
- * Compute the diffuse sun lighting.
- * If @p includeSunColor is set, the return value includes the sun color.
- * (If sun overbrightness is enabled, this might result in clamping).
- * Otherwise it returns a factor that the sun color should be multiplied by.
- */
- SColor4ub EvaluateDiffuse(const CVector3D& normal, bool includeSunColor) const
- {
- float dot = -normal.Dot(m_SunDir);
-
- if (dot <= 0)
- return SColor4ub(0, 0, 0, 255);
-
- if (includeSunColor)
- {
- return ConvertRGBColorTo4ub(m_SunColor * dot);
- }
- else
- {
- int c = clamp((int)(dot * 255), 0, 255);
- return SColor4ub(c, c, c, 255);
- }
+ int c = clamp((int)(dot * 255), 0, 255);
+ return SColor4ub(c, c, c, 255);
}
// Comparison operators
@@ -170,7 +131,6 @@ public:
{
return m_Elevation == o.m_Elevation &&
m_Rotation == o.m_Rotation &&
- m_TerrainShadowTransparency == o.m_TerrainShadowTransparency &&
m_LightingModel == o.m_LightingModel &&
m_SunColor == o.m_SunColor &&
m_TerrainAmbientColor == o.m_TerrainAmbientColor &&
@@ -186,4 +146,4 @@ private:
void CalculateSunDirection();
};
-#endif
+#endif // INCLUDED_LIGHTENV
diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp
index 0262f2f90a..93b33c8962 100644
--- a/source/graphics/MapReader.cpp
+++ b/source/graphics/MapReader.cpp
@@ -560,7 +560,6 @@ void CXMLReader::ReadEnvironment(XMBElement parent)
EL(sunrotation);
EL(terrainambientcolour);
EL(unitsambientcolour);
- EL(terrainshadowtransparency);
EL(water);
EL(waterbody);
EL(type);
@@ -620,10 +619,6 @@ void CXMLReader::ReadEnvironment(XMBElement parent)
attrs.GetNamedItem(at_g).ToFloat(),
attrs.GetNamedItem(at_b).ToFloat());
}
- else if (element_name == el_terrainshadowtransparency)
- {
- m_MapReader.m_LightEnv.SetTerrainShadowTransparency(element.GetText().ToFloat());
- }
else if (element_name == el_water)
{
XERO_ITER_EL(element, waterbody)
diff --git a/source/graphics/Material.cpp b/source/graphics/Material.cpp
index 3ad1646625..c8e87dfd44 100644
--- a/source/graphics/Material.cpp
+++ b/source/graphics/Material.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2010 Wildfire Games.
+/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -19,66 +19,31 @@
#include "Material.h"
-#include "lib/ogl.h"
-#include "ps/Game.h"
-#include "ps/Overlay.h" // for CColor
-
-CMaterial NullMaterial;
-
-static SMaterialColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f);
+static CColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f);
CMaterial::CMaterial() :
- m_Alpha(false),
+ m_AlphaBlending(false),
m_PlayerID(INVALID_PLAYER),
- m_TextureColor(BrokenColor),
- m_UsePlayerColor(false),
- m_UseTextureColor(false)
+ m_ObjectColor(BrokenColor)
{
}
-SMaterialColor CMaterial::GetObjectColor()
+void CMaterial::SetObjectColor(const CColor& colour)
{
- if (m_UseTextureColor)
- return m_TextureColor;
-
- return GetPlayerColor();
+ m_ObjectColor = colour;
}
-SMaterialColor CMaterial::GetPlayerColor()
+void CMaterial::SetDiffuseTexture(const CTexturePtr& texture)
{
- if (m_PlayerID == -1)
- return BrokenColor;
-
- CColor c(g_Game->GetPlayerColour(m_PlayerID));
- return SMaterialColor(c.r, c.g, c.b, c.a);
+ m_DiffuseTexture = texture;
}
-void CMaterial::SetPlayerID(player_id_t id)
+void CMaterial::SetShaderEffect(const CStr& effect)
{
- m_PlayerID = id;
+ m_ShaderEffect = CStrIntern(effect);
}
-void CMaterial::SetUsePlayerColor(bool use)
+void CMaterial::AddShaderDefine(const char* key, const char* value)
{
- m_UsePlayerColor = use;
-}
-
-void CMaterial::SetUseTextureColor(bool use)
-{
- m_UseTextureColor = use;
-}
-
-void CMaterial::SetTextureColor(const CColor& colour)
-{
- m_TextureColor = SMaterialColor(colour.r, colour.g, colour.b, colour.a);
-}
-
-void CMaterial::SetTexture(const CStr& texture)
-{
- m_Texture = texture;
-}
-
-void CMaterial::SetUsesAlpha(bool flag)
-{
- m_Alpha = flag;
+ m_ShaderDefines.Add(key, value);
}
diff --git a/source/graphics/Material.h b/source/graphics/Material.h
index 225cb973c1..85a7c14325 100644
--- a/source/graphics/Material.h
+++ b/source/graphics/Material.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2010 Wildfire Games.
+/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,54 +18,47 @@
#ifndef INCLUDED_MATERIAL
#define INCLUDED_MATERIAL
+#include "graphics/ShaderDefines.h"
+#include "graphics/Texture.h"
#include "ps/CStr.h"
+#include "ps/CStrIntern.h"
#include "ps/Overlay.h"
#include "simulation2/helpers/Player.h"
-// FIXME: This material system is almost entirely unused and probably broken
-
-typedef CColor SMaterialColor;
-
class CMaterial
{
public:
CMaterial();
- const CStr& GetTexture() { return m_Texture; }
+ // Whether this material's shaders use alpha blending, in which case
+ // models using this material need to be rendered in a special order
+ // relative to the alpha-blended water plane
+ void SetUsesAlphaBlending(bool flag) { m_AlphaBlending = flag; }
+ bool UsesAlphaBlending() { return m_AlphaBlending; }
- bool UsesAlpha() { return m_Alpha; }
+ // Color used for "objectColor" in shaders when USE_OBJECTCOLOR is set,
+ // to allow e.g. variations in horse colorings
+ void SetObjectColor(const CColor &colour);
+ CColor GetObjectColor() { return m_ObjectColor; }
- // Determines whether or not the model goes into the PlayerRenderer
- bool IsPlayer() { return (m_UseTextureColor || m_UsePlayerColor); }
+ void SetDiffuseTexture(const CTexturePtr& texture);
+ const CTexturePtr& GetDiffuseTexture() const { return m_DiffuseTexture; }
- // Get the player colour or texture colour to be applied to this object
- SMaterialColor GetObjectColor();
- // Get the player colour
- SMaterialColor GetPlayerColor();
+ void SetShaderEffect(const CStr& effect);
+ CStrIntern GetShaderEffect() const { return m_ShaderEffect; }
- void SetPlayerID(player_id_t id);
- void SetTextureColor(const CColor &colour);
-
- void SetUsePlayerColor(bool use);
- void SetUseTextureColor(bool use);
-
- void SetTexture(const CStr& texture);
- void SetUsesAlpha(bool flag);
+ void AddShaderDefine(const char* key, const char* value);
+ const CShaderDefines& GetShaderDefines() const { return m_ShaderDefines; }
private:
- // Path to the materials texture
- CStr m_Texture;
+ CTexturePtr m_DiffuseTexture;
+ CStrIntern m_ShaderEffect;
+ CShaderDefines m_ShaderDefines;
- // Alpha required flag
- bool m_Alpha;
+ bool m_AlphaBlending;
player_id_t m_PlayerID;
- SMaterialColor m_TextureColor; // used as an alternative to the per-player colour
-
- bool m_UsePlayerColor;
- bool m_UseTextureColor;
+ CColor m_ObjectColor;
};
-extern CMaterial NullMaterial;
-
#endif
diff --git a/source/graphics/MaterialManager.cpp b/source/graphics/MaterialManager.cpp
index 21b7c0f70b..a78614c774 100644
--- a/source/graphics/MaterialManager.cpp
+++ b/source/graphics/MaterialManager.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2009 Wildfire Games.
+/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -21,94 +21,53 @@
#include "ps/XML/Xeromyces.h"
#include "MaterialManager.h"
-static bool ParseUsage(CStr temp)
+CMaterial CMaterialManager::LoadMaterial(const VfsPath& pathname)
{
- temp = temp.LowerCase().Trim(PS_TRIM_BOTH);
- if(temp == "blend" ||
- temp == "true" ||
- temp == "yes" ||
- temp.ToInt() > 0)
- return true;
+ if (pathname.empty())
+ return CMaterial();
- return false;
-}
-
-CMaterialManager::CMaterialManager()
-{
-}
-
-CMaterialManager::~CMaterialManager()
-{
- std::map::iterator iter;
- for(iter = m_Materials.begin(); iter != m_Materials.end(); iter++)
- delete (*iter).second;
-
- m_Materials.clear();
-}
-
-CMaterial& CMaterialManager::LoadMaterial(const VfsPath& pathname)
-{
- if(pathname.empty())
- return NullMaterial;
-
- std::map::iterator iter = m_Materials.find(pathname);
- if(iter != m_Materials.end())
- {
- if((*iter).second)
- return *(*iter).second;
- }
+ std::map::iterator iter = m_Materials.find(pathname);
+ if (iter != m_Materials.end())
+ return iter->second;
CXeromyces xeroFile;
- if(xeroFile.Load(g_VFS, pathname) != PSRETURN_OK)
- return NullMaterial;
+ if (xeroFile.Load(g_VFS, pathname) != PSRETURN_OK)
+ return CMaterial();
#define EL(x) int el_##x = xeroFile.GetElementID(#x)
#define AT(x) int at_##x = xeroFile.GetAttributeID(#x)
- EL(texture);
- EL(alpha);
- AT(usage);
+ EL(alpha_blending);
+ EL(define);
+ EL(shader);
+ AT(effect);
+ AT(name);
+ AT(value);
#undef AT
#undef EL
- CMaterial *material = NULL;
- try
- {
- XMBElement root = xeroFile.GetRoot();
- XMBElementList childNodes = root.GetChildNodes();
- material = new CMaterial();
+ CMaterial material;
- for(int i = 0; i < childNodes.Count; i++)
+ XMBElement root = xeroFile.GetRoot();
+ XMBElementList childNodes = root.GetChildNodes();
+
+ XERO_ITER_EL(root, node)
+ {
+ int token = node.GetNodeName();
+ XMBAttributeList attrs = node.GetAttributes();
+ if (token == el_alpha_blending)
{
- XMBElement node = childNodes.Item(i);
- int token = node.GetNodeName();
- XMBAttributeList attrs = node.GetAttributes();
- CStr temp;
- if(token == el_texture)
- {
- CStr value(node.GetText());
- material->SetTexture(value);
- }
- else if(token == el_alpha)
- {
- temp = CStr(attrs.GetNamedItem(at_usage));
-
- // Determine whether the alpha is used for basic transparency or player color
- if (temp == "playercolor")
- material->SetUsePlayerColor(true);
- else if (temp == "objectcolor")
- material->SetUseTextureColor(true);
- else
- material->SetUsesAlpha(ParseUsage(temp));
- }
+ material.SetUsesAlphaBlending(true);
+ }
+ else if (token == el_shader)
+ {
+ material.SetShaderEffect(attrs.GetNamedItem(at_effect));
+ }
+ else if (token == el_define)
+ {
+ material.AddShaderDefine(attrs.GetNamedItem(at_name).c_str(), attrs.GetNamedItem(at_value).c_str());
}
-
- m_Materials[pathname] = material;
- }
- catch(...)
- {
- SAFE_DELETE(material);
- throw;
}
- return *material;
+ m_Materials[pathname] = material;
+ return material;
}
diff --git a/source/graphics/MaterialManager.h b/source/graphics/MaterialManager.h
index 0f063ad154..14fbfeb783 100644
--- a/source/graphics/MaterialManager.h
+++ b/source/graphics/MaterialManager.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2009 Wildfire Games.
+/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -19,20 +19,15 @@
#define INCLUDED_MATERIALMANAGER
#include