Jump to content
  • Advertisement
Sign in to follow this  

Scene Lighting : Passing structs of arrays of structs via cbuffer

This topic is 1871 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 have a variable number of spotlights in my scene and would like to pass in all my lighting info via a single cbuffer update. Ideally something that would look like this:

 

// hlsl --------------------------------------------------

struct DirectionalLight
{
    float4         ambient;
    //...
};

struct SpotLight
{
    float3        pos;
    //...
};

 

cbuffer LightingBuffer            : register (b0)
{
    DirectionalLight   gDirectionalLight;

    SpotLight           gSpotLight[4];
    int                     gNumActiveSpotLights;
};

 

// c++ -----------------------------------------------------

struct DirectionalLight
{
    XMFLOAT4         ambient;
    //...
};

struct SpotLight
{
    XMFLOAT3        pos;
    //...
};

 

struct LightingBuffer

{

   DirectionalLight    directionalLight;

   SpotLight            spotLight[4];

   int                      gNumActiveSpotLights;

};

 

Does the system tolerate the nested structs and struct arrays? - if so, could you give me guidelines to ensure that the packing will match? (4 is the maximum number of active spotLights allowed). Is there a better way of doing this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
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!