Jump to content
  • Advertisement
Sign in to follow this  
DumpAlien

OpenGL Confuzed with Direct3D10 Shaders

This topic is 3969 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 );

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!