Hello I am shader ignorant but my son is a wiz at it. I am trying to get a hlsl shader to work with orger and my son needs a few quastions awnserd
how are?
tangents,binormals,and normals passed to the shader?
I belive I read that ogre dosn't calulate binormals and he can fix that but asking anyway.
thanks
shader varable question
- TheGilb
- Halfling
- Posts: 71
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: UK
- Contact:
Normals are passed in via the regular bindings:
You dont need to tell OGRE to bind that for you - it automagically binds the vertex normals to vnormal. (Just make sure your material scripts are properly setup. And if you dont need to use a fragment program, write a straight 'pass-thru' shader anyway and pop it in your material script. You should refer to the example scripts and the online manual for reference.)
Binormal and tangent vectors can be calculated in the GPU I believe.
I can't believe you didn't know that
Just kidding!
Shaders are pretty tough, and writing them for OGRE just adds another level of complexity! If you want my advice, work with FXComposer from the nvidia developer website; Much easier working in an IDE, and even though FXComposer is for Cg, it's quite remarkable how similar HLSL and Cg really are (Assuming you didn't know Microsoft collaborated with NVidia to create Cg). Good luck!
Code: Select all
void vs_main(in float3 vnormal:NORMAL,
in float3 inPos : POSITION,
out float4 oPos : POSITION)
{
// Do stuff with vnormal here
}Binormal and tangent vectors can be calculated in the GPU I believe.
I can't believe you didn't know that
Just kidding!
Last edited by TheGilb on Fri Mar 11, 2005 1:35 am, edited 1 time in total.
-
nfz
- OGRE Retired Team Member

- Posts: 1263
- Joined: Wed Sep 24, 2003 4:00 pm
- Location: Halifax, Nova Scotia, Canada
Ogre can precalculate the tangent vector and place it in the vertex data along with the normal data. Use OgreXMLConverter with the -t option when converting a model xml file to mesh format. Normal vectors are usually supplied by the modeling package and put in with the vertex data.
You can also generate the tangent vectors at runtime after you load the mesh using :
That code snippet was taken from the Dot3Bump demo.
In the vertex shader you can calculate the binormal by taking the cross product of the tangent vector and the normal vector passed in the vertex data stream (ie the vertex shader inputs). Take a look at the Cg vertex shader for the Dot3Bump demo.
Highly suggested you look at the Dot3Bump demo.
You can also generate the tangent vectors at runtime after you load the mesh using :
Code: Select all
// Build tangent vectors, all our meshes use only 1 texture coordset
unsigned short src, dest;
if (!pMesh->suggestTangentVectorBuildParams(src, dest))
{
pMesh->buildTangentVectors(src, dest);
}
In the vertex shader you can calculate the binormal by taking the cross product of the tangent vector and the normal vector passed in the vertex data stream (ie the vertex shader inputs). Take a look at the Cg vertex shader for the Dot3Bump demo.
Highly suggested you look at the Dot3Bump demo.
-
biteme
- Halfling
- Posts: 70
- Joined: Fri Mar 11, 2005 12:49 am