Sign in to follow this  

Setting HLSL vectors from DX9 app

This topic is 4303 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, I am finally getting to grip with shaders, using HLSL. I have the first of, I am sure, a string of queries.... I have learnt how to set a matrix in the shader, from the app, like the worldview matrix etc. Can I do the same thing with vectors? Heres the code from the shader I am trying to set, particualrly thelight direction:
float4x3 WorldView  : WORLDVIEW;  
float4x4 Projection : PROJECTION;  
float3 LightDir < string UIDirectional = "Light Direction"; > ;

And heres what I am attempting to do:
D3DXMATRIX WorldView;
D3DXMatrixMultiply( &WorldView, &I, g_camera->GetViewMatrixPtr() );
m_constantTable->SetMatrix( g_device, "WorldView", &WorldView); 
m_constantTable->SetMatrix( g_device, "Projection", g_simulation->GetProjMatrixPtr() );
m_constantTable->SetVector( g_device, "LightDir", &tempLightDir );


...where tempLightDir is a D3DXVECTOR3. Is this possible? I am having problems (sorry, away from pc at the mo, so cant quite remember the error) Thanks Simon

Share this post


Link to post
Share on other sites
Vector's via the FX framework are considered to be float4 (D3DXVECTOR4) rather than float3 (D3DXVECTOR3). It matches the size of the constant registers.

You're best off packing the float3 up as a float4 on both ends. Bit awkward, but it works fine for me. Just remember to use Lightdir.xyz so that you don't get the unused component getting in the way [smile]

hth
Jack

Share this post


Link to post
Share on other sites

This topic is 4303 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.

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