Proposal for PseudoSH, what's your light system?

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Proposal for PseudoSH, what's your light system?

Post by REDDemon »

Hi there :) It has been a while, but maybe I'm going to start a Irrlicht-related job, which means I can probably use/test and eventually fix some stuff.


Is there anyone tried to implement SH lighting + light probes in irrlicht?

Actually I'm thinking to realize a prototype for realtime pseudo-SH lighting for top down 2.5D games. It would be a out-of-irrlicht stuff (it will be using irrlicht but it won't be a engine's core stuff.. I have few ideas I want to test out

Basically I want to try a different approach to lights.

The optimal (from visual quality point of view) way to achieve good lighting would be to use SH+ LightProbes, however this has several problems:
  • Need to precompute Probes
  • Probes need to be placed carefully (require a editor or a complex software to analize the scene)
  • Getting Probes have a decent performance is Tricky
My Idea was to drop the trickiest parts and dropping some quality in order to make that functionality in a library that everyone could understand and change.
(No SH. Just light projection from one direction over a sphere, and normalization).
  • Instead of using SH, use a fixed amount of lights projected over the mesh. (4-8
  • Do not use tetraeders but use shapes that are easier to place procedurally/manually (cilinders/spheres/AABoxes)
  • Lights are computed in realtime
The solution is probably a bit less efficient on CPU, a bit more efficient on GPU (4-8 vs 9 coefficients), and should not require lightmaps/SH-probes baking etc.

Anyone interested in or I could drop the idea altogheter and move on something else?

Image

If the game has a top down visual the angles can be adjusted (since bottom of objects is barely visible on 2.5D games: no need to use a regular tetraeder). And probably we can add more lights to add further quality (was thinking to add "top" light and a "center" light).

Let's also see if you have done some custom lighting system already and add your thoughts. Keep brainstorming some on it :)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Proposal for PseudoSH, what's your light system?

Post by devsh »

You're completely missing the point of using SH

you can interpolate SH probes, with some reprojection the interpolation is REALLY good.

Finally you can convert your BRDF function to a SH representiation and get the actual integral over a sphere of its product with the probe by just doing a 9 component dot product.
The SH probe represents millions of lights at every point of the sphere which are all lighting your surface, its just a filtered representation s.t. it only contains low frequency information (small point lights will appear as though they are large fuzzy area lights), so evaluating a specular function is also very cheap.

Finally you could convert your 4 lights into a SH anyway without any probe calculation XD.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Proposal for PseudoSH, what's your light system?

Post by REDDemon »

yes probes are interpolated across vertices of tetraeders (4 light probes), the problem is that getting the tetraeders is Tricky :/. So I can convert my 4 lights to a SH (actually there is a function to project a light over a SH), but then I have to interpolate the SH and to do that I need tetraeders which is the problem XD. So instead I choose to use a different approximatio (no SH), that do not require to place tetraeders (just need to know nearby lights)... Yeah I could project those nearby lights over a SH instead, but I fear doing that every frame would be much more expensive (not profiled it! :D ).

And that would still be a forward light anyway. To do decent defferred light we need compute shaders.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Proposal for PseudoSH, what's your light system?

Post by devsh »

You do realize that since a point light is a dirac-delta function on a sphere the integral reduces to an evaluation of the SH basis functions at the position of the lights and adding them together??? That, is not expensive
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Proposal for PseudoSH, what's your light system?

Post by REDDemon »

Yes but I don't want only point lights :D.

Image

Using 4 lights I just need to compute "quantity of light" emitted by a square on nearby "probes".

You have to do just a bunch operations to do that computation (not reflecting all light rays. A Surface just take some light from sources (and eventually reflections from nearby squares). Of course, this is an experiment so objections are highly expected :P. Yes there are actually functions to project squares over SH (with a decent amount of banding sometimes), but I can barely understand SH, so I prefer code that I fully understand and that everyone reading it can understand too. :mrgreen: Last time I tried to get myself the SH coefficients i missed some computations in the mid I prever avoiding that again (even if there's lot of ready code one could actually "lend"). My field is using matrices, projections, I'm comfortable with calculus. while I prefer not touching stuff like Fourier/Laplace


Square facing away from probe? => no light of the square added (unless we want to add a minimum amount in case of "dense fog").

My hope is creating something that artist can make something interesting out of it without having to realying on a raytracer to bake scene light into SHs. I hope the final result would look good :) (actually I can't predict if that would be good)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Proposal for PseudoSH, what's your light system?

Post by devsh »

you could precompute each surface's contribution to the SH into literally 9 coefficients and "only compute" the reflected light from them at runtime, the expensive stuff like working out occlusions to a probe, and they solid angle of the surface are already done... as long as the probe doesn't move.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Proposal for PseudoSH, what's your light system?

Post by REDDemon »

good point. Assume probes are fixed and light moves and change color/luminosity, I need to change contribution anyway even in this case.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Proposal for PseudoSH, what's your light system?

Post by Vectrotek »

Interesting! :P
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Proposal for PseudoSH, what's your light system?

Post by devsh »

another fun thing about SH is that they are linear, i.e. suppose you had 20 surfaces with 10 lights contributing to the SH

one light moves, you can simply compute the new minus old contribution of the light and add that to the already existing total in the SH

ofc after a while you'll be forced to recompute the whole thing due to float precision issues.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Proposal for PseudoSH, what's your light system?

Post by REDDemon »

Seems it start getting complex even trying to keep it simple :D. The dummy approach is too expensive, even assuming only part of objects are moving. (so that we can cache most results).

Code: Select all

 
 
Foreach object in IlluminatedObjects
{
    pseudoSH = object.pseudoSH;
    Foreach light in lights.Nearby( object)
    {
        Foreach surf in surfaces.Nearby( object)
        {
            if( surf.Occluded( light, surf) == false) // dot product
                pseudoSH.addLightReflectedFrom( light, surf);
            else
                light.SetOccluded();
 
            pseudoSH.AddDirectLight(surf.color, surf.position); // surface indirect lighting. Can contain light from distant sources.
        }
 
        if( light.IsOccluded()== false)
            pseudoSH.addDirectLight( light);
    }
}
 
With this implementation it mostly depends on light/surfaces disposition and efficiency of the "Nearby" method.

- Occluded just check if the surface is between objet and light source.

We also need a way to add simple reflections between surfaces. Each surface could accumulate a "color" (light) and we each frame do color propagation between surfaces
(something like)

Code: Select all

 
foreach surf in surfaces
{
    surf.color = black;  // Wee need a stable weighted average. to avoid light flickering (color of each surface change everyframe)
    foreach light in lights.nearby surf
        surf.color.AddDirectionLight(light); // Do not check occlusion, maybe we should check it?
 
    foreach nearsurf in surfaces.Nearby(surf)
        surf.colorAddColorFromSurface(nearsurf); // keep into account reciprocal surface inclination
}
 
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Proposal for PseudoSH, what's your light system?

Post by Mel »

I did some Spherical Harmonics lighting back in the days, SH just represent the amount of light incoming to a certain point, so, any light is actually supported. The best way to think of a SH probe is like a point light, but that instead emiting light, mimics whole lighting environment and anything lit by that probe acquires the (diffuse) lighting of that certain environment. You can blend linearly the SH coeficients, or even the resulting matrices. The only thing is that they don't produce very clear reflections, they look like the diffuse environment. I discarded them in order to use the deferred rendering method, because it produces much sharper specular lighting, and the lighting is performed in place, without probe interpolations of any kind. Good luck! :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Proposal for PseudoSH, what's your light system?

Post by devsh »

SH is orthogonal to deferred, use SH for indirect light not direct point lights XD
Post Reply