DwM: texture paint support & mask mode
Uses workaround so material slots are used when neither blender-internal or cycles are enabled.
This commit is contained in:
parent
44f91a9a18
commit
f21c235c6f
Notes:
blender-bot
2023-02-14 09:38:57 +01:00
Referenced by issue #51654, Texture painting segfaults when no UV Map
|
@ -1305,6 +1305,14 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma)
|
|||
|
||||
bool use_nodes = BKE_scene_use_new_shading_nodes(scene);
|
||||
bool is_bi = BKE_scene_uses_blender_internal(scene) || BKE_scene_uses_blender_game(scene);
|
||||
|
||||
/* XXX, for 2.8 testing & development its useful to have non Cycles/BI engines use material nodes
|
||||
* In the future we may have some way to check this which each engine can define.
|
||||
* For now use material slots for Clay/Eevee.
|
||||
* - Campbell */
|
||||
if (!(use_nodes || is_bi)) {
|
||||
is_bi = true;
|
||||
}
|
||||
|
||||
if (!ma)
|
||||
return;
|
||||
|
|
|
@ -162,6 +162,8 @@ data_to_c_simple(modes/shaders/object_outline_expand_frag.glsl SRC)
|
|||
data_to_c_simple(modes/shaders/object_outline_detect_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/object_grid_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/object_grid_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/paint_texture_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/paint_texture_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/paint_wire_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/paint_wire_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/paint_vert_frag.glsl SRC)
|
||||
|
|
|
@ -2065,6 +2065,23 @@ Batch **DRW_cache_mesh_surface_shaded_get(Object *ob)
|
|||
return DRW_mesh_batch_cache_get_surface_shaded(me);
|
||||
}
|
||||
|
||||
/* Return list of batches */
|
||||
Batch **DRW_cache_mesh_surface_texpaint_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ob->type == OB_MESH);
|
||||
|
||||
Mesh *me = ob->data;
|
||||
return DRW_mesh_batch_cache_get_surface_texpaint(me);
|
||||
}
|
||||
|
||||
Batch *DRW_cache_mesh_surface_texpaint_single_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ob->type == OB_MESH);
|
||||
|
||||
Mesh *me = ob->data;
|
||||
return DRW_mesh_batch_cache_get_surface_texpaint_single(me);
|
||||
}
|
||||
|
||||
Batch *DRW_cache_mesh_surface_verts_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ob->type == OB_MESH);
|
||||
|
|
|
@ -112,6 +112,8 @@ struct Batch *DRW_cache_mesh_edges_paint_overlay_get(struct Object *ob, bool use
|
|||
struct Batch *DRW_cache_mesh_faces_weight_overlay_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_mesh_verts_weight_overlay_get(struct Object *ob);
|
||||
struct Batch **DRW_cache_mesh_surface_shaded_get(struct Object *ob);
|
||||
struct Batch **DRW_cache_mesh_surface_texpaint_get(struct Object *ob);
|
||||
struct Batch *DRW_cache_mesh_surface_texpaint_single_get(struct Object *ob);
|
||||
|
||||
/* Curve */
|
||||
struct Batch *DRW_cache_curve_surface_get(struct Object *ob);
|
||||
|
|
|
@ -72,6 +72,8 @@ struct Batch *DRW_lattice_batch_cache_get_overlay_verts(struct Lattice *lt);
|
|||
/* Mesh */
|
||||
|
||||
struct Batch **DRW_mesh_batch_cache_get_surface_shaded(struct Mesh *me);
|
||||
struct Batch **DRW_mesh_batch_cache_get_surface_texpaint(struct Mesh *me);
|
||||
struct Batch *DRW_mesh_batch_cache_get_surface_texpaint_single(struct Mesh *me);
|
||||
struct Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(struct Mesh *me, bool use_wire, bool use_sel);
|
||||
struct Batch *DRW_mesh_batch_cache_get_weight_overlay_faces(struct Mesh *me);
|
||||
struct Batch *DRW_mesh_batch_cache_get_weight_overlay_verts(struct Mesh *me);
|
||||
|
|
|
@ -130,6 +130,7 @@ typedef struct MeshRenderData {
|
|||
MPoly *mpoly;
|
||||
float (*orco)[3];
|
||||
MDeformVert *dvert;
|
||||
MLoopUV *mloopuv;
|
||||
MLoopCol *mloopcol;
|
||||
|
||||
/* CustomData 'cd' cache for efficient access. */
|
||||
|
@ -200,6 +201,7 @@ enum {
|
|||
MR_DATATYPE_SHADING = 1 << 6,
|
||||
MR_DATATYPE_DVERT = 1 << 7,
|
||||
MR_DATATYPE_LOOPCOL = 1 << 8,
|
||||
MR_DATATYPE_LOOPUV = 1 << 9,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -348,6 +350,10 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, const int types)
|
|||
rdata->loop_len = me->totloop;
|
||||
rdata->mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL);
|
||||
}
|
||||
if (types & MR_DATATYPE_LOOPUV) {
|
||||
rdata->loop_len = me->totloop;
|
||||
rdata->mloopuv = CustomData_get_layer(&me->ldata, CD_MLOOPUV);
|
||||
}
|
||||
}
|
||||
|
||||
if (types & MR_DATATYPE_SHADING) {
|
||||
|
@ -1469,6 +1475,7 @@ typedef struct MeshBatchCache {
|
|||
VertexBuffer *tri_aligned_weights;
|
||||
VertexBuffer *tri_aligned_vert_colors;
|
||||
VertexBuffer *tri_aligned_select_id;
|
||||
VertexBuffer *tri_aligned_uv; /* Active UV layer (mloopuv) */
|
||||
VertexBuffer *edge_pos_with_select_bool;
|
||||
VertexBuffer *pos_with_select_bool;
|
||||
Batch *triangles_with_normals;
|
||||
|
@ -1490,6 +1497,11 @@ typedef struct MeshBatchCache {
|
|||
ElementList **shaded_triangles_in_order;
|
||||
Batch **shaded_triangles;
|
||||
|
||||
/* Texture Paint.*/
|
||||
/* per-texture batch */
|
||||
Batch **texpaint_triangles;
|
||||
Batch *texpaint_triangles_single;
|
||||
|
||||
/* Edit Cage Mesh buffers */
|
||||
VertexBuffer *ed_tri_pos;
|
||||
VertexBuffer *ed_tri_nor; /* LoopNor, VertNor */
|
||||
|
@ -1683,6 +1695,7 @@ static void mesh_batch_cache_clear(Mesh *me)
|
|||
BATCH_DISCARD_SAFE(cache->triangles_with_weights);
|
||||
BATCH_DISCARD_SAFE(cache->triangles_with_vert_colors);
|
||||
VERTEXBUFFER_DISCARD_SAFE(cache->tri_aligned_select_id);
|
||||
VERTEXBUFFER_DISCARD_SAFE(cache->tri_aligned_uv);
|
||||
BATCH_DISCARD_SAFE(cache->triangles_with_select_id);
|
||||
|
||||
BATCH_DISCARD_ALL_SAFE(cache->fancy_edges);
|
||||
|
@ -1701,6 +1714,16 @@ static void mesh_batch_cache_clear(Mesh *me)
|
|||
|
||||
MEM_SAFE_FREE(cache->shaded_triangles_in_order);
|
||||
MEM_SAFE_FREE(cache->shaded_triangles);
|
||||
|
||||
if (cache->texpaint_triangles) {
|
||||
for (int i = 0; i < cache->mat_len; ++i) {
|
||||
BATCH_DISCARD_SAFE(cache->texpaint_triangles[i]);
|
||||
}
|
||||
}
|
||||
MEM_SAFE_FREE(cache->texpaint_triangles);
|
||||
|
||||
BATCH_DISCARD_SAFE(cache->texpaint_triangles_single);
|
||||
|
||||
}
|
||||
|
||||
void DRW_mesh_batch_cache_free(Mesh *me)
|
||||
|
@ -1856,6 +1879,45 @@ static VertexBuffer *mesh_batch_cache_get_tri_shading_data(MeshRenderData *rdata
|
|||
return cache->shaded_triangles_data;
|
||||
}
|
||||
|
||||
static VertexBuffer *mesh_batch_cache_get_tri_uv_active(
|
||||
MeshRenderData *rdata, MeshBatchCache *cache)
|
||||
{
|
||||
BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_LOOPUV));
|
||||
BLI_assert(rdata->edit_bmesh == NULL);
|
||||
|
||||
if (cache->tri_aligned_uv == NULL) {
|
||||
unsigned int vidx = 0;
|
||||
|
||||
static VertexFormat format = { 0 };
|
||||
static struct { uint uv; } attr_id;
|
||||
if (format.attrib_ct == 0) {
|
||||
attr_id.uv = VertexFormat_add_attrib(&format, "uv", COMP_F32, 2, KEEP_FLOAT);
|
||||
}
|
||||
|
||||
const int tri_len = mesh_render_data_looptri_len_get(rdata);
|
||||
|
||||
VertexBuffer *vbo = cache->tri_aligned_uv = VertexBuffer_create_with_format(&format);
|
||||
|
||||
const int vbo_len_capacity = tri_len * 3;
|
||||
int vbo_len_used = 0;
|
||||
VertexBuffer_allocate_data(vbo, vbo_len_capacity);
|
||||
|
||||
const MLoopUV *mloopuv = rdata->mloopuv;
|
||||
|
||||
for (int i = 0; i < tri_len; i++) {
|
||||
const MLoopTri *mlt = &rdata->mlooptri[i];
|
||||
VertexBuffer_set_attrib(vbo, attr_id.uv, vidx++, mloopuv[mlt->tri[0]].uv);
|
||||
VertexBuffer_set_attrib(vbo, attr_id.uv, vidx++, mloopuv[mlt->tri[1]].uv);
|
||||
VertexBuffer_set_attrib(vbo, attr_id.uv, vidx++, mloopuv[mlt->tri[2]].uv);
|
||||
}
|
||||
vbo_len_used = vidx;
|
||||
|
||||
BLI_assert(vbo_len_capacity == vbo_len_used);
|
||||
}
|
||||
|
||||
return cache->tri_aligned_uv;
|
||||
}
|
||||
|
||||
static VertexBuffer *mesh_batch_cache_get_tri_pos_and_normals_ex(
|
||||
MeshRenderData *rdata, const bool use_hide,
|
||||
VertexBuffer **r_vbo)
|
||||
|
@ -3146,6 +3208,60 @@ Batch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me)
|
|||
return cache->shaded_triangles;
|
||||
}
|
||||
|
||||
Batch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me)
|
||||
{
|
||||
MeshBatchCache *cache = mesh_batch_cache_get(me);
|
||||
|
||||
if (cache->texpaint_triangles == NULL) {
|
||||
/* create batch from DM */
|
||||
const int datatype =
|
||||
MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOPUV;
|
||||
MeshRenderData *rdata = mesh_render_data_create(me, datatype);
|
||||
|
||||
const int mat_len = mesh_render_data_mat_len_get(rdata);
|
||||
|
||||
cache->texpaint_triangles = MEM_callocN(sizeof(*cache->texpaint_triangles) * mat_len, __func__);
|
||||
|
||||
ElementList **el = mesh_batch_cache_get_shaded_triangles_in_order(rdata, cache);
|
||||
|
||||
VertexBuffer *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
|
||||
for (int i = 0; i < mat_len; ++i) {
|
||||
cache->texpaint_triangles[i] = Batch_create(
|
||||
PRIM_TRIANGLES, vbo, el[i]);
|
||||
VertexBuffer *vbo_uv = mesh_batch_cache_get_tri_uv_active(rdata, cache);
|
||||
if (vbo_uv) {
|
||||
Batch_add_VertexBuffer(cache->texpaint_triangles[i], vbo_uv);
|
||||
}
|
||||
}
|
||||
mesh_render_data_free(rdata);
|
||||
}
|
||||
|
||||
return cache->texpaint_triangles;
|
||||
}
|
||||
|
||||
Batch *DRW_mesh_batch_cache_get_surface_texpaint_single(Mesh *me)
|
||||
{
|
||||
MeshBatchCache *cache = mesh_batch_cache_get(me);
|
||||
|
||||
if (cache->texpaint_triangles_single == NULL) {
|
||||
/* create batch from DM */
|
||||
const int datatype =
|
||||
MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOPUV;
|
||||
MeshRenderData *rdata = mesh_render_data_create(me, datatype);
|
||||
|
||||
VertexBuffer *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
|
||||
|
||||
cache->texpaint_triangles_single = Batch_create(
|
||||
PRIM_TRIANGLES, vbo, NULL);
|
||||
VertexBuffer *vbo_uv = mesh_batch_cache_get_tri_uv_active(rdata, cache);
|
||||
if (vbo_uv) {
|
||||
Batch_add_VertexBuffer(cache->texpaint_triangles_single, vbo_uv);
|
||||
}
|
||||
mesh_render_data_free(rdata);
|
||||
}
|
||||
return cache->texpaint_triangles_single;
|
||||
}
|
||||
|
||||
Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(Mesh *me, bool use_wire, bool use_sel)
|
||||
{
|
||||
MeshBatchCache *cache = mesh_batch_cache_get(me);
|
||||
|
|
|
@ -26,13 +26,24 @@
|
|||
#include "DRW_engine.h"
|
||||
#include "DRW_render.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
|
||||
/* If builtin shaders are needed */
|
||||
#include "GPU_shader.h"
|
||||
#include "GPU_texture.h"
|
||||
|
||||
#include "draw_common.h"
|
||||
|
||||
#include "draw_mode_engines.h"
|
||||
|
||||
#include "DNA_mesh_types.h"
|
||||
|
||||
extern char datatoc_common_globals_lib_glsl[];
|
||||
extern char datatoc_paint_texture_vert_glsl[];
|
||||
extern char datatoc_paint_texture_frag_glsl[];
|
||||
extern char datatoc_paint_wire_vert_glsl[];
|
||||
extern char datatoc_paint_wire_frag_glsl[];
|
||||
|
||||
/* If needed, contains all global/Theme colors
|
||||
* Add needed theme colors / values to DRW_globals_update() and update UBO
|
||||
* Not needed for constant color. */
|
||||
|
@ -50,7 +61,10 @@ typedef struct PAINT_TEXTURE_PassList {
|
|||
/* Declare all passes here and init them in
|
||||
* PAINT_TEXTURE_cache_init().
|
||||
* Only contains (DRWPass *) */
|
||||
struct DRWPass *pass;
|
||||
struct DRWPass *image_faces;
|
||||
|
||||
struct DRWPass *wire_overlay;
|
||||
struct DRWPass *face_overlay;
|
||||
} PAINT_TEXTURE_PassList;
|
||||
|
||||
typedef struct PAINT_TEXTURE_FramebufferList {
|
||||
|
@ -93,13 +107,22 @@ static struct {
|
|||
* Add sources to source/blender/draw/modes/shaders
|
||||
* init in PAINT_TEXTURE_engine_init();
|
||||
* free in PAINT_TEXTURE_engine_free(); */
|
||||
struct GPUShader *custom_shader;
|
||||
struct GPUShader *fallback_sh;
|
||||
struct GPUShader *image_sh;
|
||||
|
||||
struct GPUShader *wire_overlay_shader;
|
||||
struct GPUShader *face_overlay_shader;
|
||||
} e_data = {NULL}; /* Engine data */
|
||||
|
||||
typedef struct PAINT_TEXTURE_PrivateData {
|
||||
/* This keeps the references of the shading groups for
|
||||
* easy access in PAINT_TEXTURE_cache_populate() */
|
||||
DRWShadingGroup *group;
|
||||
DRWShadingGroup *shgroup_fallback;
|
||||
DRWShadingGroup **shgroup_image_array;
|
||||
|
||||
/* face-mask */
|
||||
DRWShadingGroup *lwire_shgrp;
|
||||
DRWShadingGroup *face_shgrp;
|
||||
} PAINT_TEXTURE_PrivateData; /* Transient data */
|
||||
|
||||
/* *********** FUNCTIONS *********** */
|
||||
|
@ -130,11 +153,33 @@ static void PAINT_TEXTURE_engine_init(void *vedata)
|
|||
* tex, 2);
|
||||
*/
|
||||
|
||||
if (!e_data.custom_shader) {
|
||||
e_data.custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
if (!e_data.fallback_sh) {
|
||||
e_data.fallback_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
}
|
||||
if (!e_data.image_sh) {
|
||||
e_data.image_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
|
||||
e_data.image_sh = DRW_shader_create_with_lib(
|
||||
datatoc_paint_texture_vert_glsl, NULL,
|
||||
datatoc_paint_texture_frag_glsl,
|
||||
datatoc_common_globals_lib_glsl, NULL);
|
||||
|
||||
}
|
||||
|
||||
if (!e_data.wire_overlay_shader) {
|
||||
e_data.wire_overlay_shader = DRW_shader_create_with_lib(
|
||||
datatoc_paint_wire_vert_glsl, NULL,
|
||||
datatoc_paint_wire_frag_glsl,
|
||||
datatoc_common_globals_lib_glsl,
|
||||
"#define VERTEX_MODE\n");
|
||||
}
|
||||
|
||||
if (!e_data.face_overlay_shader) {
|
||||
e_data.face_overlay_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
/* Here init all passes and shading groups
|
||||
* Assume that all Passes are NULL */
|
||||
static void PAINT_TEXTURE_cache_init(void *vedata)
|
||||
|
@ -145,12 +190,14 @@ static void PAINT_TEXTURE_cache_init(void *vedata)
|
|||
if (!stl->g_data) {
|
||||
/* Alloc transient pointers */
|
||||
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
||||
stl->g_data->shgroup_image_array = NULL;
|
||||
}
|
||||
|
||||
{
|
||||
/* Create a pass */
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE;
|
||||
psl->pass = DRW_pass_create("My Pass", state);
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS |
|
||||
DRW_STATE_BLEND | DRW_STATE_WIRE;
|
||||
psl->image_faces = DRW_pass_create("Image Color Pass", state);
|
||||
|
||||
/* Create a shadingGroup using a function in draw_common.c or custom one */
|
||||
/*
|
||||
|
@ -158,14 +205,78 @@ static void PAINT_TEXTURE_cache_init(void *vedata)
|
|||
* -- or --
|
||||
* stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
|
||||
*/
|
||||
stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
|
||||
stl->g_data->shgroup_fallback = DRW_shgroup_create(e_data.fallback_sh, psl->image_faces);
|
||||
|
||||
/* Uniforms need a pointer to it's value so be sure it's accessible at
|
||||
* any given time (i.e. use static vars) */
|
||||
static float color[4] = {0.2f, 0.5f, 0.3f, 1.0};
|
||||
DRW_shgroup_uniform_vec4(stl->g_data->group, "color", color, 1);
|
||||
static float color[4] = {1.0f, 0.0f, 1.0f, 1.0};
|
||||
DRW_shgroup_uniform_vec4(stl->g_data->shgroup_fallback, "color", color, 1);
|
||||
|
||||
MEM_SAFE_FREE(stl->g_data->shgroup_image_array);
|
||||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
Object *ob = draw_ctx->obact;
|
||||
if (ob && ob->type == OB_MESH) {
|
||||
Scene *scene = draw_ctx->scene;
|
||||
bool use_material_slots = (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_MATERIAL);
|
||||
const Mesh *me = ob->data;
|
||||
|
||||
stl->g_data->shgroup_image_array = MEM_mallocN(
|
||||
sizeof(*stl->g_data->shgroup_image_array) * (use_material_slots ? me->totcol : 1), __func__);
|
||||
|
||||
if (use_material_slots) {
|
||||
for (int i = 0; i < me->totcol; i++) {
|
||||
Material *ma = give_current_material(ob, i + 1);
|
||||
Image *ima = (ma && ma->texpaintslot) ? ma->texpaintslot[ma->paint_active_slot].ima : NULL;
|
||||
GPUTexture *tex = ima ?
|
||||
GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, false, false) : NULL;
|
||||
|
||||
if (tex) {
|
||||
DRWShadingGroup *grp = DRW_shgroup_create(e_data.image_sh, psl->image_faces);
|
||||
DRW_shgroup_uniform_texture(grp, "image", tex);
|
||||
stl->g_data->shgroup_image_array[i] = grp;
|
||||
}
|
||||
else {
|
||||
stl->g_data->shgroup_image_array[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Image *ima = scene->toolsettings->imapaint.canvas;
|
||||
GPUTexture *tex = ima ?
|
||||
GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, false, false) : NULL;
|
||||
|
||||
if (tex) {
|
||||
DRWShadingGroup *grp = DRW_shgroup_create(e_data.image_sh, psl->image_faces);
|
||||
DRW_shgroup_uniform_texture(grp, "image", tex);
|
||||
stl->g_data->shgroup_image_array[0] = grp;
|
||||
}
|
||||
else {
|
||||
stl->g_data->shgroup_image_array[0] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Face Mask */
|
||||
{
|
||||
psl->wire_overlay = DRW_pass_create(
|
||||
"Wire Pass",
|
||||
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
|
||||
|
||||
stl->g_data->lwire_shgrp = DRW_shgroup_create(e_data.wire_overlay_shader, psl->wire_overlay);
|
||||
}
|
||||
|
||||
{
|
||||
psl->face_overlay = DRW_pass_create(
|
||||
"Face Mask Pass",
|
||||
DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND);
|
||||
|
||||
stl->g_data->face_shgrp = DRW_shgroup_create(e_data.face_overlay_shader, psl->face_overlay);
|
||||
|
||||
static float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
|
||||
DRW_shgroup_uniform_vec4(stl->g_data->face_shgrp, "color", col, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add geometry to shadingGroups. Execute for each objects */
|
||||
|
@ -178,10 +289,53 @@ static void PAINT_TEXTURE_cache_populate(void *vedata, Object *ob)
|
|||
|
||||
if (ob->type == OB_MESH) {
|
||||
/* Get geometry cache */
|
||||
struct Batch *geom = DRW_cache_mesh_surface_get(ob);
|
||||
const Mesh *me = ob->data;
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
Scene *scene = draw_ctx->scene;
|
||||
bool use_material_slots = (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_MATERIAL);
|
||||
|
||||
/* Add geom to a shading group */
|
||||
DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat);
|
||||
if (use_material_slots) {
|
||||
struct Batch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob) : NULL;
|
||||
if ((me->totcol == 0) || (geom_array == NULL)) {
|
||||
struct Batch *geom = DRW_cache_mesh_surface_get(ob);
|
||||
DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom, ob->obmat);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < me->totcol; i++) {
|
||||
if (stl->g_data->shgroup_image_array[i]) {
|
||||
DRW_shgroup_call_add(stl->g_data->shgroup_image_array[i], geom_array[i], ob->obmat);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom_array[i], ob->obmat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
struct Batch *geom = DRW_cache_mesh_surface_texpaint_single_get(ob);
|
||||
if (geom && stl->g_data->shgroup_image_array[0]) {
|
||||
DRW_shgroup_call_add(stl->g_data->shgroup_image_array[0], geom, ob->obmat);
|
||||
}
|
||||
else {
|
||||
if (geom == NULL) {
|
||||
geom = DRW_cache_mesh_surface_get(ob);
|
||||
}
|
||||
DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom, ob->obmat);
|
||||
}
|
||||
}
|
||||
|
||||
/* Face Mask */
|
||||
const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
|
||||
if (use_face_sel) {
|
||||
struct Batch *geom;
|
||||
/* Note: ideally selected faces wouldn't show interior wire. */
|
||||
const bool use_wire = true;
|
||||
geom = DRW_cache_mesh_edges_paint_overlay_get(ob, use_wire, use_face_sel);
|
||||
DRW_shgroup_call_add(stl->g_data->lwire_shgrp, geom, ob->obmat);
|
||||
|
||||
geom = DRW_cache_mesh_faces_weight_overlay_get(ob);
|
||||
DRW_shgroup_call_add(stl->g_data->face_shgrp, geom, ob->obmat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +346,9 @@ static void PAINT_TEXTURE_cache_finish(void *vedata)
|
|||
PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
|
||||
|
||||
/* Do something here! dependant on the objects gathered */
|
||||
UNUSED_VARS(psl, stl);
|
||||
UNUSED_VARS(psl);
|
||||
|
||||
MEM_SAFE_FREE(stl->g_data->shgroup_image_array);
|
||||
}
|
||||
|
||||
/* Draw time ! Control rendering pipeline from here */
|
||||
|
@ -207,20 +363,10 @@ static void PAINT_TEXTURE_draw_scene(void *vedata)
|
|||
|
||||
UNUSED_VARS(fbl, dfbl, dtxl);
|
||||
|
||||
/* Show / hide entire passes, swap framebuffers ... whatever you fancy */
|
||||
/*
|
||||
* DRW_framebuffer_texture_detach(dtxl->depth);
|
||||
* DRW_framebuffer_bind(fbl->custom_fb);
|
||||
* DRW_draw_pass(psl->pass);
|
||||
* DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
|
||||
* DRW_framebuffer_bind(dfbl->default_fb);
|
||||
*/
|
||||
DRW_draw_pass(psl->image_faces);
|
||||
|
||||
/* ... or just render passes on default framebuffer. */
|
||||
DRW_draw_pass(psl->pass);
|
||||
|
||||
/* If you changed framebuffer, double check you rebind
|
||||
* the default one with its textures attached before finishing */
|
||||
DRW_draw_pass(psl->face_overlay);
|
||||
DRW_draw_pass(psl->wire_overlay);
|
||||
}
|
||||
|
||||
/* Cleanup when destroying the engine.
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
in vec2 uv_interp;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D image;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = texture(image, uv_interp);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
|
||||
in vec2 uv;
|
||||
in vec3 pos;
|
||||
|
||||
out vec2 uv_interp;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
|
||||
uv_interp = uv;
|
||||
|
||||
}
|
Loading…
Reference in New Issue