• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #Actualiedoc

Posted 12 February 2012 - 01:07 PM

I get the tangent of each vertex when i load my model in, then find the binormal in the pixel shaders using the interpolated tangent and normal for each vertex.

Here is the section i do the normal map stuff in my shader:

//Load normal from normal map
float4 normalMap = ObjNormMap.Sample( ObjSamplerState, input.TexCoord );

//Change normal map range from [0, 1] to [-1, 1]
normalMap = (2.0f*normalMap) - 1.0f;

//Make sure tangent is completely orthogonal to normal
input.tangent = normalize(input.tangent - dot(input.tangent, input.normal)*input.normal);

//Create the biTangent
float3 biTangent = cross(input.normal, input.tangent);

//Create the "Texture Space"
float3x3 texSpace = float3x3(input.tangent, biTangent, input.normal);

//Convert normal from normal map to texture space and store in input.normal
input.normal = normalize(mul(normalMap, texSpace));

This was taken from a lesson on normal maps for direct3d 11, maybe you could find it usefull
http://www.braynzars...?p=D3D11NORMMAP

Oh yeah, to find which triangles use a vertex, first when creating your tangents for each triangle, keep track of the triangles, so that the number of tangents match with the number of triangles. then loop through each vertex in your vertex array. for each vertex, loop through each triangle. each triangle can be defined by 3 indices. if one of those 3 indices is the current vertex, then add that triangles tangent to any other triangles tangent that shares that vertex. After your finished looping through the triangles, just divide the tangent sum by the number of triangles that share that vertex, then normalize the result.

Something like this:

D3DXVECTOR3 tangentSum = D3DXVECTOR3 (0.0f, 0.0f, 0.0f, 0.0f);
int facesUsing = 0;
float tX, tY, tZ;

//Go through each vertex
for(int i = 0; i < totalVerts; ++i)
{
//Check which triangles use this vertex
for(int j = 0; j < meshTriangles; ++j)
{
if(indices[j*3] == i ||
indices[(j*3)+1] == i ||
indices[(j*3)+2] == i)
{
tX = tangentSum.x + tempTangent[j].x;
tY = tangentSum.y + tempTangent[j].y;
tZ = tangentSum.z + tempTangent[j].z;

tangentSum = D3DXVECTOR3(tX, tY, tZ, 0.0f); //sum up face tangents using this vertex

facesUsing++;
}
}

tangentSum = tangentSum / facesUsing;
D3DXVec3Normalize(&tangentSum , tangentSum);
}

I can't promise the code above will work since i didn't actually try it out after i changed it from using the xna math library to using the d3dx library, but it's the idea i mean to get across

### #14iedoc

Posted 12 February 2012 - 01:06 PM

I get the tangent of each vertex when i load my model in, then find the binormal in the pixel shaders using the interpolated tangent and normal for each vertex.

Here is the section i do the normal map stuff in my shader:

//Load normal from normal map
float4 normalMap = ObjNormMap.Sample( ObjSamplerState, input.TexCoord );

//Change normal map range from [0, 1] to [-1, 1]
normalMap = (2.0f*normalMap) - 1.0f;

//Make sure tangent is completely orthogonal to normal
input.tangent = normalize(input.tangent - dot(input.tangent, input.normal)*input.normal);

//Create the biTangent
float3 biTangent = cross(input.normal, input.tangent);

//Create the "Texture Space"
float3x3 texSpace = float3x3(input.tangent, biTangent, input.normal);

//Convert normal from normal map to texture space and store in input.normal
input.normal = normalize(mul(normalMap, texSpace));

This was taken from my lesson on normal maps for direct3d 11, maybe you could find it usefull
http://www.braynzars...?p=D3D11NORMMAP

Oh yeah, to find which triangles use a vertex, first when creating your tangents for each triangle, keep track of the triangles, so that the number of tangents match with the number of triangles. then loop through each vertex in your vertex array. for each vertex, loop through each triangle. each triangle can be defined by 3 indices. if one of those 3 indices is the current vertex, then add that triangles tangent to any other triangles tangent that shares that vertex. After your finished looping through the triangles, just divide the tangent sum by the number of triangles that share that vertex, then normalize the result.

Something like this:

D3DXVECTOR3 tangentSum = D3DXVECTOR3 (0.0f, 0.0f, 0.0f, 0.0f);
int facesUsing = 0;
float tX, tY, tZ;

//Go through each vertex
for(int i = 0; i < totalVerts; ++i)
{
//Check which triangles use this vertex
for(int j = 0; j < meshTriangles; ++j)
{
if(indices[j*3] == i ||
indices[(j*3)+1] == i ||
indices[(j*3)+2] == i)
{
tX = tangentSum.x + tempTangent[j].x;
tY = tangentSum.y + tempTangent[j].y;
tZ = tangentSum.z + tempTangent[j].z;

tangentSum = D3DXVECTOR3(tX, tY, tZ, 0.0f); //sum up face tangents using this vertex

facesUsing++;
}
}

tangentSum = tangentSum / facesUsing;
D3DXVec3Normalize(&tangentSum , tangentSum);
}

