From cf4f00b2fa6dfecc400519a635c41798bf45ca88 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 7 Oct 2009 14:48:29 +0000 Subject: Preview Render: * Fixes for texture and material nodes. * Texture node previews now work more like materials. --- source/blender/editors/include/ED_render.h | 14 ++-- source/blender/editors/render/render_preview.c | 33 ++++++---- source/blender/editors/space_node/node_draw.c | 3 + source/blender/editors/space_node/space_node.c | 6 +- source/blender/makesdna/DNA_scene_types.h | 5 +- source/blender/makesrna/intern/rna_material.c | 2 +- source/blender/makesrna/intern/rna_texture.c | 12 +++- source/blender/nodes/intern/TEX_nodes/TEX_at.c | 2 +- source/blender/nodes/intern/TEX_nodes/TEX_bricks.c | 4 +- .../blender/nodes/intern/TEX_nodes/TEX_checker.c | 4 +- .../blender/nodes/intern/TEX_nodes/TEX_compose.c | 2 +- source/blender/nodes/intern/TEX_nodes/TEX_coord.c | 4 +- source/blender/nodes/intern/TEX_nodes/TEX_curves.c | 4 +- .../blender/nodes/intern/TEX_nodes/TEX_decompose.c | 8 +-- .../blender/nodes/intern/TEX_nodes/TEX_distance.c | 4 +- .../blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c | 2 +- source/blender/nodes/intern/TEX_nodes/TEX_image.c | 4 +- source/blender/nodes/intern/TEX_nodes/TEX_invert.c | 4 +- source/blender/nodes/intern/TEX_nodes/TEX_math.c | 4 +- source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c | 4 +- source/blender/nodes/intern/TEX_nodes/TEX_output.c | 44 +++++++------ source/blender/nodes/intern/TEX_nodes/TEX_proc.c | 5 +- source/blender/nodes/intern/TEX_nodes/TEX_rotate.c | 2 +- source/blender/nodes/intern/TEX_nodes/TEX_scale.c | 2 +- .../blender/nodes/intern/TEX_nodes/TEX_texture.c | 4 +- .../blender/nodes/intern/TEX_nodes/TEX_translate.c | 2 +- .../blender/nodes/intern/TEX_nodes/TEX_valToNor.c | 4 +- .../blender/nodes/intern/TEX_nodes/TEX_valToRgb.c | 6 +- source/blender/nodes/intern/TEX_nodes/TEX_viewer.c | 11 +++- source/blender/nodes/intern/TEX_util.c | 75 +++++----------------- source/blender/nodes/intern/TEX_util.h | 5 +- source/blender/render/intern/source/shadeinput.c | 2 +- source/blender/render/intern/source/texture.c | 2 +- 33 files changed, 127 insertions(+), 162 deletions(-) (limited to 'source') diff --git a/source/blender/editors/include/ED_render.h b/source/blender/editors/include/ED_render.h index be93bf92e5e..13028dac1a2 100644 --- a/source/blender/editors/include/ED_render.h +++ b/source/blender/editors/include/ED_render.h @@ -64,21 +64,19 @@ typedef struct RenderInfo { /* Render the preview pr_method: -- PR_DRAW_RENDER: preview is rendered and drawn, as indicated by called context (buttons panel) -- PR_ICON_RENDER: the preview is not drawn and the function is not dynamic, - so no events are processed. Hopefully fast enough for at least 32x32 -- PR_DO_RENDER: preview is rendered, not drawn, but events are processed for afterqueue, - in use for node editor now. +- PR_BUTS_RENDER: preview is rendered for buttons window +- PR_ICON_RENDER: preview is rendered for icons. hopefully fast enough for at least 32x32 +- PR_NODE_RENDER: preview is rendered for node editor. */ -#define PR_DRAW_RENDER 0 +#define PR_BUTS_RENDER 0 #define PR_ICON_RENDER 1 -#define PR_DO_RENDER 2 +#define PR_NODE_RENDER 2 void ED_preview_init_dbase(void); void ED_preview_free_dbase(void); -void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID *id, struct ID *parent, struct MTex *slot, int sizex, int sizey); +void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID *id, struct ID *parent, struct MTex *slot, int sizex, int sizey, int method); void ED_preview_icon_job(const struct bContext *C, void *owner, struct ID *id, unsigned int *rect, int sizex, int sizey); void ED_preview_draw(const struct bContext *C, void *idp, void *parentp, void *slot, rcti *rect); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 4a671e4d2ba..92380a56d3d 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -359,7 +359,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre } else { sce->lay= 1<pr_type; - if(mat->nodetree) + if(mat->nodetree && sp->pr_method==PR_NODE_RENDER) ntreeInitPreview(mat->nodetree, sp->sizex, sp->sizey); } } @@ -408,6 +408,9 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre } } } + + if(tex && tex->nodetree && sp->pr_method==PR_NODE_RENDER) + ntreeInitPreview(tex->nodetree, sp->sizex, sp->sizey); } else if(id_type==ID_LA) { Lamp *la= (Lamp *)id; @@ -529,7 +532,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r } if(ok==0) { - ED_preview_shader_job(C, sa, id, parent, slot, newx, newy); + ED_preview_shader_job(C, sa, id, parent, slot, newx, newy, PR_BUTS_RENDER); } } } @@ -880,11 +883,12 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs Render *re; Scene *sce; float oldlens; + short idtype= GS(id->name); char name[32]; int sizex; /* get the stuff from the builtin preview dbase */ - sce= preview_prepare_scene(sp->scene, id, GS(id->name), sp); // XXX sizex + sce= preview_prepare_scene(sp->scene, id, idtype, sp); // XXX sizex if(sce==NULL) return; if(!split || first) sprintf(name, "Preview %p", sp->owner); @@ -896,14 +900,19 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs re= RE_NewRender(name); /* sce->r gets copied in RE_InitState! */ - if(sp->pr_method==PR_DO_RENDER) { - sce->r.scemode |= R_NODE_PREVIEW; - sce->r.scemode &= ~R_NO_IMAGE_LOAD; + sce->r.scemode &= ~(R_MATNODE_PREVIEW|R_TEXNODE_PREVIEW); + sce->r.scemode &= ~R_NO_IMAGE_LOAD; + + if(sp->pr_method==PR_ICON_RENDER) { + sce->r.scemode |= R_NO_IMAGE_LOAD; + } + else if(sp->pr_method==PR_NODE_RENDER) { + if(idtype == ID_MA) sce->r.scemode |= R_MATNODE_PREVIEW; + else if(idtype == ID_TE) sce->r.scemode |= R_TEXNODE_PREVIEW; sce->r.mode |= R_OSA; } - else { /* PR_ICON_RENDER */ - sce->r.scemode &= ~R_NODE_PREVIEW; - sce->r.scemode |= R_NO_IMAGE_LOAD; + else { /* PR_BUTS_RENDER */ + sce->r.mode |= R_OSA; } /* in case of split preview, use border render */ @@ -917,7 +926,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs RE_InitState(re, NULL, &sce->r, sizex, sp->sizey, NULL); /* callbacs are cleared on GetRender() */ - if(sp->pr_method==PR_DO_RENDER) { + if(sp->pr_method==PR_BUTS_RENDER) { RE_display_draw_cb(re, sp, shader_preview_draw); RE_test_break_cb(re, sp, shader_preview_break); } @@ -1125,7 +1134,7 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r WM_jobs_start(CTX_wm_manager(C), steve); } -void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, MTex *slot, int sizex, int sizey) +void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, MTex *slot, int sizex, int sizey, int method) { wmJob *steve; ShaderPreview *sp; @@ -1138,7 +1147,7 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M sp->owner= owner; sp->sizex= sizex; sp->sizey= sizey; - sp->pr_method= PR_DO_RENDER; + sp->pr_method= method; sp->id = id; sp->parent= parent; sp->slot= slot; diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 3fc91fea914..dd2dc0d796a 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -54,6 +54,7 @@ #include "MEM_guardedalloc.h" #include "BKE_context.h" +#include "BKE_depsgraph.h" #include "BKE_global.h" #include "BKE_image.h" #include "BKE_library.h" @@ -102,6 +103,7 @@ void ED_node_changed_update(bContext *C, bNode *node) return; if(snode->treetype==NTREE_SHADER) { + DAG_id_flush_update(snode->id, 0); WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, snode->id); } else if(snode->treetype==NTREE_COMPOSIT) { @@ -127,6 +129,7 @@ void ED_node_changed_update(bContext *C, bNode *node) WM_event_add_notifier(C, NC_SCENE|ND_NODES, CTX_data_scene(C)); } else if(snode->treetype==NTREE_TEXTURE) { + DAG_id_flush_update(snode->id, 0); WM_event_add_notifier(C, NC_TEXTURE|ND_NODES, snode->id); } diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 2cfd9d99123..bdd2a65984f 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -179,12 +179,14 @@ static void node_area_refresh(const struct bContext *C, struct ScrArea *sa) { /* default now: refresh node is starting preview */ SpaceNode *snode= sa->spacedata.first; + + snode_set_context(snode, CTX_data_scene(C)); if(snode->nodetree) { if(snode->treetype==NTREE_SHADER) { Material *ma= (Material *)snode->id; if(ma->use_nodes) - ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100); + ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); } else if(snode->treetype==NTREE_COMPOSIT) { Scene *scene= (Scene *)snode->id; @@ -194,7 +196,7 @@ static void node_area_refresh(const struct bContext *C, struct ScrArea *sa) else if(snode->treetype==NTREE_TEXTURE) { Tex *tex= (Tex *)snode->id; if(tex->use_nodes) { - ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100); + ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); } } } diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 63415662d2b..437b45cfda1 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -840,7 +840,7 @@ typedef struct Scene { #define R_PASSEPARTOUT 0x0004 #define R_PREVIEWBUTS 0x0008 #define R_EXTENSION 0x0010 -#define R_NODE_PREVIEW 0x0020 +#define R_MATNODE_PREVIEW 0x0020 #define R_DOCOMP 0x0040 #define R_COMP_CROP 0x0080 #define R_FREE_IMAGE 0x0100 @@ -852,7 +852,8 @@ typedef struct Scene { #define R_STAMP_INFO 0x4000 /* deprecated */ #define R_FULL_SAMPLE 0x8000 #define R_COMP_RERENDER 0x10000 -#define R_RECURS_PROTECTION 0x20000 +#define R_RECURS_PROTECTION 0x20000 +#define R_TEXNODE_PREVIEW 0x40000 /* r->stamp */ #define R_STAMP_TIME 0x0001 diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index 9ad42174413..28fcc3103b8 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -1716,7 +1716,7 @@ void RNA_def_material(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "use_nodes", 1); RNA_def_property_boolean_funcs(prop, NULL, "rna_Material_use_nodes_set"); RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the material."); - RNA_def_property_update(prop, NC_MATERIAL, NULL); + RNA_def_property_update(prop, 0, "rna_Material_update"); prop= RNA_def_property(srna, "active_node_material", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "Material"); diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c index 78d7f012487..428df15ef4e 100644 --- a/source/blender/makesrna/intern/rna_texture.c +++ b/source/blender/makesrna/intern/rna_texture.c @@ -107,6 +107,14 @@ static void rna_Texture_update(bContext *C, PointerRNA *ptr) WM_event_add_notifier(C, NC_TEXTURE, tex); } +static void rna_Texture_nodes_update(bContext *C, PointerRNA *ptr) +{ + Tex *tex= ptr->id.data; + + DAG_id_flush_update(&tex->id, 0); + WM_event_add_notifier(C, NC_TEXTURE|ND_NODES, tex); +} + static void rna_Texture_type_set(PointerRNA *ptr, int value) { Tex *tex= (Tex*)ptr->data; @@ -1678,12 +1686,12 @@ static void rna_def_texture(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "use_nodes", 1); RNA_def_property_boolean_funcs(prop, NULL, "rna_Texture_use_nodes_set"); RNA_def_property_ui_text(prop, "Use Nodes", "Make this a node-based texture"); - RNA_def_property_update(prop, 0, "rna_Texture_update"); + RNA_def_property_update(prop, 0, "rna_Texture_nodes_update"); prop= RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "nodetree"); RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node-based textures"); - RNA_def_property_update(prop, 0, "rna_Texture_update"); + RNA_def_property_update(prop, 0, "rna_Texture_nodes_update"); rna_def_animdata_common(srna); diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_at.c b/source/blender/nodes/intern/TEX_nodes/TEX_at.c index 4d714d91130..7e6cce9f35a 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_at.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_at.c @@ -50,7 +50,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_at = { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c b/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c index f1f3b0919ae..2093679e39d 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_bricks.c @@ -109,9 +109,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_bricks= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_checker.c b/source/blender/nodes/intern/TEX_nodes/TEX_checker.c index b889f1e2164..7b736206c51 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_checker.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_checker.c @@ -61,9 +61,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_checker= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_compose.c b/source/blender/nodes/intern/TEX_nodes/TEX_compose.c index 9fc4b2ff7c2..dac6ca7c3ef 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_compose.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_compose.c @@ -49,7 +49,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_compose= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_coord.c b/source/blender/nodes/intern/TEX_nodes/TEX_coord.c index e5c2b309fb3..a33a2608af0 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_coord.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_coord.c @@ -42,9 +42,7 @@ static void vectorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, sho static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &vectorfn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &vectorfn, data); } bNodeType tex_node_coord= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_curves.c b/source/blender/nodes/intern/TEX_nodes/TEX_curves.c index 61ebcea7360..a1b20370687 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_curves.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_curves.c @@ -50,7 +50,7 @@ static void time_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, static void time_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &time_colorfn); + tex_output(node, in, out[0], &time_colorfn, data); } @@ -100,7 +100,7 @@ static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, static void rgb_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &rgb_colorfn); + tex_output(node, in, out[0], &rgb_colorfn, data); } static void rgb_init(bNode *node) diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_decompose.c b/source/blender/nodes/intern/TEX_nodes/TEX_decompose.c index f7a409f0230..d5eeba2253c 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_decompose.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_decompose.c @@ -67,10 +67,10 @@ static void valuefn_a(float *out, TexParams *p, bNode *node, bNodeStack **in, sh static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &valuefn_r); - tex_output(node, in, out[1], &valuefn_g); - tex_output(node, in, out[2], &valuefn_b); - tex_output(node, in, out[3], &valuefn_a); + tex_output(node, in, out[0], &valuefn_r, data); + tex_output(node, in, out[1], &valuefn_g, data); + tex_output(node, in, out[2], &valuefn_b, data); + tex_output(node, in, out[3], &valuefn_a, data); } bNodeType tex_node_decompose= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_distance.c b/source/blender/nodes/intern/TEX_nodes/TEX_distance.c index 4e145e26b72..297fc02939d 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_distance.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_distance.c @@ -53,9 +53,7 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &valuefn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &valuefn, data); } bNodeType tex_node_distance= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c b/source/blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c index 192c7a39ee8..b267dc7acbb 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_hueSatVal.c @@ -84,7 +84,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_hue_sat= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_image.c b/source/blender/nodes/intern/TEX_nodes/TEX_image.c index 0a55af70b52..123063a7900 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_image.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_image.c @@ -73,9 +73,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &colorfn, data); } static void init(bNode* node) diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_invert.c b/source/blender/nodes/intern/TEX_nodes/TEX_invert.c index 5663f897ff5..f2fcbfbf9eb 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_invert.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_invert.c @@ -55,9 +55,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_invert= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_math.c b/source/blender/nodes/intern/TEX_nodes/TEX_math.c index 4ee04140fca..8c400a44832 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_math.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_math.c @@ -171,9 +171,7 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &valuefn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &valuefn, data); } bNodeType tex_node_math= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c b/source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c index 24bdde70127..f6955b47376 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_mixRgb.c @@ -57,9 +57,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_mix_rgb= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_output.c b/source/blender/nodes/intern/TEX_nodes/TEX_output.c index 7ce5ec88c48..140c31a7986 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_output.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_output.c @@ -83,28 +83,30 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) TexCallData *cdata = (TexCallData *)data; TexResult *target = cdata->target; - if(in[1]->hasinput && !in[0]->hasinput) - tex_do_preview(node, in[1], data); - else - tex_do_preview(node, in[0], data); - - if(!cdata->do_preview) { - if(cdata->which_output == node->custom1) - { - TexParams params; - params_from_cdata(¶ms, cdata); - - osa(tex_input_rgba, &target->tr, in[0], ¶ms, cdata->thread); - - target->tin = (target->tr + target->tg + target->tb) / 3.0f; - target->talpha = 1.0f; + if(cdata->do_preview) { + TexParams params; + params_from_cdata(¶ms, cdata); + + if(in[1]->hasinput && !in[0]->hasinput) + tex_input_rgba(&target->tr, in[1], ¶ms, cdata->thread); + else + tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); + tex_do_preview(node, params.coord, &target->tr); + } + else if(cdata->which_output == node->custom1) { + TexParams params; + params_from_cdata(¶ms, cdata); - if(target->nor) { - if(in[1]->hasinput) - osa(tex_input_vec, target->nor, in[1], ¶ms, cdata->thread); - else - target->nor = 0; - } + osa(tex_input_rgba, &target->tr, in[0], ¶ms, cdata->thread); + + target->tin = (target->tr + target->tg + target->tb) / 3.0f; + target->talpha = 1.0f; + + if(target->nor) { + if(in[1]->hasinput) + osa(tex_input_vec, target->nor, in[1], ¶ms, cdata->thread); + else + target->nor = 0; } } } diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_proc.c b/source/blender/nodes/intern/TEX_nodes/TEX_proc.c index ce7324e2085..9f355e6d8f0 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_proc.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_proc.c @@ -125,9 +125,8 @@ static int count_outputs(bNode *node) static void name##_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) \ { \ int outs = count_outputs(node); \ - if(outs >= 1) tex_output(node, in, out[0], &name##_colorfn); \ - if(outs >= 2) tex_output(node, in, out[1], &name##_normalfn); \ - if(outs >= 1) tex_do_preview(node, out[0], data); \ + if(outs >= 1) tex_output(node, in, out[0], &name##_colorfn, data); \ + if(outs >= 2) tex_output(node, in, out[1], &name##_normalfn, data); \ } diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c b/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c index bdf5a1ce079..2184d32fcf2 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c @@ -95,7 +95,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor } static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_rotate= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_scale.c b/source/blender/nodes/intern/TEX_nodes/TEX_scale.c index 3d4415365aa..205549c97d9 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_scale.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_scale.c @@ -56,7 +56,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor } static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_scale = { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_texture.c b/source/blender/nodes/intern/TEX_nodes/TEX_texture.c index 0ca80a82271..d0536a8fda8 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_texture.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_texture.c @@ -79,9 +79,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_texture= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_translate.c b/source/blender/nodes/intern/TEX_nodes/TEX_translate.c index ba3dcfa27a2..c2f7377da3b 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_translate.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_translate.c @@ -56,7 +56,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor } static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &colorfn); + tex_output(node, in, out[0], &colorfn, data); } bNodeType tex_node_translate = { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c b/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c index 75b88c3a460..6b8349e90af 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_valToNor.c @@ -72,9 +72,7 @@ static void normalfn(float *out, TexParams *p, bNode *node, bNodeStack **in, sho } static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &normalfn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &normalfn, data); } bNodeType tex_node_valtonor = { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_valToRgb.c b/source/blender/nodes/intern/TEX_nodes/TEX_valToRgb.c index 90a444bcff0..669f45ec89a 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_valToRgb.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_valToRgb.c @@ -50,7 +50,7 @@ static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack * static void valtorgb_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &valtorgb_colorfn); + tex_output(node, in, out[0], &valtorgb_colorfn, data); } static void valtorgb_init(bNode *node) @@ -97,9 +97,7 @@ static void rgbtobw_valuefn(float *out, TexParams *p, bNode *node, bNodeStack ** static void rgbtobw_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_output(node, in, out[0], &rgbtobw_valuefn); - - tex_do_preview(node, out[0], data); + tex_output(node, in, out[0], &rgbtobw_valuefn, data); } bNodeType tex_node_rgbtobw= { diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c b/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c index 2d29b03b38c..5ebd971d9fb 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_viewer.c @@ -39,7 +39,16 @@ static bNodeSocketType outputs[]= { static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) { - tex_do_preview(node, in[0], data); + TexCallData *cdata = (TexCallData *)data; + + if(cdata->do_preview) { + TexParams params; + float col[4]; + params_from_cdata(¶ms, cdata); + + tex_input_rgba(col, in[0], ¶ms, cdata->thread); + tex_do_preview(node, params.coord, col); + } } bNodeType tex_node_viewer = { diff --git a/source/blender/nodes/intern/TEX_util.c b/source/blender/nodes/intern/TEX_util.c index f2333ffcf2e..867bbd8c14e 100644 --- a/source/blender/nodes/intern/TEX_util.c +++ b/source/blender/nodes/intern/TEX_util.c @@ -49,8 +49,12 @@ void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread) { - if(dg->node->need_exec) + if(dg->node->need_exec) { dg->fn(out, params, dg->node, dg->in, thread); + + if(dg->cdata->do_preview) + tex_do_preview(dg->node, params->coord, out); + } } void tex_input(float *out, int sz, bNodeStack *in, TexParams *params, short thread) @@ -95,26 +99,6 @@ float tex_input_value(bNodeStack *in, TexParams *params, short thread) return out[0]; } -static void init_preview(bNode *node) -{ - int xsize = (int)(node->prvr.xmax - node->prvr.xmin); - int ysize = (int)(node->prvr.ymax - node->prvr.ymin); - - if(xsize == 0) { - xsize = PREV_RES; - ysize = PREV_RES; - } - - if(node->preview==NULL) - node->preview= MEM_callocN(sizeof(bNodePreview), "node preview"); - - if(node->preview->rect==NULL) { - node->preview->rect= MEM_callocN(4*xsize + xsize*ysize*sizeof(float)*4, "node preview rect"); - node->preview->xsize= xsize; - node->preview->ysize= ysize; - } -} - void params_from_cdata(TexParams *out, TexCallData *in) { out->coord = in->coord; @@ -123,48 +107,19 @@ void params_from_cdata(TexParams *out, TexCallData *in) out->cfra = in->cfra; } -void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata) +void tex_do_preview(bNode *node, float *coord, float *col) { - int x, y; - float *result; - bNodePreview *preview; - float coord[3] = {0, 0, 0}; - TexParams params; - int resolution; - int xsize, ysize; - - if(!cdata->do_preview) - return; - - if(!(node->typeinfo->flag & NODE_PREVIEW)) - return; - - init_preview(node); - - preview = node->preview; - xsize = preview->xsize; - ysize = preview->ysize; - - params.dxt = 0; - params.dyt = 0; - params.cfra = cdata->cfra; - params.coord = coord; - - resolution = (xsize < ysize) ? xsize : ysize; - - for(x=0; xrect + 4 * (xsize*y + x); - - tex_input_rgba(result, ns, ¶ms, cdata->thread); + bNodePreview *preview= node->preview; + + if(preview) { + int xs= ((coord[0] + 1.0f)*0.5f)*preview->xsize; + int ys= ((coord[1] + 1.0f)*0.5f)*preview->ysize; + + nodeAddToPreview(node, col, xs, ys); } } -void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn) +void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata) { TexDelegate *dg; if(!out->data) @@ -173,7 +128,7 @@ void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn) else dg = out->data; - + dg->cdata= cdata; dg->fn = texfn; dg->node = node; memcpy(dg->in, in, MAX_SOCKET * sizeof(bNodeStack*)); diff --git a/source/blender/nodes/intern/TEX_util.h b/source/blender/nodes/intern/TEX_util.h index fd3d47f4729..14e2773414a 100644 --- a/source/blender/nodes/intern/TEX_util.h +++ b/source/blender/nodes/intern/TEX_util.h @@ -87,6 +87,7 @@ typedef struct TexParams { typedef void(*TexFn) (float *out, TexParams *params, bNode *node, bNodeStack **in, short thread); typedef struct TexDelegate { + TexCallData *cdata; TexFn fn; bNode *node; bNodeStack *in[MAX_SOCKET]; @@ -99,8 +100,8 @@ void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread) void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread); float tex_input_value(bNodeStack *in, TexParams *params, short thread); -void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn); -void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata); +void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *data); +void tex_do_preview(bNode *node, float *coord, float *col); void params_from_cdata(TexParams *out, TexCallData *in); diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index e5684e2ebe9..30ff213b95b 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -1306,7 +1306,7 @@ void shade_input_initialize(ShadeInput *shi, RenderPart *pa, RenderLayer *rl, in shi->sample= sample; shi->thread= pa->thread; - shi->do_preview= R.r.scemode & R_NODE_PREVIEW; + shi->do_preview= (R.r.scemode & R_MATNODE_PREVIEW) != 0; shi->lay= rl->lay; shi->layflag= rl->layflag; shi->passflag= rl->passflag; diff --git a/source/blender/render/intern/source/texture.c b/source/blender/render/intern/source/texture.c index 7b0e5d8abbc..aee2d8d1866 100644 --- a/source/blender/render/intern/source/texture.c +++ b/source/blender/render/intern/source/texture.c @@ -721,7 +721,7 @@ static int evalnodes(Tex *tex, float *texvec, float *dxt, float *dyt, TexResult short rv = TEX_INT; bNodeTree *nodes = tex->nodetree; - ntreeTexExecTree(nodes, texres, texvec, dxt, dyt, thread, tex, which_output, R.r.cfra, (R.r.scemode & R_NODE_PREVIEW)); + ntreeTexExecTree(nodes, texres, texvec, dxt, dyt, thread, tex, which_output, R.r.cfra, (R.r.scemode & R_TEXNODE_PREVIEW) != 0); if(texres->nor) rv |= TEX_NOR; rv |= TEX_RGB; -- cgit v1.2.3