Page 8 of 17

Re: Bump mapping for Animated meshes

Posted: Tue Sep 29, 2015 9:26 pm
by Vectrotek
Here is the Appcode:

Code: Select all

 
 
 
 #include <irrlicht.h>
 
 using namespace irr;
 using namespace video;
 using namespace scene;
 using namespace core;
 using namespace io;
 using namespace gui;
 
  #pragma comment(lib,"irrlicht.lib")
 //------------------------------ ----- ---- --- -- - 
 class CST : public irr::video::IShaderConstantSetCallBack
  {public:
   CST()
    {// device = createDevice(EDT_DIRECT3D9, dimension2d(800, 600), 32);
     device = createDevice(EDT_DIRECT3D9, core::dimension2d<u32>(1024, 768));
     driver = device->getVideoDriver();
     smgr = device->getSceneManager();
     camera = smgr->addCameraSceneNodeFPS(0, 100.0, 0.005);
     camera->setPosition(vector3df(0.0f, 0.0f, -5.0f));
     //                                                                                                                          
 
     scene::IMesh*                       IMesh0003;
     scene::IAnimatedMesh*               AniMesh0003;  
 
     AniMesh0003 = smgr ->getMesh("Data/OBJ_001_SHAPE_UVs.obj"); 
 
     IMesh0003 = smgr->getMeshManipulator()->createMeshWithTangents(AniMesh0003,    // The Mesh..
                                                                    false,          // Recalculate Nomrals..
                                                                    false,          // Smooth..
                                                                    false,          // Angle Weighted..
                                                                    true            // Recalculate Tangents..
                                                                    );
 
     // Now if we can show the tangents through the shader then we are well on our way..
 
     ISceneNode* OurFIRST3DNode = smgr->addMeshSceneNode(IMesh0003); // Now that Imesh0003 has tangents..
 
 
     //                                                                                                                          
     OurFIRST3DNode->getMaterial(0).setTexture(0, driver->getTexture("Data/lialique.bmp"));
     OurFIRST3DNode->getMaterial(0).setTexture(1, driver->getTexture("Data/cel.png"));
     OurFIRST3DNode->getMaterial(0).TextureLayer[1].BilinearFilter = false;
     u32 lastFPS = 0;
     video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
     s32 celMat 
       = gpu->addHighLevelShaderMaterialFromFiles("Shaders/cel.hlsl",
                                                  "vertexMain",
                                                  EVST_VS_3_0,
                                                  "Shaders/cel.hlsl",
                                                  "pixelMain",
                                                  EPST_PS_3_0, // THIS HELPED!! (was 02)
                                                  this);
 
     OurFIRST3DNode->getMaterial(0).MaterialType = (E_MATERIAL_TYPE)celMat;
     lightPosition = vector3df(100, 100, 100);
     while(device->run())
      {driver->beginScene(true, true, SColor(0xff88aadd));
       smgr->drawAll();
       driver->endScene();
       if(driver->getFPS() != lastFPS)
        {lastFPS = driver->getFPS();
         stringw windowCaption = "CST FPS: ";
         windowCaption += lastFPS;
         device->setWindowCaption(windowCaption.c_str());
        }
      }
    }
   ~CST()
    {if(device)
      {device->closeDevice();
       device->run();
       device->drop();
       device = NULL;
      }
    }
   virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
    {matrix4 world = driver->getTransform(ETS_WORLD); // We have this for GLSL too..
     matrix4 invWorld;
     world.getInverse(invWorld);
     vector3df lightPosOS;
     invWorld.transformVect(lightPosOS, lightPosition);
     // If you dont use a Shader Variable then make sure that you dont try set it in the Appcode..
     // HLSL is much stricter on this than GLSL..
     // services->setVertexShaderConstant("mLightPos", &lightPosOS.X, 3);
     vector3df camPosOS;
     invWorld.transformVect(camPosOS, camera->getPosition()); // Check the function!!
     services->setVertexShaderConstant("CameraXYZPosition", &camPosOS.X, 3);
     matrix4 wvp = driver->getTransform(ETS_PROJECTION);
     wvp *= driver->getTransform(ETS_VIEW);
     wvp *= world;
    services->setVertexShaderConstant("mWorldViewProj", wvp.pointer(), 16);\
 
 
 //   services->setVertexShaderConstant("WvpXf", wvp.pointer(), 16);  // NO! just checking..
    }
   ICameraSceneNode* camera;
   IVideoDriver* driver;
   ISceneManager* smgr;
   IrrlichtDevice* device;
   vector3df lightPosition;
  };
 //------------------------------ ----- ---- --- -- - 
 int main()
  {CST app;
   return 0;
  }
 
 

