Page MenuHome

Environment lighting for the GLSL mode
ClosedPublic

Authored by Alexander Romanov (a.romanov) on Oct 1 2014, 3:43 PM.

Details

Summary

Environment lighting (aka ambient) is a key component of any renderer.
It's implemented like the Environment lighting of BI render for Approximate Gather mode. It support "Sky Color" and "White" Environment lighting modes.

It would be great if the user could see actual lighting conditions right in the Blender viewport instead of waiting for the renderer to complete the final image, exporting for external renderer or for a game engine.

Before:

After:

Example file:

Original author: valentin_b4w

Alexander (Blend4Web Team)

Diff Detail

Event Timeline

Dontsov Valentin (valentin_b4w) retitled this revision from to Implementation of environment lighting in GLSL render.Oct 1 2014, 3:43 PM
Dontsov Valentin (valentin_b4w) updated this object.
Dontsov Valentin (valentin_b4w) set the repository for this revision to rB Blender.
Dontsov Valentin (valentin_b4w) updated this revision to Diff 2644.
Thomas Dinges (dingto) added inline comments.
source/blender/makesrna/intern/rna_world.c
265

Is rna_World_draw_mist_update needed here, or does rna_World_draw_update work too? If we need the ND_DRAW notifier, I would recommend renaming the mist_update function, to something more generic.

One question about this is, should this environment light be enabled by default or not? The lack of shadows might make it look very different than what you would get rendering with Blender Internal, with a single background color it's going to be like an ambient term which might wash out the result colors more than it helps.

source/blender/gpu/intern/gpu_material.c
1495

What is the reason for this line? All this code is basically trying to emulate Blender internal materials, so it's not clear to me why this needs a special check.

It would perhaps make sense to add a mat->scene->gm.flag & GAME_GLSL_NO_ENVIRONMENT flag and associated property in the user interface for users that want to disable this, the same way lights, shadows, textures, etc. can be disabled for GLSL shading.

One question about this is, should this environment light be enabled by default or not? The lack of shadows might make it look very different than what you would get rendering with Blender Internal, with a single background color it's going to be like an ambient term which might wash out the result colors more than it helps.

I guess, it should be enabled by default because it's useful in another cases. "Environment lighting" flag can be set to false for a while if it's needed. Several flags can lead to confusion.

source/blender/gpu/intern/gpu_material.c
1495

The reason for this line is the lack of "Zenith Color" parameter in "Blender Game" mode.
I agree that probably additional flag and property would make sense. I'll change it.
Maybe it make sense to add "Zenith Color" parameter to "Blender game" world settings If "GLSL Environment lighting" flag appears.

There are three ways to implement "Environment Lighting" in "Blender Game":

  1. Allow to change "Zenith Color" and some other world settings. Also shade sky when game engine is run like default sky shading when "Only Render" flag is enabled.

  1. Draw "Environment Lighting" using "Zenith Color" like "Horizon Color". Perhaps it makes sense to update sky shading when "Only Render" flag is enabled in "Blender Game" mode if this way is chosen.
  2. Add "GAME_GLSL_NO_ENVIRONMENT" flag only. Leave this implementation as is.

I think that second way is happy medium.

source/blender/makesrna/intern/rna_world.c
265

"rna_World_draw_update" doesn't work when "Only Render" flag is turned off until you change something else. Renaming make sense.

Dontsov Valentin (valentin_b4w) updated this revision to Diff 2668.

Added implementation of environment lighting for the "Blender Game" mode.
"Environment Lighting" panel has been added to the world settings (similar to the "Mist" panel) for the "Blender Game" mode.
"Zenith Color" parameter has been added for tweaking environment lighting in the "Blender Game" mode.
Now, it updates the viewport when the sky color parameters, environment lighting parameters or mist parameters are changed.

Does the code need any changes?

Update for the actual master.

Yuri Kovelenov (yurikovelenov) retitled this revision from Implementation of environment lighting in GLSL render to Environment lighting for the GLSL mode.Nov 26 2014, 6:08 PM
Yuri Kovelenov (yurikovelenov) updated this object.

