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 »

Virtually limitless physically based lights now in arrays to
HLSL and GLSL..

Image
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

Looks great! So it supports 4 lights, and gives a reflection of the skybox?
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

I've tested it successfully with up to 32 lights. (hypothetically this would be limited to the card, profile or GPU speed etc)
I wanted to post the App (GLSL and HLSL) but then ran into the following problem.

GLSL.. (Still to convert the HLSL)
From the App I feed into Shader the Lights Number, Colours and Positions as an "integer" and "float arrays" i.e. "s32 Arrays" and "f32 Arrays".
(Straight into the Fragment Shader)
(There is a very special trick by which to do this and I couldn't find it documented anywhere!)
That's fine, but I have two machines, the one significantly faster than the other.
So during tea time I test the thing on the office machine and.. I get a BIG Frame rate drop..
Oh no! So I tried all sorts of things ..
Among others I "accidentally" Re-assigned the (uniform integer) "ActiveLightCount" (which results in a GLSL warning)
in the Shader itself.. This value should be, and is, sent from App code as that is where I want to control the amount of lights from.
(I don't want the Shader looping through more Light Indices than what is necessary)
Now, suddenly, because I typed "ActiveLightCount = 32" (In the Shader) the frame rate is way cool!?!
All the while the App STILL sends these arrays and Integers to the Shader! Huh?
It makes no sense to me but isn't critical. I would however have liked to know WHY I get a Frame rate Drop if I Don't
intervene in the Shader by simply re-assigning these (int AND float) values!
To make things even more wacky, I did a test to see if the value was actually fed correctly from the shader and it was proved
that "ActiveLightCount" was actually "32" as I had fed it from the App code!

So.. I simply re-assigned the "ActiveLightCount" to the value already fed by Appcode into the Shader then the Framerate became cool???
It's the sort of thing that makes me lose sleep and to make matters worse, I can't help following
the cool things happening on Guillaum's Stereoscopic topic! (I've a ton of things to do)..

Any opinion?
Last edited by Vectrotek on Fri Dec 04, 2015 9:13 pm, edited 1 time in total.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

The shader codes shows 4 variables for light position, so I thought it was fixed. Will take another look.

That's software for you, a pain in the neck! The shader code is sensitive, global vars cannot be set from the HSLS code, you have to have them as locals, all sorts of limitations with loops, all that unrolling stiff, and each shader model has its own limits.

If you´re using anything less than shader model 3 its very restricted.
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

I haven't yet posted the latest App and Shader code. It still has the small problem mentioned earlier.
Thanks anyhow! I'll post it as soon as I can then you can have a look. It is a strange problem!
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

I see you're online, would you like some snippets?
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

This post was edited.. See [[CORRECTION_XXX]] and [[ADDITION_XXX]]..

Here is the Fragment Shader (Vertex Program is the same)..
You'll see that lights are now in ARRAYS and LOOPED through in the code..

Code: Select all

 
 
 
 // "Vectrotek Shader V2.1"  Jacques Andre Pretorius    email: pretoriusjacq@gmail.com 
 // ToDo: 1 - Falloff Lights (with Conditional Radius) (Irrlicht System? or Custom System?)
 //       2 - Lerped Ambience Emulation
 //       3 - 
 
 #define MAX__LIGHTS 8
 
 uniform sampler2D DTCDSample;              // The "ClipMap" is determined by a "Selected Cutoff Range" somewhere between 0.0 and 1.0 in the
                                            // Diffuse ALPHA Channel. The "Droplet Mask" is also "Fitted In" that way..
                                            // Transparency could also be "Fitted In".. (see the code)
 uniform sampler2D NSGSample;               // Normals (X & Y), Specular and Gloss is encoded into one 32 bit image.
 uniform sampler2D ERMSample;               // These RGB values are "mixed" into the final render in a way that simulates emmision..
 uniform sampler2D CUBEMAPSample;           // WORK-AROUND (Under Irrlicht, a special "Recompile" of the engine makes up to EIGHT images possible)
 uniform sampler2D Image005;                // Reserved.. (engine recompile fine for GLSL but NOT for HLSL!) 
 uniform sampler2D Image006;                // Reserved.. 
 uniform sampler2D Image007;                // Reserved.. 
 uniform sampler2D Image008;                // Reserved.. 
 
 // INTEGERS SEEMS TO SLOW DOWN THE SYSTEM.. IS THIS THE CASE WITH FLOATS TOO?
 
 uniform int       GPURenderMode;           // This Integer, controlled from the User App, changes the RENDER MODE of this Fragment Shader (press buttons 1 to 0..)
 uniform int       PLAECFActive;            // PLAECF* Implemented ot not. (ON by default)..
 uniform int       DropletEnabled;          // Set from App..
 uniform int       ActiveLightCount;        // The light calculation loops index should not exceed this value..
 
 uniform float     ElapsedTime;             // N/A ..
 uniform float     GlobalLightMultiplier;   // To have control over Global Light Brightness from the User App.
 
 uniform vec3      CameraPos;               // The Position of the camera i.e. the EYE..
                                            // For demonstrative purposes we have a light hooked to the camera..
 
 uniform vec3      LightsPosArray[MAX__LIGHTS];      // CRACKED IT!! See how, in the Appcode, this Variable is referred to as "LightsPosArray[0]"..
                                                     // NOW WE HAVE PROPER ARRAYS AND NEED NO MORE DEPEND ON THE "mat4" WORK-AROUND..
                                                     // We DON'T want to send more items than the "[8]" (MAX) from Appcode!
 uniform vec3      LightsColArray[MAX__LIGHTS];      // Colours..
                                            // We need an array of lights from the scene which is either processed 
                                            // for "importance" by the CPU in the code or in here by the GPU.. 
 varying vec2      UVCoordsXY;              // Passed on to here from the Vertex Program..
 varying vec3      VNormal;                 // Effectively (interpolated?) "Fragment Normal" after passing through the Vertex Progam.
 varying vec3      Tangent;                 // The result of a calculation using "Polygon Edge Definitions", "UV Coordinates" and Vertex Normals.
                                            // Tangents, when combined with other 3D Scene parameters like World Matrices, ensure correct
                                            // Normal Mapped Surface Lighting and offers the freedom of having Multiple Vertices
                                            // share the same UV Space.  UV Mirroring is a technique to save space on the physical area used
                                                                       // by a Normal Map Image..
 varying vec3      Binormal;                // Closely related to the Tangent in that it is the Cross Product between The Tangent and the Vertex Normal..
 varying vec3      VertexGLPosition;        // UNSEEN GLSL (attribute) thing as also occurs in HLSL, FX, CG, and CGFX methods.. 
 
 
 // INTERNAL VARIABLES.. 
 vec3              LightDirArray      [MAX__LIGHTS];      // Tested up to 800!! (excepts high values!)
 float             SpecBaseArray      [MAX__LIGHTS];   
 float             DiffBaseArray      [MAX__LIGHTS];
 vec3              DiffColouredArray  [MAX__LIGHTS];
 float             DropletRawArray    [MAX__LIGHTS];
 vec3              DropletColourArray [MAX__LIGHTS];
 float             DropletBaseArray   [MAX__LIGHTS];
 
 
 // WHAT MAKES A VARIABLE NEED THE PREFIX "varying"??
  vec4      CubemapReflection;       // RGBA values aquired from the "CUBEMAPSample" using a cool "Cubemap Refelection Work-around"..
  vec3      SpecColledFINAL;
  vec3      DiffColledFINAL;
  vec4      DiffuseMinusDropletMask; // If the diffuse texture was designed with DROPLET NOT in mind..   [[CORRECTION_001]]
                                            // It simply Subtracts the DROPLET Mask in terms of Percentage from Diffuse.. [[CORRECTION_002]]
 
 
 
 // =============================================================================
 vec4 Interpolate(float Slider, vec4 ArgA, vec4 ArgB) 
  {vec4 OutputVal = ArgB * Slider + ArgA * (1.0 - Slider);
   return OutputVal;
  } // Duh.. Use "lerp"..
 
 
 // =  M A I N  = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 void main()
  {
   // if (ActiveLightCounts == 4) {return;} // It did return so it was 4..
   // SOMETHING ABOUT SETTING THE INTEGERS FROM THE APP AND NOT RE-SETTING THEN IN HERE
   // CREATES A MYSTERIOUS DROP IN FRAMERATE?????
  // ONLY IF THIS VALUE WAS USED IN A "WHILE" OR "FOR" LOOP..
  // What is is about using "ActiveLightCounts " in a FOR loop that slows things down?    [[ADDITION_001]]
  
  
   // WHY DOES RE-ASSIGNING THE VALUES LIKE "ActiveLightCount " to 4 IMPROVE FRAMERATE WHEN IT WAS 4?   [[ADDITION_002]]
   GlobalLightMultiplier = 1.0; // FLOAT CASE..
   GPURenderMode = 1;
   DropletEnabled = 1; 
   PLAECFActive = 1;
 
  // DOING THIS FIXES THE FRAME RATE BUT IT WAS ALREADY SET TO THIS BY APPCODE!!
   ActiveLightCount = 4;  // AAARGH! it WAS 4 before this moment..
 
 
   vec4 MappedDTCDrgba   = texture2D(DTCDSample,UVCoordsXY.xy);   // ALPHA is "Clipmap"..
   vec4 FinalDiffuse; // (XYZ and W) We try not to touch the mapped values as it may cause problems in CG conversions..
 
   vec4 NSGMapZYXW    = texture2D(NSGSample,UVCoordsXY.xy);    // R and G is Normal, B is Specular and ALPHA is GLOSS Map..
 
   // Emmission and Reflection Mask Image..
   vec4 MappedEMRM  = texture2D(ERMSample,UVCoordsXY.xy);  // Emmision Mapping for wider effect domain..
   // == SPEC ==
   //NSGMapZYXW.z *= GPUFloatArray[0][0];
   // == GLOSS ==
   //NSGMapZYXW.w += GPUFloatArray[0][1];
 
   // Fixing UVs in the shader aren't really necessary but for this implementation we have a UV render-mode for tests..
   // This simply fixes them to be view-able in the UV render-mode..
   // Sometimes, with some 3D formats, all the UV Coords are shifted along an axis by 1.0 unit. (which we may or may not have noticed in our modeler)
   // We should really address this in the Apcode as Tangent/Binormal Calculation depends among others on UV Coords...
  // This should be addressed in Appcode and not in the Shader..
 
   vec2 RenderedUVs = UVCoordsXY;
   //*  // This is not a good idea for passes of images that are tiled via NON STANDARD GREATER THAT 1 UNIT UVS!!
   // Wed probably have different shaders for levels that we'd have for skinned characters anyway..
   // This is a new Tangents from WHICH UV SET issue..(most likely the LIGHTMAP type UVs)..
   // if (RenderedUVs.x < 0.0){RenderedUVs.x += 1.0;}
   // if (RenderedUVs.x > 1.0){RenderedUVs.x -= 1.0;}
   // if (RenderedUVs.y < 0.0){RenderedUVs.y += 1.0;}
   // if (RenderedUVs.y > 1.0){RenderedUVs.y -= 1.0;}
   //*/
 
   FinalDiffuse = MappedDTCDrgba;              // This should be the last time we touch Final Diffuse..
 
   vec4 MAPSpecXGlossYORIG = MAPSpecXGlossY;  // So we can render it as it was before it was altered by the "Gloss Controll" keys..
   vec4 MAPDiffORIG = MappedDTCDrgba; // WE NEED MAP DIFF ORIG!!!! (I just have that feeling..)
   float LerpSliderDiffmap; // How much is the final render is "lerped" toward the Mapped Raw Diffuse Colour..
                           // The true meaning of Ambience is debate-able but lerping to the original mapped colours as a means of
                           // emulating Ambience works fine for me..
   // Get "Un Range Compressed Normals"..
   vec3 UnCompressedNormal;
   
   vec3 UnCompressedNormalXYInverted;
   
   // We IGNORE the incoming Z value (now another free channel) as we use a derivative of Pythagoras's Theorem to aquire Z..
 
   float NormalAmp =  2.0 ;   // default 2.0!!
 
   UnCompressedNormal.x = (NSGMapZYXW.x -0.5) * NormalAmp; // Intersting concept..
   UnCompressedNormal.y = (NSGMapZYXW.y -0.5) * NormalAmp;
  
   // The droplet mask will have to fit into the Diffuse Alpha. Which is very possible as we use the alpha channel for "Clip mapping".
   // Now, Clip mapping requires only a small contrast between pixel intensity allowing us to assign this droplet mask
   // to, say, a value of anything above 60% and as a bonus still giving us a "smooth" border which we shall define in the shader..
   // We could cut of the intensity between 60% and 100% as a finite line which we then convert to a slightly "posterised" softness
   // for the Droplet Mask..
   // Calculate Z on the fly by Manipulating Pythagoras's Theorem.
   UnCompressedNormal.z = sqrt(-(UnCompressedNormal.x*UnCompressedNormal.x) - (UnCompressedNormal.y*UnCompressedNormal.y) + 1.0);
 
    // normalize(UnCompressedNormal); // Only if your normal baking wasn't cool. (neglible) 
    // Note XNormal bakes a slightly better quality than Blender..
    vec3 FinalNormal;
  
    // DO NOT TRY TO CALCULATE THE BINORMALS IN THE SHADER..
    // =============================================================
    // This procedure is where the Normal is "Adjusted" by the Tangent and Binormal..
    // Note: In Appcode we update these at every frame if we want Physically Correct Lighting..
    FinalNormal = normalize(
                            (UnCompressedNormal.x * Tangent)
                           +(UnCompressedNormal.y * Binormal)
                           +(UnCompressedNormal.z * VNormal) 
                           );
 
   // =============================================================   
   // What follows is a "Broken Down" version of the above for us to see how it works..
   // Comment the one and uncomment the other to see..
   // =============================================================   
   /*
   vec3 AddA;  vec3 AddB;  vec3 AddC;
   // - T A N G E N T - 
   AddA.x = UnCompressedNormal.x * Tangent.x;  // WAS STATIC, NOW DYNAMIC!
   AddA.y = UnCompressedNormal.x * Tangent.y;
   AddA.z = UnCompressedNormal.x * Tangent.z;
   // - B I N O R M A L - 
   AddB.x = UnCompressedNormal.y * Binormal.x; // WAS STATIC, NOW DYNAMIC!
   AddB.y = UnCompressedNormal.y * Binormal.y;
   AddB.z = UnCompressedNormal.y * Binormal.z;
   // - V E R T E X   N O R M A L - (updated with skinned deformation) 
   AddC.x = UnCompressedNormal.z * VNormal.x; // DYNAMIC !!
   AddC.y = UnCompressedNormal.z * VNormal.y;
   AddC.z = UnCompressedNormal.z * VNormal.z;
   vec3 AddFin;
   AddFin.x = AddA.x + AddB.x + AddC.x;
   AddFin.y = AddA.y + AddB.y + AddC.y;
   AddFin.z = AddA.z + AddB.z + AddC.z;
   FinalNormal =  normalize (AddFin);  
   //*/
      // =============================================================
   
   // - NORMALISED DIRECTIONS - (used for Diffuse and Specularity) 
   vec3 ViewDir     = normalize(CameraPos - VertexGLPosition);
   // CALCULATE REFLECTION. (Combining into final render done elsewhere)..
   //  vec3 ReflectVec = normalize(vec3(reflect(ViewDir, VNormal)));  // Reflection based on Vertex Normals..
   vec3 ReflectVec = normalize(vec3(reflect(ViewDir, FinalNormal)));  // Reflection based on Normal Mapped Normals..
 
   // for irrlicht, set z coordinate to y coordinate (rotation of coordinates)..
   float TZ = ReflectVec.y;  float TY = ReflectVec.x;
   ReflectVec.x = ReflectVec.z;  ReflectVec.y = TY; ReflectVec.z = TZ;
 
   vec3 AbsReflect = abs(ReflectVec);
   vec2 sky_coord; // texture coordinates of the sky point viewed..
   // Selection of the face to use (so texture sector)..  (See Jimmy's work around..)
   // Note that the following pretty much depends on how you had laid out your six images in the "PseudoCubemap"..
   // It is a cool work around done by "jimmy_beyerly" that will be used here until Irrlicht
   // gets proper cube mapping working..
   if (ReflectVec.z >= AbsReflect.x && ReflectVec.z >= AbsReflect.y)
    {sky_coord = vec2( ReflectVec.x / ReflectVec.z +  4.0 , ReflectVec.y / ReflectVec.z +  2.0 );}  // Top.. (6)   Y Negative ..
   else if (ReflectVec.y >=  AbsReflect.x && ReflectVec.y >= AbsReflect.z) 
    {sky_coord = vec2( -ReflectVec.x / ReflectVec.y +  2.0 , ReflectVec.z / ReflectVec.y);}      // Front.. (2)  .. X_POSITIVE  
   else if (ReflectVec.x >=  AbsReflect.y && ReflectVec.x >=  AbsReflect.z)
    {sky_coord = vec2(  ReflectVec.y / ReflectVec.x +  4.0 , (  ReflectVec.z / ReflectVec.x));}   // Left.. (3)   .. Z_NEGATIVE    MAIN..
   else if (ReflectVec.z <= -AbsReflect .x && ReflectVec.z <= -AbsReflect .y)
    {sky_coord = vec2(-ReflectVec.x / ReflectVec.z ,    ReflectVec.y / ReflectVec.z +  2.0 );}    // Bottom (4)..   Y Positive ..O.K.
   else if (ReflectVec.y <= -AbsReflect .x && ReflectVec.y <= -AbsReflect .z)
    {sky_coord = vec2(-ReflectVec.x / ReflectVec.y +  2.0 , -ReflectVec.z / ReflectVec.y +  2.0 );}   // Back (5)..  ..X NEGATIVE  
                                                          // Why dont ".ys" cause an error but .yd does.. 
   else
    {sky_coord = vec2( ( ReflectVec.y / ReflectVec.x ) + ( 0.0 ), (   -ReflectVec.z / ReflectVec.x ) - ( 0.0 )   );}     // (1)Right    ..  Z_POSITIVE   
   CubemapReflection = texture2D(CUBEMAPSample, (sky_coord + 1.0) * (1.0 / 6.0) );
   // Done getting the right RGB values for Reflection.
   // How we mix this into the final render is up to you..
   // Here we have a special "ERM" (Emission Reflection Map) that apart from Emission has its "Alpha Value" determine what reflects and what doesnt.
   // For these maps a good understanding of how to use bitmap editors like Photoshop and Gimp is needed.
 
   // These are the Normalized Directions of the light positions relative to the surface of the object being lit..
   
 
   //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
   // D I F F U S E  Shading..
   // NEW..
   DiffColledFINAL.xyz  = vec3 (0.0 , 0.0 , 0.0); // Seems necessary but is it? (Could different cards / compilers have an issue?)
 
   for (int LghtI = 0; LghtI < ActiveLightCount; LghtI++)
      {DiffColouredArray [LghtI].xyz =
         max(dot(FinalNormal, (normalize(LightsPosArray[LghtI] - VertexGLPosition))),0.0) * LightsColArray[LghtI].xyz * GlobalLightMultiplier; // All xyz..
       DiffColledFINAL += DiffColouredArray [LghtI];
       SpecBaseArray [LghtI] =
         clamp(pow(clamp(dot(normalize((ViewDir + normalize(LightsPosArray[LghtI] - VertexGLPosition))),
                             FinalNormal),0.0,1.0),
                             pow(2.0, (NSGMapZYXW.w * 10.0)) ), 0.0 , 1.0 );
       SpecColledFINAL += LightsColArray[LghtI] * GlobalLightMultiplier * SpecBaseArray [LghtI] ;
      }
 
   // S P E C U L A R  Shading..
   if (PLAECFActive == 0)
    {for (int LghtI = 0; LghtI < ActiveLightCount; LghtI++)
      {SpecBaseArray [LghtI] =
         clamp(pow(clamp(dot(normalize((ViewDir + normalize(LightsPosArray[LghtI] - VertexGLPosition))),
                           FinalNormal),0.0,1.0),  NSGMapZYXW.w * 77.777 ), 0.0 , 1.0 );
      SpecColledFINAL.xyz += LightsColArray[LghtI].xyz * SpecBaseArray [LghtI]  * GlobalLightMultiplier; 
      }
    }
   // That was the "Normal" Specularity method..
 
   // start **** PRETORIUS's LINEARLY ACCESSED EXPONENTIAL CURVE FORMULA *** 
 
// /*
   if (PLAECFActive == 1)
    {for (int LghtI = 0; LghtI < ActiveLightCount; LghtI++)
      {SpecBaseArray [LghtI] =
         clamp(pow(clamp(dot(normalize((ViewDir + normalize(LightsPosArray[LghtI] - VertexGLPosition))),
                             FinalNormal),0.0,1.0),
                             pow(2.0, (NSGMapZYXW.w * 10.0)) ), 0.0 , 1.0 );
       SpecColledFINAL.xyz += LightsColArray[LghtI].xyz * SpecBaseArray [LghtI] * GlobalLightMultiplier;
      }
    }
// */
 
 
   // end **** PRETORIUS's LINEARLY ACCESSED EXPONENTIAL CURVE FORMULA *** 
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 
 
   // SpecColledFINAL.xyz = 0; // reset.. Necessary?
  // for (int LghtI = 0; LghtI < ActiveLightCount; LghtI++)
  //  {SpecColledFINAL += LightsColArray[LghtI] * GlobalLightMultiplier * SpecBaseArray [LghtI] ;
  //  }
   // SPECULAR (quite colourless in itself) is mathematically based on REFLECTION and should thus reflect LIGHT COLOUR..
   vec3 SpecularColour; // (Intensity)..
   SpecularColour.xyz =  NSGMapZYXW.z * SpecColledFINAL.xyz ;  // where .z (blue channel) is the Specular Intensity and NOT Glossyness..
 
   // Just dim the other lighting effects so we can see what emits light..
   if (GPURenderMode == 10)          // Vertex Normals..
    {DiffColledFINAL.xyz *= 0.3; // Tweak..
     SpecularColour.xyz *= 0.6;       // Tweak..
    } 
 
   // " D R O P L E  T   S H A D E R "   P A R T   1   o f   3 ..   
   // This effect is useful for gems and particularly the lenses and irisses in eyes..
   DiffuseMinusDropletMask.xyz = FinalDiffuse.xyz; // (NOT "w") DO THIS BEFORE OTHER CALCULATIONS.. // XXX 
   // MAPDiffORIG
 
   if (DropletEnabled == 1)
    {// Start Droplet..
     float GlobalDropConcavity = -1.0; // Think of the "Convexity" of the "Lens" of an eye then of the "Concavity" of the "Iris"..
     vec3 AlteredUCN = UnCompressedNormal;
     // vec3 AlteredUCN = FinalNormal; /// NO!!
     // T H E R E   I S   A   B E T T E R   W A Y ! ! INTERVENE AT IMAGE CREATION PHASE!!!!!!
     // UnCompressedNormalXYInverted
     // Invert the X and Y normals to simulate the Concavity of an Iris or back of a gem..
     AlteredUCN.x *= GlobalDropConcavity;    // Tweakable value.. Originally -1.
     AlteredUCN.y *= GlobalDropConcavity;    // It is not a mathematically perfect thing so tweaking is O.K..
     // AlteredUCN.x = UnCompressedNormalXYInverted.x;    // Tweakable value.. Originally -1.
     // AlteredUCN.y = UnCompressedNormalXYInverted.y;    // It is not a mathematically perfect thing so tweaking is O.K..
     // vec3 DropletNormal = normalize((AlteredUCN.y * Binormal)  // The "Altered Normal" is an Inverse of the X and Y of the
     //                               +(AlteredUCN.x * Tangent)   
     //                               +((AlteredUCN.z * VNormal) * 1.0)  ); // "Original Normal" with the Z of the Normal UNTOUCHED..
     // This 1.0 could be used to flatten the concavity a bit on the Normal Plane..
     // Remember to change these once we get Skinned Deformation right..
     vec3 DropletNormal = normalize((AlteredUCN.y * Binormal)  // The "Altered Normal" is an Inverse of the X and Y of the
                                   +(AlteredUCN.x * Tangent)   
                                   +((AlteredUCN.z * VNormal) * 1.0) );
     float GlobalDropFact = 1.0;
     float GlobalDropPhong = 8.0;  // "Tightness" of "Reversed" back light (usually 8.0)..
 
 
     // - DROPLET FOR ALL ALL LIGHTS - 
     // We could also have DROPLET work for ONE OR SELECTED LIGHTS ONLY..
     vec3 DropletFINAL;
      for (int LghtI = 0; LghtI < ActiveLightCount; LghtI++)
        {DropletBaseArray [LghtI] =
         clamp(pow(clamp(dot(normalize((ViewDir + normalize(LightsPosArray[LghtI] - VertexGLPosition))),
                             DropletNormal),0.0,1.0),  NSGMapZYXW.w * 16.0 ), 0.0 , 1.0 );
         DropletColourArray[LghtI].xyz = DropletBaseArray [LghtI] * LightsColArray[LghtI].xyz;
         DropletFINAL += DropletColourArray[LghtI];
 
      }
   float DropletMask = 0.0; // What is our guarantee that variables under Shaders are always initialized as ZERO..
 
 
   // This is almost as cool as Binary Image Encoding but not quite!
   if (MappedDTCDrgba.w > 0.6) // Referring to the Upper 40% of Alpha Intensity..
    {DropletMask = (MappedDTCDrgba.w - 0.6) * 2.5; // Convert our Upper 40% into 100% for smooth bordering..
    }
   FinalDiffuse.xyz *= (1.0 - DropletMask); // Darken the areas covered by the droplet mask..
    
   // This is now added to the masked area.. Multiplication instead of "if ()" ensures smooth transition..
   // If Normal Map alpha is the determining factor.. (with NSG this is not possible..)
   FinalDiffuse.xyz += DropletFINAL.xyz * MappedDTCDrgba.xyz * DropletMask;
   // See how "Clip Cutoff" occurs at just below 50% grey allowing us
   // some latitude above that value.. (We use above 60% to be safe)..
  } // END if droplet enabled..
 
 //------------------------------------------------ ----- ---- --- -- -
 
    // FinalDiffuse = MappedDTCDrgba; // Re-apply the MASKED mapped diffuse to Gl_Col before further diffuse shading.. 
   FinalDiffuse.xyz *= DiffColledFINAL.xyz;
 
 
 
   if (GPURenderMode == 0)  // -- LERPED --  () 
    {// INTERPOLATE BETWEEN THE RAW MAPPED DIFFUSE COLOUR AND THE SHADED COLOUR AS A WAY OF CONTROLLING AMBIENT LIGHTING..
     // Often Misunderstood, the "AMBIENT" value for a scene is merely how much of the ORIGINAL MAPPED DIFFUSE COLOUR is rendered..
     // "Ambience" in my understanding is NOT REALLY a "Material Specific" attribute but rather a "Scene Specific" attribute..
     // "Ambience" could even be expressed as the render PLUS a perentage of the Originally Mapped Colour..
     // For this wed need to KEEP SPECULAR UNTOUCHED.. The concept is debatable...
     // Keep pressing 1, 2 and 0 on the keyboard during runtime to understand the concept..
     // float AmbientSlider = 0.5;  // 0 is pure MAPPED values and 1 is pure SHADED values.. 0.85 is a good balance when considering "Droplet Shading"..
     // gl_FragColor = Interpolate(AmbientSlider, DiffuseMinusDropletMask, gl_FragColor  );
     
     LerpSliderDiffmap = 0.8; // 0.5 - middle ; 0.0 = full LEFT Parameter ; 1 = full RIGHT Parameter..
     
     // THIS SHOULD REALLY EXCLUDE THE SPECULAR HIGHLIGHTS AND BE DONE BEFORE SPECULAR IS MIXED IN!!
    }  else {LerpSliderDiffmap = 0.8;} // 1.0 says all the way to the Second (fragcolor) value..
 
    CubemapReflection.xyz *= MappedEMRM.w;  // SHOULD BE REFLECTION MASK..
 
    int ReflectionMode = 1;
 
    if (ReflectionMode == 1)
     {FinalDiffuse.x -= (MappedEMRM.w * 1.0); // If we don't design the Diffuse Bitmap with Reflection in mind.. (same thing goes for Droplet Effect)
      FinalDiffuse.y -= (MappedEMRM.w * 1.0);
      FinalDiffuse.z -= (MappedEMRM.w * 1.0);
     }
    if (ReflectionMode == 2)
     {// OR this..
      FinalDiffuse.x *= 1.0 - (MappedEMRM.w * 1.0); // If we dont design the Diffuse Bitmap with Reflection in mind..
      FinalDiffuse.y *= 1.0 - (MappedEMRM.w * 1.0);
      FinalDiffuse.z *= 1.0 - (MappedEMRM.w * 1.0);
     }
    vec4 FinalOutput = Interpolate(LerpSliderDiffmap, MappedDTCDrgba , FinalDiffuse);
    // FINAL REFLECTION "ADD"..
    FinalOutput.xyz += CubemapReflection.xyz;
    // FINAL SPECULAR "ADD"..
    FinalOutput.xyz += SpecularColour.xyz;
    gl_FragColor.xyz = FinalOutput.xyz;
    gl_FragColor.w = MappedDTCDrgba.w;  // Ensures our Clipmap stays the way we adjusted it..
 
    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
    
    //|||  SHADER COMMANDS  ||||||
    // deleted for space..
  }// -- END -- 
 
 
Last edited by Vectrotek on Fri Dec 04, 2015 9:21 pm, edited 2 times in total.
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 GLSL callback version: (bit untidy still)

Code: Select all

 
     if ( SelectedDriverType == EDT_OPENGL)  // The HLSL version looks similar (I'll post it later)
      {//                                                                                                                                              
       M01World = TheDriver->getTransform(video::ETS_WORLD); // For GLSL this is all we need!
       TheMATRENDServices->setVertexShaderConstant("M01World", M01World.pointer(), 16);
       TheMATRENDServices->setPixelShaderConstant("DTCDSample",      (s32*)(&TexAddresses [DTCD_LAYER]), 1);      
       TheMATRENDServices->setPixelShaderConstant("NSGSample",       (s32*)(&TexAddresses [NSG_LAYER]), 1);  
       TheMATRENDServices->setPixelShaderConstant("ERMSample",  (s32*)(&TexAddresses [ERM_LAYER]), 1);
       TheMATRENDServices->setPixelShaderConstant("CUBEMAPSample",      (s32*)(&TexAddresses [CUBE_MAP_LAYER]), 1);  // I4 IMAGE O.K.
       // Here we have our old MAX 4 Image thing solved to a degree except that for HLSL, an engine recompilation has issues. (GLSL is O.K. however).
       // This is probably due to the DX API by the Irrlicht bigshots being a different version to my DX API!!
       // This will definitely have to be solved..
 
       // Now.. I've disabled this "8 Image Fix" for now, because this program harnesses both GLSL and HLSL and as mentioned,
       // my particular engine recompile (which seems to look at my DX API) causes problems with HLSL..
       // I am however happy enough with progress to ignore this and continue..
       //TheMATRENDServices->setPixelShaderConstant("Image005",     (s32*)(&TexAddresses [IMAGEX005]), 1);       // I5 IMAGE  O.K. (after engine recompile)
       //TheMATRENDServices->setPixelShaderConstant("Image006",     (s32*)(&TexAddresses [IMAGEX006]), 1);       // I6 IMAGE  O.K.
       //TheMATRENDServices->setPixelShaderConstant("Image007",     (s32*)(&TexAddresses [IMAGEX007]), 1);       // I7 IMAGE  O.K.      
       //TheMATRENDServices->setPixelShaderConstant("Image008",     (s32*)(&TexAddresses [IMAGEX008]), 1);       // I8 IMAGE  O.K.
       //  CGparameter cgEnvironmentMap;   // Textures..  WHAT IS THIS CG THING'S COUNTERPART IN GLSL? (comes from CG!!)
       TheMATRENDServices->setPixelShaderConstant("CameraPos", &CameraPositionFRAG.X, 3);    // see how we have the ".x" to indicate the first in an array..
                                                                                             // We also don't need the FOURTH item..
       // ARRAYS POSSIBLE!!
       TheMATRENDServices->setPixelShaderConstant("LightsPosArray[0]", (f32*)(&LightsPosArray[0].X), (ACTIVE_LIGHT_COUNT * 3));
       // see how we have the "[0].X" indicating [0],
 
       TheMATRENDServices->setPixelShaderConstant("LightsColArray[0]", (f32*)(&LightsColArray[0].X), (ACTIVE_LIGHT_COUNT * 3));
       // SEE HOW the "INDEX NUMBER" in the "STRINGED NAME" IS "LightPos001[0]"! In the Shader it is declared as "LightPos001[16]"!
       // This solves a LOT of problems..
       // Also see how the "Count" value is "Max Array Index" * "vector3df's Float ItemCount" which is THREE..
       // This essentially allows us to use "Loops" in the shader for our "Many Lights"..
       // (but, the Slow Loop Problem...)
 
       // The actual act of sending these variables don't really result in a penalty..
       // It is the accessing them in the Shader that does..
       // Inexplicably when these values are manually "RE ASSIGNED" in the shader code the TIME PENALTY DISSAPEARS.
       // I Could find no logical explanation for this!!
       // HOW MUCH OF THIS IS HARDWARE RELATED?????
       // TRY PASSING THROUGH THE VERTEX PROGRAM????  (tried, but no joy)
 
       TheMATRENDServices->setPixelShaderConstant("GlobalLightMultiplier", (f32*)(&GlobalLightMultiplier), 1);
       PLAECFActive = 1;
       
       // "ActiveLightCount" is sent to the shader correctly but again, if used inside any type of loop, then we have a problem with a drop in framerate.. WHY?
       // Simply typing "ActiveLightCount = (AnyValue)" fixes this frarate drop.. WHY? 
       TheMATRENDServices->setPixelShaderConstant("ActiveLightCount", (s32*)(&ActiveLightCount ), 1); // Used for Light loops inside the Shaders..
       TheMATRENDServices->setPixelShaderConstant("PLAECFActive",  (s32*)(&PLAECFActive) , 1);
       DropletEnabled = 1;
       TheMATRENDServices->setPixelShaderConstant("DropletEnabled",  (s32*)(&DropletEnabled) , 1);
       TheMATRENDServices->setPixelShaderConstant("GPURenderMode",  (s32*)(&GPURenderMode) , 1);
      }//                                                                                           
 
Last edited by Vectrotek on Fri Dec 04, 2015 9:24 pm, edited 2 times in total.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

Looks good!

Could you send me a link to your model above, I´d like to see how (bad) it looks using my shader! ;)
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

