diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-06-03 15:59:49 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-06-03 17:18:50 +0300 |
commit | 054923c8607c804a717cb5bb8ef15c0d4b151df3 (patch) | |
tree | 543cda2dc165bc032aba0c4bb754085414bd2594 /source/blender/nodes | |
parent | 47bdb288412db819672b3b8345b18f36c4f96373 (diff) |
GPUMaterial: Rework/simplify environment texture filtering
This use the latest GPUTexture change to use the sampler state to avoid
the pole issues instead of using GLSL hacks.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_tex_environment.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c index a62c2ee22b2..0cf4b51f307 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -19,6 +19,8 @@ #include "../node_shader_util.h" +#include "GPU_draw.h" + /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_environment_in[] = { @@ -56,7 +58,10 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node_original = node->original ? node->original : node; NodeTexImage *tex_original = node_original->storage; ImageUser *iuser = &tex_original->iuser; - eGPUSamplerState sampler_state = GPU_SAMPLER_MAX; + eGPUSamplerState sampler = GPU_SAMPLER_REPEAT | GPU_SAMPLER_ANISO | GPU_SAMPLER_FILTER; + if (GPU_get_mipmap()) { + sampler |= GPU_SAMPLER_MIPMAP; + } GPUNodeLink *outalpha; @@ -73,49 +78,41 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, /* Compute texture coordinate. */ if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) { - /* To fix pole issue we clamp the v coordinate. The clamp value depends on the filter size. */ - float clamp_size = (ELEM(tex->interpolation, SHD_INTERP_CUBIC, SHD_INTERP_SMART)) ? 1.5 : 0.5; - GPU_link(mat, - "node_tex_environment_equirectangular", - in[0].link, - GPU_constant(&clamp_size), - GPU_image(mat, ima, iuser, sampler_state), - &in[0].link); + GPU_link(mat, "node_tex_environment_equirectangular", in[0].link, &in[0].link); + /* To fix pole issue we clamp the v coordinate. */ + sampler &= ~GPU_SAMPLER_REPEAT_T; + /* Force the highest mipmap and don't do anisotropic filtering. + * This is to fix the artifact caused by derivatives discontinuity. */ + sampler &= ~(GPU_SAMPLER_MIPMAP | GPU_SAMPLER_ANISO); } else { GPU_link(mat, "node_tex_environment_mirror_ball", in[0].link, &in[0].link); + /* Fix pole issue. */ + sampler &= ~GPU_SAMPLER_REPEAT; } - /* Sample texture with correct interpolation. */ + const char *gpufunc; + static const char *names[] = { + "node_tex_image_linear", + "node_tex_image_cubic", + }; + switch (tex->interpolation) { case SHD_INTERP_LINEAR: - /* Force the highest mipmap and don't do anisotropic filtering. - * This is to fix the artifact caused by derivatives discontinuity. */ - GPU_link(mat, - "node_tex_image_linear_no_mip", - in[0].link, - GPU_image(mat, ima, iuser, sampler_state), - &out[0].link, - &outalpha); + gpufunc = names[0]; break; case SHD_INTERP_CLOSEST: - GPU_link(mat, - "node_tex_image_nearest", - in[0].link, - GPU_image(mat, ima, iuser, sampler_state), - &out[0].link, - &outalpha); + sampler &= ~(GPU_SAMPLER_FILTER | GPU_SAMPLER_MIPMAP); + gpufunc = names[0]; break; default: - GPU_link(mat, - "node_tex_image_cubic", - in[0].link, - GPU_image(mat, ima, iuser, sampler_state), - &out[0].link, - &outalpha); + gpufunc = names[1]; break; } + /* Sample texture with correct interpolation. */ + GPU_link(mat, gpufunc, in[0].link, GPU_image(mat, ima, iuser, sampler), &out[0].link, &outalpha); + if (out[0].hasoutput) { if (ELEM(ima->alpha_mode, IMA_ALPHA_IGNORE, IMA_ALPHA_CHANNEL_PACKED) || IMB_colormanagement_space_name_is_data(ima->colorspace_settings.name)) { |