Sign in to follow this  

lights : number of it and infinite number of it

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

I have a trouble to understand one thing about light in many games we have a lot of lights, but the graphics card caps give only 4 lights (it depend of the card i supose) but if we want to made a game with a infinite of lights and run it on any graphics card : how do that ? thanks for your help

Share this post


Link to post
Share on other sites
It sounds like you are being limited by a fixed function renderer. OpenGL and Direct3D only support 4 lights in fixed function mode. You might try going to a renderer that uses vertex and pixel shading.

Even if you use shaders it is unlikely that your performance will be very good with any more than 4 lights. You could look into differred shading, but I think that the jury is still out on that technique.

Share this post


Link to post
Share on other sites
There are many ways you can fake "lights". This wouldn't require an actual light in the D3D sense of the word, but as far as the user cares it would count as a light. Specific methods depend on exactly what you're doing, but I can think of about 4 to 5 different ways off the top of my head. If you're looking for a specific solution to a specific situation, you'd likely get a more specific answer :).

Hope this helps.

Share this post


Link to post
Share on other sites
You can have as many lights as you want. The restriction is on how many you can use at the same time. You might draw one part of the scene with one set of lights and draw another part of the scene with another set of lights.

Share this post


Link to post
Share on other sites
Quote:
Original post by jkleinecke
It sounds like you are being limited by a fixed function renderer. OpenGL and Direct3D only support 4 lights in fixed function mode. You might try going to a renderer that uses vertex and pixel shading.
...


That's not true for Direct3D.

Share this post


Link to post
Share on other sites
Or you can move one light to x,y,z coordinate, set light parameters, and do it again on different position, and do this
n times between BeginScene and EndScene.

Share this post


Link to post
Share on other sites
There is no restriction imposed by Direct3D on the maximum number of lights when using the fixed-function pipeline (up to the number of lights that can be expressed by a DWORD).

Your card may have a restriction (if you're using hardware vertex processing), but the API doesn't. You'd know this if you retrieved the D3DCAPS9::MaxActiveLights when using software vertex processing or hardware vertex processing with the reference device.

Share this post


Link to post
Share on other sites
You can have an infinite number of lights if you use static lighting like in Quake 3. It uses a map compiler that generates the light information so that the game renderer doesn't have to do it in real-time. If you want infinite dynamic lights, do what JohnBolton said, render only the lights that are close to the camera. If want to be really sneaky, use static lighting for far away objects and dynamic lighting for close objects, kind of like Level of Detail. Just wanted to throw some ideas from the top of my head :-)

Share this post


Link to post
Share on other sites
Quote:
Original post by don
There is no restriction imposed by Direct3D on the maximum number of lights when using the fixed-function pipeline (up to the number of lights that can be expressed by a DWORD).


Actually Direct3D states that you may have only 8 lights active at any one time. You can define as many as you'd like, but you will have to activate and deactivate them dynamically. Thanks for pointing out that 4 lights was wrong though, it's been a while since I've messed with a fixed function pipeline.

Share this post


Link to post
Share on other sites
Quote:
Actually Direct3D states that you may have only 8 lights active at any one time. You can define as many as you'd like, but you will have to activate and deactivate them dynamically. Thanks for pointing out that 4 lights was wrong though, it's been a while since I've messed with a fixed function pipeline.




I'd be interested to know where in the D3D9 SDK docs that it states that you can only have a max of eight active lights so that I can log a doc bug.

What do you think D3DCAPS9::MaxActiveLights is for?

Share this post


Link to post
Share on other sites
Quote:
Actually Direct3D states that you may have only 8 lights active at any one time.


Actually, 8 lights is the minimum number of lights supported, I believe. Depends on the video card for how many more it'll support.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thats right, you dont have to enable every light of you level. You can have 500 lights and cleverly switch them on and off depending on their visibility fo5 example (that would require some extra-attention on the level designer's side of course, to ensure not too many lights can be visible at the same time)

And in the same scene, you dont have to enable lights to render objects wich are not illiminated by that light. For example imagine a circular room with 8 pillars arround it and 4 spotlights at the bottom of each pillar that are oriented towards the wall of the room. That would be possible if you render each pillar one after each other resetting the active lights after each one.

- Janta

Share this post


Link to post
Share on other sites
Quote:

Actually, 8 lights is the minimum number of lights supported, I believe. Depends on the video card for how many more it'll support.



