Sign in to follow this  
Chris_J_H

Scene Lighting : Passing structs of arrays of structs via cbuffer

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

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