shader varable question

The place for artists, modellers, level designers et al to discuss their approaches for creating content for OGRE.
Post Reply
biteme
Halfling
Posts: 70
Joined: Fri Mar 11, 2005 12:49 am

shader varable question

Post by biteme »

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
User avatar
TheGilb
Halfling
Posts: 71
Joined: Sun Oct 06, 2002 11:19 pm
Location: UK
Contact:

Post by TheGilb »

Normals are passed in via the regular bindings:

Code: Select all

void vs_main(in float3 vnormal:NORMAL,
             in float3 inPos : POSITION,
            out float4 oPos  : POSITION)
{
        // Do stuff with vnormal here
}
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 :roll:

Just kidding! :wink: 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!
Last edited by TheGilb on Fri Mar 11, 2005 1:35 am, edited 1 time in total.
nfz
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 1263
Joined: Wed Sep 24, 2003 4:00 pm
Location: Halifax, Nova Scotia, Canada

Post by nfz »

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 :

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);
            }
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.
biteme
Halfling
Posts: 70
Joined: Fri Mar 11, 2005 12:49 am

Post by biteme »

thanks guys the binormal is worked out and i assumu that as long as i exported the model with the -t option tanget is passed as tanget?


btw the shader is loading with no errors but model is invisible IE you cant see it but you can crash into it :lol:
Post Reply