DRW/Eevee: Fix camera texture coordinates in renders
This patch fix the issue introduced by recent refactor and fixes computation when using overscans.
This commit is contained in:
parent
d10bab7160
commit
8b52619ff8
|
@ -53,6 +53,8 @@ void EEVEE_render_init(EEVEE_Data *ved, RenderEngine *engine, struct Depsgraph *
|
|||
EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
|
||||
Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||
const float *size_orig = DRW_viewport_size_get();
|
||||
float size_final[2];
|
||||
float camtexcofac[4];
|
||||
|
||||
/* Init default FB and render targets:
|
||||
* In render mode the default framebuffer is not generated
|
||||
|
@ -73,10 +75,22 @@ void EEVEE_render_init(EEVEE_Data *ved, RenderEngine *engine, struct Depsgraph *
|
|||
if (scene->eevee.flag & SCE_EEVEE_OVERSCAN) {
|
||||
g_data->overscan = scene->eevee.overscan / 100.0f;
|
||||
g_data->overscan_pixels = roundf(max_ff(size_orig[0], size_orig[1]) * g_data->overscan);
|
||||
|
||||
madd_v2_v2v2fl(size_final, size_orig, (float[2]){2.0f, 2.0f}, g_data->overscan_pixels);
|
||||
|
||||
camtexcofac[0] = size_final[0] / size_orig[0];
|
||||
camtexcofac[1] = size_final[1] / size_orig[1];
|
||||
|
||||
camtexcofac[2] = -camtexcofac[0] * g_data->overscan_pixels / size_final[0];
|
||||
camtexcofac[3] = -camtexcofac[1] * g_data->overscan_pixels / size_final[1];
|
||||
|
||||
print_v4_id(camtexcofac);
|
||||
}
|
||||
else {
|
||||
copy_v2_v2(size_final, size_orig);
|
||||
g_data->overscan = 0.0f;
|
||||
g_data->overscan_pixels = 0.0f;
|
||||
copy_v4_fl4(camtexcofac, 1.0f, 1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
/* XXX overiding viewport size. Simplify things but is not really 100% safe. */
|
||||
|
@ -114,6 +128,7 @@ void EEVEE_render_init(EEVEE_Data *ved, RenderEngine *engine, struct Depsgraph *
|
|||
invert_m4_m4(viewmat, viewinv);
|
||||
|
||||
DRWView *view = DRW_view_create(viewmat, winmat, NULL, NULL, NULL);
|
||||
DRW_view_camtexco_set(view, camtexcofac);
|
||||
DRW_view_default_set(view);
|
||||
DRW_view_set_active(view);
|
||||
|
||||
|
|
|
@ -548,6 +548,7 @@ void DRW_view_default_set(DRWView *view);
|
|||
void DRW_view_set_active(DRWView *view);
|
||||
|
||||
void DRW_view_clip_planes_set(DRWView *view, float (*planes)[4], int plane_len);
|
||||
void DRW_view_camtexco_set(DRWView *view, float texco[4]);
|
||||
|
||||
/* For all getters, if view is NULL, default view is assumed. */
|
||||
void DRW_view_winmat_get(const DRWView *view, float mat[4][4], bool inverse);
|
||||
|
|
|
@ -656,7 +656,7 @@ static void drw_viewport_var_init(void)
|
|||
|
||||
DST.pixsize = rv3d->pixsize;
|
||||
DST.view_default = DRW_view_create(rv3d->viewmat, rv3d->winmat, NULL, NULL, NULL);
|
||||
copy_v4_v4(DST.view_default->storage.viewcamtexcofac, rv3d->viewcamtexcofac);
|
||||
DRW_view_camtexco_set(DST.view_default, rv3d->viewcamtexcofac);
|
||||
|
||||
if (DST.draw_ctx.sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
||||
int plane_len = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
|
||||
|
|
|
@ -874,8 +874,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
|
|||
drw_shgroup_builtin_uniform(shgroup, GPU_UNIFORM_VIEWPROJECTION_INV, storage->persinv, 16, 1);
|
||||
drw_shgroup_builtin_uniform(shgroup, GPU_UNIFORM_PROJECTION, storage->winmat, 16, 1);
|
||||
drw_shgroup_builtin_uniform(shgroup, GPU_UNIFORM_PROJECTION_INV, storage->wininv, 16, 1);
|
||||
drw_shgroup_builtin_uniform(
|
||||
shgroup, GPU_UNIFORM_CAMERATEXCO, DST.view_storage_cpy.viewcamtexcofac, 4, 1);
|
||||
}
|
||||
|
||||
/* Not supported. */
|
||||
|
@ -1327,10 +1325,7 @@ DRWView *DRW_view_create(const float viewmat[4][4],
|
|||
view->visibility_fn = visibility_fn;
|
||||
view->parent = NULL;
|
||||
|
||||
/* TODO move elsewhere */
|
||||
if (DST.view_default) {
|
||||
copy_v4_v4(view->storage.viewcamtexcofac, DST.view_default->storage.viewcamtexcofac);
|
||||
}
|
||||
copy_v4_fl4(view->storage.viewcamtexcofac, 1.0f, 1.0f, 0.0f, 0.0f);
|
||||
|
||||
DRW_view_update(view, viewmat, winmat, culling_viewmat, culling_winmat);
|
||||
|
||||
|
@ -1350,11 +1345,6 @@ DRWView *DRW_view_create_sub(const DRWView *parent_view,
|
|||
*view = *parent_view;
|
||||
view->parent = (DRWView *)parent_view;
|
||||
|
||||
/* TODO move elsewhere */
|
||||
if (DST.view_default) {
|
||||
copy_v4_v4(view->storage.viewcamtexcofac, DST.view_default->storage.viewcamtexcofac);
|
||||
}
|
||||
|
||||
DRW_view_update_sub(view, viewmat, winmat);
|
||||
|
||||
return view;
|
||||
|
@ -1471,6 +1461,11 @@ void DRW_view_clip_planes_set(DRWView *view, float (*planes)[4], int plane_len)
|
|||
}
|
||||
}
|
||||
|
||||
void DRW_view_camtexco_set(DRWView *view, float texco[4])
|
||||
{
|
||||
copy_v4_v4(view->storage.viewcamtexcofac, texco);
|
||||
}
|
||||
|
||||
/* Return world space frustum corners. */
|
||||
void DRW_view_frustum_corners_get(const DRWView *view, BoundBox *corners)
|
||||
{
|
||||
|
|
|
@ -44,9 +44,8 @@ typedef enum {
|
|||
GPU_UNIFORM_PROJECTION_INV, /* mat4 ProjectionMatrixInverse */
|
||||
GPU_UNIFORM_VIEWPROJECTION_INV, /* mat4 ViewProjectionMatrixInverse */
|
||||
|
||||
GPU_UNIFORM_NORMAL, /* mat3 NormalMatrix */
|
||||
GPU_UNIFORM_CAMERATEXCO, /* vec4 CameraTexCoFactors */
|
||||
GPU_UNIFORM_ORCO, /* vec3 OrcoTexCoFactors[] */
|
||||
GPU_UNIFORM_NORMAL, /* mat3 NormalMatrix */
|
||||
GPU_UNIFORM_ORCO, /* vec3 OrcoTexCoFactors[] */
|
||||
|
||||
GPU_UNIFORM_COLOR, /* vec4 color */
|
||||
GPU_UNIFORM_CALLID, /* int callId */
|
||||
|
|
|
@ -61,7 +61,6 @@ static const char *BuiltinUniform_name(GPUUniformBuiltin u)
|
|||
[GPU_UNIFORM_VIEWPROJECTION_INV] = "ViewProjectionMatrixInverse",
|
||||
|
||||
[GPU_UNIFORM_NORMAL] = "NormalMatrix",
|
||||
[GPU_UNIFORM_CAMERATEXCO] = "CameraTexCoFactors",
|
||||
[GPU_UNIFORM_ORCO] = "OrcoTexCoFactors",
|
||||
|
||||
[GPU_UNIFORM_COLOR] = "color",
|
||||
|
|
Loading…
Reference in New Issue