The project was a bit lame so I deleted it..

Re: Bump mapping for Animated meshes

Posted: Sun Oct 04, 2015 8:32 pm
by Vectrotek
- GLSL to HLSL -

When it comes to GLSL to HLSL conversion there are many opinions!
FX Composer and the old Rendermonkey looks useful for their shipped examples..
I'm finding it very difficult.
Opinions?

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 12:23 am
by The_Glitch
Sorry haven't been on lately... so what are you trying to do?

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 4:06 am
by Vectrotek
Trying to figure out which GLSL matrices match up with which HLSL versions.
I know now that there are differences that makes straight conversion very tricky.
I'll put together an example of what I'm trying then you can have a look.

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 7:28 pm
by Vectrotek
Something interesting in the pipeline.
Played around with "Rendermonkey".
New inspiration.
Figured out that semantics, "TEXCOORD1" & "TEXCOORD2" is used for Tangent and Binormal.
Still have problems adding variables in appcode and shader that the system says it can't find when they are definitely there.
Will post code shortly..

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 7:44 pm
by Vectrotek
My main question is: "Why is it so difficult to add new variables in existing examples in both Appcode and Shader code?"

Some fresh eyes may help.
Here is my last appcode (in a mess as usual):

Code: Select all

 
 // This was a "stripped down" version of Example 10 in which
 // we tried converting it surgically from a good working GLSL shader into
 // an (Irrlicht flavored) HLSL shader.
 // We want it to do exactly the same things as the GLSL shader..
 
 // It now resembles nothing like the Example 10 Shader code and
 // was "morphed" more towards an HLSL example from FX Composer..
 // (specifically one of the surface shaders in the Nissan Car example)
 // So this HLSL now resembles an "FX Composer" Example.
 // This specific shader deals with normal maps which is exactly what we want.
 
 // Yes, the Hardware Channels "Semantics" for Tangent and Binormal is now "TEXCOORD_1" and "TEXCOORD_2"
 
 // The "Cube" object was replaced with "FusionBall.x" (or *.b3d) skinned model.
 // The goal here is to render this skinned mesh in the same way as is possible
 // with an existing GLSL Shader.
 // This existing GLSL shader happens to have a good grip on
 // physical lighting and now serves as a basis and reference for all other shaders
 // in other languages (for me, now)..
 // The skinned model includes a Diffuse Map and an NSG Map which holds all the
 // information needed to render a pretty realistic scene..
 // It can be animated (by its bones), and obviously Rotated, Scaled and Translated
 // making it a good skinned mesh to conduct tests with..
 // If we have a light connected to the camera then it would be easy
 // to see if the specular highlights or diffuse lighting has problems.
 // We could also have lights placed in "definitive positions" like far down
 // on the Y axis to check if it "Looks Right"..
 
 // At this stage I still have a problem with:
 //   1. Adding things like just a plain "mWorld" matrix
 //   2. For some reason variables passed from appcode like "ColourSampler" is not accepted..
 //      and a message concerning this is displayed in the Irrlicht console..
 
 // I've looked at the order by which I send these variables to the shader code
 // prompted by the "[Begin: 7 Count: 1]" type of messages from the console.
 // Order didn't seem to help..
 
 // In the shader code itself I have a kind of "plug connector" set of lines where I 
 // tried various "Connections" between Incoming Matrices and Existing Matrices
 // already in the FX, now HLSL example.
 
 #include <irrlicht.h>
 #include <iostream>
 #include "driverChoice.h"
 using namespace irr;
 #ifdef _MSC_VER
 #pragma comment(lib, "Irrlicht.lib")
 #endif
 
 
 // = = = = = = = = = = = = = = = = = = = = = = 
 using namespace irr;
 using namespace core;
 using namespace scene;
 using namespace video;
 using namespace gui;
 // = = = = = = = = = = = = = = = = = = = = = = 
 
 IrrlichtDevice*         TheDevice = 0;
 IrrlichtDevice*         TheIRRNullDevice = 0; // is this "= 0" stil mandatory?
 core::dimension2d<u32>  TheDeskResolution;
 
 
 
 
 core::matrix4 WorldVievProjectionMatrix;
 core::matrix4 WorldMatrix;
 core::matrix4 TransposedWorldMatrix;
 core::matrix4 InverseWorldMatrix ;
 
 // We need to know what GLSL's "gl_ModelViewProjectionMatrix" is in HLSL..
 // I suspect that GLSL's "gl_Vertex" is "MyVertVar : POSITION" (semantically) in HLSL. ?
 
 //                                    - ANIMATED MODELS (DirectX or BLITZ BASIC) -                                   
 
