Jump to content
  • Advertisement
Sign in to follow this  
a24710

DX10 : problem updating a cbuffer in a shader

This topic is 3727 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

Hi i´ve got a constant buffer in the shader for the lights #define MAX_LIGHTS 16 cbuffer light_parameters { uint light_count; float4 light_color[MAX_LIGHTS]; float3 light_position[MAX_LIGHTS]; float light_radius[MAX_LIGHTS]; }; i´m trying to update the buffer from my app with no success with this code dx10_effect->GetVariableByName("light_color")->AsVector()->SetFloatVectorArray(evs->light_diffuse, 0, sizeof(float) * 4 * RENDER_MAX_LIGHTS); dx10_effect->GetVariableByName("light_position")->AsVector()->SetRawValue(evs->light_position, 0, sizeof(float) * 3 * RENDER_MAX_LIGHTS); dx10_effect->GetVariableByName("light_radius")->AsVector()->SetRawValue(evs->light_radius, 0, sizeof(float) * RENDER_MAX_LIGHTS); dx10_effect->GetVariableByName("light_count")->AsScalar()->SetInt(evs->active_lights); evs has this members on it float light_position[RENDER_MAX_LIGHTS*3]; float light_diffuse[RENDER_MAX_LIGHTS*4]; float light_radius[RENDER_MAX_LIGHTS]; unsigned int active_lights; the active lights count is updating ok and the first light position and diffuse color are right too. but the radius vec and the positions of lights beyond light number one are not right when i debug later with pix any idea???

Share this post


Link to post
Share on other sites
Advertisement
when i´m updating the

float3 light_position[MAX_LIGHTS];

i do the dx10_effect->GetVariableByName("light_position")->AsVector()->SetRawValue(evs->light_position, 0, sizeof(float) * 3 * RENDER_MAX_LIGHTS);

using pix i can see that the first 3 coordinates are ok, but the second position of the array starts with the second position of the second element.

for example if a have this

evs->light_position[0] = 0;
evs->light_position[1] = 1;
evs->light_position[2] = 2;
evs->light_position[3] = 3;
evs->light_position[4] = 4;
evs->light_position[5] = 5;
evs->light_position[6] = 6;

later in pix i can see how the float3 light_position[0] = {0, 1, 2} and light_position[1] = {4, 5, 6}

it´s like the float3 is in fact a float4. Any explanation about this??

thanks

Share this post


Link to post
Share on other sites
If you look at the constant buffer layout in the disassembled code you'll see that any array actually takes a multiple of 4 components, because we can't address across components, only across vectors.

This means that if you defined a float3[2] array, the register index would be 0 for the first four, and 1 for the last two. If this is really what you want to do, you can by defining the float4[2] array, and casting it to a float3[2] array, but this will result in poor codegen when you index it.

In other words, yes, it's actually an array of 4-component vectors, but you have no way of accessing the last component.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!