Skip to main content
GameDev.net gamedev.net
🔒 Locked

stream mapping

Started by genesys Dec 13, 2005 at 1:30 AM 4 replies 1.2k views
Original Post
genesys
genesys
How do I pass the vertex streams (like NORMAL, TEXCOORD, TANGENT, POSITION and so on..) to my HLSL shaders? thx!
Armadon
Armadon
You use a structure called semantics.
Semantics allows you to actually pass your vertex information to your shader.
In your shader you will specify an application to vertex shader structure that will look like this.

//application to vertex structurestruct a2v{     float4 position   : POSITION0;    float3 normal     : NORMAL;    float2 tex0       : TEXCOORD0;    float3 tangent    : TANGENT;    float3 binormal   : BINORMAL;};


When you then render with your shader, DirectX will do the work of passing it to the vertex shader for you. Effects are easy to work with and I suggest you using them. You could follow these tutorials on how it all works together.

I hope this helps.
Take care.
genesys
genesys
Hi!

thanks for your help - but it's not really helping me...

the shader part isn't a problem for me!
I'm writing realtime shaders using rendermonkey and everything works fine...

But now i created a shader that uses the BINORMAL and TANGENT semantics (worked fine in renderMonkey) and as i wanted to test it in our engnine, i had to notice that it doesn't pass these two streams to the shader! (it's the same thing if i disable the BINORMAL and TANGENT stream in the stream mapping in render Monkey!)

NORMAL, POSITION, TEXCOORD and COLOR works fine in our engine - but BINORMAL and TANGENT doesnt...

So i think that there is somewhere in the code a place where one has to define which streams are passed to the shaders...


Can you help?
genesys
genesys
no one who can help me with that?
jollyjeffers
jollyjeffers
Quote:
Original post by genesys
no one who can help me with that?

Your HLSL shaders can only operate on the information it is given by the application. Thus you need to modify your engine to provide the TANGENT and BINORMAL components.

It could be fairly straightforward if you're using ID3DXMesh - use the ID3DXMesh::CloneMesh() method to expand the vertex structure to handle the TANGENT and BINORMAL values. Next you could use something like D3DXComputeTangentFrameEx() to actually generate those values.

However, if you're using some sort of custom mesh/geometry then you'll have to improvise [smile]

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Monder
Monder
Well you need BINOMIAL and TANGENT data in your vertex buffer to be able to use it in your vertex shader. You also need to tell DX where the data is with a vertex declaration, e.g. say you vertex was like this:

struct{   D3DVECTOR Position;   DWORD Color;   float u, v;   D3DVECTOR Binomial;   D3DVECTOR Tanget;};


Then you'd need a vertex declartion like this:

D3DVERTEXELEMENT9 VertexElements[] = {{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},{0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},{0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINOMIAL, 0},{0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},D3D_DECLEND};LPDIRECT3DVERTEXDECLARATION9 VertexDecl = 0;Device->CreateVertexDeclaration(VertexElements, &VertexDecl);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.