// scene::IAnimatedMeshSceneNode*     TheNode; 
 
 scene::IAnimatedMesh*              AniMesh0001;  
 scene::IAnimatedMeshSceneNode*     AniMeshNode0001; 
 //                                                                                                                  
 
 
 
 
 class OurShaderCallBackClass : public video::IShaderConstantSetCallBack
  {               
   public:
   virtual void OnSetConstants(video::IMaterialRendererServices* TheServices, s32 userData)
    {video::IVideoDriver* TheDriver = TheServices->getVideoDriver();
     WorldMatrix = TheDriver->getTransform(video::ETS_WORLD);
  // Transformations..
  // ETS_VIEW        View transformation.
  // ETS_WORLD       World transformation.
  // ETS_PROJECTION  Projection transformation.
 
     // OUR NEW ONES!!
     // TheServices->setVertexShaderConstant("mWorld", WorldMatrix.pointer(), 16);  // System complains.. 
 /* // As the matrices exist in the HLSL shader code..
 float4x4   mWorldViewProj;   // WorldViewProjection         [ Begin: 0  Count: 4 ]
 float4x4   mTransWorld;      // Transposed world matrix     [ Begin: 4  Count: 3 ]
 float3     mLightPos;        // Light position              [ Begin: 7  Count: 1 ]
                              // PROBLEMS: Cant send to the shader and getting error messages..
 float4     mLightColor;      // Light color                 [ ****************** ]
 float4x4   mWorld;           // Plain World Matrix          [ ****************** ]
 float4x4   mInvWorld;        // Inverted world matrix       [ ****************** ]
 sampler2D  ColorSampler;     // Diffuse Image               [ ****************** ]
 */     
 
 
 
     // ..
 
     // [ Begin 0:   Count: 4 ]  O.K. 
     WorldVievProjectionMatrix =  TheDriver->getTransform(video::ETS_PROJECTION);
     WorldVievProjectionMatrix *= TheDriver->getTransform(video::ETS_VIEW);
     WorldVievProjectionMatrix *= TheDriver->getTransform(video::ETS_WORLD);
     TheServices->setVertexShaderConstant("mWorldViewProj", WorldVievProjectionMatrix.pointer(), 16);
 
 
     // [ Begin 4:   Count: 3 ]  O.K. 
     WorldMatrix = TheDriver->getTransform(video::ETS_WORLD);
     TransposedWorldMatrix  = WorldMatrix.getTransposed();
 
     TheServices->setVertexShaderConstant("mTransWorld", TransposedWorldMatrix.pointer(), 16);
 
 
     // [ Begin 7:   Count: 1 ]  O.K. 
     core::vector3df CameraPosition = TheDevice->getSceneManager()->getActiveCamera()->getAbsolutePosition();
     TheServices->setVertexShaderConstant("mLightPos", reinterpret_cast<f32*>(&CameraPosition), 3); // Light is Camera Pos..
 
 
     // [ Begin XXX:   Count: XXX ]  NOT O.K! 
 
     // set Inverted World Matrix..
     WorldMatrix = TheDriver->getTransform(video::ETS_WORLD);
 
     TheServices->setVertexShaderConstant("mWorld", InverseWorldMatrix.pointer(), 16);
 
     // [ Begin XXX:   Count: XXX ]  NOT O.K! 
 
     // set Inverted World Matrix..
     InverseWorldMatrix = TheDriver->getTransform(video::ETS_WORLD);
     InverseWorldMatrix.makeInverse();
 
     TheServices->setVertexShaderConstant("mInvWorld", InverseWorldMatrix.pointer(), 16);
 
 
 
     // [ Begin XXX:   Count: XXX ]  NOT O.K! 
 
     video::SColorf col(0.0f,1.0f,1.0f,0.0f);
     TheServices->setVertexShaderConstant("mLightColor", reinterpret_cast<f32*>(&col), 4);
 
 
     // [ Begin XXX:   Count: XXX ]  NOT O.K! 
 
     s32 TextureLayerID = 0;
     TheServices->setPixelShaderConstant("ColorSampler", &TextureLayerID, 1); // Thankfully like GLSL to the Fragment Shader..
 
     int AppShaderCommand = 0;
 
     TheServices->setPixelShaderConstant("ShaderCommand001", reinterpret_cast<int*> (&AppShaderCommand), 1);
     TheServices->setPixelShaderConstant("ShaderCommand002", reinterpret_cast<int*> (&AppShaderCommand), 1);
     TheServices->setPixelShaderConstant("ShaderCommand003", reinterpret_cast<int*> (&AppShaderCommand), 1);
     TheServices->setPixelShaderConstant("ShaderCommand004", reinterpret_cast<int*> (&AppShaderCommand), 1);
     TheServices->setPixelShaderConstant("ShaderCommand005", reinterpret_cast<int*> (&AppShaderCommand), 1);
    }
  }                ;
 //----------------------------------------------------------- ------ ----- ---- --- -- -
 int main()
  {TheIRRNullDevice    = createDevice(video::EDT_NULL); // Null Device for us to get our windows resolution..
   TheDeskResolution   = TheIRRNullDevice->getVideoModeList()->getDesktopResolution();    // As set by you in windows..
   TheIRRNullDevice->drop(); // We got the desktop resolution, so drop the Null Device..
   TheDevice = createDevice(video::EDT_DIRECT3D9,TheDeskResolution,32);
   if (TheDevice == 0) return 1;
   video::IVideoDriver* TheDriver = TheDevice->getVideoDriver();
   scene::ISceneManager* TheSceneManager = TheDevice->getSceneManager();
   io::path vsFileName; 
   io::path psFileName; 
   psFileName = "Shaders/d3d9.hlsl";
   vsFileName = psFileName; // Both shaders are in the same file..
   video::IGPUProgrammingServices* TheGPUProgrammingServices = TheDriver->getGPUProgrammingServices();
   s32 OurShaderMaterial = 0;
   if (TheGPUProgrammingServices)
    {OurShaderCallBackClass* OurCallback = new OurShaderCallBackClass();
     const video::E_GPU_SHADING_LANGUAGE shadingLanguage = video::EGSL_CG; // O.K. 
/*
     OurShaderMaterial
      = TheGPUProgrammingServices->addHighLevelShaderMaterialFromFiles(vsFileName, "vertexMain", video::EVST_VS_3_0,
                                                                       psFileName, "pixelMain", video::EPST_PS_3_0,
                                                                       OurCallback, video::EMT_SOLID, 0, shadingLanguage);
*/
 
 
 
     OurShaderMaterial
     = TheGPUProgrammingServices->addHighLevelShaderMaterialFromFiles("Shaders/HLSL_0006_WAS_FX.hlsl",
                                                                      "vertexMain",
                                                                      EVST_VS_3_0,   // Was 2 ..
                                                                      "Shaders/HLSL_0006_WAS_FX.hlsl", // Ja.. Same name..
                                                                      "pixelMain",
                                                                      EPST_PS_3_0, // THIS HELPED!! (was 02)
                                                                      OurCallback,
                                                                      video::EMT_SOLID,
                                                                      0,
                                                                      shadingLanguage);
 
     OurCallback->drop();
    }
   // TheNode = TheSceneManager->addCubeSceneNode(50);
 
   AniMesh0001 = TheSceneManager ->getMesh("Data/0013_FUSION_BALL/X_001.x");
 
   ((ISkinnedMesh*)AniMesh0001)->convertMeshToTangents(); // Right Place?
 
   AniMeshNode0001 = TheSceneManager->addAnimatedMeshSceneNode(AniMesh0001);
   AniMeshNode0001->setDebugDataVisible(EDS_NORMALS);
 
   AniMeshNode0001 -> setScale(vector3df( 10.0 , 10.0 , 10.0 )); // My modeller (Blender 2.75) likes things to be in a cube of 20 x 20 units..
 
 
   float AniPlaySpeed =  0.0 ; // Default..
   // AniPlayAtPause = AniPlaySpeed;
   AniMeshNode0001 -> setAnimationSpeed  (AniPlaySpeed) ;   // Get this into command..
 
   AniMeshNode0001 -> setFrameLoop  ( 0.0   +  1.0  ,  AniMeshNode0001 -> getEndFrame () -  0.0 );  // Automate this..
 
 
 
   AniMeshNode0001->setPosition(core::vector3df(0,0,0));
   AniMeshNode0001->setMaterialTexture(0, TheDriver->getTexture("Data/0013_FUSION_BALL/NSG_MAP.tga"));
   AniMeshNode0001->setMaterialFlag(video::EMF_LIGHTING, false);
   AniMeshNode0001->setMaterialType((video::E_MATERIAL_TYPE) OurShaderMaterial);
   scene::ISceneNodeAnimator* TheAnimator = TheSceneManager->createRotationAnimator(core::vector3df(0,0.0f,0));
   AniMeshNode0001->addAnimator(TheAnimator);
   TheAnimator->drop();
   TheDriver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
   // Add a camera and disable the mouse cursor..
   scene::ICameraSceneNode* TheCamera = TheSceneManager->addCameraSceneNodeFPS();
   TheCamera->setPosition(core::vector3df(-100,50,100));
   TheCamera->setTarget(core::vector3df(0,0,0));
   TheDevice->getCursorControl()->setVisible(false);
   int lastFPS = -1;
   while(TheDevice->run())
    {
      if (TheDevice->isWindowActive())
       {TheDriver->beginScene(true, true, video::SColor( 255 , 207 , 211 , 192 ));
        TheSceneManager->drawAll();
        TheDriver->endScene();
        int fps = TheDriver->getFPS();
        if (lastFPS != fps)
         {core::stringw str = L"Irrlicht Engine - Vertex and pixel shader example [";
          str += TheDriver->getName();
          str += "] FPS:";
          str += fps;
          TheDevice->setWindowCaption(str.c_str());
          lastFPS = fps;
         }
       }
    }
   TheDevice->drop();
   return 0;
  }
 
 

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 7:58 pm
by Vectrotek
Here is the HLSL Shader..

