Fixes for blender internal viewport render:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 15 May 2013 17:09:45 +0000 (17:09 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 15 May 2013 17:09:45 +0000 (17:09 +0000)
* Particles did not render at viewport resolution like meshes.
* Properties editor preview render of hair was crashing, solution is to have
  two separate flags for this preview render and viewport preview render.

source/blender/editors/render/render_internal.c
source/blender/editors/render/render_preview.c
source/blender/makesdna/DNA_scene_types.h
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/external_engine.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/pointdensity.c
source/blender/render/intern/source/rendercore.c
source/blender/render/intern/source/shadeoutput.c
source/blender/render/intern/source/sss.c

index 293eba0f658d38350ff73a9b4dda69f2cb49ca75..a172287113f3bfdbb3919cc04b7e6a0c3b7f32b5 100644 (file)
@@ -853,7 +853,7 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda
                rdata = rp->scene->r;
                rdata.mode &= ~(R_OSA | R_MBLUR | R_BORDER | R_PANORAMA);
                rdata.scemode &= ~(R_DOSEQ | R_DOCOMP | R_FREE_IMAGE);
-               rdata.scemode |= R_PREVIEWBUTS;
+               rdata.scemode |= R_VIEWPORT_PREVIEW;
                
                /* we do use layers, but only active */
                rdata.scemode |= R_SINGLE_LAYER;
index 34903c26ca0e85fabfc5f9f7be2109e7df65267e..76fa79029fd027074ac05ff4761857634c72733e 100644 (file)
@@ -273,7 +273,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
        if (sce) {
                
                /* this flag tells render to not execute depsgraph or ipos etc */
-               sce->r.scemode |= R_PREVIEWBUTS;
+               sce->r.scemode |= R_BUTS_PREVIEW;
                /* set world always back, is used now */
                sce->world = pr_main->world.first;
                /* now: exposure copy */
index eb8c8138e850ea65ffa439905a14d268223bd921..bc911f9addca972c1ec21f5350cb68bb38aefc97 100644 (file)
@@ -1300,7 +1300,7 @@ typedef struct Scene {
 #define R_BG_RENDER                    0x0002
                /* passepartout is camera option now, keep this for backward compatibility */
 #define R_PASSEPARTOUT         0x0004
-#define R_PREVIEWBUTS          0x0008
+#define R_BUTS_PREVIEW         0x0008
 #define R_EXTENSION                    0x0010
 #define R_MATNODE_PREVIEW      0x0020
 #define R_DOCOMP                       0x0040
@@ -1316,6 +1316,7 @@ typedef struct Scene {
 /* #define R_DEPRECATED                0x10000 */
 /* #define R_RECURS_PROTECTION 0x20000 */
 #define R_TEXNODE_PREVIEW      0x40000
+#define R_VIEWPORT_PREVIEW     0x80000
 
 /* r->stamp */
 #define R_STAMP_TIME   0x0001
index 5721fa3719d3df269891bb1a916b6e8f6cd2bfab..c70ee0e91127d01a18fbec9ad84660d15256f63b 100644 (file)
@@ -1539,7 +1539,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
        float random, simplify[2], pa_co[3];
        const float cfra= BKE_scene_frame_get(re->scene);
        int i, a, k, max_k=0, totpart, do_simplify = FALSE, do_surfacecache = FALSE, use_duplimat = FALSE;
-       int totchild=0;
+       int totchild=0, step_nbr;
        int seed, path_nbr=0, orco1=0, num;
        int totface;
        char **uv_name=0;
@@ -1581,8 +1581,12 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
        if (part->type==PART_HAIR && !psys->childcache)
                totchild= 0;
 
-       if (G.is_rendering == FALSE) {  /* preview render */
+       if (re->r.scemode & R_VIEWPORT_PREVIEW) { /* preview render */
                totchild = (int)((float)totchild * (float)part->disp / 100.0f);
+               step_nbr = part->draw_step;
+       }
+       else {
+               step_nbr = part->ren_step;
        }
 
        psys->flag |= PSYS_DRAWING;
@@ -1668,7 +1672,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
 
 /* 2.6 setup strand rendering */
        if (part->ren_as == PART_DRAW_PATH && psys->pathcache) {
-               path_nbr=(int)pow(2.0, (double) part->ren_step);
+               path_nbr=(int)pow(2.0, (double) step_nbr);
 
                if (path_nbr) {
                        if (!ELEM(ma->material_type, MA_TYPE_HALO, MA_TYPE_WIRE)) {
@@ -3379,8 +3383,8 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
        mask |= CD_MASK_ORIGINDEX | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
 #endif
 
-       if (re->r.scemode & R_PREVIEWBUTS)
-               dm = mesh_get_derived_final(re->scene, ob, mask);
+       if (re->r.scemode & R_VIEWPORT_PREVIEW)
+               dm= mesh_create_derived_view(re->scene, ob, mask);
        else
                dm= mesh_create_derived_render(re->scene, ob, mask);
        if (dm==NULL) return;   /* in case duplicated object fails? */
@@ -4113,7 +4117,7 @@ static void set_material_lightgroups(Render *re)
        Material *ma;
        
        /* not for preview render */
-       if (re->scene->r.scemode & R_PREVIEWBUTS)
+       if (re->scene->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))
                return;
        
        for (group= re->main->group.first; group; group=group->id.next)
@@ -4689,8 +4693,8 @@ static void init_render_object_data(Render *re, ObjectRen *obr, int timeoffset)
                        /* the emitter mesh wasn't rendered so the modifier stack wasn't
                         * evaluated with render settings */
                        DerivedMesh *dm;
-                       if (re->r.scemode & R_PREVIEWBUTS)
-                               dm = mesh_get_derived_final(re->scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
+                       if (re->r.scemode & R_VIEWPORT_PREVIEW)
+                               dm = mesh_create_derived_view(re->scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
                        else
                                dm = mesh_create_derived_render(re->scene, ob,  CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
                        dm->release(dm);
@@ -4735,7 +4739,8 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject *
                show_emitter= 0;
                for (psys=ob->particlesystem.first; psys; psys=psys->next) {
                        show_emitter += psys->part->draw & PART_DRAW_EMITTER;
-                       psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, timeoffset);
+                       if (!(re->r.scemode & R_VIEWPORT_PREVIEW))
+                               psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, timeoffset);
                }
 
                /* if no psys has "show emitter" selected don't render emitter */
@@ -4779,7 +4784,8 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject *
                        if (dob)
                                psys->flag |= PSYS_USE_IMAT;
                        init_render_object_data(re, obr, timeoffset);
-                       psys_render_restore(ob, psys);
+                       if (!(re->r.scemode & R_VIEWPORT_PREVIEW))
+                               psys_render_restore(ob, psys);
                        psys->flag &= ~PSYS_USE_IMAT;
 
                        /* only add instance for objects that have not been used for dupli */
@@ -4831,7 +4837,7 @@ void RE_Database_Free(Render *re)
        
        /* statistics for debugging render memory usage */
        if ((G.debug & G_DEBUG) && (G.is_rendering)) {
-               if ((re->r.scemode & R_PREVIEWBUTS)==0) {
+               if ((re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0) {
                        BKE_image_print_memlist();
                        MEM_printmemlist_stats();
                }
@@ -4893,7 +4899,7 @@ void RE_Database_Free(Render *re)
 
        if (re->scene)
                if (re->scene->r.scemode & R_FREE_IMAGE)
-                       if ((re->r.scemode & R_PREVIEWBUTS)==0)
+                       if ((re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0)
                                BKE_image_free_all_textures();
 
        if (re->memArena) {
@@ -4961,6 +4967,9 @@ static void dupli_render_particle_set(Render *re, Object *ob, int timeoffset, in
        ParticleSystem *psys;
        DerivedMesh *dm;
 
+       if (re->r.scemode & R_VIEWPORT_PREVIEW)
+               return;
+
        if (level >= MAX_DUPLI_RECUR)
                return;
        
@@ -4978,10 +4987,7 @@ static void dupli_render_particle_set(Render *re, Object *ob, int timeoffset, in
                        /* this is to make sure we get render level duplis in groups:
                         * the derivedmesh must be created before init_render_mesh,
                         * since object_duplilist does dupliparticles before that */
-                       if (re->r.scemode & R_PREVIEWBUTS)
-                               dm = mesh_get_derived_final(re->scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
-                       else
-                               dm = mesh_create_derived_render(re->scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
+                       dm = mesh_create_derived_render(re->scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
                        dm->release(dm);
 
                        for (psys=ob->particlesystem.first; psys; psys=psys->next)
@@ -5245,7 +5251,7 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l
                lay &= 0xFF000000;
        
        /* applies changes fully */
-       if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0)
+       if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0)
                BKE_scene_update_for_newframe(re->main, re->scene, lay);
        
        /* if no camera, viewmat should have been set! */
index b7cd40043f42927597ad10f657abbdbb5032de0b..011d48e1994375802256c53bc7be126b934b65cb 100644 (file)
@@ -258,7 +258,7 @@ void RE_engine_end_result(RenderEngine *engine, RenderResult *result, int cancel
 
                if (re->result->do_exr_tile)
                        render_result_exr_file_merge(re->result, result);
-               else if (!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS)))
+               else if (!(re->test_break(re->tbh) && (re->r.scemode & R_BUTS_PREVIEW)))
                        render_result_merge(re->result, result);
 
                /* draw */
@@ -401,7 +401,7 @@ int RE_engine_render(Render *re, int do_all)
        /* verify if we can render */
        if (!type->render)
                return 0;
-       if ((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW))
+       if ((re->r.scemode & R_BUTS_PREVIEW) && !(type->flag & RE_USE_PREVIEW))
                return 0;
        if (do_all && !(type->flag & RE_USE_POSTPROCESS))
                return 0;
@@ -410,7 +410,7 @@ int RE_engine_render(Render *re, int do_all)
 
        /* create render result */
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-       if (re->result == NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
+       if (re->result == NULL || !(re->r.scemode & R_BUTS_PREVIEW)) {
                int savebuffers;
 
                if (re->result)
@@ -444,14 +444,14 @@ int RE_engine_render(Render *re, int do_all)
 
        if (re->flag & R_ANIMATION)
                engine->flag |= RE_ENGINE_ANIMATION;
-       if (re->r.scemode & R_PREVIEWBUTS)
+       if (re->r.scemode & R_BUTS_PREVIEW)
                engine->flag |= RE_ENGINE_PREVIEW;
        engine->camera_override = re->camera_override;
 
        engine->resolution_x = re->winx;
        engine->resolution_y = re->winy;
 
-       if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_PREVIEWBUTS)) == 0)
+       if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_BUTS_PREVIEW)) == 0)
                BKE_scene_update_for_newframe(re->main, re->scene, re->lay);
 
        RE_parts_init(re, FALSE);
index 8690939fe64a6b38c1ea1be4a749025c77e57800..5a672a572373a06057a121e3d6b8b904669c473d 100644 (file)
@@ -580,7 +580,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, SceneRenderLayer *
        /* if preview render, we try to keep old result */
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
 
-       if (re->r.scemode & R_PREVIEWBUTS) {
+       if (re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW)) {
                if (had_freestyle || (re->r.mode & R_EDGE_FRS)) {
                        /* freestyle manipulates render layers so always have to free */
                        render_result_free(re->result);
@@ -729,7 +729,7 @@ static int render_display_draw_enabled(Render *re)
 {
        /* don't show preprocess for previewrender sss */
        if (re->sss_points)
-               return !(re->r.scemode & R_PREVIEWBUTS);
+               return !(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW));
        else
                return 1;
 }
@@ -766,7 +766,7 @@ static void *do_part_thread(void *pa_v)
                }
                else if (render_display_draw_enabled(&R)) {
                        /* on break, don't merge in result for preview renders, looks nicer */
-                       if (R.test_break(R.tbh) && (R.r.scemode & R_PREVIEWBUTS)) {
+                       if (R.test_break(R.tbh) && (R.r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))) {
                                /* pass */
                        }
                        else {
@@ -947,7 +947,7 @@ static void threaded_tile_processor(Render *re)
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
 
        /* first step; free the entire render result, make new, and/or prepare exr buffer saving */
-       if (re->result == NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
+       if (re->result == NULL || !(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))) {
                render_result_free(re->result);
 
                if (re->sss_points && render_display_draw_enabled(re))
index d740780ec307730b1b5f872bd5be25503fd89d2f..82428f792bb6d72583dd2ccedcc3e9a79022b783 100644 (file)
@@ -298,7 +298,7 @@ void make_pointdensities(Render *re)
 {
        Tex *tex;
        
-       if (re->scene->r.scemode & R_PREVIEWBUTS)
+       if (re->scene->r.scemode & R_BUTS_PREVIEW)
                return;
        
        re->i.infostr = IFACE_("Caching Point Densities");
@@ -318,7 +318,7 @@ void free_pointdensities(Render *re)
 {
        Tex *tex;
        
-       if (re->scene->r.scemode & R_PREVIEWBUTS)
+       if (re->scene->r.scemode & R_BUTS_PREVIEW)
                return;
        
        for (tex= re->main->tex.first; tex; tex= tex->id.next) {
index 2d0f575b3e3d158c6e1632db5c89f65214591b0d..fa3cf1cef872bb0e0965b7888e25e7792ac5080f 100644 (file)
@@ -1622,7 +1622,7 @@ void zbufshade_sss_tile(RenderPart *pa)
        VlakRen *vlr;
        Material *mat= re->sss_mat;
        float (*co)[3], (*color)[3], *area, *fcol;
-       int x, y, seed, quad, totpoint, display = !(re->r.scemode & R_PREVIEWBUTS);
+       int x, y, seed, quad, totpoint, display = !(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW));
        int *ro, *rz, *rp, *rbo, *rbz, *rbp, lay;
 #if 0
        PixStr *ps;
index 6b48bb79e4db82cf1202991419847dc41d1af203..3eeaebff92d0f2d8dff501b3c552b91cebcb516d 100644 (file)
@@ -71,7 +71,7 @@ extern struct Render R;
 ListBase *get_lights(ShadeInput *shi)
 {
        
-       if (R.r.scemode & R_PREVIEWBUTS)
+       if (R.r.scemode & R_BUTS_PREVIEW)
                return &R.lights;
        if (shi->light_override)
                return &shi->light_override->gobject;
index abce12977836a07a257e6c9a0e4c282a23b0cb22..7a58d20be1025ad3c7f74009ac6b04053f7af44c 100644 (file)
@@ -880,14 +880,14 @@ static void sss_create_tree_mat(Render *re, Material *mat)
        re->sss_mat= mat;
        re->i.partsdone = FALSE;
 
-       if (!(re->r.scemode & R_PREVIEWBUTS))
+       if (!(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW)))
                re->result= NULL;
        BLI_rw_mutex_unlock(&re->resultmutex);
 
        RE_TileProcessor(re);
        
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-       if (!(re->r.scemode & R_PREVIEWBUTS)) {
+       if (!(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))) {
                RE_FreeRenderResult(re->result);
                re->result= rr;
        }
@@ -937,7 +937,7 @@ static void sss_create_tree_mat(Render *re, Material *mat)
                float error = mat->sss_error;
 
                error= get_render_aosss_error(&re->r, error);
-               if ((re->r.scemode & R_PREVIEWBUTS) && error < 0.5f)
+               if ((re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW)) && error < 0.5f)
                        error= 0.5f;
                
                sss->ss[0]= scatter_settings_new(mat->sss_col[0], radius[0], ior, cfac, fw, bw);