I can't promise the code above will work since i didn't actually try it out after i changed it from using the xna math library to using the d3dx library, but it's the idea i mean to get across

### #13iedoc

Posted 12 February 2012 - 01:04 PM

I get the tangent of each vertex when i load my model in, then find the binormal in the pixel shaders using the interpolated tangent and normal for each vertex.

Here is the section i do the normal map stuff in my shader:

//Load normal from normal map
float4 normalMap = ObjNormMap.Sample( ObjSamplerState, input.TexCoord );

//Change normal map range from [0, 1] to [-1, 1]
normalMap = (2.0f*normalMap) - 1.0f;

//Make sure tangent is completely orthogonal to normal
input.tangent = normalize(input.tangent - dot(input.tangent, input.normal)*input.normal);

//Create the biTangent
float3 biTangent = cross(input.normal, input.tangent);

//Create the "Texture Space"
float3x3 texSpace = float3x3(input.tangent, biTangent, input.normal);

//Convert normal from normal map to texture space and store in input.normal
input.normal = normalize(mul(normalMap, texSpace));

This was taken from my lesson on normal maps for direct3d 11, maybe you could find it usefull
http://www.braynzars...?p=D3D11NORMMAP

Oh yeah, to find which triangles use a vertex, first when creating your tangents for each triangle, keep track of the triangles, so that the number of tangents match with the number of triangles. then loop through each vertex in your vertex array. for each vertex, loop through each triangle. each triangle can be defined by 3 indices. if one of those 3 indices is the current vertex, then add that triangles tangent to any other triangles tangent that shares that vertex. After your finished looping through the triangles, just divide the tangent sum by the number of triangles that share that vertex, then normalize the result.

Something like this:

D3DXVECTOR3 tangentSum = D3DXVECTOR3 (0.0f, 0.0f, 0.0f, 0.0f);
int facesUsing = 0;
float tX, tY, tZ;

//Go through each vertex
for(int i = 0; i < totalVerts; ++i)
{
//Check which triangles use this vertex
for(int j = 0; j < meshTriangles; ++j)
{
if(indices[j*3] == i ||
indices[(j*3)+1] == i ||
indices[(j*3)+2] == i)
{
tX = tangentSum.x + tempTangent[j].x;
tY = tangentSum.y + tempTangent[j].y;
tZ = tangentSum.z + tempTangent[j].z;

tangentSum = D3DXVECTOR3(tX, tY, tZ, 0.0f); //sum up face tangents using this vertex

facesUsing++;
}
}

tangentSum = tangentSum / facesUsing;
D3DXVec3Normalize(&tangentSum , tangentSum);
}

### #12iedoc

Posted 12 February 2012 - 01:04 PM

I get the tangent of each vertex when i load my model in, then find the binormal in the pixel shaders using the interpolated tangent and normal for each vertex.

Here is the section i do the normal map stuff in my shader:

//Load normal from normal map
float4 normalMap = ObjNormMap.Sample( ObjSamplerState, input.TexCoord );

//Change normal map range from [0, 1] to [-1, 1]
normalMap = (2.0f*normalMap) - 1.0f;

//Make sure tangent is completely orthogonal to normal
input.tangent = normalize(input.tangent - dot(input.tangent, input.normal)*input.normal);

//Create the biTangent
float3 biTangent = cross(input.normal, input.tangent);

//Create the "Texture Space"
float3x3 texSpace = float3x3(input.tangent, biTangent, input.normal);

//Convert normal from normal map to texture space and store in input.normal
input.normal = normalize(mul(normalMap, texSpace));

This was taken from my lesson on normal maps for direct3d 11, maybe you could find it usefull
http://www.braynzars...?p=D3D11NORMMAP

Oh yeah, to find which triangles use a vertex, first when creating your tangents for each triangle, keep track of the triangles, so that the number of tangents match with the number of triangles. then loop through each vertex in your vertex array. for each vertex, loop through each triangle. each triangle can be defined by 3 indices. if one of those 3 indices is the current vertex, then add that triangles tangent to any other triangles tangent that shares that vertex. After your finished looping through the triangles, just divide the tangent sum by the number of triangles that share that vertex, then normalize the result.

Something like this:

D3DXVECTOR3 tangentSum = D3DXVECTOR3 (0.0f, 0.0f, 0.0f, 0.0f);
int facesUsing = 0;
float tX, tY, tZ;

//Go through each vertex
for(int i = 0; i < totalVerts; ++i)
{
//Check which triangles use this vertex
for(int j = 0; j < meshTriangles; ++j)
{
if(indices[j*3] == i ||
indices[(j*3)+1] == i ||
indices[(j*3)+2] == i)
{
tX = tangentSum.x + tempTangent[j].x;
tY = tangentSum.y + tempTangent[j].y;
tZ = tangentSum.z + tempTangent[j].z;

tangentSum = D3DXVECTOR3(tX, tY, tZ, 0.0f); //sum up face tangents using this vertex

facesUsing++;
}
}

tangentSum = tangentSum / facesUsing;
D3DXVec3Normalize(&tangentSum , tangentSum);
}