Updated for the actual master.

I am not really convinced this is a nice idea.

The model used is very simplistic and it does not even match the renderer output for blender internal by default or cycles for textured worlds.

I would instead go for nice image based lighting like in http://blenderartists.org/forum/showthread.php?343278-GLSL-PBR-Shader-for-viewport

I am not really convinced this is a nice idea.
The model used is very simplistic and it does not even match the renderer output for blender internal by default or cycles for textured worlds.
I would instead go for nice image based lighting like in http://blenderartists.org/forum/showthread.php?343278-GLSL-PBR-Shader-for-viewport

Hi Antony,

Indeed, the background differs between the internal renderer and Cycles, but this is current Blender behaviour. While it wasn't our goal, perhaps we could achieve their sameness with an additional patch. We could also submit a patch for textured worlds.

I absolutely agree that this model is a very primitive approximation. Its main advantage is that it is fast enough for real-time and it looks better than a plain black color which is the only supported option for now (see the first screenshot). Another reason for this patch is that this model is already supported by Blender Internal, and we just extend it to the viewport for consistency.

Image-based lighting is supported in Blend4Web and we'll be happy to implement it in Blender too, in addition to this simplistic model.

Thank you for your time and involvement.

Updated for the actual master.
Added additional flag in the user interface for users that want to disable this.
Now this feature is supported only for BI and BGE.

Updated for the actual master.
Added zenith dynamic uniform. Replaced horizon and zenith GPU_uniforms with GPU_dynamic_uniforms.

Updated for the actual master.

I hope we could see this patch in the master soon. I personnaly like it. And It's a nice thing for the BGE. And even if it's an approximation, this would make the viewport nicer and offer the possibility for the Blender internal artists to have a better preview of what will have in their final rendered image, and for the BGE designers to have the exact look they will have in the bge (This lines: (STREQ(mat->scene->r.engine, "BLENDER_RENDER") || STREQ(mat->scene->r.engine, "BLENDER_GAME"))) are really needed? as it works both for GE and Blender render?)

Porteries Tristan (panzergame) added inline comments.
source/blender/gpu/intern/gpu_material.c
1594

Why (mat->scene->r.mode & R_SHADOW) ?

1595

This condition is a habit in the code ?

source/blender/gpu/shaders/gpu_shader_material.glsl
1980

can you pass only the Z view matrix axis instead of the full matrix (3 flots vs 16) ?

Alexander Romanov (a.romanov) updated this revision to Diff 6980.
  • Updated for the current master
  • Added blend example

Since future Viewport will be in branch 2.8, I think that it's not necessary to block this patch because it could be very useful for B4W and BGE in 2.7 branch.

Alexander Romanov (a.romanov) marked 2 inline comments as done.Jun 29 2016, 5:16 PM
Alexander Romanov (a.romanov) added inline comments.
source/blender/gpu/intern/gpu_material.c
94

It's just for matching with BI behavior

Brecht Van Lommel (brecht) accepted this revision.

I don't much like an unshadowed environment lighting term and think this should really be influenced by AO, but I guess that will have to wait for a proper PBR shader. It can be turned off anyway.

source/blender/gpu/intern/gpu_material.c
1746–1747

!is_zero_v3(&world->horr) would be a little shorter.

source/blender/makesrna/intern/rna_scene.c
4384

I would prefer no abbreviation in the property name even if it's long.

source/blender/makesrna/intern/rna_world.c
267

Rename rna_World_draw_mist_update to rna_World_draw_update, since this is not just for mist now.

This revision is now accepted and ready to land.Jul 2 2016, 9:01 PM
Alexander Romanov (a.romanov) marked an inline comment as done.Jul 4 2016, 9:57 AM
Alexander Romanov (a.romanov) edited edge metadata.
Alexander Romanov (a.romanov) updated this revision to Diff 6995.
  • final corrections
Alexander Romanov (a.romanov) marked 3 inline comments as done.Jul 4 2016, 9:59 AM
This revision was automatically updated to reflect the committed changes.