Bump mapping for Animated meshes
Bump mapping for Animated meshes
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?
Has anyone found a way to bump map an animated mesh in Irrlicht yet?
Re: Bump mapping for Animated meshes
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?
http://irrlicht.sourceforge.net/forum/v ... hp?t=36637
Has anyone tried it out?
Re: Bump mapping for Animated meshes
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?
How to do this selectively for only those submeshes that need bump mapping?
Re: Bump mapping for Animated meshes
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
Re: Bump mapping for Animated meshes
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?
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?
Re: Bump mapping for Animated meshes
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
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!
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!
Re: Bump mapping for Animated meshes
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.
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.
Re: Bump mapping for Animated meshes
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);
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.
Re: Bump mapping for Animated meshes
What? You can use built-in normal map material.robmar wrote:Without this shader irrlicht models can´t be have bump mapped surfaces.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: Bump mapping for Animated meshes
I think you´re missing the bit about calculating tangents for animated models totally overloading the CPU!
Re: Bump mapping for Animated meshes
Use skinning mesh then.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: Bump mapping for Animated meshes
That's not what we´re talking about here.
Re: Bump mapping for Animated meshes
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.
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
Re: Bump mapping for Animated meshes
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?
Re: Bump mapping for Animated meshes
If this is possible, is there a sample we can look at that will work with this type of animated b3d model?