Allow combining lightmaps and normal maps
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11428 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
d585e548fe
commit
4b9d02cc25
@ -3,6 +3,8 @@
|
||||
|
||||
uniform sampler2D BumpTex; //The bump-map
|
||||
uniform sampler2D DecalTex; //The texture
|
||||
uniform sampler2D LightMapTex;
|
||||
int HasLightMap;
|
||||
|
||||
// New bumpmapping
|
||||
varying vec3 lightVec;
|
||||
@ -22,6 +24,13 @@ void main()
|
||||
|
||||
diffuseMaterial = texture2D (DecalTex, gl_TexCoord[0].st);
|
||||
|
||||
// 0.4 is the ambient light
|
||||
gl_FragColor = diffuseMaterial * (0.5 + lamberFactor*0.5);
|
||||
if (HasLightMap < 1)
|
||||
{
|
||||
// 0.5 is the ambient light
|
||||
gl_FragColor = diffuseMaterial * (0.5 + lamberFactor*0.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_FragColor = diffuseMaterial * (0.5 + lamberFactor*0.5) * texture2D(LightMapTex, gl_TexCoord[0].st);
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,16 @@ const unsigned int VCLAMP = 2;
|
||||
|
||||
class NormalMapProvider : public video::IShaderConstantSetCallBack
|
||||
{
|
||||
bool m_with_lightmap;
|
||||
|
||||
public:
|
||||
LEAK_CHECK()
|
||||
|
||||
NormalMapProvider(bool withLightmap)
|
||||
{
|
||||
m_with_lightmap = withLightmap;
|
||||
}
|
||||
|
||||
virtual void OnSetConstants(
|
||||
irr::video::IMaterialRendererServices *services,
|
||||
s32 userData)
|
||||
@ -62,6 +69,12 @@ public:
|
||||
s32 bumptex = 1;
|
||||
services->setPixelShaderConstant("BumpTex", &bumptex, 1);
|
||||
|
||||
s32 lightmapTex = (m_with_lightmap ? 2 : 0);
|
||||
services->setPixelShaderConstant("LightMapTex", &lightmapTex, 1);
|
||||
|
||||
s32 hasLightMap = (m_with_lightmap ? 1 : 0);
|
||||
services->setPixelShaderConstant("HasLightMap", &hasLightMap, 1);
|
||||
|
||||
// We could calculate light direction as coming from the sun (then we'd need to
|
||||
// transform it into camera space). But I find that pretending light
|
||||
// comes from the camera gives good results
|
||||
@ -410,6 +423,8 @@ Material::Material(const XMLNode *node, int index)
|
||||
fprintf(stderr, "[Material] WARNING: could not find normal map image in materials.xml\n");
|
||||
}
|
||||
|
||||
node->get("normal-light-map", &m_normal_map_shader_lightmap);
|
||||
|
||||
// not supported by irrlicht
|
||||
//m_normal_map_uv2 = false;
|
||||
//node->get("normal-map-uv2", &m_normal_map_uv2);
|
||||
@ -967,9 +982,28 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
|
||||
}
|
||||
m->setTexture(1, tex);
|
||||
|
||||
if (m_shaders[NORMAL_MAP] == NULL)
|
||||
bool with_lightmap = false;
|
||||
|
||||
if (m_normal_map_shader_lightmap.size() > 0)
|
||||
{
|
||||
m_shaders[NORMAL_MAP] = new NormalMapProvider();
|
||||
ITexture* lm_tex = irr_driver->getTexture(m_normal_map_shader_lightmap);
|
||||
m->setTexture(2, lm_tex);
|
||||
with_lightmap = true;
|
||||
}
|
||||
|
||||
if (with_lightmap)
|
||||
{
|
||||
if (m_shaders[NORMAL_MAP_WITH_LIGHTMAP] == NULL)
|
||||
{
|
||||
m_shaders[NORMAL_MAP_WITH_LIGHTMAP] = new NormalMapProvider(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_shaders[NORMAL_MAP] == NULL)
|
||||
{
|
||||
m_shaders[NORMAL_MAP] = new NormalMapProvider(false);
|
||||
}
|
||||
}
|
||||
|
||||
const char* vertex_shader = "shaders/normalmap.vert";
|
||||
@ -985,7 +1019,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
|
||||
(file_manager->getDataDir() + pixel_shader).c_str(),
|
||||
"main",
|
||||
video::EPST_PS_2_0,
|
||||
m_shaders[NORMAL_MAP],
|
||||
m_shaders[with_lightmap ? NORMAL_MAP_WITH_LIGHTMAP : NORMAL_MAP],
|
||||
video::EMT_SOLID_2_LAYER );
|
||||
m->MaterialType = (E_MATERIAL_TYPE)material_type;
|
||||
m->Lighting = false;
|
||||
|
@ -76,6 +76,7 @@ private:
|
||||
enum Shaders
|
||||
{
|
||||
NORMAL_MAP,
|
||||
NORMAL_MAP_WITH_LIGHTMAP,
|
||||
SPLATTING,
|
||||
WATER_SHADER,
|
||||
SPHERE_MAP,
|
||||
@ -138,6 +139,8 @@ private:
|
||||
/** For normal maps */
|
||||
bool m_normal_map;
|
||||
std::string m_normal_map_tex;
|
||||
std::string m_normal_map_shader_lightmap;
|
||||
|
||||
//bool m_normal_map_uv2; //!< Whether to use a second UV layer for normal map
|
||||
bool m_is_heightmap;
|
||||
bool m_parallax_map;
|
||||
|
Loading…
Reference in New Issue
Block a user