Page 9 of 17

Re: Bump mapping for Animated meshes

Posted: Tue Oct 06, 2015 7:51 pm
by Vectrotek
There is something wrong with my HLSL implementation..
I certainly don't expect some parts of an HLSL shader to work and then
see a rendered diffuse map which was not fed into the shader.

I have "tex2D(ColorSampler,IN.UV).rgb" yes, in the shader but I didn't feed "ColorSampler" from the Appcode!
When I do the system complains! (another headache)
I can only guess that..
"AniMeshNode0001->setMaterialTexture(0, TheDriver->getTexture("Data/0013_FUSION_BALL/NSG_MAP.tga"));"
somehow finds it's way to the final render either through the GPU or in another way..
O.K. This is an Irrlicht and HLSL thing.

Re: Bump mapping for Animated meshes

Posted: Tue Oct 06, 2015 8:02 pm
by Vectrotek
This render shows how adding a bit of "RED" to the final colour proves
that the Shader was activated and that it renders.
What is completely wierd though is that the Diffuse Image mapped onto the ball
was NOT fed to the shader. So HOW did it get there?
Image

Re: Bump mapping for Animated meshes

Posted: Wed Oct 07, 2015 8:10 pm
by The_Glitch
Think of it like this, the diffuse texture I believe loads when the file is loaded, depending on the file type. It's basically a fallback if your shader doesn't compile or has errors. The model and usually it's diffuse texture will be displayed but the intended results won't be there due to the shader not compiling or an error in it. It's a pretty normal thing in Irrlicht.

Re: Bump mapping for Animated meshes

Posted: Wed Oct 07, 2015 9:50 pm
by Vectrotek
Thanks. Maybe you could look at this..

Tell me Glitch.. Are you generating Binormals in your Shader by crossing Tangents with Normals?


Scratching in strange and dark corners for answers..
Image

I could not find the Project and code for this, but I've learned
a lot from the HLSL.. By "sio2"

If you recognize the graphics you'll know what to do with this..

