Enable tangents on every lod instance and fix normalmap

This will increase the memory footprint of lod object,
however this is the only way I found to make meshbuffer using
GE_NORMAL_MAP to provide the necessary info to this shader.

Now the pedestal in overlord looks perfectly normal mapped.
This commit is contained in:
Vincent Lejeune
2014-01-17 21:29:39 +01:00
parent 8e1d76dd8f
commit 7da65c15f0
4 changed files with 5 additions and 9 deletions

View File

@@ -4,7 +4,6 @@ uniform sampler2D normalMap; //The bump-map
noperspective in vec3 tangent;
noperspective in vec3 bitangent;
noperspective in vec3 normal;
in vec2 uv;
void main()
@@ -13,11 +12,10 @@ void main()
vec3 TS_normal = 2.0 * texture2D (normalMap, uv).rgb - 1.0;
// Because of interpolation, we need to renormalize
vec3 Frag_tangent = normalize(tangent);
vec3 Frag_bitangent = normalize(cross(normal, tangent));
vec3 Frag_normal = cross(Frag_tangent, Frag_bitangent);
vec3 Frag_normal = normalize(cross(Frag_tangent, bitangent));
vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent);
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent + TS_normal.z * Frag_normal;
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
FragmentNormal = normalize(FragmentNormal);

View File

@@ -4,13 +4,11 @@ uniform mat4 TransposeInverseModelView;
noperspective out vec3 tangent;
noperspective out vec3 bitangent;
noperspective out vec3 normal;
out vec2 uv;
void main()
{
uv = gl_MultiTexCoord0.st;
normal = (TransposeInverseModelView * vec4(gl_Normal, 1.)).xyz;
tangent = (TransposeInverseModelView * gl_MultiTexCoord1).xyz;
bitangent = (TransposeInverseModelView * gl_MultiTexCoord2).xyz;
gl_Position = ModelViewProjectionMatrix * gl_Vertex;

View File

@@ -764,7 +764,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
{
if (mb->getVertexType() != video::EVT_TANGENTS)
Log::fatal("material", "Requiring normal map without tangent enabled mesh");
Log::error("material", "Requiring normal map without tangent enabled mesh");
ITexture* tex = irr_driver->getTexture(m_normal_map_tex);
if (m_is_heightmap)
{

View File

@@ -92,7 +92,7 @@ LODNode* LodNodeLoader::instanciate(const XMLNode* node, scene::ISceneNode* pare
continue;
}
if (group[m].m_tangent && a_mesh->getMeshBuffer(0)->getVertexType() != video::EVT_TANGENTS)
//if (group[m].m_tangent && a_mesh->getMeshBuffer(0)->getVertexType() != video::EVT_TANGENTS)
{
scene::IMeshManipulator* manip = irr_driver->getVideoDriver()->getMeshManipulator();
scene::IMesh* m2 = manip->createMeshWithTangents(a_mesh);