Sign in to follow this  
fboivin

Vertex Shader constants

Recommended Posts

In my HLSL vertex shader, I have an array of floats constants declared like this: float factors[6]; In my C++ code, I set the values of the array using the ID3DXConstantTable interface like this: ConstantTable->SetFloatArray( d3dDevice, "factors", factors, 6); However, what if I wanted to set the constants using the IDirect3DDevice9 SetVertexShaderConstantF method? The method only allows to upload vector4s so it's not possible to only upload 6 floats. Did I miss a method that allows to upload single floats in the IDirect3DDevice9 interface? If possible, I don't want to "patch" my array to 8 floats. Thanks! Francis

Share this post


Link to post
Share on other sites
Quote:
Original post by fboivin
However, what if I wanted to set the constants using the IDirect3DDevice9 SetVertexShaderConstantF method? The method only allows to upload vector4s so it's not possible to only upload 6 floats.


It looks like SetVertexShaderConstantF() will only accept float4s. This is probably because a constant in HLSL is defined as a float4.

So you can do one of two things:

(1) Continue using the constant table
(2) Use ID3DXEffect

The SetVertexShaderConstant*() functions aren't used much anymore, especially for HLSL shaders.

Share this post


Link to post
Share on other sites
D3DDevice::SetVertexShaderConstantF is really there to deal with assembled shaders that don't have constant tables. GPU's are vector processors, so single floats don't really exist in hardware, they're actually represented as float4's. This would be why no single-float constant setting methods exist. The HLSL compiler can re-arrange single-float constants and pack four of them into a float4 constant implicitly.

Since you're using HLSL, it's probably best to continue using constant tables to set your VS constants.

Share this post


Link to post
Share on other sites
Does SetFloatArray(...) not work? I use this on the PS' and VS'.... Does that not work for effects?

I grab the constant table, get the constant with GetConstantByName(...). Then do a SetFloatArray(..., 6);

Share this post


Link to post
Share on other sites
Playing a little more with this, I found out that if I declare a constant as "float my_array[6]" in HLSL, the compiler expands it to something like "float4 my_array[6]". Checking the output assemnly confirmed this as my_array's size was said to be 6.

Nice way to eat some bandwidth without noticing (ie: 24 floats when you think it's 6)!

Share this post


Link to post
Share on other sites
Quote:
Original post by fboivin
Playing a little more with this, I found out that if I declare a constant as "float my_array[6]" in HLSL, the compiler expands it to something like "float4 my_array[6]". Checking the output assemnly confirmed this as my_array's size was said to be 6.

Nice way to eat some bandwidth without noticing (ie: 24 floats when you think it's 6)!


So if you declare:
float my_array[4]
float my_array2[4]

then its only 8?

Share this post


Link to post
Share on other sites
I'd have to test it out, but I'd think from what I've seen that this would be expanded to float4 my_array[4] and float4 my_array2[4].

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