### #11iedoc

Posted 12 February 2012 - 01:04 PM

I get the tangent of each vertex when i load my model in, then find the binormal in the pixel shaders using the interpolated tangent and normal for each vertex.

Here is the section i do the normal map stuff in my shader:

//Load normal from normal map
float4 normalMap = ObjNormMap.Sample( ObjSamplerState, input.TexCoord );

//Change normal map range from [0, 1] to [-1, 1]
normalMap = (2.0f*normalMap) - 1.0f;

//Make sure tangent is completely orthogonal to normal
input.tangent = normalize(input.tangent - dot(input.tangent, input.normal)*input.normal);

//Create the biTangent
float3 biTangent = cross(input.normal, input.tangent);

//Create the "Texture Space"
float3x3 texSpace = float3x3(input.tangent, biTangent, input.normal);

//Convert normal from normal map to texture space and store in input.normal
input.normal = normalize(mul(normalMap, texSpace));

This was taken from my lesson on normal maps for direct3d 11, maybe you could find it usefull
http://www.braynzars...?p=D3D11NORMMAP

Oh yeah, to find which triangles use a vertex, first when creating your tangents for each triangle, keep track of the triangles, so that the number of tangents match with the number of triangles. then loop through each vertex in your vertex array. for each vertex, loop through each triangle. each triangle can be defined by 3 indices. if one of those 3 indices is the current vertex, then add that triangles tangent to any other triangles tangent that shares that vertex. After your finished looping through the triangles, just divide the tangent sum by the number of triangles that share that vertex, then normalize the result.

Something like this:

D3DXVECTOR3 tangentSum = D3DXVECTOR3 (0.0f, 0.0f, 0.0f, 0.0f);
int facesUsing = 0;
float tX, tY, tZ;

//Go through each vertex
for(int i = 0; i < totalVerts; ++i)
{
//Check which triangles use this vertex
for(int j = 0; j < meshTriangles; ++j)
{
if(indices[j*3] == i ||
indices[(j*3)+1] == i ||
indices[(j*3)+2] == i)
{
tX = tangentSum.x + tempTangent[j].x;
tY = tangentSum.y + tempTangent[j].y;
tZ = tangentSum.z + tempTangent[j].z;

tangentSum = D3DXVECTOR3(tX, tY, tZ, 0.0f); //sum up face tangents using this vertex

facesUsing++;
}
}

tangentSum = tangentSum / facesUsing;
D3DXVec3Normalize(&tangentSum , tangentSum);
}

### #10iedoc

Posted 12 February 2012 - 01:03 PM

I get the tangent of each vertex when i load my model in, then find the binormal in the pixel shaders using the interpolated tangent and normal for each vertex.

Here is the section i do the normal map stuff in my shader:

//Load normal from normal map
float4 normalMap = ObjNormMap.Sample( ObjSamplerState, input.TexCoord );

//Change normal map range from [0, 1] to [-1, 1]
normalMap = (2.0f*normalMap) - 1.0f;

//Make sure tangent is completely orthogonal to normal
input.tangent = normalize(input.tangent - dot(input.tangent, input.normal)*input.normal);

//Create the biTangent
float3 biTangent = cross(input.normal, input.tangent);

//Create the "Texture Space"
float3x3 texSpace = float3x3(input.tangent, biTangent, input.normal);

//Convert normal from normal map to texture space and store in input.normal
input.normal = normalize(mul(normalMap, texSpace));

This was taken from my lesson on normal maps for direct3d 11, maybe you could find it usefull
http://www.braynzars...?p=D3D11NORMMAP

Oh yeah, to find which triangles use a vertex, first when creating your tangents for each triangle, keep track of the triangles, so that the number of tangents match with the number of triangles. then loop through each vertex in your vertex array. for each vertex, loop through each triangle. each triangle can be defined by 3 indices. if one of those 3 indices is the current vertex, then add that triangles tangent to any other triangles tangent that shares that vertex. After your finished looping through the triangles, just divide the tangent sum by the number of triangles that share that vertex, then normalize the result.

Something like this:

D3DXVECTOR3 tangentSum = D3DXVECTOR3 (0.0f, 0.0f, 0.0f, 0.0f);
int facesUsing = 0;
float tX, tY, tZ;

//Go through each vertex
for(int i = 0; i < totalVerts; ++i)
{
//Check which triangles use this vertex
for(int j = 0; j < meshTriangles; ++j)
{
if(indices[j*3] == i ||
indices[(j*3)+1] == i ||
indices[(j*3)+2] == i)
{
tX = tangentSum.x + tempTangent[j].x;
tY = tangentSum.y + tempTangent[j].y;
tZ = tangentSum.z + tempTangent[j].z;

tangentSum = D3DXVECTOR3(tX, tY, tZ, 0.0f); //sum up face tangents using this vertex

facesUsing++;
}
}

tangentSum = tangentSum / facesUsing;
D3DXVec3Normalize(&tangentSum , tangentSum);
}

PARTNERS