Use new normal map shader for overworld columns. Remove 2-UV-layer normal map feature, irrlicht just doesn't support it

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10675 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2012-01-15 21:52:07 +00:00
parent 93a7099cf9
commit d6221dae92
10 changed files with 59 additions and 83 deletions

@ -38,5 +38,4 @@ void main()
}
gl_FragColor += ambientLight;
}

@ -1,26 +0,0 @@
// By http://content.gpwiki.org/index.php/OpenGL:Tutorials:GLSL_Bump_Mapping
// Released under GNU FDL license, without invariant (so DFSG-compliant, see
// http://wiki.debian.org/DFSGLicenses#Exception)
uniform sampler2D BumpTex; //The bump-map
uniform sampler2D DecalTex; //The texture
varying vec4 passcolor; //Receiving the vertex color from the vertex shader
varying vec3 LightDir; //Receiving the transformed light direction
void main()
{
vec4 LightDirTransformed4 = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(LightDir[0], LightDir[1], LightDir[2], 0);
vec3 LightDirTransformed = vec3(LightDirTransformed4[0], LightDirTransformed4[1], LightDirTransformed4[2]);
//Get the color of the bump-map
vec3 BumpNorm = vec3(texture2D(BumpTex, gl_TexCoord[1].xy));
//Get the color of the texture
vec3 DecalCol = vec3(texture2D(DecalTex, gl_TexCoord[0].xy));
//Expand the bump-map into a normalized signed vector
BumpNorm = (BumpNorm -0.5) * 2.0;
//Find the dot product between the light direction and the normal
float NdotL = max(dot(BumpNorm, LightDirTransformed), 0.0) / 3.0 * 2.1 + 0.5;
//Calculate the final color gl_FragColor
vec3 diffuse = NdotL * passcolor.xyz * DecalCol;
//Set the color of the fragment... If you want specular lighting or other types add it here
gl_FragColor = vec4(diffuse, passcolor.w);
}

@ -1,25 +0,0 @@
// By http://content.gpwiki.org/index.php/OpenGL:Tutorials:GLSL_Bump_Mapping
// Released under GNU FDL license, without invariant (so DFSG-compliant, see
// http://wiki.debian.org/DFSGLicenses#Exception)
varying vec4 passcolor; //The vertex color passed
varying vec3 LightDir; //The transformed light direction, to pass to the fragment shader
attribute vec3 tangent; //The inverse tangent to the geometry
attribute vec3 binormal; //The inverse binormal to the geometry
uniform vec3 lightdir; //The direction the light is shining
void main()
{
//Put the color in a varying variable
passcolor = gl_Color;
//Put the vertex in the position passed
gl_Position = ftransform();
//Construct a 3x3 matrix from the geometrys inverse tangent, binormal, and normal
mat3 rotmat = mat3(tangent,binormal,gl_Normal);
//Rotate the light into tangent space
LightDir = rotmat * normalize(lightdir);
//Normalize the light
normalize(LightDir);
//Use the first set of texture coordinates in the fragment shader
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
}

