Jump to content

Image of the Day

BL00DG0R3
#screenshotsaturday #gamedev #indiedev https://t.co/SytiLEa4G5
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

Scene Lighting : Passing structs of arrays of structs via cbuffer

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 Chris_J_H   Members   

256
Like
0Likes
Like

Posted 05 April 2013 - 08:39 AM

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.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.