   general lighting structure - help!
  Hi there.im pretty new to game programming (only just finished 1st year of degree) but over summer ive been working my way through Frank Luna's Introduction to 3d game programming with directx 9.0c : a Shader approachEverything is goin pretty well, however i do have a big question about lighting in relation to its structure with the rest of an app. what is the easiest way to code multiple lights? (lets use for example 3 lights)do i:A) hard code 3 lights into the basic shader (although this seems inflexible and surely would be inefficient as would need lots of tests to see which lights were/were not active i.e. range, point vs directional vs ambient etc) B) leave the shader as a 1-light shader, and simply Re-Render the scene say 3 times each time adding the result to the back buffer (although this seems expensive as it'd mean effectively rendering a scene 3 times!)Also ive been told its best to include as few as possible tests (eg if statements switches etc) in shaders. so does that mean id need to create multiple fx files, each one taking different input for each possible combination of lights??? eg. fx1 for a pointx1 + directional, fx2 for a pointx2 +directional,  perhaps another for pointx3 + directional etc  (although that seems crazy!) anyway sorry for my inexperience!!   
Quote:Original post by NovaBlackB) leave the shader as a 1-light shader, and simply Re-Render the scene say 3 times each time adding the result to the back buffer (although this seems expensive as it'd mean effectively rendering a scene 3 times!)I'm pretty sure that this is the approach that Doom3 used.It may seem like a bad idea to draw the scene 3 times, but as long as your scene-graph traversal is fast, it shouldn't be a problem.If you use shadow maps, then you'll also have to render the scene once from the perspective of the light source, and some reflection techniques might also need their own passes... So a modern game engine rendering a scene with 5 light sources might actually render the scene over 10 times to produce the final screen!I also know that Horde3D uses this approach (or at least it's default forward shading pipeline does).   ;  ahh excellent! i didnt realise at all that modern games actually renedered a scene that many times with a reasonable frame rate!hmm well ok for now ill try stick with that apporach and see how it goes!also whilst im on the topic, say i made a 'Light' class, so i could just instantiate lights by passing say directional/point as an argument, whats the best way of iterating through them all when rendering?Is it ok to say build all the fx handles in the light constructor, then just make some kind of linked list/container, holding pointers to the lights and iterate through each one pulling out the relevant handles for each one (e.g position, direction vector, color etc) and plugging them into the relavant fx file variables before a render pass? (then obviously doing 1 pass for each light present)ps. thanks for the quick reply!! its early!! lol appreciate the advice   