@ -154,7 +154,7 @@ void ThreeDAnimation::createPhysicsBody(const std::string &shape)
if (mb->getVertexType() != video::EVT_STANDARD &&
mb->getVertexType() != video::EVT_2TCOORDS)
{
fprintf(stderr, "WARNING: Physics::convertTrack: Ignoring type '%d'!",
fprintf(stderr, "WARNING: Physics::convertTrack: Ignoring type '%d'!\n",
mb->getVertexType());
continue;
}

@ -82,7 +82,6 @@ private:
enum {RES_CHANGE_NONE, RES_CHANGE_YES,
RES_CHANGE_CANCEL} m_resolution_changing;
void setAllMaterialFlags(scene::IMesh *mesh) const;
public:
/** A simple class to store video resolutions. */
class VideoMode
@ -114,6 +113,8 @@ public:
~IrrDriver();
void initDevice();
void setAllMaterialFlags(scene::IMesh *mesh) const;
/** Returns a list of all video modes supports by the graphics card. */
const std::vector<VideoMode>& getVideoModes() const { return m_modes; }
/** Returns the frame size. */

@ -297,8 +297,9 @@ Material::Material(const XMLNode *node, int index)
fprintf(stderr, "[Material] WARNING: could not find normal map image in materials.xml\n");
}
m_normal_map_uv2 = false;
node->get("normal-map-uv2", &m_normal_map_uv2);
// not supported by irrlicht
//m_normal_map_uv2 = false;
//node->get("normal-map-uv2", &m_normal_map_uv2);
// TODO: add support for parallax maps?
@ -458,7 +459,7 @@ void Material::init(unsigned int index)
m_zipper_max_speed_increase = -1.0f;
m_zipper_speed_gain = -1.0f;
m_normal_map = false;
m_normal_map_uv2 = false;
//m_normal_map_uv2 = false;
m_parallax_map = false;
m_is_heightmap = false;
m_alpha_to_coverage = false;
@ -784,18 +785,14 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
video_driver->makeNormalMapTexture( tex );
}
m->setTexture(1, tex);
if (m_normal_map_provider == NULL)
{
m_normal_map_provider = new NormalMapProvider();
}
const char* vertex_shader = (m_normal_map_uv2 ?
"shaders/normalmap2uv.vert" :
"shaders/normalmap.vert");
const char* pixel_shader = (m_normal_map_uv2 ?
"shaders/normalmap2uv.frag" :
"shaders/normalmap.frag");
const char* vertex_shader = "shaders/normalmap.vert";
const char* pixel_shader = "shaders/normalmap.frag";
// Material and shaders
IGPUProgrammingServices* gpu =

@ -114,7 +114,7 @@ private:
/** For normal maps */
bool m_normal_map;
std::string m_normal_map_tex;
bool m_normal_map_uv2; //!< Whether to use a second UV layer for normal map
//bool m_normal_map_uv2; //!< Whether to use a second UV layer for normal map
bool m_is_heightmap;
bool m_parallax_map;
float m_parallax_height;