@robmar..
Only if you promise a screenshot! :)
Here it is..

http://s000.tinyupload.com/?file_id=689 ... 7757769568

I use special image maps that use different channels for shader data.
I gave you a version that includes the most used formats like Diffuse, Normal and Specular.
There is a Glossmap which you probably wont use unless you check how I handle
specular and gloss in my previous posts.
It is an Alias Wavefront "*.obj" model. (I work from Blender with my characters in a 20 X 20 cube)
This one I haven't skinned yet..
By the way, check out http://www.tf3dm.com if you want
test models. (I usually put the image maps through some processing though)
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Have a look at the "*.mtl" file..

Code: Select all

 
newmtl S_A
Ka 0 0 0
Kd 1 1 1
Ks 1 1 1
illum 2
Ns 8
map_Kd DIFFUSE_MAP_A.png
# map_bump NORMAL_MAP_A.png # When Irrlicht sees this, it implements an internal "bumpmap" 
                                                    # routine which OVERRIDES YOUR NORMAL MAP, so disable it with "#" comment in "*.mtl" lingo..
map_kS SPECULAR_MAP_A.png
map_Ns GLOSS_MAP_A.png    # there is no program that I know of that uses this kind of map successfully. (see PLAECF)
 
newmtl S_B
Ka 0 0 0
Kd 1 1 1
Ks 1 1 1
illum 2
Ns 8
map_Kd DIFFUSE_MAP_B.png
# map_bump NORMAL_MAP_B.png
map_kS SPECULAR_MAP_B.png
map_Ns GLOSS_MAP_B.png
delete the "#" and view it in the free "ASIMP Viewer" for a normal preview..
For Irrlicht, when you load "*.obj" and "*.mtl" comment (#) the Bumpmap reference
because Irrlicht does things with it even if you had invoked your shader thus
"killing" all your normal mapping effort!
(OBJ is what I use for static models because of this flexible MTL file)
If you look at this material file it's almost as if it was written for shaders in mind.
This is quite cool of you consider that this format has been around for long before shaders came out..
Last edited by Vectrotek on Fri Dec 04, 2015 9:31 pm, edited 2 times in total.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

Okay, here is a jpg of your model rendered with the irrlich source pixel shader with HD 4K skydome on reflective surface, with bump mapping.

I did one in red so the bump map is more visible.

http://s000.tinyupload.com/index.php?fi ... 7947447180
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Heyhey! That looks cool! I like the way you have the Red Base Material included!
Vertex Colours?
What are you working on?
(I'm just enjoying the engine, but hope to produce something cool someday)
Is this GLSL or HLSL?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Bump mapping for Animated meshes

Post by robmar »

Thanks! Its just the standard HLSL per pixel shader with bump mapping, with multiple lights.

I set the texture to red just to highlight the bump mapping.

I´m working on a virtual fishtank with fairly realistic looking fish, long project! ;)
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Bump mapping for Animated meshes

Post by Vectrotek »

Fishtank? Yes, that should have all the elements for a realistic render.
Reflection, Refraction, Transparency, Skinning, Bump mapping, Post processing, Multi pass rendering etc etc..
I'd Love to see when done! Enjoy!
Post Reply