Code: Select all

 
 
 
 // UN-TWEAKABLES - AUTOMATICALLY-TRACKED TRANSFORMS (composer things I left here)
 
 // float4x4 WorldITXf : WorldInverseTranspose < string UIWidget="None"; >;
 // float4x4 WvpXf :     WorldViewProjection < string UIWidget="None"; >;
 // float4x4 WorldXf :   World < string UIWidget="None"; >;
 // float4x4 ViewIXf :   ViewInverse < string UIWidget="None"; >;
 
 
 // The system just don't accept some of these!?!
 float4x4 mWorldViewProj; // WorldViewProjection transformation    From Appcode like: ""
 float4x4 mInvWorld;      // Inverted world matrix
 float4x4 mTransWorld;    // Transposed world matrix
 float3   mLightPos;      // Light position
 float4   mLightColor;    // Light color
 
 int      ShaderCommand001;
 int      ShaderCommand002;
 int      ShaderCommand003;
 int      ShaderCommand004;
 int      ShaderCommand005;  // Just a range of tests..
 
 float    SpecExpon = 512.0;
 float4   SpecColour;
 
// CONNECTOR DATA STRUCTURES 
 
// Data from application vertex buffer..
struct appdata {
    float3 Position : POSITION;
    float4 UV       : TEXCOORD0;
    float4 Normal   : NORMAL;
    float4 Tangent  : TEXCOORD1;  // we know what this is in irrlicht..
    float4 Binormal : TEXCOORD2;
};
 
