Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-08-10 17:16:09 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-08-10 17:16:35 +0300
commit767386736070cfe7294e217f3734c1e7b736f4ae (patch)
treee11c348a370e943c4d77c3a10a65cee3a3469c7b
parent2cbffc8e4088d0d6a88fe90d1095cc90d2fa2b61 (diff)
GPUMaterial: Fix color ramp node with constant interpolation
Color ramp with constant interpolation must bypass texture filtering and use nearest neighboor sampling in order to appear correctly sharp. This patch use a GLSL hack to use nearest sampling on thoses particular color band.
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_valToRgb.c11
2 files changed, 15 insertions, 2 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 91104fe51bd..40aba1cc004 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -818,6 +818,12 @@ void valtorgb(float fac, sampler1DArray colormap, float layer, out vec4 outcol,
outalpha = outcol.a;
}
+void valtorgb_nearest(float fac, sampler1DArray colormap, float layer, out vec4 outcol, out float outalpha)
+{
+ outcol = texelFetch(colormap, ivec2(fac * textureSize(colormap, 0).x, layer), 0);
+ outalpha = outcol.a;
+}
+
void rgbtobw(vec4 color, out float outval)
{
vec3 factors = vec3(0.2126, 0.7152, 0.0722);
diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c
index 00940b5acaf..5f583e1e29b 100644
--- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c
@@ -65,12 +65,19 @@ static void node_shader_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node)
static int gpu_shader_valtorgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
+ struct ColorBand *coba = node->storage;
float *array, layer;
int size;
- BKE_colorband_evaluate_table_rgba(node->storage, &array, &size);
+ BKE_colorband_evaluate_table_rgba(coba, &array, &size);
GPUNodeLink *tex = GPU_texture_ramp(mat, size, array, &layer);
- return GPU_stack_link(mat, node, "valtorgb", in, out, tex, GPU_uniform(&layer));
+
+ if (coba->ipotype == COLBAND_INTERP_CONSTANT) {
+ return GPU_stack_link(mat, node, "valtorgb_nearest", in, out, tex, GPU_uniform(&layer));
+ }
+ else {
+ return GPU_stack_link(mat, node, "valtorgb", in, out, tex, GPU_uniform(&layer));
+ }
}
void register_node_type_sh_valtorgb(void)