diff options
author | Alexander Romanov <a.romanov@blend4web.com> | 2016-07-04 11:01:32 +0300 |
---|---|---|
committer | Alexander Romanov <a.romanov@blend4web.com> | 2016-07-04 11:01:32 +0300 |
commit | fe44eacf78736f99bdfd3bc3ac86abd17e8ad514 (patch) | |
tree | d455a08416a08ea5a8bd2debd5afb8ef1deb63ea /source/blender/gpu/intern | |
parent | 9269574089a742130f02c0a1184a19d94f0e665d (diff) |
Environment lighting for the GLSL mode
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:
{F113921}
After:
{F113922}
Example file: {F319013}
Original author: valentin_b4w
Alexander (Blend4Web Team)
Reviewers: valentin_b4w, campbellbarton, merwin, brecht
Reviewed By: brecht
Subscribers: panzergame, youle, duarteframos, AlexKowel, yurikovelenov, dingto, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx
Differential Revision: https://developer.blender.org/D810
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index f14b2e6e170..095a5b1b66a 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -88,6 +88,7 @@ static struct GPUWorld { float mistcol[4]; float horicol[3]; float ambcol[4]; + float zencol[3]; } GPUWorld; struct GPUMaterial { @@ -1673,6 +1674,11 @@ void GPU_ambient_update_color(float color[3]) GPUWorld.ambcol[3] = 1.0f; } +void GPU_zenith_update_color(float color[3]) +{ + copy_v3_v3(GPUWorld.zencol, color); +} + void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) { GPUMaterial *mat = shi->gpumat; @@ -1729,6 +1735,33 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) ulinfac, ulogfac, &shr->spec); } + /* environment lighting */ + if (!(mat->scene->gm.flag & GAME_GLSL_NO_ENV_LIGHTING) && (world->mode & WO_ENV_LIGHT) && (mat->scene->r.mode & R_SHADOW) && + !BKE_scene_use_new_shading_nodes(mat->scene)) + { + if ((world->ao_env_energy != 0.0f) && (GPU_link_changed(shi->amb) || ma->amb != 0.0f) && + (GPU_link_changed(shi->refl) || ma->ref != 0.0f)) + { + if (world->aocolor != WO_AOPLAIN) { + if (!(is_zero_v3(&world->horr) & is_zero_v3(&world->zenr))) + { + GPUNodeLink *fcol, *f; + GPU_link(mat, "math_multiply", shi->amb, shi->refl, &f); + GPU_link(mat, "math_multiply", f, GPU_uniform(&world->ao_env_energy), &f); + GPU_link(mat, "shade_mul_value", f, shi->rgb, &fcol); + GPU_link(mat, "env_apply", shr->combined, GPU_dynamic_uniform(GPUWorld.horicol, GPU_DYNAMIC_HORIZON_COLOR, NULL), + GPU_dynamic_uniform(GPUWorld.zencol, GPU_DYNAMIC_ZENITH_COLOR, NULL), fcol, GPU_builtin(GPU_VIEW_MATRIX), shi->vn, &shr->combined); + } + } + else { + GPUNodeLink *f; + GPU_link(mat, "math_multiply", shi->amb, shi->refl, &f); + GPU_link(mat, "math_multiply", f, GPU_uniform(&world->ao_env_energy), &f); + GPU_link(mat, "shade_maddf", shr->combined, f, shi->rgb, &shr->combined); + } + } + } + /* ambient color */ if (GPU_link_changed(shi->amb) || ma->amb != 0.0f) { GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb), |