diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-12-23 17:20:06 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-01-11 18:00:23 +0300 |
commit | 9177bb33f68f66609b29e1e53a90552cae8026b3 (patch) | |
tree | 666aacdcceabeadb05c8cb6e890ab84be2a62069 /source/blender/draw/engines/workbench/workbench_materials.c | |
parent | 1459a7048958de229f35a23a1a760c28a06a5f44 (diff) |
Workbench: Support node texture "closest" interpolation option
This makes it possible to paint pixel art using the workbench.
Cubic interpolation is not supported but could be added if needed.
Diffstat (limited to 'source/blender/draw/engines/workbench/workbench_materials.c')
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_materials.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index faca4b401dc..679f11620b4 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -5,10 +5,15 @@ #include "BIF_gl.h" #include "BKE_image.h" +#include "BKE_node.h" #include "BLI_dynstr.h" #include "BLI_hash.h" +#include "DNA_node_types.h" + +#include "ED_uvedit.h" + #define HSV_SATURATION 0.5 #define HSV_VALUE 0.8 @@ -186,9 +191,24 @@ int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd, Image *i return color_type; } +void workbench_material_get_image_and_mat(Object *ob, int mat_nr, Image **r_image, int *r_interp, Material **r_mat) +{ + bNode *node; + *r_mat = give_current_material(ob, mat_nr); + ED_object_get_active_image(ob, mat_nr, r_image, NULL, &node, NULL); + if (node) { + BLI_assert(node->type == SH_NODE_TEX_IMAGE); + NodeTexImage *storage = node->storage; + *r_interp = storage->interpolation; + } + else { + *r_interp = 0; + } +} + void workbench_material_shgroup_uniform( WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp, WORKBENCH_MaterialData *material, Object *ob, - const bool use_metallic, const bool deferred) + const bool use_metallic, const bool deferred, const int interp) { if (deferred && !MATDATA_PASS_ENABLED(wpd)) { return; @@ -201,6 +221,7 @@ void workbench_material_shgroup_uniform( GPUTexture *tex = GPU_texture_from_blender(material->ima, NULL, GL_TEXTURE_2D, false, 0.0f); DRW_shgroup_uniform_texture(grp, "image", tex); DRW_shgroup_uniform_bool_copy(grp, "imageSrgb", do_color_correction); + DRW_shgroup_uniform_bool_copy(grp, "imageNearest", (interp == SHD_INTERP_CLOSEST)); } else { DRW_shgroup_uniform_vec3(grp, "materialDiffuseColor", (use_metallic) ? material->base_color : material->diffuse_color, 1); |