Code: Select all

 
 
 // "sio2" wrote the original code for this cool shader, but the App Project would have been great to have! 
 
 // Note: I only posted this because someone out there like me might benefit from it..
 // For me it shed some light on my problem..
 // I still don't understand why I sometimes get error messages, but it renders..
 
 // Just replace the HLSL code with this..
 // I changed a few things..
 
 bool parallaxMapping; 
 // Ensure samplers read from correct registers
 sampler2D  decalMap    : register(s0); // Seen these before..
 sampler2D  normalMap   : register(s1); // O.K!
 sampler2D  heightMap   : register(s2); // Mmmm..
 sampler2D  glossMap    : register(s3); // Aha!
 
 float4x4   mWorldViewProj;     // World * View * Projection transformation
 float4x4   mInvWorld;          // Inverted world matrix
 float4x4   mWorldView;         // Transposed world matrix
 float3     mEyePos;            // Eye position
 float3     mLightPos;          // Light position
 float4     mLightAmbient;      // Light ambient colour
 float4     mLightDiffuse;      // Light diffuse colour
 
 // irr::video::S3DVertexTangents
 struct VS_IN 
  {float3 Pos      : POSITION;
   float3 Normal   : NORMAL;
   float4 Color    : COLOR0;
   float2 Tex0     : TEXCOORD0;
   float3 Tangent  : TEXCOORD1; // This gives us our Tangents & Binormals..
   float3 Binormal : TEXCOORD2; // Do not use - binormal calculated in shader  (Mmmm..)
                                // The Appcode "SHOULD HAVE" done this!
 
   // float3 Tangent  : TANGENT; // THIS IS WHAT IT WAS (which Im not sure about, but could be old imlementation)
   // float3 Binormal : BINORMAL; // Do not use - binormal calculated in shader (Mmmm..)
   // Uncomment the above two (and comment the others) to see that "TANGENT" and "BINORMAL" 
   // Channel Semantics don't give joy.
  };
 
 // Output from from Vetex Shader and input to Pixel Shader
 struct VS_OUT 
  {float4 Pos            : POSITION;
   float2 TexCoord       : TEXCOORD0;
   float3 lightVec       : TEXCOORD1; // Dont serve as Tangent anymore.. O.K.
   float3 halfVec        : TEXCOORD2;
   float3 eyeVec         : TEXCOORD3;
   float3 PassedValue    : TEXCOORD4; // NEW.. I wanted to see things in the render..
   
  };
  
 // -------------------------------------------------------
 // Vertex shader's main entry point.
 
 // Bump mapping with parallax offset.
 // -------------------------------------------------------
 VS_OUT vertexMain(VS_IN In)
  {VS_OUT Out = (VS_OUT)0;
   // output vertex position
   Out.Pos = mul(float4(In.Pos,1), mWorldViewProj);
   float3 n = normalize(mul((float3x3)mInvWorld, In.Normal));
   float3 t = normalize(mul((float3x3)mInvWorld, In.Tangent));
   float3 b = normalize(mul((float3x3)mInvWorld, In.Binormal)); // Again, Apcode MUST do this..
   //float3 b = cross(n, t);  // This gives an apparent desired visual effect, but believe me, don't do it..
                              // Feel free to debate this.. (I really tried but no joy, and after seeing
                              // Nvidia FX Composer examples also steer clear of this, I'm convinced)
                              // Things may have changed since, so...
 
   // output texture coordinates for decal and normal maps
   Out.TexCoord = In.Tex0;
   // transform light and half angle vectors by tangent basis
   // mLightPos = mEyePos; // WE "CANNOT" ASSIGN INPUT VARIABLES FED FROM APPCODE ??..
   float3 LocalLightPos = mLightPos;
   //HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 
   // Why does this cause the error messages????
   // LocalLightPos = mEyePos;  // The inherent problem with this becomes apparent when you uncomment this..
                                // For some reason I cannot fathom it also causes error messages but renders.
   
   float3 TempVal;
   TempVal.x = mEyePos.x;
   TempVal.y = mEyePos.y;
   TempVal.z = mEyePos.z;
   float3 SecLightPos = LocalLightPos;
   
   // Uncomment this to see in the console window why I say what I say..
   // SecLightPos.x = TempVal.x; // Neither one of these are FED, so what is the problem?
   // SecLightPos.y = TempVal.y; // ALSO CAUSES ERRORS! (*&^#^$)
   // SecLightPos.z = TempVal.z; // ..
   
   //HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
   
   
   // float3 Silencer = mLightPos;
 
   float3 v;
    v.x = dot (float3 (SecLightPos), t);
    v.y = dot (float3 (SecLightPos), b);
    v.z = dot (float3 (SecLightPos), n);
 
 
   // v.x = dot (float3 (mEyePos), t);  // ALSO CAUSES ERRORS! (D3D HLSL is like drinking bitter medicine)
   // v.y = dot (float3 (mEyePos), b);  // Simply wanted to temporarily assign Eye pos to light pos..
   // v.z = dot (float3 (mEyePos), n);
   
   
   Out.lightVec = normalize (v);
   // float3 halfVector = normalize(mLightPos - Out.Pos); // Order looks right..
   // float3 halfVector = normalize(Out.Pos - mLightPos); // Order looks right..
 
   // float3 halfVector = normalize(SecLightPos - Out.Pos);
   
    float3 halfVector = normalize(mEyePos - Out.Pos);
    
    
   halfVector = normalize(halfVector + mEyePos);
   v.x = dot (halfVector, t);
   v.y = dot (halfVector, b);
   v.z = dot (halfVector, n);
   Out.halfVec = normalize (v);
   float3 eyeVec = float3 (mul((float3x3)mWorldView, In.Pos));
   v.x = dot(eyeVec, t);
   v.y = dot(eyeVec, b);
   v.z = dot(eyeVec, n);
   Out.eyeVec = normalize(v);
   
   // Out.PassedValue   = In.Tangent;  // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   
   // Uncomment different ones..
   // Out.PassedValue   = t;   
   // Out.PassedValue   = b; // This gives no joy if you didn't try cross with normal
   // which isn't a good idea anyway..
    
   Out.PassedValue = n;  // Gives Vertex Normal..
   
   
   return Out;
  }
 
 
