Todo item:
authorTon Roosendaal <ton@blender.org>
Wed, 5 Jan 2011 15:10:35 +0000 (15:10 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 5 Jan 2011 15:10:35 +0000 (15:10 +0000)
Object color option now is incorporated in preview render, and
in display in 3D window.

Note that Object-color is "modulating" the render result, it just
multiplies... which is very limited for practical use. This was
added for Apricot game project. The original meaning however was
to replace diffuse only... so specular and light work still correct.

ALso made header for properties editor start on top, to reflect
default (report in tracker).

source/blender/editors/render/render_preview.c
source/blender/editors/space_buttons/space_buttons.c
source/blender/gpu/intern/gpu_draw.c
source/blender/makesdna/DNA_object_types.h
source/blender/makesrna/intern/rna_material.c

index 9589c46d726e00b14b0523fe96b59505f3ef1eb6..10f5ed20b0c784ada07dda908f88f4076522ca60 100644 (file)
@@ -151,6 +151,7 @@ typedef struct ShaderPreview {
        
        /* node materials need full copy during preview render, glsl uses it too */
        Material *matcopy;
+       float col[4];           /* active object color */
        
        int sizex, sizey;
        unsigned int *pr_rect;
@@ -389,6 +390,10 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                
                                init_render_material(mat, 0, NULL);             /* call that retrieves mode_l */
                                end_render_material(mat);
+                               
+                               /* un-useful option */
+                               if(sp->pr_method==PR_ICON_RENDER)
+                                       mat->shade_flag &= ~MA_OBCOLOR;
 
                                /* turn on raytracing if needed */
                                if(mat->mode_l & MA_RAYMIRROR)
@@ -452,6 +457,9 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                        
                        for(base= sce->base.first; base; base= base->next) {
                                if(base->object->id.name[2]=='p') {
+                                       /* copy over object color, in case material uses it */
+                                       copy_v4_v4(base->object->col, sp->col);
+                                       
                                        if(ELEM4(base->object->type, OB_MESH, OB_CURVE, OB_SURF, OB_MBALL)) {
                                                /* don't use assign_material, it changed mat->id.us, which shows in the UI */
                                                Material ***matar= give_matarar(base->object);
@@ -1230,7 +1238,7 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r
 {
        wmJob *steve;
        ShaderPreview *sp;
-
+       
        /* suspended start means it starts after 1 timer step, see WM_jobs_timer below */
        steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner, "Icon Preview", WM_JOB_EXCL_RENDER|WM_JOB_SUSPEND);
        sp= MEM_callocN(sizeof(ShaderPreview), "shader preview");
@@ -1254,6 +1262,7 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r
 
 void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, MTex *slot, int sizex, int sizey, int method)
 {
+       Object *ob= CTX_data_active_object(C);
        wmJob *steve;
        ShaderPreview *sp;
 
@@ -1269,6 +1278,8 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
        sp->id = id;
        sp->parent= parent;
        sp->slot= slot;
+       if(ob && ob->totcol) copy_v4_v4(sp->col, ob->col);
+       else sp->col[0]= sp->col[1]= sp->col[2]= sp->col[3]= 1.0f;
        
        /* setup job */
        WM_jobs_customdata(steve, sp, shader_preview_free);
index 90e11e6dc3712fc1bd5cdcef83d43b4e9861365d..171dad4bed9d542b03749c7a4efa89049c3fe749 100644 (file)
@@ -69,7 +69,7 @@ static SpaceLink *buttons_new(const bContext *UNUSED(C))
        
        BLI_addtail(&sbuts->regionbase, ar);
        ar->regiontype= RGN_TYPE_HEADER;
-       ar->alignment= RGN_ALIGN_BOTTOM;
+       ar->alignment= RGN_ALIGN_TOP;
        
 #if 0
        /* context area */
index e54002a85db9f5a1e3890b81afad9d998d691053..5763cd958d071d7d28a112c4dae21a8ecd36c48b 100644 (file)
@@ -901,7 +901,7 @@ static struct GPUMaterialState {
 } GMS = {NULL};
 
 /* fixed function material, alpha handed by caller */
-static void gpu_material_to_fixed(GPUMaterialFixed *smat, const Material *bmat, const int gamma)
+static void gpu_material_to_fixed(GPUMaterialFixed *smat, const Material *bmat, const int gamma, const Object *ob)
 {
        if (bmat->mode & MA_SHLESS) {
                copy_v3_v3(smat->diff, &bmat->r);
@@ -915,6 +915,9 @@ static void gpu_material_to_fixed(GPUMaterialFixed *smat, const Material *bmat,
                mul_v3_v3fl(smat->diff, &bmat->r, bmat->ref + bmat->emit);
                smat->diff[3]= 1.0; /* caller may set this to bmat->alpha */
 
+               if(bmat->shade_flag & MA_OBCOLOR)
+                       mul_v3_v3(smat->diff, ob->col);
+               
                mul_v3_v3fl(smat->spec, &bmat->specr, bmat->spec);
                smat->spec[3]= 1.0; /* always 1 */
                smat->hard= CLAMPIS(bmat->har, 0, 128);
@@ -979,7 +982,7 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
 
        /* no materials assigned? */
        if(ob->totcol==0) {
-               gpu_material_to_fixed(&GMS.matbuf[0], &defmaterial, 0);
+               gpu_material_to_fixed(&GMS.matbuf[0], &defmaterial, 0, ob);
 
                /* do material 1 too, for displists! */
                memcpy(&GMS.matbuf[1], &GMS.matbuf[0], sizeof(GPUMaterialFixed));
@@ -1009,7 +1012,7 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
                }
                else {
                        /* fixed function opengl materials */
-                       gpu_material_to_fixed(&GMS.matbuf[a], ma, gamma);
+                       gpu_material_to_fixed(&GMS.matbuf[a], ma, gamma, ob);
 
                        blendmode = (ma->alpha == 1.0f)? GPU_BLEND_SOLID: GPU_BLEND_ALPHA;
                        if(do_alpha_pass && GMS.alphapass)
index 87f03aec06a2b8fae37023557bd642e089a4cf97..6d92b1d09a52061a9a67d791331ef9eaaded98a4 100644 (file)
@@ -198,7 +198,7 @@ typedef struct Object {
        float bbsize[3];
        short index;                    /* custom index, for renderpasses */
        unsigned short actdef;  /* current deformation group, note: index starts at 1 */
-       float col[4];                   /* object color, adjusted via IPO's only */
+       float col[4];                   /* object color */
        /**
         * Settings for game objects
         * bit 0: Object has dynamic behaviour
index 43dfd36d516d3f4b5ff003e5c1fa828528f593c9..ba2cea3defddfdd4e3ba1b2e86ddc0e4c090d402 100644 (file)
@@ -1601,7 +1601,7 @@ void RNA_def_material(BlenderRNA *brna)
        prop= RNA_def_property(srna, "use_object_color", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_OBCOLOR);
        RNA_def_property_ui_text(prop, "Object Color", "Modulate the result with a per-object color");
-       RNA_def_property_update(prop, 0, "rna_Material_update");
+       RNA_def_property_update(prop, 0, "rna_Material_draw_update");
 
        prop= RNA_def_property(srna, "shadow_ray_bias", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "sbias");