Iterate over all point light sources in a single pass

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
sasmaster
Gnoblar
Posts: 9
Joined: Sun Jun 27, 2021 4:09 pm

Iterate over all point light sources in a single pass

Post by sasmaster »

Hi.
I am implementing custom PBR shading with point light sources. I took GLTF2/PBR sample material as the base.
So far I have been able to guess most of the Ogre's material semantics myself, but here's one thing I can understand:

I created 3 point light source in the scene. Inside gLTF2_PBR.material there is a standard parameter:

Code: Select all

        param_named_auto u_LightDirection light_position  0
        param_named_auto u_LightDirection1 light_position 1
        param_named_auto u_LightDirection1 light_position 2
     
My interpretation of is: "light_position" is the position of light source with the index 0 , 1 ,2 in the array of lights.

But in reality I see my assumption is wrong. Once I start moving any of the 3 lights in the scene around 3d model, I am getting switch from one source position to another which is a function of light's location. E.g, moving light#0 along Z performs correct shading of the surface till it gets to a distance of 100 units from the center ,than it stops working, and the direction of light#1 which was located closer to the surface takes effect. If I leave only one light source in the scene, it works perfectly.

I found it the docs this:
iteration once
The pass is only executed once which is the default behaviour.

iteration once\_per\_light point
The pass is executed once for each point light.

iteration 5
The render state for the pass will be setup and then the draw call will execute 5 times.

iteration 5 per\_light point
The render state for the pass will be setup and then the draw call will execute 5 times. This will be done for each point light.

iteration 1 per\_n\_lights 2 point
I tried the last one (which I assumed to be getting all the light sources in one pass),but it doesn't change.

So here is my question: How do I iterated over all the light source in a single pass shader program? I have 3 point lights in the scene.

Thanks.







Thanks!
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: Iterate over all point light sources in a single pass

Post by paroj »

sasmaster wrote: Tue Jun 29, 2021 8:56 am My interpretation of is: "light_position" is the position of light source with the index 0 , 1 ,2 in the array of lights.
this is correct. However, the array is sorted by distance to camera each frame. There is no easy way to identify a specific light due to this - you will have to compute lighting for all of them for consistent results.

The light iteration stuff you found in the docs considers multi-pass rendering.
sasmaster
Gnoblar
Posts: 9
Joined: Sun Jun 27, 2021 4:09 pm

Re: Iterate over all point light sources in a single pass

Post by sasmaster »

you will have to compute lighting for all of them for consistent results.
Yeah, once I connected all the lights into shading function, it all started working well.

Thanks for your attention!
xinxiao
Gnoblar
Posts: 1
Joined: Tue Feb 07, 2023 2:37 am

Re: Iterate over all point light sources in a single pass

Post by xinxiao »

if i want to add light runtime, and i dont know the number, is there a way to pass light info to shader program without modifying shader dynamiclly?

Last edited by xinxiao on Mon Mar 06, 2023 4:04 am, edited 1 time in total.
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 449
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 155

Re: Iterate over all point light sources in a single pass

Post by sercero »

There is a parameter called: "ACT_LIGHT_COUNT"
https://ogrecave.github.io/ogre/api/1.1 ... 4fa668133d

In the shader it would be: light_count

Post Reply