// -------------------------------------------------------
// Fragment shader's main entry point.
// Bump mapping with parallax offset.  I take inspiration
// from nVidia's bump mapping demo for this program.
// -------------------------------------------------------
 
 float4 pixelMain (VS_OUT In) : COLOR
  {float2 texCoords;
   if (parallaxMapping)
    {// use parallax mapping
     float height = tex2D(heightMap, In.TexCoord.xy).x;
     height = height * 0.04 - 0.02;
     float3 eye = normalize(In.eyeVec);
     texCoords = In.TexCoord.xy + (eye.xy * height);
    }
   else 
    {// standard bump mapping
     texCoords = In.TexCoord.xy;
    }
   // fetch normal from normal map, expand to the [-1, 1] range, and normalize
   float3 MappedNormal = tex2D (normalMap, In.TexCoord.xy);
   // float3 normal = 2.0 * (tex2D (normalMap, In.TexCoord.xy).rbg - 0.5); // "rbg"??!
   float3 normal = (2.0 * MappedNormal) - 0.5;
   normal = normalize (normal);
   // compute diffuse lighting 
   float3 diffuse = max (dot (In.lightVec, normal), 0.0) * mLightDiffuse.rgb;
   float3 decalColor = tex2D(decalMap, texCoords).rgb;
   // compute specular lighting 
   float3 specularCoeff = tex2D (glossMap, texCoords).rgb;
   float specular = max (dot (In.halfVec, normal), 0.0);
   specular = pow (specular, 8.0);
   // output final color
   float3 finalDiffuse = diffuse * decalColor;
   float3 finalSpecular = specular * specularCoeff;
   
   float4 FinalOutput;
   
   FinalOutput = float4(finalDiffuse + finalSpecular, 1.0) + mLightAmbient;
   
   // Works, but the system screams error messages at you in the console..
   // FinalOutput.x = (In.PassedValue.x / 2.0) + 0.5; // Which depends on actions earlier....
   // FinalOutput.y = (In.PassedValue.y / 2.0) + 0.5; //   See lines 128 to 135..
   // FinalOutput.z = (In.PassedValue.z / 2.0) + 0.5;
   
 
   // FinalOutput.x = (normal.x / 2.0) + 0.5; // WORKS..
   // FinalOutput.y = (normal.y / 2.0) + 0.5;
   // FinalOutput.z = (normal.z / 2.0) + 0.5;
 
   // FinalOutput.x = normal.x;   // WORKS..
   // FinalOutput.y = normal.y;
   // FinalOutput.z = normal.z;
 
   
   // FinalOutput.x = MappedNormal.x;  // WORKS..
   // FinalOutput.y = MappedNormal.y;
   // FinalOutput.z = MappedNormal.z;
   
   FinalOutput.w = 1.0; // Just to be sure..
   
   
   // return float4(finalDiffuse+finalSpecular, 1.0) + mLightAmbient;
   return FinalOutput;
   
   // I am currently trying to call this from my appcode with my data...
}
 
 

Re: Bump mapping for Animated meshes

Posted: Wed Oct 07, 2015 9:58 pm
by Vectrotek
Between the "Cell" shader, Example 10 and others this is the most like what I'd like to do..
HLSL is very fussy about how you handle variables. Very uncomfortable..

Re: Bump mapping for Animated meshes

Posted: Wed Oct 07, 2015 10:17 pm
by The_Glitch
No I'm not generating the Binormals in the shader, I was going to use your code snippet to have irrlicht do it, but It has to be updated to work with shaderpipeline.

Re: Bump mapping for Animated meshes

Posted: Wed Oct 07, 2015 10:20 pm
by Vectrotek
Sorry.. How does this "Pipeline" thing work?

Re: Bump mapping for Animated meshes

Posted: Wed Oct 07, 2015 11:57 pm
by The_Glitch
It's just a different branch of Irrlicht it's mostly the same except for some things.

Re: Bump mapping for Animated meshes

Posted: Sat Oct 10, 2015 9:41 pm
by Vectrotek
HLSL O.K.
Image

Re: Bump mapping for Animated meshes

Posted: Sat Oct 10, 2015 9:42 pm
by Vectrotek
This code was updated in a later post..

Re: Bump mapping for Animated meshes

Posted: Sat Oct 10, 2015 9:43 pm
by Vectrotek
This code was also updated in a later post..

Re: Bump mapping for Animated meshes

Posted: Sat Oct 10, 2015 9:45 pm
by Vectrotek
Shout if you want the Project and *.exe..

Re: Bump mapping for Animated meshes

Posted: Sat Oct 10, 2015 9:45 pm
by Vectrotek
First render.
Image

Re: Bump mapping for Animated meshes

Posted: Sat Oct 10, 2015 9:49 pm
by Vectrotek
This might help with game asset creation:
http://s000.tinyupload.com/?file_id=013 ... 2297253813
Cheers!

Re: Bump mapping for Animated meshes

Posted: Sun Oct 11, 2015 11:56 pm
by The_Glitch
Good job bud.

The_Glitch.