// data passed from vertex shader to pixel shader..
struct VS_OUTPUT {
    float4 HPosition    : POSITION;
    float2 UV       : TEXCOORD0;
    // The following values are passed in "World" coordinates since
    //   it tends to be the most flexible and easy for handling
    //   reflections, sky lighting, and other "global" effects.
    float3 LightVec : TEXCOORD1;
    float3 WorldNormal  : TEXCOORD2;
    float3 WorldTangent : TEXCOORD3;
    float3 WorldBinormal : TEXCOORD4;
    float3 WorldView    : TEXCOORD5;
};
 
 // struct VS_OUTPUT
 // {float4 Position : POSITION;  // vertex position
 //  float4 Diffuse  : COLOR0;    // vertex diffuse color
 //  float2 TexCoord : TEXCOORD0; // tex coords
 // };
 
 
 
 
 
// ------------------------------------------------------ ----- ---- --- -- -
// VERTEX SHADING /////////////////////
 
VS_OUTPUT vertexMain(appdata IN) 
 {
  VS_OUTPUT OUT = (VS_OUTPUT)0;
  float4x4 WorldITXf;
  float4x4 WvpXf;
  float4x4 WorldXf;
  float4x4 ViewIXf;
 
  // Here I tried "Connecting the dots", but until I can add what I want I cant really
  // look at this even when I think that this must be the crux of the matter..
  // I know there is work here to be done, but would like to add things at will..
  // There is definitely something I'm not aware of here..
  
 
  WorldITXf =  mInvWorld;
  WvpXf     =  mWorldViewProj;
  WorldXf   =  mTransWorld;
  ViewIXf   =  mTransWorld;
    
   OUT.WorldNormal = mul(IN.Normal,WorldITXf).xyz;  // There is a definite reverse in mull (OPENGL vs DIRECTX)!!!
   OUT.WorldTangent = mul(IN.Tangent,WorldITXf).xyz;
   OUT.WorldBinormal = mul(IN.Binormal,WorldITXf).xyz;
 
  // Just to see them without matrix influence..
  // OUT.WorldNormal = IN.Normal.xyz;
  // OUT.WorldTangent = IN.Tangent.xyz;
  // OUT.WorldBinormal = IN.Binormal.xyz;
  //
 
 
    float4 Po = float4(IN.Position.xyz,1);
    float3 Pw = mul(Po,WorldXf).xyz;
    OUT.LightVec = (mLightPos - Pw);
#ifdef FLIP_TEXTURE_Y // Not needed (composer stuff)
    OUT.UV = float2(IN.UV.x,(1.0-IN.UV.y));
#else /* !FLIP_TEXTURE_Y */
    OUT.UV = IN.UV.xy;
#endif /* !FLIP_TEXTURE_Y */
    OUT.WorldView = normalize(ViewIXf[3].xyz - Pw);
    OUT.HPosition = mul(Po,WvpXf);
    return OUT;
}
// ------------------------------------------------------ ----- ---- --- -- -
 
