diff options
author | Alexander Romanov <a.romanov@blend4web.com> | 2016-07-04 11:08:48 +0300 |
---|---|---|
committer | Alexander Romanov <a.romanov@blend4web.com> | 2016-07-04 11:08:48 +0300 |
commit | 4aaf5baccf1b2f6bb0d618ab5005848431e168d0 (patch) | |
tree | 3fb91f05f76e0e713deaaaa597a44d63b439f702 | |
parent | fe44eacf78736f99bdfd3bc3ac86abd17e8ad514 (diff) |
Fix input for Texture node (envmap+world_space_shading)
This patch fixes shortcoming of D2046.
The original behavior without world_space_shading flag is that Texture node expects the reflected vector in view space. But with world_space_shading it should be in world space.
In attached file you will see a simple material setup and a node material analogue.
Simple material must have the same behavior regardless world_space_shading flag.
{F318866}
Alexander (Blend4Web Team)
Reviewers: brecht
Reviewed By: brecht
Subscribers: campbellbarton, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov
Differential Revision: https://developer.blender.org/D2072
-rw-r--r-- | source/blender/render/intern/source/envmap.c | 28 | ||||
-rw-r--r-- | source/blender/render/intern/source/render_texture.c | 15 |
2 files changed, 33 insertions, 10 deletions
diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index b1afb86e5af..d97e18d6511 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -52,6 +52,7 @@ #include "BKE_main.h" #include "BKE_image.h" /* BKE_imbuf_write */ #include "BKE_texture.h" +#include "BKE_scene.h" /* this module */ #include "render_types.h" @@ -737,21 +738,28 @@ int envmaptex(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int o /* rotate to envmap space, if object is set */ copy_v3_v3(vec, texvec); - if (env->object) mul_m3_v3(env->obimat, vec); - else mul_mat3_m4_v3(R.viewinv, vec); + if (env->object) { + mul_m3_v3(env->obimat, vec); + if (osatex) { + mul_m3_v3(env->obimat, dxt); + mul_m3_v3(env->obimat, dyt); + } + } + else { + if (!BKE_scene_use_world_space_shading(R.scene)) { + // texvec is in view space + mul_mat3_m4_v3(R.viewinv, vec); + if (osatex) { + mul_mat3_m4_v3(R.viewinv, dxt); + mul_mat3_m4_v3(R.viewinv, dyt); + } + } + } face = envcube_isect(env, vec, sco); ibuf = env->cube[face]; if (osatex) { - if (env->object) { - mul_m3_v3(env->obimat, dxt); - mul_m3_v3(env->obimat, dyt); - } - else { - mul_mat3_m4_v3(R.viewinv, dxt); - mul_mat3_m4_v3(R.viewinv, dyt); - } set_dxtdyt(dxts, dyts, dxt, dyt, face); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, texres, pool, skip_load_image); diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 530ebc084be..dc22859bdc1 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -1720,6 +1720,21 @@ static void texco_mapping(ShadeInput *shi, Tex *tex, MTex *mtex, } else dxt[2]= dyt[2] = 0.f; } + + if (mtex->tex->type == TEX_ENVMAP) { + EnvMap *env = tex->env; + if (!env->object) { + // env->object is a view point for envmap rendering + // if it's not set, return the result depending on the world_space_shading flag + if (BKE_scene_use_world_space_shading(R.scene)) { + mul_mat3_m4_v3(R.viewinv, texvec); + if (shi->osatex) { + mul_mat3_m4_v3(R.viewinv, dxt); + mul_mat3_m4_v3(R.viewinv, dyt); + } + } + } + } } } |