diff options
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 224 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 49 |
2 files changed, 93 insertions, 180 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 6a58b41a34f..5924cf36fa1 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -3373,196 +3373,60 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) bool use_color_correction = (fx_settings->fx_flag2 && (fx_settings->fx_flag2 & GPU_FX_FLAG_COLORMANAGEMENT)) ? false : true; if (scene->world && (v3d->flag3 & V3D_SHOW_WORLD)) { - bool glsl = GPU_glsl_support(); - - if (glsl) { - RegionView3D *rv3d = ar->regiondata; - GPUMaterial *gpumat; - GPUProbe *gpuprobe; - bool material_not_bound; - - if (v3d->flag3 & V3D_SHOW_WORLD_DIFFUSE) { - gpuprobe = GPU_probe_world(scene, scene->world); - GPU_probe_sh_shader_bind(gpuprobe); - } - else { - gpumat = GPU_material_world(scene, scene->world); - - /* calculate full shader for background */ - GPU_material_bind(gpumat, 1, 1, 1.0, true, rv3d->viewmat, rv3d->viewinv, rv3d->viewcamtexcofac, (v3d->scenelock != 0)); - - material_not_bound = !GPU_material_bound(gpumat); - - if (material_not_bound) { - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - glColor4f(0.0f, 0.0f, 0.0f, 1.0f); - } - } - // Draw world - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); - glBegin(GL_TRIANGLE_STRIP); - glVertex3f(-1.0, -1.0, 1.0); - glVertex3f(1.0, -1.0, 1.0); - glVertex3f(-1.0, 1.0, 1.0); - glVertex3f(1.0, 1.0, 1.0); - glEnd(); - - if (v3d->flag3 & V3D_SHOW_WORLD_DIFFUSE) { - GPU_probe_sh_shader_unbind(); - } - else { - if (material_not_bound) { - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - } - - GPU_material_unbind(gpumat); - } - - glDepthFunc(GL_LEQUAL); - glDisable(GL_DEPTH_TEST); + RegionView3D *rv3d = ar->regiondata; + GPUMaterial *gpumat; + GPUProbe *gpuprobe; + bool material_not_bound; + + if (v3d->flag3 & V3D_SHOW_WORLD_DIFFUSE) { + gpuprobe = GPU_probe_world(scene, scene->world); + GPU_probe_sh_shader_bind(gpuprobe); } - else if (scene->world->skytype & WO_SKYBLEND) { /* blend sky */ - int x, y; - float col_hor[3]; - float col_zen[3]; - -#define VIEWGRAD_RES_X 16 -#define VIEWGRAD_RES_Y 16 - - GLubyte grid_col[VIEWGRAD_RES_X][VIEWGRAD_RES_Y][4]; - static float grid_pos[VIEWGRAD_RES_X][VIEWGRAD_RES_Y][3]; - static GLushort indices[VIEWGRAD_RES_X - 1][VIEWGRAD_RES_X - 1][4]; - static bool buf_calculated = false; - - if (use_color_correction) { - 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); - } - else { - copy_v3_v3(col_hor, &scene->world->horr); - copy_v3_v3(col_zen, &scene->world->zenr); - } - - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - /* calculate buffers the first time only */ - if (!buf_calculated) { - for (x = 0; x < VIEWGRAD_RES_X; x++) { - for (y = 0; y < VIEWGRAD_RES_Y; y++) { - const float xf = (float)x / (float)(VIEWGRAD_RES_X - 1); - const float yf = (float)y / (float)(VIEWGRAD_RES_Y - 1); - - /* -1..1 range */ - grid_pos[x][y][0] = (xf - 0.5f) * 2.0f; - grid_pos[x][y][1] = (yf - 0.5f) * 2.0f; - grid_pos[x][y][2] = 1.0; - } - } - - for (x = 0; x < VIEWGRAD_RES_X - 1; x++) { - for (y = 0; y < VIEWGRAD_RES_Y - 1; y++) { - indices[x][y][0] = x * VIEWGRAD_RES_X + y; - indices[x][y][1] = x * VIEWGRAD_RES_X + y + 1; - indices[x][y][2] = (x + 1) * VIEWGRAD_RES_X + y + 1; - indices[x][y][3] = (x + 1) * VIEWGRAD_RES_X + y; - } - } - - buf_calculated = true; - } - - for (x = 0; x < VIEWGRAD_RES_X; x++) { - for (y = 0; y < VIEWGRAD_RES_Y; y++) { - const float xf = (float)x / (float)(VIEWGRAD_RES_X - 1); - const float yf = (float)y / (float)(VIEWGRAD_RES_Y - 1); - const float mval[2] = {xf * (float)ar->winx, yf * ar->winy}; - const float z_up[3] = {0.0f, 0.0f, 1.0f}; - float out[3]; - GLubyte *col_ub = grid_col[x][y]; - - float col_fac; - float col_fl[3]; - - 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)VIEWGRAD_RES_Y) - 0.5f) * 2.0f; - } - else { - col_fac = (float)y / (float)VIEWGRAD_RES_Y; - } - } - else { - if (scene->world->skytype & WO_SKYREAL) { - col_fac = fabsf((angle_normalized_v3v3(z_up, out) / (float)M_PI) - 0.5f) * 2.0f; - } - else { - col_fac = 1.0f - (angle_normalized_v3v3(z_up, out) / (float)M_PI); - } - } + else { + gpumat = GPU_material_world(scene, scene->world); - interp_v3_v3v3(col_fl, col_hor, col_zen, col_fac); + /* calculate full shader for background */ + GPU_material_bind(gpumat, 1, 1, 1.0, false, rv3d->viewmat, rv3d->viewinv, rv3d->viewcamtexcofac, (v3d->scenelock != 0)); + + material_not_bound = !GPU_material_bound(gpumat); - rgb_float_to_uchar(col_ub, col_fl); - col_ub[3] = 255; - } + if (material_not_bound) { + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); } + } - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(3, GL_FLOAT, 0, grid_pos); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, grid_col); - - glDrawElements(GL_QUADS, (VIEWGRAD_RES_X - 1) * (VIEWGRAD_RES_Y - 1) * 4, GL_UNSIGNED_SHORT, indices); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glDepthFunc(GL_LEQUAL); - glDisable(GL_DEPTH_TEST); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + /* Draw world */ + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); + glBegin(GL_TRIANGLE_STRIP); + glVertex3f(-1.0, -1.0, 1.0); + glVertex3f(1.0, -1.0, 1.0); + glVertex3f(-1.0, 1.0, 1.0); + glVertex3f(1.0, 1.0, 1.0); + glEnd(); -#undef VIEWGRAD_RES_X -#undef VIEWGRAD_RES_Y + if (v3d->flag3 & V3D_SHOW_WORLD_DIFFUSE) { + GPU_probe_sh_shader_unbind(); } - else { /* solid sky */ - float col_hor[3]; - if (use_color_correction) { - IMB_colormanagement_pixel_to_display_space_v3(col_hor, &scene->world->horr, &scene->view_settings, - &scene->display_settings); - } - else { - copy_v3_v3(col_hor, &scene->world->horr); + else { + if (material_not_bound) { + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); } - glClearColor(col_hor[0], col_hor[1], col_hor[2], 1.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + GPU_material_unbind(gpumat); } + + glDepthFunc(GL_LEQUAL); + glDisable(GL_DEPTH_TEST); } else { if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) { diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index af86fb72070..8582952d1a0 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -592,6 +592,54 @@ void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +static void sync_viewport_camera_smoothview(bContext *C, View3D *v3d, Object *ob, const int smooth_viewtx) +{ + Main *bmain = CTX_data_main(C); + for (bScreen *screen = bmain->screen.first; screen != NULL; screen = screen->id.next) { + for (ScrArea *area = screen->areabase.first; area != NULL; area = area->next) { + for (SpaceLink *space_link = area->spacedata.first; space_link != NULL; space_link = space_link->next) { + if (space_link->spacetype == SPACE_VIEW3D) { + View3D *other_v3d = (View3D *)space_link; + if (other_v3d == v3d) { + continue; + } + if (other_v3d->camera == ob) { + continue; + } + if (v3d->scenelock) { + ListBase *lb = (space_link == area->spacedata.first) + ? &area->regionbase + : &space_link->regionbase; + for (ARegion *other_ar = lb->first; other_ar != NULL; other_ar = other_ar->next) { + if (other_ar->regiontype == RGN_TYPE_WINDOW) { + if (other_ar->regiondata) { + RegionView3D *other_rv3d = other_ar->regiondata; + if (other_rv3d->persp == RV3D_CAMOB) { + Object *other_camera_old = other_v3d->camera; + other_v3d->camera = ob; + ED_view3d_lastview_store(other_rv3d); + ED_view3d_smooth_view( + C, other_v3d, other_ar, smooth_viewtx, + &(const V3D_SmoothParams) { + .camera_old = other_camera_old, + .camera = other_v3d->camera, + .ofs = other_rv3d->ofs, + .quat = other_rv3d->viewquat, + .dist = &other_rv3d->dist, + .lens = &other_v3d->lens}); + } + else { + other_v3d->camera = ob; + } + } + } + } + } + } + } + } + } +} static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op) { @@ -628,6 +676,7 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op) } if (v3d->scenelock) { + sync_viewport_camera_smoothview(C, v3d, ob, smooth_viewtx); WM_event_add_notifier(C, NC_SCENE, scene); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, scene); |