And yet killan claims that his card reports 4 lights via the caps. Are you sure about this?

Share this post


Link to post
Share on other sites
But, most games don't need more than 8 lights at once shining on any one part. There are not that many situations where this is necessary. Just have the 8 closes lights shine on an object, and it will look extremely realistic. Even 8 lights is, in many situations, unnecessarily high.

Share this post


Link to post
Share on other sites
Quote:
Original post by don
Quote:

Actually, 8 lights is the minimum number of lights supported, I believe. Depends on the video card for how many more it'll support.



And yet killan claims that his card reports 4 lights via the caps. Are you sure about this?


I don't know about direct3d, but opengl spec states that at least eight lights must be supported. I'm guessing direct3d probably conforms to this minumum too, since the hardware devs have to conform to the eight light minimum anyway to be up to opengl spec.

Share this post


Link to post
Share on other sites
i have look again for caps of my cards and it say 8 active lights max.

4 it's maybe for my previous old card, sorry


so if i understand your point of view, in my render, for each objet i determine X lights near the objects (with 8 as maximum) i set them, i render and so one for each object ?

just ?

thanks a lot, i have better comprehention now :)

Share this post


Link to post
Share on other sites
Nop. It's not true. I had a scene with hundreds of lights, off course not hardwer supported. As I mentioned before all you need to do is:
-setup and create light
-in render procedure, between BeginScene and EndScene change light coordintes (or any other property of light) and SetLight again.
-do step two as much as you need it.
For example if you have on scene 16 visible lights, use light as much as your graphic card can have. Then reuse them again.
It is slower off course, but you can use as many lights as you want.


Share this post


Link to post
Share on other sites

begin scene;

for(i=0;i<10000;i++)
{
activateLight(i);
render
deactivateLight(i);
}

end scene

present.

it'll run like crap but it will run.

there is nothing stopping you from spending 10 hours to render 1 frame.
as far as i am aware multi pass rendering is required.

Share this post


Link to post
Share on other sites
Quote:
Original post by killan
but we have talk about 8 light maximum supported, how you do this for 16 lights ?, or i not understand your explanation sorry


lets take another example:
You want to have one object that is in fog and another one that isn't. You may ask why you want one object in fog and another one not. For example you may want all objects in fog except sky.
You do something like this:
-BeginScene
-enable fog
-draw objects <- here fog is enabled and all objects are in fog
-disable fog
-draw objects <- here fog is disabled and all objects are NOT in fog
-EndScene

this applies to lights, and to all directx stuff too.


D3DXVECTOR3 vPos(0,0,0);

D3DLight9 d3dLight;
HRESULT hr;

// Initialize the structure.
ZeroMemory(&D3dLight, sizeof(d3dLight));

// Set up a white point light.
d3dLight.Type = D3DLIGHT_POINT;
d3dLight.Diffuse.r = 1.0f;
d3dLight.Diffuse.g = 1.0f;
d3dLight.Diffuse.b = 1.0f;
d3dLight.Ambient.r = 1.0f;
d3dLight.Ambient.g = 1.0f;
d3dLight.Ambient.b = 1.0f;
d3dLight.Specular.r = 1.0f;
d3dLight.Specular.g = 1.0f;
d3dLight.Specular.b = 1.0f;
d3dLight.Position = vPos;

pDevice->BeginScene();

pDevice->SetLight(0,&d3dLight);
vPos.x = 10.0f; vPos.y = 10.0f; vPos.z = 10.0f;
d3dLight.Position = vPos;
pDevice->SetLight(0,&d3dLight);

vPos.x = 20.0f; vPos.y = 20.0f; vPos.z = 20.0f;
d3dLight.Position = vPos;
pDevice->SetLight(0,&d3dLight);
// notice that we are using in this example only light 0
vPos.x = 30.0f; vPos.y = 30.0f; vPos.z = 30.0f;
d3dLight.Position = vPos;
pDevice->SetLight(0,&d3dLight);

...
// here draw your scene
...
pDevice->EndScene();





cheers


Share this post


Link to post
Share on other sites
if you setlight after an other setlight, you replace the previous setlight, not ? and at final you have only one light at one position ? not ?

i'm don't know the DX with c++ (i work in C#) so i don't know if it the same

so if this code set an infinite of light, so it's super :)

Share this post


Link to post
Share on other sites

This topic is 4201 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.

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