Jump to content
  • Advertisement
Sign in to follow this  

Setting HLSL vectors from DX9 app

This topic is 4673 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:
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]


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!