//  - PIXEL SHADING - 
 
// Utility function for phong shading
  sampler2D ColorSampler;
// ------------------------------------------------------ ----- ---- --- -- -
void phong_shading(VS_OUTPUT IN,
            float3 LightColor,
            float3 Nn,
            float3 Ln,
            float3 Vn,
            out float3 DiffuseContrib,
            out float3 SpecularContrib)
{
    float3 Hn = normalize(Vn + Ln);
    float4 litV = lit(dot(Ln,Nn),dot(Hn,Nn),SpecExpon);
    DiffuseContrib = litV.y * LightColor;
    SpecularContrib = litV.y * litV.z * SpecColour * LightColor;
}
 
 struct PS_OUTPUT
  {float4 RGBColor : COLOR0; // Pixel color
  };
 
// ------------------------------------------------------ ----- ---- --- -- -
 
PS_OUTPUT pixelMain(VS_OUTPUT IN) : COLOR 
 {
   PS_OUTPUT Output;
  float4 colOUR = tex2D( ColorSampler, IN.UV); // sample color map
    float3 diffContrib;
    float3 specContrib;
    float3 Ln = normalize(IN.LightVec);
    float3 Vn = normalize(IN.WorldView);
    float3 Nn = normalize(IN.WorldNormal);
    float3 Tn = normalize(IN.WorldTangent);
    float3 Bn = normalize(IN.WorldBinormal);
    // float3 bump = Bump * (tex2D(NormalSampler,IN.UV).rgb - float3(0.5,0.5,0.5));
    // Nn = Nn + bump.x*Tn + bump.y*Bn;
    Nn = normalize(Nn);
    phong_shading(IN,mLightColor,Nn,Ln,Vn,diffContrib,specContrib);
    float3 diffuseColor ;
    diffuseColor.x = 1.0; diffuseColor.y = 1.0; diffuseColor.z = 1.0;
 
     diffuseColor = tex2D(ColorSampler,IN.UV).rgb;
    // float3 result = specContrib+(diffuseColor*(diffContrib+AmbiColor));
    float3 result = specContrib+(diffuseColor*diffContrib);
    float3 R = -reflect(Vn,Nn);
    // float3 reflColor = Kr * texCUBE(EnvSampler,R.xyz).rgb;
    diffuseColor = float3(0.90,0.90,0.90);
    // result += diffuseColor*reflColor;
    
    result += diffuseColor;
    
     result.xyz = (Nn.xyz / 2.0) + 0.5; // Currently rendering "Vertex Normals"..
 
 
    //result.x = (Tn.x / 2.0) + 0.5;
 
    //result.x = (Bn.x / 2.0) + 0.5;
 
    // result.x = (IN.WorldTangent.x / 2.0) + 0.5;
    
    // result.x = IN.UV.x; result.y = IN.UV.y;
    // result.x *= 10.5;
    
    
    Output.RGBColor.xyz = result.xyz;
    
    Output.RGBColor.w = 1;
    return Output;
    // return float4(result,1);
}
 
 // Just re-discovered Rendermonkey!
 // Will certainly try to pull some of that in!
 
 // All of this under DirectX 9..
 
 
 