@ -23,9 +23,9 @@ using namespace irr;
#include "graphics/lod_node.hpp"
#include "io/xml_node.hpp"
#include <IAnimatedMeshSceneNode.h>
#include <IMeshSceneNode.h>
#include <ISceneManager.h>
#include <IMeshManipulator.h>
#include <algorithm>
LodNodeLoader::LodNodeLoader()
@ -34,7 +34,7 @@ LodNodeLoader::LodNodeLoader()
// ----------------------------------------------------------------------------
bool PairCompare(const std::pair<int, std::string>& i, const std::pair<int, std::string>& j)
bool PairCompare(const std::pair<int, LodModel>& i, const std::pair<int, LodModel>& j)
{
return (i.first < j.first);
}
@ -53,6 +53,9 @@ bool LodNodeLoader::check(const XMLNode* xml)
std::string lodgroup;
xml->get("lod_group", &lodgroup);
bool tangent = false;
xml->get("tangents", &tangent);
if (!lodgroup.empty())
{
if (lod_instance)
@ -64,7 +67,7 @@ bool LodNodeLoader::check(const XMLNode* xml)
std::string model_name;
xml->get("model", &model_name);
lod_groups[lodgroup][(int)lod_distance] = model_name;
lod_groups[lodgroup][(int)lod_distance] = LodModel(model_name, tangent);
}
return true;
}
@ -92,16 +95,16 @@ void LodNodeLoader::done(std::string directory,
// but it was done this way to minimize the work needed on the side of the artists
// 1. Sort LOD groups (highest detail first, lowest detail last)
std::map<std::string, std::vector< std::pair<int, std::string> > > sorted_lod_groups;
std::map<std::string, std::vector< std::pair<int, LodModel> > > sorted_lod_groups;
std::map<std::string, std::map<int, std::string> >::iterator it;
std::map<std::string, std::map<int, LodModel> >::iterator it;
for (it = lod_groups.begin(); it != lod_groups.end(); it++)
{
std::map<int, std::string>::iterator it2;
std::map<int, LodModel>::iterator it2;
for (it2 = it->second.begin(); it2 != it->second.end(); it2++)
{
//printf("Copying before sort : (%i) %s is in group %s\n", it2->first, it2->second.c_str(), it->first.c_str());
sorted_lod_groups[it->first].push_back( std::pair<int, std::string>(it2->first, it2->second) );
sorted_lod_groups[it->first].push_back( std::pair<int, LodModel>(it2->first, it2->second) );
}
std::sort( sorted_lod_groups[it->first].begin(), sorted_lod_groups[it->first].end(), PairCompare );
@ -117,7 +120,7 @@ void LodNodeLoader::done(std::string directory,
std::map< std::string, std::vector< const XMLNode* > >::iterator it3;
for (it3 = lod_instances.begin(); it3 != lod_instances.end(); it3++)
{
std::vector< std::pair<int, std::string> >& group = sorted_lod_groups[it3->first];
std::vector< std::pair<int, LodModel> >& group = sorted_lod_groups[it3->first];
std::vector< const XMLNode* >& v = it3->second;
for (unsigned int n=0; n<v.size(); n++)
@ -134,7 +137,7 @@ void LodNodeLoader::done(std::string directory,
node->get("hpr", &hpr);
core::vector3df scale(1.0f, 1.0f, 1.0f);
node->get("scale", &scale);
std::string full_path;
if (group.size() > 0)
@ -142,22 +145,31 @@ void LodNodeLoader::done(std::string directory,
LODNode* lod_node = new LODNode(groupname, sroot, sm);
for (unsigned int m=0; m<group.size(); m++)
{
full_path = directory + "/" + group[m].second;
full_path = directory + "/" + group[m].second.m_model_file;
// TODO: check whether the mesh contains animations or not, and use a static
// mesh when there are no animations?
scene::IAnimatedMesh *a_mesh = irr_driver->getAnimatedMesh(full_path);
// TODO: check whether the mesh contains animations or not?
scene::IMesh *a_mesh = irr_driver->getMesh(full_path);
if(!a_mesh)
{
fprintf(stderr, "Warning: object model '%s' not found, ignored.\n",
full_path.c_str());
continue;
}
if (group[m].second.m_tangent)
{
scene::IMeshManipulator* manip = irr_driver->getVideoDriver()->getMeshManipulator();
scene::IMesh* m2 = manip->createMeshWithTangents(a_mesh);
// FIXME: do we need to clean up 'a_mesh' ?
a_mesh = m2;
irr_driver->setAllMaterialFlags(a_mesh);
}
a_mesh->grab();
cache.push_back(a_mesh);
irr_driver->grabAllTextures(a_mesh);
scene::IAnimatedMeshSceneNode* scene_node =
irr_driver->addAnimatedMesh(a_mesh);
scene::IMeshSceneNode* scene_node = irr_driver->addMesh(a_mesh);
scene_node->setPosition(xyz);
scene_node->setRotation(hpr);
scene_node->setScale(scale);

@ -35,13 +35,31 @@ namespace irr
}
}
struct LodModel
{
std::string m_model_file;
bool m_tangent;
/** Constructor to allow storing this in STL containers */
LodModel()
{
m_tangent = false;
}
LodModel(std::string& model, bool tangent)
{
m_model_file = model;
m_tangent = tangent;
}
};
/** Utility class to load level-of-detail nodes
* \ingroup tracks
*/
class LodNodeLoader
{
private:
std::map< std::string, std::map< int, std::string > > lod_groups;
std::map< std::string, std::map< int, LodModel > > lod_groups;
std::map< std::string, std::vector< const XMLNode* > > lod_instances;
public:

@ -517,7 +517,7 @@ void Track::convertTrackToBullet(scene::ISceneNode *node)
if (mb->getVertexType() != video::EVT_STANDARD &&
mb->getVertexType() != video::EVT_2TCOORDS)
{
fprintf(stderr, "WARNING: Physics::convertTrack: Ignoring type '%d'!",
fprintf(stderr, "WARNING: Physics::convertTrack: Ignoring type '%d'!\n",
mb->getVertexType());
continue;
}