Sign in to follow this  
paic

Matrices and HLSL

Recommended Posts

Hi, Is there a way to tell the HLSL that a given global matrix is the current world matrix, so that a call to pd3dDevice->SetTransfrom(D3DTS_WORLD, ...) would update it ? It's the case for texture samplers, so I wondered if there is a possibility to do it with matrices. For example, something like this in the HLSL : float4x4 g_mWorld : WORLDTRANSFORM; And that would tell the effect to take the current world matrix, so that a simple call to pd3dDevice->SetTransform(D3DTS_WORLD, ...) would work ... Maybe I'm dreaming, but such a fonctionality would really make my work easier ^^

Share this post


Link to post
Share on other sites
Nope, all functions like SetTransform(), SetMaterial(), SetTexture(), ect, are purely for the Fixed-Function Pipeline. They have no effect on the programmable pipeline at all.

However, making your own is really easy. Check this out (note that this is slightly psuedocoded):

// At init time
D3DXHANDLE worldHandle = effect->GetParameterBySemantic( NULL, "WORLD" );

HRESULT SetTransform( DWORD type, D3DXMATRIX mat )
{
if( type == D3DTS_WORLD )
{
effect->SetMatrix( worldHandle, mat );
}
else if( type == D3DTS_VIEW )
{
...
}
...
}

Share this post


Link to post
Share on other sites
The point is that I already have a mesh class which use the FFP. And I want to encapsulate that class in a one that use a shader without modifying the actual code.

And for texture, I assure you that the FFP call to SetTexture actually sets the texture even when you're using a shader and you DON'T use effect->SetTexture()

If you have 2 global texture samplers defined in the HLSL, the first one will correspond to the texture channel 0 and the second one to the channel 1. So, if I have something like :


texture g_tDiffuseTexture
sampler g_tDiffuseSampler = sampler_state
{
g_tDiffuseTexture;
}

in my HLSL, the 2 following lines will produce the exact same result :


effect->SetTexture("g_tDiffuseTexture", myTexture);
pd3dDevice->SetTexture(0, myTexture);

That's the reason why I thought their was a similar "trick" with matrices. But from your answer, it seems not :(

Share this post


Link to post
Share on other sites
Extending Circlesoft's reply, with effect files you can use the ID3DXEffect::SetMatrix(), the method is available. You can call this each frame/update or whatever you wish and that will have the same effect as pDevice->SetTransform(D3DTS_WORLD, ...)

I hope this helps.
Take care.

[Edited by - Armadon on November 10, 2005 12:26:25 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this