Page 1 of 1

Iterate over all point light sources in a single pass

Posted: Tue Jun 29, 2021 8:56 am
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!

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

Posted: Tue Jun 29, 2021 12:38 pm
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.

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

Posted: Tue Jun 29, 2021 5:59 pm
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!

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

Posted: Mon Mar 06, 2023 3:48 am
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?


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

Posted: Wed Mar 08, 2023 12:29 pm
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