Sign in to follow this  
n3Xus

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

Recommended Posts

n3Xus    951
Hello, i'm not sure how to send multiply lights to my shader. what is the "best" way to send a varying numbers of lights to the shader so that i won't waste too much processing power?

Share this post


Link to post
Share on other sites
n3Xus    951
ok thanks.

so i thought of it this way:
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?

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
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.

hth
Jack

Share this post


Link to post
Share on other sites
Ender1618    254
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