[Bf-blender-cvs] [215f1c928e4] temp-udim-images: Support UDIM textures in workbench engine and texture painting

Lukas Stockner noreply at git.blender.org
Mon Jul 23 02:51:31 CEST 2018


Commit: 215f1c928e4ecd39274d70a7552fb3f90e27bfaf
Author: Lukas Stockner
Date:   Sun Jul 22 21:03:41 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB215f1c928e4ecd39274d70a7552fb3f90e27bfaf

Support UDIM textures in workbench engine and texture painting

===================================================================

M	source/blender/draw/engines/workbench/workbench_deferred.c
M	source/blender/draw/engines/workbench/workbench_forward.c
M	source/blender/draw/engines/workbench/workbench_materials.c
M	source/blender/draw/engines/workbench/workbench_private.h
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/modes/paint_texture_mode.c

===================================================================

diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c
index 4e90a08a543..2bf55e6313d 100644
--- a/source/blender/draw/engines/workbench/workbench_deferred.c
+++ b/source/blender/draw/engines/workbench/workbench_deferred.c
@@ -32,6 +32,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_rand.h"
 
+#include "BKE_image.h"
 #include "BKE_node.h"
 #include "BKE_modifier.h"
 #include "BKE_particle.h"
@@ -565,7 +566,7 @@ void workbench_deferred_cache_init(WORKBENCH_Data *vedata)
 }
 
 static WORKBENCH_MaterialData *get_or_create_material_data(
-        WORKBENCH_Data *vedata, Object *ob, Material *mat, Image *ima, int color_type)
+        WORKBENCH_Data *vedata, Object *ob, Material *mat, Image *ima, int color_type, int image_tile)
 {
 	WORKBENCH_StorageList *stl = vedata->stl;
 	WORKBENCH_PassList *psl = vedata->psl;
@@ -580,6 +581,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
 	material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd) ? engine_object_data->object_id : 1;
 	material_template.color_type = color_type;
 	material_template.ima = ima;
+	material_template.image_tile = image_tile;
 	uint hash = workbench_material_get_hash(&material_template);
 
 	material = BLI_ghash_lookup(wpd->material_hash, SET_UINT_IN_POINTER(hash));
@@ -625,7 +627,7 @@ static void workbench_cache_populate_particles(WORKBENCH_Data *vedata, Object *o
 			Material *mat = give_current_material(ob, part->omat);
 			ED_object_get_active_image(ob, part->omat, &image, NULL, NULL, NULL);
 			int color_type = workbench_material_determine_color_type(wpd, image);
-			WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, mat, image, color_type);
+			WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, mat, image, color_type, 0);
 
 			struct GPUShader *shader = (color_type != V3D_SHADING_TEXTURE_COLOR) ?
 			        wpd->prepass_solid_hair_sh :
@@ -677,23 +679,32 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
 		bool is_drawn = false;
 		if (!is_sculpt_mode && TEXTURE_DRAWING_ENABLED(wpd) && ELEM(ob->type, OB_MESH)) {
 			const Mesh *me = ob->data;
-			if (me->mloopuv) {
+			if (me->mloopuv && me->totcol) {
 				const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol));
-				struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
-				struct GPUBatch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob) : NULL;
-				if (materials_len > 0 && geom_array) {
-					for (int i = 0; i < materials_len; i++) {
-						if (geom_array[i] == NULL) {
-							continue;
-						}
 
-						Material *mat = give_current_material(ob, i + 1);
-						Image *image;
-						ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
-						int color_type = workbench_material_determine_color_type(wpd, image);
-						material = get_or_create_material_data(vedata, ob, mat, image, color_type);
-						DRW_shgroup_call_object_add(material->shgrp, geom_array[i], ob);
+				bool *is_tiled = MEM_mallocN(sizeof(bool)*materials_len, "workbench deferred is tiled");
+				for(int i = 0; i < materials_len; i++) {
+					Image *image;
+					ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
+					is_tiled[i] = image && (image->source == IMA_SRC_TILED);
+				}
+
+				int num_batches = 0;
+				struct TexpaintCacheBatch *geom_batches = DRW_cache_mesh_surface_texpaint_get(ob, is_tiled, &num_batches);
+
+				for (int i = 0; i < num_batches; i++) {
+					if (geom_batches[i].batch == NULL) {
+						continue;
 					}
+
+					int matid = geom_batches[i].material + 1;
+					Material *mat = give_current_material(ob, matid);
+					Image *image;
+					ED_object_get_active_image(ob, matid, &image, NULL, NULL, NULL);
+					int color_type = workbench_material_determine_color_type(wpd, image);
+					material = get_or_create_material_data(vedata, ob, mat, image, color_type, geom_batches[i].tile);
+					DRW_shgroup_call_object_add(material->shgrp, geom_batches[i].batch, ob);
+
 					is_drawn = true;
 				}
 			}
@@ -705,7 +716,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
 				/* No material split needed */
 				struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
 				if (geom) {
-					material = get_or_create_material_data(vedata, ob, NULL, NULL, wpd->shading.color_type);
+					material = get_or_create_material_data(vedata, ob, NULL, NULL, wpd->shading.color_type, 0);
 					if (is_sculpt_mode) {
 						DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat);
 					}
@@ -730,7 +741,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
 						}
 
 						Material *mat = give_current_material(ob, i + 1);
