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!
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Here is the FULL PROJECT with its data..

http://s000.tinyupload.com/?file_id=457 ... 9221471855
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

Nice looking metal! Will have to give it a try!
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Thanks! Just get the project compiled once and you'll have 50% of the work done!!
I needed to test, recompile, test, recompile ......
Trust me.. compile the project before looking at the code..
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Bug found in the Tangent Updater..

Code: Select all

 
 // ... For those interested..
 
 // This thing had a bug in it in that it would not update all the buffers..
 // I discovered that Irrlicht buffers are related to materials (not just max poly numbers).
 // It is fixed now..Sorry..
 
 // Cool stuff coming!
 
   // Initialization.. 
   
   // Variables concerned with "LIVE TANGENT UPDATES"..
   // We assign this "SceneMeshCount" value during the main render loop as well 
   // as things can be added or removed during run-time..
   // This part of the Tangent Updater DO NOT get called at each frame as it is an "Initialisation"..
   // *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
   SceneMeshCount = TheSceneManager ->getMeshCache()->getMeshCount();
   irr::scene::IMeshBuffer* TempMeshBuffer;
   video::S3DVertexTangents* TempVertTansPTR;
   TempMeshBuffer    = TheSceneManager->getMeshCache()->getMeshByIndex(0)->getMeshBuffer(0);
   TempVertTansPTR   = (video::S3DVertexTangents*)TempMeshBuffer->getVertices(); 
   TheSceneMeshCache = TheSceneManager->getMeshCache();
   S3DVertexTangents VertexTriA;
   S3DVertexTangents VertexTriB;
   S3DVertexTangents VertexTriC;
   // *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
 
 
   // Other code..
 
   // Looped..
 
       //================================================
       SceneMeshCount = TheSceneManager ->getMeshCache()->getMeshCount();
       //  PLEASE OPTIMIZE THIS or simply do it as irrlicht does it internally....
       if (TanUpdStatus == true) // globally updated for all Animated "Skinned" meshes..(not for NON-Skinned items..)
        {// SceneMeshCount..
         for (u32 SMeshI = 0; SMeshI < SceneMeshCount; SMeshI++) 
          {// We want to recalculate Tangents for Skinned Meshes only so we must determine which ones are "Skinned"..
           if (TheSceneMeshCache->getMeshByIndex(SMeshI)->getMeshType() == EAMT_SKINNED)
            {// start procedure: Only "Skinned" meshes..
             AcquiredAnimeshByIndex = TheSceneMeshCache->getMeshByIndex(SMeshI); 
             AcquiredImesh = AcquiredAnimeshByIndex ;
             u32 TheMBufferCount = AcquiredImesh->getMeshBufferCount();
             // FIXED BUG!!! NOW WE TRUELY HAVE ALL BUFFER'S TANGENTS (and hence Binormals) UPDATED!!
             // This bug was not noticed because my single material models had only 1 buffer.. 
             // Adding more materials in your 3d modelling app results in more buffers in Irrlicht..
             // Extra buffers also result from very high polygon-count models..
             u16* TheINDEXPtr;
             u32 TheIndexCount;
             for (u32 MBuffI = 0 ; MBuffI < TheMBufferCount ; MBuffI++)
              {// start Buffer Loop (some models may have more than one buffer)..
               // It would be cool if Buffers could also be considered for Frustum Culling..
               CurrMeshBuffPtr = AcquiredImesh->getMeshBuffer(MBuffI);  // FIXED!! WE MUST ALSO LOOP BUFFERS..
               CurrTanVertsPtr  = (video::S3DVertexTangents*)CurrMeshBuffPtr->getVertices(); // Many Buffers for Many Meshes..
               TheINDEXPtr =    TheSceneMeshCache->getMeshByIndex(SMeshI)->getMeshBuffer(MBuffI)->getIndices(); // ALSO!
               TheIndexCount = (u32)TheSceneMeshCache->getMeshByIndex(SMeshI)->getMeshBuffer(MBuffI)->getIndexCount();
 
               for (u32 IndexII = 0; IndexII < TheIndexCount; IndexII+=3)
                {// start Index Loop..  // Get all all three of our Triangle Vertices and UV Coords..
                 VertexTriA = CurrTanVertsPtr[TheINDEXPtr[IndexII]];
                 VertexTriB = CurrTanVertsPtr[TheINDEXPtr[IndexII+1]];
                 VertexTriC = CurrTanVertsPtr[TheINDEXPtr[IndexII+2]];
                 // Here we get the THREE POINTS XYZ Positions for the TRIANGLE..
                 f32 TAX = VertexTriA.Pos.X;   f32 TAY = VertexTriA.Pos.Y; f32 TAZ = VertexTriA.Pos.Z; 
                 f32 TBX = VertexTriB.Pos.X;   f32 TBY = VertexTriB.Pos.Y; f32 TBZ = VertexTriB.Pos.Z;
                 f32 TCX = VertexTriC.Pos.X;   f32 TCY = VertexTriC.Pos.Y; f32 TCZ = VertexTriC.Pos.Z;
                 // Here we get the UV Coordinates for each of the three Points.
                 f32 TAU = VertexTriA.TCoords.X; f32 TAV = VertexTriA.TCoords.Y;   VertexTriA.TCoords.X = 1.0;
                 f32 TBU = VertexTriB.TCoords.X; f32 TBV = VertexTriB.TCoords.Y;
                 f32 TCU = VertexTriC.TCoords.X; f32 TCV = VertexTriC.TCoords.Y;
                 // We introduce THREE new "Delta Vectors" which will eventually become "Triangle Edges"..
                 // This is a special "recipe" using "Triangle Points" and "UV Coordinates"..
                 // "Subtraction" hence "Delta Vectors"..
                 f32 DV1X = TBX - TAX ; f32 DV1Y = TBU - TAU ; f32 DV1Z = TBV - TAV;
                 f32 DV2X = TCX - TAX ; f32 DV2Y = TCU - TAU ; f32 DV2Z = TCV - TAV;
                 f32 DV3X = TBY - TAY ; f32 DV3Y = TBU - TAU ; f32 DV3Z = TBV - TAV;
                 f32 DV4X = TCY - TAY ; f32 DV4Y = TCU - TAU ; f32 DV4Z = TCV - TAV;
                 f32 DV5X = TBZ - TAZ ; f32 DV5Y = TBU - TAU ; f32 DV5Z = TBV - TAV;
                 f32 DV6X = TCZ - TAZ ; f32 DV6Y = TCU - TAU ; f32 DV6Z = TCV - TAV;
                 // Now we introduce THREE "Cross Products". Cross Product A, Cross Product B and Cross Product C.
                 f32 CAX = (DV1Y * DV2Z) - (DV2Y * DV1Z); f32 CAY = (DV1Z * DV2X) - (DV2Z * DV1X);
                 f32 CAZ = (DV1X * DV2Y) - (DV2X * DV1Y); f32 CBX = (DV3Y * DV4Z) - (DV4Y * DV3Z);
                 f32 CBY = (DV3Z * DV4X) - (DV4Z * DV3X); f32 CBZ = (DV3X * DV4Y) - (DV4X * DV3Y);
                 f32 CCX = (DV5Y * DV6Z) - (DV6Y * DV5Z); f32 CCY = (DV5Z * DV6X) - (DV6Z * DV5X);
                 f32 CCZ = (DV5X * DV6Y) - (DV6X * DV5Y);
                 // Calculate our TANGENT..
                 f32 TanX = (CAY / CAX);  f32 TanY = (CBY / CBX);  f32 TanZ = (CCY / CCX); 
                 // ..and our BINORMAL..
                 // In this implementation the act of subtraction to get the Delta Vectors effectively
                 // makes getting Binormals elsewhere (like shaders) impossible!!
                 f32 BinX = (CAZ / CAX);  f32 BinY = (CBZ / CBX);  f32 BinZ = (CCZ / CCX); 
                 // Now we replace the Static Tangents/Binormals with our animated ones..
                 CurrTanVertsPtr[TheINDEXPtr[IndexII]].Tangent.X = -TanX;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII]].Tangent.Y = -TanY;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII]].Tangent.Z = -TanZ;  // CurrTanVertsPtr[TheINDEXPtr[IndexII]]. TCoords.X = 1.0;;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+1]].Tangent.X = -TanX;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+1]].Tangent.Y = -TanY;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+1]].Tangent.Z = -TanZ;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+2]].Tangent.X = -TanX;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+2]].Tangent.Y = -TanY;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+2]].Tangent.Z = -TanZ;
                 // Binormals are NOT done in the shader by crossing Tangents with Normals..
                 CurrTanVertsPtr[TheINDEXPtr[IndexII]].Binormal.X = BinX;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII]].Binormal.Y = BinY;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII]].Binormal.Z = BinZ;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+1]].Binormal.X = BinX;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+1]].Binormal.Y = BinY;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+1]].Binormal.Z = BinZ;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+2]].Binormal.X = BinX;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+2]].Binormal.Y = BinY;
                 CurrTanVertsPtr[TheINDEXPtr[IndexII+2]].Binormal.Z = BinZ;
                }  // end Index Loop..     
              }  // end Buffer Loop 
            } // End Only "Skinned" meshes..
          } // end loop "SMESHI"     
        }  // End user determined conditional Tangents & Binormal Update..
             
       // END of Tangent and Binormals Updating..
       // Note that you may encounter strange black areas on your models..
       // This is not a bug, it is the result of poor UV UNWRAPPING..
       // The solution would be to Re-Unwrap your UV Map and to make sure that UV positions for a given triangle
       // does not overlap..
       // This is a common problem in even the latest game ripped models..
       
       // By the way, when is CUBE MAPPING for HLSL and GLSL coming and when is 2TCOORDS and TANGENT going
       // to be in the same VERTEX DESCRIPTOR?  :o) 
 
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Found another bug! The old version denied you any more materials.

