   Nvidia's Ocean.fx question (Bumpmapping question)
  Hey all,I was looking over nvidia's ocean sample and had a question regarding their bumpmapping implementation. In their input structure, they ask the program for the vertex's normal, tangent, and binormal vectors. While I kind of understand how to acquire these, they don't seem to use them anywhere. How does the program take these into account?( Here is the ocean.fx file for reference: )http://www.efd.lth.se/~d00jkr/asr/Ocean.fxThanks in advance for any help.   
  I´d say it just doesn´t take the normal, binormal and tangent from the input structure into account, but seems to calculate a set of these three vectors of its own based on the evaluateWave function.So I guess the normal, binormal and tangent of the vertex aren´t needed at all and could be left out. Did you try what happens if you take them out? Should yield the same result, I guess.   ;  Yes, I have. This results in just a flat plane that seems to be reflecting the cubemap, but incorrectly.   ;  Here are some screenshots for reference:The water as seen in FXComposer:http://www.freeimagehosting.net/b0c4f89f6f.jpgWhen put in engine:http://www.freeimagehosting.net/c6bd9bc41b.jpg(Note: Ignore the green columns, wood plane, and spheres. The water messing up is that bright bluish plane).   ;  hmm... not sure about it, but it seems like the plane used in the sample from nVidia is subdivided. Is the plane in your engine subdivided, too? Because if it is not it might be that the evaluateWave and evaluateWaveDeriv functions in the shader yield useless results and I think the normal, tangent and binormal on the whole plane would be the same since these functions are executed per-vertex.Furthermore:Do you have a normal map set up? With the undivided plane and no normal map set up I´d guess I´d end up with the screenshot you posted. Otherwise I´m out of guesses, sry ;)   ;  I am loading a normal map into a texture, but not really accessing it anywhere other than setting the proper u,v, coordinates of each vertex. Also, not quite sure what you mean by the plane is subdivided. Could you explain that?Thanks!   ;  Just to give you a brief overview of how the vectors are used. Bump mapping/Normal mapping is a technique where you basically define a new space known as texture space. You define this new space by using 3 vectors. You can think of these vectors as your x, y, z vectors of your new space. So what happens is that you feed these 3 vectors (tangent, bitangent and normal) to your shader. Your shader then constructs a matrix that will be used to transform either your light to this new space which is very easy to do and then according to the normal map (which is located in texture space) light the model/mesh appropriately. This is just a very small breakdown of what bump mapping does.a simple shader would look something like thisfloat4x4 ModelViewProj: WORLDVIEWPROJ; //our world view projection matrixfloat4x4 ModelViewIT: WORLDVIEWIT; //our inverse transpose matrixfloat4x4 ModelWorld: WORLD; //our world matrixfloat4 lightPos; //our light positionfloat4 eyePos;texture texture0;texture texture1; sampler2D texSampler0 : TEXUNIT0 = sampler_state{Texture  = (texture0);    MIPFILTER = LINEAR    MAGFILTER = LINEAR;    MINFILTER = LINEAR;};sampler2D texSampler1 : TEXUNIT1 = sampler_state{Texture   = (texture1);    MIPFILTER = LINEAR;    MAGFILTER = LINEAR;    MINFILTER = LINEAR;}; //application to vertex structurestruct a2v{float4 position   : POSITION0;    float3 normal  : NORMAL;    float2 tex0  : TEXCOORD0;    float3 tangent    : TANGENT;    float3 binormal  : BINORMAL;}; //vertex to pixel shader structurestruct v2p{    float4 position   : POSITION0;    float2 tex0   : TEXCOORD0;    float2 tex1   : TEXCOORD1;    float3 lightVec    : TEXCOORD2;    float att   : TEXCOORD3;    float3 vHalf   : TEXCOORD4;}; //pixel shader to screenstruct p2f{    float4 color    : COLOR0;}; //VERTEX SHADERvoid vs( in a2v IN, out v2p OUT ) {    //getting to position to object space    OUT.position    = mul(IN.position, ModelViewProj);//getting the position of the vertex in the world    float4 posWorld = mul(IN.position, ModelWorld); //IN.position;//getting vertex -> light vector    float3 light    = normalize(lightPos - posWorld);   //getting the eye -> eye Vector    float3 eye = normalize(eyePos - light);   //placing the half vector in the object space    float3 vHalf = normalize(eye - lightPos);    //calculating the binormal and setting the Tangent Binormal and Normal matrix    float3x3 TBNMatrix = float3x3(IN.tangent, IN.binormal , IN.normal); //setting the lightVector    OUT.lightVec = mul(TBNMatrix, light);   //setting the half vector and passing it to the pixel shader    OUT.vHalf = mul(TBNMatrix, vHalf);   //calculate the attenuation    OUT.att = 1/( 1 + ( 0.005 * distance(lightPos.xyz, posWorld) ) );OUT.tex0 = IN.tex0;    OUT.tex1 = IN.tex0;} //PIXEL SHADERvoid ps( in v2p IN, out p2f OUT ){    //calculate the color and the normal    float4 color = tex2D(texSampler0, IN.tex0);/*this is apparently how you uncompress a normal map*/    float3 normal = 2.0f * tex2D(texSampler1, IN.tex1).rgb - 1.0f;//normalize the light    float3 light = normalize(IN.lightVec);   //normalize the half vector    float3 vHalf = normalize(IN.vHalf);   //set the output color    float diffuse = saturate(dot(normal, light));   //calculating the specular component    float specular = pow(dot( normal, IN.vHalf) , 16);   //setting ds(diffuse * specular)Color    float dsColor = 2.0 * (diffuse * specular) + 1.0; //last part is ambient   //multiply the attenuation with the colorOUT.color = IN.att * color * dsColor;} technique bump{    pass p0    {   vertexshader = compile vs_1_1 vs();   pixelshader = compile ps_2_0 ps();    }}Looking at your implementation it seems that its not really bump mapping at all.  You could look at the following tutorial if you want to look at just bump mapping.Other than that. Make sure that your application is sending the correct vectors (normal, tangent, bitangent) to the shader. Try and phase out other variables for now if you want to get the bump mapping working.I hope this helps.Take care.   ;Quote:Original post by ETFBladeAlso, not quite sure what you mean by the plane is subdivided. Could you explain that?Sure. In the screenshot from FX composer the plane´s edge is not a simple straight line. Therefore I assume the plane consists of more than 4 vertices and 2 triangles. Could be something like 32 x 32 vertices. So with the plane in FX composer you will end up with 32 x 32 different normals, tangents and binormals (if I´m right about the plane there).But if you´ve set the normal map you should see the bump mapping effect never the less, since you would end up with a valid set of normal, tangent and binormal for it even with only 4 vertices for your plane and therefore should be able to see the bump mapping.I´m a bit clueless, sry... try Armadon´s suggestion, to implement bump mapping all by itself first.   ;  Ah, alright. Thanks alot both of you guys for the replies. I will work on figuring out the bumpmapping more for now.Matches81: Thanks for the clarification on the subdivision. So it does look like I am subdividing my plane, as currently it's in the order of 32x32 vertex grid. Now I have another question. As I'm not currently calculating the each vertex's normal, bitangent, and tangent every frame, I'm wondering what the most efficient way to do this is. It seems like this process would be pretty costly outside of a doing it on the hardware, (it also seems pretty complicated). Thanks in advance!   