Board index FlightGear Development Effects and shaders

Compositor shadows change in shaders

An exciting "new" option in FlightGear, that includes reflections, lightmaps, the particle system etc.. A lot is yet to be discovered/implemented!

Compositor shadows change in shaders

Postby Flying toaster » Wed Mar 10, 2021 7:18 pm

Hello,

Playing with Compositor, I realised that shadows remove both specular and diffuse shading
Image
And this is consistent with the equations in the model-ALS-ultra.frag shader
Code: Select all
float shadowmap = getShadowing();
light_diffuse *= shadowmap;
...
Specular *= shadowmap;

While it seems consistent with Phong lighting model, having the 3D models appear completely flat is disturbing, and I would expect something more like this (where you can still see the shape of an object that is in the shadow)
Image
I agree that in real life the source to seeing something that is in the shadow maybe ambient lighting, but ambient lighting is very simplistic in our lighting model (omni-directionnal) and will still give this "flat" look.
I would be tempted to use attenuation instead of complete occlusion or any other trick.
Any idea ?
Flying toaster
 
Posts: 390
Joined: Wed Nov 29, 2006 7:25 am
Location: Toulouse France

Re: Compositor shadows change in shaders

Postby Thorsten » Wed Mar 10, 2021 7:39 pm

While it seems consistent with Phong lighting model, having the 3D models appear completely flat is disturbing, and I would expect something more like this (where you can still see the shape of an object that is in the shadow)


It's usually sky-light which resolves this in reality, ALS used to do an irradiance map for the diffuse light outside and a user-controlled map ('where are the windows?' ) inside to provide structure in shadow.

Without irradiance map:

Image

With irradiance map:

Image

Here's an example of sky light triggering the specular channel in the absence of direct light:

Image
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Compositor shadows change in shaders

Postby icecode » Fri Mar 12, 2021 8:20 pm

While it seems consistent with Phong lighting model, having the 3D models appear completely flat is disturbing, and I would expect something more like this (where you can still see the shape of an object that is in the shadow)


Unfortunately this is a limitation inherent to the Phong lighting model that ALS uses. More advanced BRDF models (like Cook-Torrance) offer more realistic results. There are several problems when it comes to implementing a PBR shading model in FG though, so the issue does not have an easy solution unfortunately. Thorsten's irradiance implementation somewhat helps with the issue, so feel free to use that.
icecode
 
Posts: 709
Joined: Thu Aug 12, 2010 1:17 pm
Location: Spain
Version: next
OS: Fedora

Re: Compositor shadows change in shaders

Postby Thorsten » Sat Mar 13, 2021 8:22 am

Unfortunately this is a limitation inherent to the Phong lighting model that ALS uses.


I'd disagree that ALS uses Blinn-Phong - it stared out that way and has the naming convention carried over, but I introduced half a dozen of non Blinn-Phong expressions whenever I noticed we're missing a lightsource which is there in reality.

So mature ALS is a far more elaborate scheme than basic Blinn-Phong with far less limitations. If we need a fancy name, we may call it the 'Renk scheme' since I really created the additions mostly from my own knowledge of light and not so much copying from work of others.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Compositor shadows change in shaders

Postby icecode » Sat Mar 13, 2021 7:39 pm

You are confusing BRDF model with lighting model. The BRDF that ALS uses is clearly Blinn-Phong:

Code: Select all
    NdotL = dot(n, lightDir);
    if (NdotL > 0.0) {
        float shadowmap = getShadowing();
        color += diffuse_term * NdotL * shadowmap;
        NdotHV = max(dot(n, halfVector), 0.0);
        if (gl_FrontMaterial.shininess > 0.0)
            specular.rgb = (gl_FrontMaterial.specular.rgb
                            * light_specular.rgb
                            * pow(NdotHV, gl_FrontMaterial.shininess)
                            * shadowmap);
    }
    color.a = diffuse_term.a;


Of course the sunlight color, hazes, fogging, etc. are all ALS-specific, but those have nothing to do with materials or surface properties. I guess you could say that ALS doesn't strictly use Blinn-Phong because you do take fresnel into account under some specific circumstances (like on the water shader), although I wouldn't go as far as calling it something else. Doing that would just unnecessarily complicate things for someone willing to play with ALS and its shaders.
icecode
 
Posts: 709
Joined: Thu Aug 12, 2010 1:17 pm
Location: Spain
Version: next
OS: Fedora

Re: Compositor shadows change in shaders

Postby Thorsten » Sun Mar 14, 2021 8:20 am

Well - no.

Blinn-Phong is a 5-liner, we might reasonably ask the question what the other 660 lines of, say the terrain shader are doing. For instance in addition to the lines you posted there's other terms coming later which do give definition to specularity and shape in the absence of direct light.

I think it's grossly misleading to say something still is the 5-liner and has the same limitations when these lines are less than a percent of the total that's happening.

(And yes, not all the 660 lines deal with lighting - some indeed process texture or light color, we could do a detailed breakdown if you really wanted...)

Doing that would just unnecessarily complicate things for someone willing to play with ALS and its shaders.


Not doing so would pretend that 660 lines of shader code are not relevant and be far more complicated to understand. The code will not respond like B-P, it even discards some things you can set for B-P.

On a different note, calling the whole 'Blinn-Phong' after the 1% that you cited would also deny my authorship of things that are clearly beyond the scheme and which I added based on my own insights.

As far as materials or alternative descriptions are concerned, that's in my view merely a way of organizing your thoughts about what you see - it has no particular relevance otherwise. The goal of rendering is to produce a credible pixel color for every screen pixel - how you organize the path there - whether you define something in terms of 'diffuse color' and 'specularity' or 'metallicity' - is a question of how you conceptualize what you see, not of the output - in math terms, you're changing the coordinate description of a problem, not the problem itself.

Short version: ALS is a lighting scheme that gives you specular skylight reflection and irradiance definition in the complete absence of direct light, B-P does not, thus the output is different, thus they're not the same schemes.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Compositor shadows change in shaders

Postby Johan G » Mon Mar 22, 2021 11:58 am

Thorsten wrote in Sun Mar 14, 2021 8:20 am:As far as materials or alternative descriptions are concerned, that's in my view merely a way of organizing your thoughts about what you see - it has no particular relevance otherwise. [...] whether you define something in terms of 'diffuse color' and 'specularity' or 'metallicity' - is a question of how you conceptualize what you see [...]

Interesting point.
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit


Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 6 guests