Ill post a full project if something interesting happens.

Chow!

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 8:34 pm
by Vectrotek
Here is the "FusionBall" test model..
http://s000.tinyupload.com/?file_id=316 ... 8718575137

This animated "*.b3d" does not have the textures assigned to it
in the model file data itself because I usually assign them in Irrlicht.
The Textures are however included.
Note: The Normal map is in "Normal, Specular, Gloss" (NSG) format.
Just the X and Y of the normal is used as we can extract
the Z component with a manipulation mentioned in an earlier post.
You can easily just "whiten" the Blue channel with a bitmap editor like photoshop.
Realtime normalisation would then reult in a slightly deviated normal which is
still sufficient for testing. (I can post a vanilla Normal Map if you like)

I'm also posting a screengrab of the UV map because the model is essentially
mirrored along TWO axes simply because this really tests your tangents. (space saving technique)
(it already works in GLSL so I consider it a safe testing model)

Fusion Ball UV's
Image

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 8:44 pm
by Vectrotek
So Glitch.. Why can't I simply add Matrices and things in my Appcode and HLSL shader like other languages?
Why the error messages? Take your time, I'm in no hurry! :)
I still develop and test "concepts" in GLSL because at this stage I know whats going on there..
(a new procedure that bases fog on the distance of fragments or pixels from a given plane, i.e. point and normal is in the works)
It would be great if I could do all this work in HLSL! Let me know what you think..
Thanks!

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 9:07 pm
by Vectrotek
This is how far I got.. I can see the Binormals.
I dont know what the matrices had done to them though.
(with row and column major order etc)
Im working on a lit scene sothat I can use the Test Model.
Now that I've got Rendermonkey more interesting things could also happen.

Image

Re: Bump mapping for Animated meshes

Posted: Mon Oct 05, 2015 10:05 pm
by The_Glitch
The only thing about rendermonkey is that it handles things a lot of things behind the scenes for you. When I get some free time I'll look more into this thread.

Re: Bump mapping for Animated meshes

Posted: Tue Oct 06, 2015 11:35 am
by Vectrotek
That's true, but one might be able to emulate some of these "backstage things".
Once I get past this error message I keep getting.. I'll definitely try some Rendermonkey things.
The "Illumination" set of HLSL shaders are quite straight forward, just, again Matrix Matchup will have to be done.
If you render the "Fusion Ball" with your app, I'd like to see a screenshot of it with tangents/binormals
in "range-compressed" form. i.e.

Code: Select all

 
   result.x = (Tn.x / 2.0) + 0.5; // For Tangents..
   // or..
   result.x = (Bn.x / 2.0) + 0.5; // For Binormals..
 
Currently looking at the differences between GLSL and HLSL of this very set of shaders..

Re: Bump mapping for Animated meshes

Posted: Tue Oct 06, 2015 12:12 pm
by Vectrotek
Irllicht GLSL is cool but HLSL would be great.

SKULL BOX
Image

CHAINS:
Image

Re: Bump mapping for Animated meshes

Posted: Tue Oct 06, 2015 12:12 pm
by Vectrotek
ARMADILLO:
Tiny Pic has issues..

DROIDFACE:
Image

Re: Bump mapping for Animated meshes

Posted: Tue Oct 06, 2015 12:14 pm
by Vectrotek
GUN:
Image

MULTICHARS:
Image

Now all I want is a working HLSL basis.