diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-06 19:02:23 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-06 19:02:23 +0400 |
commit | 8ee99cc39cdcc07611795c16ee57b5936d5b924e (patch) | |
tree | bab055a4a4ca253e037a57feebf006c4f30c2629 /source/blender | |
parent | 0fd4a102e0f312daf8c56fd22e611feeeaf7a992 (diff) |
add ability to use world gradient rendering when 'Only Render' option is enabled.
supports paper/blend/real.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 116 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_world.c | 8 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 2 |
3 files changed, 111 insertions, 15 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 76f62db3c5b..43022e2a5d2 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -2987,20 +2987,116 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const GPU_default_lights(); } + /* setup view matrices */ + view3d_main_area_setup_view(scene, v3d, ar, NULL, NULL); + /* clear background */ - if ((v3d->flag2 & V3D_RENDER_OVERRIDE) && scene->world) { - IMB_colormanagement_pixel_to_display_space_v3(backcol, &scene->world->horr, &scene->view_settings, - &scene->display_settings); + if (scene->world && (v3d->flag2 & V3D_RENDER_OVERRIDE)) { /* clear with solid color */ + if (scene->world->skytype & WO_SKYBLEND) { /* blend sky */ + int x, y; + float col_hor[3]; + float col_zen[3]; + +#define XTOT 16 +#define YTOT 16 + + GLubyte grid_col[XTOT][YTOT][3]; + float grid_pos[XTOT][YTOT][2]; + + IMB_colormanagement_pixel_to_display_space_v3(col_hor, &scene->world->horr, &scene->view_settings, + &scene->display_settings); + IMB_colormanagement_pixel_to_display_space_v3(col_zen, &scene->world->zenr, &scene->view_settings, + &scene->display_settings); + + glClearColor(col_hor[0], col_hor[1], col_hor[2], 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glShadeModel(GL_SMOOTH); + + for (x = 0; x < XTOT; x++) { + for (y = 0; y < YTOT; y++) { + const float xf = (float)x / (float)(XTOT - 1); + const float yf = (float)y / (float)(YTOT - 1); + const float mval[2] = {xf * (float)ar->winx, yf * ar->winy}; + float out[3]; + const float up[3] = {0.0f, 0.0f, 1.0f}; + GLubyte *col_ub = grid_col[x][y]; + + float col_fac; + float col_fl[3]; + + /* -1..1 range */ + grid_pos[x][y][0] = (xf - 0.5f) * 2.0f; + grid_pos[x][y][1] = (yf - 0.5f) * 2.0f; + + ED_view3d_win_to_vector(ar, mval, out); + + if (scene->world->skytype & WO_SKYPAPER) { + if (scene->world->skytype & WO_SKYREAL) { + col_fac = fabsf(((float)y / (float)YTOT) - 0.5f) * 2.0f; + } + else { + col_fac = (float)y / (float)YTOT; + } + } + else { + if (scene->world->skytype & WO_SKYREAL) { + col_fac = fabsf((angle_v3v3(up, out) / (float)M_PI) - 0.5f) * 2.0f; + } + else { + col_fac = 1.0f - (angle_v3v3(up, out) / (float)M_PI); + } + } + + interp_v3_v3v3(col_fl, col_hor, col_zen, col_fac); + + rgb_float_to_uchar(col_ub, col_fl); + } + } + + glBegin(GL_QUADS); + for (x = 0; x < XTOT - 1; x++) { + for (y = 0; y < YTOT - 1; y++) { + glColor3ubv(grid_col[x][y]); + glVertex2fv(grid_pos[x][y]); + glColor3ubv(grid_col[x][y + 1]); + glVertex2fv(grid_pos[x][y + 1]); + glColor3ubv(grid_col[x + 1][y + 1]); + glVertex2fv(grid_pos[x + 1][y + 1]); + glColor3ubv(grid_col[x + 1][y]); + glVertex2fv(grid_pos[x + 1][y]); + } + } + glEnd(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + glShadeModel(GL_FLAT); +#undef XTOT +#undef YTOT + } + else { /* solid sky */ + IMB_colormanagement_pixel_to_display_space_v3(backcol, &scene->world->horr, &scene->view_settings, + &scene->display_settings); - glClearColor(backcol[0], backcol[1], backcol[2], 0.0); + glClearColor(backcol[0], backcol[1], backcol[2], 0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } } - else + else { UI_ThemeClearColor(TH_BACK); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - /* setup view matrices */ - view3d_main_area_setup_view(scene, v3d, ar, NULL, NULL); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c index a84b1124d44..7a94566c6ee 100644 --- a/source/blender/makesrna/intern/rna_world.c +++ b/source/blender/makesrna/intern/rna_world.c @@ -529,7 +529,7 @@ void RNA_def_world(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "zenr"); RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Zenith Color", "Color at the zenith"); - RNA_def_property_update(prop, 0, "rna_World_update"); + RNA_def_property_update(prop, NC_WORLD | ND_WORLD_DRAW, "rna_World_update"); prop = RNA_def_property(srna, "ambient_color", PROP_FLOAT, PROP_COLOR); RNA_def_property_float_sdna(prop, NULL, "ambr"); @@ -554,17 +554,17 @@ void RNA_def_world(BlenderRNA *brna) prop = RNA_def_property(srna, "use_sky_blend", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "skytype", WO_SKYBLEND); RNA_def_property_ui_text(prop, "Blend Sky", "Render background with natural progression from horizon to zenith"); - RNA_def_property_update(prop, 0, "rna_World_update"); + RNA_def_property_update(prop, NC_WORLD | ND_WORLD_DRAW, "rna_World_update"); prop = RNA_def_property(srna, "use_sky_paper", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "skytype", WO_SKYPAPER); RNA_def_property_ui_text(prop, "Paper Sky", "Flatten blend or texture coordinates"); - RNA_def_property_update(prop, 0, "rna_World_update"); + RNA_def_property_update(prop, NC_WORLD | ND_WORLD_DRAW, "rna_World_update"); prop = RNA_def_property(srna, "use_sky_real", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "skytype", WO_SKYREAL); RNA_def_property_ui_text(prop, "Real Sky", "Render background with a real horizon, relative to the camera angle"); - RNA_def_property_update(prop, 0, "rna_World_update"); + RNA_def_property_update(prop, NC_WORLD | ND_WORLD_DRAW, "rna_World_update"); /* nested structs */ prop = RNA_def_property(srna, "light_settings", PROP_POINTER, PROP_NONE); diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index d3ce25b4f04..f3837203c9a 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -847,7 +847,7 @@ static void bpy_prop_string_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p value[0] = '\0'; } else { - memcpy(value, buffer, length+1); + memcpy(value, buffer, length + 1); } Py_DECREF(ret); |