Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

MDX Effect SetValue for float2 and float3

Started by janoside 1 reply 1.2k views
Original Post
janoside
janoside
I am wondering how to set float2 and float3 values in an HLSL Effect. The method exposed by the Dx Effects framework "SetValue" has 16 overloads, two of which have signatures: void SetValue(EffectHandle handle, Vector4 v4) void SetValue(EffectHandle handle, void* data, int dataSize) Unfortunately, I cannot figure out how to set the value of a float2 or a float3 using either of these (none of the other overloads seem helpful either). For the first overload listed I tried having a dummy Vector4 and setting its X and Y components to the X and Y of the intended Vector2; an exception was thrown as a result (presumably since the Effect parameter did not have a Z or W component to work with, but who knows since Dx error messages are worthless). Using the second listed overload I tried: unsafe { fixed ( void* pointer = &myVector2 ) { myEffect.SetValue(myEffectHandle, pointer, 8); } } which also threw an exception. If anyone knows how to do this I would appreciate any help. I would prefer a "safe" implementation, but will be glad to have anything that works. Thanks in advance.
-janoside [Firestorm Engine]
turnpast
turnpast
Something like:
yourEffect.SetValue(new Vector4(yourVector2.X, yourVector2.Y,0,1));

For a Vector2 the float3 version should be obvious -- it does not really matter what the last value is: 0 or 1 whatever you feel like.
Armadon
Armadon
If you have any problems with overloads you can utilize the functions given to you. Such as in HLSL you can use the swizzle operator to actually get the informat you want. This means that if you want a float3 set you can use a float4 and then set it via the Vector4 overload. Now let's assume you want the first 3 values. You can just do something like the following in your shader.
float4 valueSetViaApplication;
float3 myVector3 = valueSetViaApplication.xyz;

I hope this helps.
Take care.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.