Confuzed with Direct3D10 Shaders

Started by
4 comments, last by DumpAlien 16 years, 4 months ago
Hello there! :) I am a little confuzed with Direct3D 10 shaders. All the MS SDK Examples are using fx files and Techniques. I want a more "non easy/utility" way to do it.. so I am using functions like D3D10CompileShader(), CreateVertexShader() etc.. Now I can't find information about how I set the shader constants! for example .. i want to pass the view, world and projection matrices in the vertex shader. How i do that? ps: I dont have any previous Direct3D experience. (only OpenGL with ARB ASM programs) thanks for your time!
Advertisement
Hey DumpAlien,

I haven't written any Direct X 10 stuff yet, just read a few articles and from my understanding you set constants using the new CB's (Constant Buffers). So for example:

Your objects constant buffer in HLSL could be.

cbuffer obj
{
float4x4 matWorld
float4 vPos
}

When you call D3D10CompileShader you can get back the constant table from the last parameter (LPD3DXCONSTANTTABLE * ppConstantTable). You can then access this information using the ID3DXConstantTable interface functions ie GetConstantByName, SetMatrixArray etc.

Hope thats some help and someone can give u a better answer
ID3DXConstantTable is for DX9.
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
Reflect the compiled shader so you can get the count and name of the CBs the shader is using. Save which name belongs to which index. Create CBs, fill them. Then set the CBs with XXSetConstantBuffers.

Yeah, it's not so straightforward, the documentation is very much lacking.
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
Yes very true, my answer was a mix of direct x 9 and 10 lol..

Had another look at the SDK and the information is in there, look in the programming guide under resources and "Creating Buffer Resources".

ID3D10Buffer*   g_pConstantBuffer10 = NULL;struct VS_CONSTANT_BUFFER{    D3DXMATRIX mWorldViewProj;      //mWorldViewProj will probably be global to all shaders in a project.                                    //It's a good idea not to move it around between shaders.    D3DXVECTOR4 vSomeVectorThatMayBeNeededByASpecificShader;    float fSomeFloatThatMayBeNeededByASpecificShader;    float fTime;                    //fTime may also be global to all shaders in a project.    float fSomeFloatThatMayBeNeededByASpecificShader2;    float fSomeFloatThatMayBeNeededByASpecificShader3;};    D3D10_BUFFER_DESC cbDesc;    cbDesc.ByteWidth = sizeof( VS_CONSTANT_BUFFER );    cbDesc.Usage = D3D10_USAGE_DYNAMIC;    cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;    cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;    cbDesc.MiscFlags = 0;    hr = g_pd3dDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer10 );    if( FAILED( hr ) )       return hr;    g_pd3dDevice->VSSetConstantBuffers( 0, 1, g_pConstantBuffer10 );
Thanks for your replies guys!
I found some information from Humus framework (www.humus.ca)
Like you said me, he reflects the shaders to get the information and then
he access the variables using UpdateSubresource() function.
The code is a little confuzing for start but I will fight it:P

Thanks again guys!

This topic is closed to new replies.

Advertisement