Jump to content
  • Advertisement
Sign in to follow this  
n3Xus

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

This topic is 3564 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

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
Advertisement
Just send them as shader constants, using as few registers as possible. You shouldn't have a problem.

Share this post


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