-						material = get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR);
+						material = get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR, 0);
 						if (is_sculpt_mode) {
 							DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat);
 						}
diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c
index 825b80ace52..6c9353cc132 100644
--- a/source/blender/draw/engines/workbench/workbench_forward.c
+++ b/source/blender/draw/engines/workbench/workbench_forward.c
@@ -31,6 +31,7 @@
 #include "BLI_dynstr.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_image.h"
 #include "BKE_node.h"
 #include "BKE_particle.h"
 #include "BKE_modifier.h"
@@ -134,7 +135,7 @@ static void workbench_init_object_data(DrawData *dd)
 }
 
 static WORKBENCH_MaterialData *get_or_create_material_data(
-        WORKBENCH_Data *vedata, Object *ob, Material *mat, Image *ima, int color_type)
+        WORKBENCH_Data *vedata, Object *ob, Material *mat, Image *ima, int color_type, int image_tile)
 {
 	WORKBENCH_StorageList *stl = vedata->stl;
 	WORKBENCH_PassList *psl = vedata->psl;
@@ -150,6 +151,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
 	material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd) ? engine_object_data->object_id : 1;
 	material_template.color_type = color_type;
 	material_template.ima = ima;
+	material_template.image_tile = image_tile;
 	uint hash = workbench_material_get_hash(&material_template);
 
 	material = BLI_ghash_lookup(wpd->material_hash, SET_UINT_IN_POINTER(hash));
@@ -178,9 +180,12 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
 
 		/* Depth */
 		if (workbench_material_determine_color_type(wpd, material->ima) == V3D_SHADING_TEXTURE_COLOR) {
+			ImageUser iuser = {NULL};
+			iuser.ok = 1;
+			iuser.tile = material->image_tile;
 			material->shgrp_object_outline = DRW_shgroup_create(
 			        e_data.object_outline_texture_sh, psl->object_outline_pass);
-			GPUTexture *tex = GPU_texture_from_blender(material->ima, NULL, GL_TEXTURE_2D, false, 0.0f);
+			GPUTexture *tex = GPU_texture_from_blender(material->ima, &iuser, GL_TEXTURE_2D, false, 0.0f);
 			DRW_shgroup_uniform_texture(material->shgrp_object_outline, "image", tex);
 		}
 		else {
@@ -415,7 +420,7 @@ static void workbench_forward_cache_populate_particles(WORKBENCH_Data *vedata, O
 			Material *mat = give_current_material(ob, part->omat);
 			ED_object_get_active_image(ob, part->omat, &image, NULL, NULL, NULL);
 			int color_type = workbench_material_determine_color_type(wpd, image);
-			WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, mat, image, color_type);
+			WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, mat, image, color_type, 0);
 
 			struct GPUShader *shader = (color_type != V3D_SHADING_TEXTURE_COLOR)
 			                           ? wpd->transparent_accum_hair_sh
@@ -485,31 +490,39 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
 			const Mesh *me = ob->data;
 			if (me->mloopuv) {
 				const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol));
-				struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
-				struct GPUBatch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob) : NULL;
-				if (materials_len > 0 && geom_array) {
-					for (int i = 0; i < materials_len; i++) {
-						if (geom_array[i] == NULL) {
-							continue;
-						}
 
-						Material *mat = give_current_material(ob, i + 1);
-						Image *image;
-						ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
-						/* use OB_SOLID when no texture could be determined */
+				bool *is_tiled = MEM_mallocN(sizeof(bool)*materials_len, "workbench forward is tiled");
+				for(int i = 0; i < materials_len; i++) {
+					Image *image;
+					ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
+					is_tiled[i] = image && (image->source == IMA_SRC_TILED);
+				}
 
-						int color_type = wpd->shading.color_type;
-						if (color_type == V3D_SHADING_TEXTURE_COLOR) {
-							/* use OB_SOLID when no texture could be determined */
-							if (image == NULL) {
-								color_type = V3D_SHADING_MATERIAL_COLOR;
-							}
-						}
+				int num_batches = 0;
+				struct TexpaintCacheBatch *geom_batches = DRW_cache_mesh_surface_texpaint_get(ob, is_tiled, &num_batches);
 
-						material = get_or_create_material_data(vedata, ob, mat, image, color_type);
-						DRW_shgroup_call_object_add(material->shgrp_object_outline, geom_array[i], ob);
-						DRW_shgroup_call_object_add(material->shgrp, geom_array[i], ob);
+				for (int i = 0; i < num_batches; i++) {
+					if (geom_batches[i].batch == NULL) {
+						continue;
 					}
+
+					int matid = geom_batches[i].material + 1;
+					Material *mat = give_current_material(ob, matid);
+					Image *image;
+					ED_object_get_active_image(ob, matid, &image, NULL, NULL, NULL);
+					/* use OB_SOLID when no texture could be determined */
+
+					int color_type = wpd->shading.color_type;
+					if (color_type == V3D_SHADING_TEXTURE_COLOR) {
+						/* use OB_SOLID when no texture could be determined */
+						if (image == NULL) {
+							color_type = V3D_SHADING_MATERIAL_COLOR;
+						}
+					}
+
+					material = get_or_create_material_data(vedata, ob, mat, ima

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list