Bump mapping for Animated meshes

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Bump mapping for Animated meshes

Post by robmar »

I remember discussing this but can´t find the post, as Animated meshes in Irrlicht don´t support bump mapping.

Has anyone found a way to bump map an animated mesh in Irrlicht yet?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

Found this post with google which seems to be a solution!

http://irrlicht.sourceforge.net/forum/v ... hp?t=36637

Has anyone tried it out?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

Testing with an animated model with 1000 frames causes the system to run out of memory.

How to do this selectively for only those submeshes that need bump mapping?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Bump mapping for Animated meshes

Post by Nadro »

You can apply material type per each mesh buffer eg. Node->getMaterial(neshBufferNumber);
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

Yes I know, the problem is the tangent conversion for all the frames, which is needed as well.

I´m sort of confused... the model has bones which can be controlled through rotation, but it also has animation frames...

So the frames are what exactly? Are they meshes of pre-done bone rotations?

I guess for bump map to work on rotation, after each rotation, which must create a new mesh morph, then a call to convert..tangents would be needed, right?

So the frames all need tangentizing for them to work with bump mapping...

Is it possible to only convert the meshes say of one sub-mesh, say the hair? Can that submesh be processed from each frame?
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Re: Bump mapping for Animated meshes

Post by ent1ty »

For a quick&dirty solution, you can "approximate" the tangent and binormal from the normal in the vertex shader. That way you dont need tangent meshes at all
Check out this: https://bitbucket.org/entity/irrrendere ... at=default

Of course, the quality is nowhere near a static mesh with pre-calculated tangents
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Bump mapping for Animated meshes

Post by mongoose7 »

You would still need to calculate the normal per frame.

Hmm, I don't think you should multiply the tangent by the normal matrix. The same for the binormal.

@robmar: The mesh, I think, is saved and the bone transformations are applied to it per frame in the meshbuffers. So you have to generate the normals on each frame. I don't know if the vertex type is retained, so I can't tell if you could just calculate the normal every nth frame.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

The shader is the solution of course, offload the work to the GPU. Why isn't this already in Irrlicht?

Without this shader irrlicht models can´t be have bump mapped surfaces.

So maybe we could patch this line into this shader below and have a quality pixel shader with fast bump mapping!

vec3 Tangent = -vec3(abs(gl_Normal.y) + abs(gl_Normal.z), abs(gl_Normal.x), 0);

Code: Select all

 
// Bump map pixel shader HLSL
 
  sampler2D tex0;
  sampler2D tex1;
 
  struct v2p
  {
    float4 Position  : POSITION;
    float2 Texcoord0 : TEXCOORD0;
    float2 Texcoord1 : TEXCOORD1;
    float4 Diffuse   : COLOR0;
  };
 
// p2f is the final output data structure.
 
  struct p2f
  {
    float4 Color : COLOR0;
  };
 
// Main function has one input from vertex shader and two texture samplers. OUT is an object of p2f.
 
  void mainPS( in v2p IN, out p2f OUT )
  {
     float4 Color = tex2D(tex0, IN.Texcoord0);  // fetch base Color and Normal
     float4 Normal = tex2D(tex1, IN.Texcoord1);
 
     OUT.Color = Color*dot(2.0*(Normal-0.5), 2.0*(IN.Diffuse-0.5));  // set final color
  }
 
// Following code is the vertex shader
 
  float4x4  ModelWorld;
  float4x4  ModelViewProj;
  float4    vLight;
  float4    vEye;
  float4    vDiffuseMaterial;
  float4    vSpecularMaterial;
  float4    vAmbient;
  float     power;
 
global variables
   struct a2v {
    float4 Position : POSITION;
    float2 Texcoord : TEXCOORD0;
    float4 Normal   : NORMAL; 
    float4 Tangent  : TANGENT;      
  };
 
  struct v2p {
    float4 Position  : POSITION;
    float4 Color     : COLOR0;
    float2 Texcoord0 : TEXCOORD0;
    float2 Texcoord1 : TEXCOORD1;
  };
 
// Define mainVS function, get position
 
  void mainVS( in a2v IN, out v2p OUT )
  {
    OUT.Position = mul(IN.Position, ModelViewProj);
 
// transform normal from model-space to view-space
    float4 tangent = mul(float4(IN.Tangent.xyz,0.0),ModelWorld);
    float4 normal = mul(float4(IN.Normal.xyz,0.0),ModelWorld);
    float3 binormal = cross(normal.xyz,tangent.xyz);
 
// Position in World
    float4 posWorld = mul(IN.Position, ModelWorld);
 
// get normalize light, eye vector, and half angle vector
    float4 light = normalize(posWorld-vLight);
    float4 eye = normalize(vEye-light);
    float4 vhalf = normalize(eye-vLight);
 
// transform light and vhalf vectors to tangent space
    float3 L = float3(dot(tangent, light), dot(binormal, light.xyz), dot(normal, light));
    float3 H = float3(dot(tangent, vhalf), dot(binormal, vhalf.xyz), dot(normal, vhalf));
 
// calculate diffuse and specular components
    float diffuse = dot(normal, L);
    float specular = dot(normal, H);
    specular = pow(specular, power);
 
// combine diffuse and specular contributions and output final vertex color, set texture coordinates, and return output object.
    OUT.Color = 2.0*(diffuse*vDiffuseMaterial + specular*vSpecularMaterial) + 0.5 + vAmbient;
 
    OUT.Texcoord0 = IN.Texcoord;
    OUT.Texcoord1 = IN.Texcoord;
  }
 
Last edited by robmar on Fri Apr 18, 2014 6:43 pm, edited 2 times in total.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Bump mapping for Animated meshes

Post by Nadro »

robmar wrote:Without this shader irrlicht models can´t be have bump mapped surfaces.
What? You can use built-in normal map material.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

I think you´re missing the bit about calculating tangents for animated models totally overloading the CPU!
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Bump mapping for Animated meshes

Post by Nadro »

Use skinning mesh then.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

That's not what we´re talking about here.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Bump mapping for Animated meshes

Post by Nadro »

No, you said that bump mapping with animated models doesn't workd out of box, but it's not true. SkinnedMeshes are compatible with normal mapping, so I don't see any problems. Only small marigin of users need support normal mapping + key frame based animations. If someone really need it I don't see any problems to use custom shader.

Next time, before you will say something like 'it doesn't work' etc. you should check available solutions for that case, because as I said before you don't need your shader to get normal mapping on animated mesh in Irrlicht. Of course you can prepare your own (eg. more optimized for your game), but it isn't require.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

So you are telling me that a B3D animated model with 96 bones, 1080 frames, and 18 materials and their submeshes can be bump mapped differently on each material (and animated) with Irrlicht SkinnedMeshes?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

If this is possible, is there a sample we can look at that will work with this type of animated b3d model?
Post Reply