Code: Select all

 
     // Replace the old one with this or you will have headaches with "Multiple Materials"
     if ( SelectedDriverType == EDT_OPENGL) // ALSO HLSL!!
      { M01World = TheDriver->getTransform(video::ETS_WORLD); // For GLSL this is all we need!
       TheMATRENDServices->setVertexShaderConstant("M01World", M01World.pointer(), 16);
       // We don't have to send images at each and every frame! But we could if we wanted to.. BULL!!
       // if (ImageAssignedStatus == 0) // THIS WAS A MISTAKE!!
        //{
         TheMATRENDServices->setPixelShaderConstant("DiffuseMapSample",   (s32*)(&TexAddresses [DIFFUSE_LAYER]), 1);      
         TheMATRENDServices->setPixelShaderConstant("NormalMapSample",    (s32*)(&TexAddresses [NORMALS_LAYER]), 1);  
         TheMATRENDServices->setPixelShaderConstant("SpecularMapSample",  (s32*)(&TexAddresses [SPECULAR_LAYER]), 1);
         TheMATRENDServices->setPixelShaderConstant("GlossMapSample",     (s32*)(&TexAddresses [GLOSS_LAYER]), 1);
         TheMATRENDServices->setPixelShaderConstant("Image005",    (s32*)(&TexAddresses [FIFTH_LAYER]), 1);      
         TheMATRENDServices->setPixelShaderConstant("Image006",    (s32*)(&TexAddresses [SIXTH_LAYER]), 1);  
         TheMATRENDServices->setPixelShaderConstant("Image007",    (s32*)(&TexAddresses [SEVENTH_LAYER]), 1);
         TheMATRENDServices->setPixelShaderConstant("Image008",     (s32*)(&TexAddresses [EIGHTH_LAYER]), 1);
       // }
      // ImageAssignedStatus = 1; // THIS HAS NOTHING TO DO WITH "EACH FRAME" REMOVE THE CONDITIONAL!!
      // It, infact, denies you the ability to add more materials!!
      // I post this cause I see there was some downloads..
 
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Both bugs were found because I started using multiple materials in my objects. (multi buffers).
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Both bugs were found because I started using multiple materials in my objects. (multi buffers).
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Oops!

Image
Last edited by Vectrotek on Sun May 01, 2016 10:50 pm, edited 1 time in total.
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Gone in hiding..
Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Havelock from "Dishonoured" Irrlicht style.
Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Kenway..
Image
Last edited by Vectrotek on Mon May 02, 2016 12:48 am, edited 1 time in total.
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Oh mama!
Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Game ripper..
Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

GPU Programmer..
Image
Post Reply