Sign in to follow this  

[HLSL] Send a varying number of lights to the shader

Recommended Posts

Original post by n3Xus
send an array of lights to the shader and an int that stores the number of lights so i than loop through them. would this be ok?
That is definitely one way of doing it. Another way is to "pre-bake" combinations of lights via techniques. You can use a uniform variable to avoid the dynamic looping and simply switch techniques according to the number of lights you want to use.


Share this post

Link to post
Share on other sites
The way I have been doing it is like so:

#define MAX_LIGHTS 4

uniform extern int gNumActiveLights : LIGHTNUMACTIVE <string Source = "Scene";>;

uniform extern float3 gLightPosArray[MAX_LIGHTS] : LIGHTPOSARRAY <string Source = "Scene";>;
uniform extern float4 gLightAmbientArray[MAX_LIGHTS] : LIGHTAMBIENTARRAY <string Source = "Scene";>;
uniform extern float4 gLightDiffuseArray[MAX_LIGHTS] : LIGHTDIFFUSEARRAY <string Source = "Scene";>;
uniform extern float4 gLightSpecularArray[MAX_LIGHTS] : LIGHTSPECULARARRAY <string Source = "Scene";>;
uniform extern float3 gLightAttenuationArray[MAX_LIGHTS] : LIGHTATTENUATIONARRAY <string Source = "Scene";>;

I do it with separate arrays because I couldn't find a way to set an array of structures (light structs) from the app with the effect interface, using handles.

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