UI: Adaptive HDRI preview resolution
HDRI preview should have resolution dependent on dpi, viewport scale and HDRI gizmo size. This patch uses a LOD to render a more round sphere. Reviewed By: Jeroen Bakker Differential Revision: https://developer.blender.org/D9382
This commit is contained in:
parent
b35b8c8849
commit
4efd87d56b
|
@ -65,7 +65,8 @@ static void eevee_lookdev_hdri_preview_init(EEVEE_Data *vedata, EEVEE_ViewLayerD
|
|||
Scene *scene = draw_ctx->scene;
|
||||
DRWShadingGroup *grp;
|
||||
|
||||
struct GPUBatch *sphere = DRW_cache_sphere_get();
|
||||
const EEVEE_EffectsInfo *effects = vedata->stl->effects;
|
||||
struct GPUBatch *sphere = DRW_cache_sphere_get(effects->sphere_lod);
|
||||
int mat_options = VAR_MAT_MESH | VAR_MAT_LOOKDEV;
|
||||
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS |
|
||||
|
@ -126,6 +127,19 @@ void EEVEE_lookdev_init(EEVEE_Data *vedata)
|
|||
|
||||
if (sphere_size != effects->sphere_size || rect->xmax != effects->anchor[0] ||
|
||||
rect->ymin != effects->anchor[1]) {
|
||||
/* Make sphere resolution adaptive to viewport_scale, dpi and lookdev_sphere_size */
|
||||
float res_scale = clamp_f(
|
||||
(U.lookdev_sphere_size / 400.0f) * viewport_scale * U.dpi_fac, 0.1f, 1.0f);
|
||||
|
||||
if (res_scale > 0.7f) {
|
||||
effects->sphere_lod = DRW_LOD_HIGH;
|
||||
}
|
||||
else if (res_scale > 0.25f) {
|
||||
effects->sphere_lod = DRW_LOD_MEDIUM;
|
||||
}
|
||||
else {
|
||||
effects->sphere_lod = DRW_LOD_LOW;
|
||||
}
|
||||
/* If sphere size or anchor point moves, reset TAA to avoid ghosting issue.
|
||||
* This needs to happen early because we are changing taa_current_sample. */
|
||||
effects->sphere_size = sphere_size;
|
||||
|
|
|
@ -734,6 +734,7 @@ typedef struct EEVEE_EffectsInfo {
|
|||
float prev_persmat[4][4];
|
||||
/* Lookdev */
|
||||
int sphere_size;
|
||||
eDRWLevelOfDetail sphere_lod;
|
||||
int anchor[2];
|
||||
struct DRWView *lookdev_view;
|
||||
/* Bloom */
|
||||
|
|
|
@ -128,7 +128,7 @@ void OVERLAY_extra_cache_init(OVERLAY_Data *vedata)
|
|||
cb->empty_plain_axes = BUF_INSTANCE(grp_sub, format, DRW_cache_plain_axes_get());
|
||||
cb->empty_single_arrow = BUF_INSTANCE(grp_sub, format, DRW_cache_single_arrow_get());
|
||||
cb->empty_sphere = BUF_INSTANCE(grp_sub, format, DRW_cache_empty_sphere_get());
|
||||
cb->empty_sphere_solid = BUF_INSTANCE(grp_sub, format, DRW_cache_sphere_get());
|
||||
cb->empty_sphere_solid = BUF_INSTANCE(grp_sub, format, DRW_cache_sphere_get(DRW_LOD_LOW));
|
||||
cb->field_cone_limit = BUF_INSTANCE(grp_sub, format, DRW_cache_field_cone_limit_get());
|
||||
cb->field_curve = BUF_INSTANCE(grp_sub, format, DRW_cache_field_curve_get());
|
||||
cb->field_force = BUF_INSTANCE(grp_sub, format, DRW_cache_field_force_get());
|
||||
|
|
|
@ -66,6 +66,17 @@
|
|||
#define VCLASS_EMPTY_AXES_SHADOW (1 << 13)
|
||||
#define VCLASS_EMPTY_SIZE (1 << 14)
|
||||
|
||||
/* Sphere shape resolution */
|
||||
/* Low */
|
||||
#define DRW_SPHERE_SHAPE_LATITUDE_LOW 32
|
||||
#define DRW_SPHERE_SHAPE_LONGITUDE_LOW 24
|
||||
/* Medium */
|
||||
#define DRW_SPHERE_SHAPE_LATITUDE_MEDIUM 64
|
||||
#define DRW_SPHERE_SHAPE_LONGITUDE_MEDIUM 48
|
||||
/* High */
|
||||
#define DRW_SPHERE_SHAPE_LATITUDE_HIGH 80
|
||||
#define DRW_SPHERE_SHAPE_LONGITUDE_HIGH 60
|
||||
|
||||
typedef struct Vert {
|
||||
float pos[3];
|
||||
int class;
|
||||
|
@ -88,7 +99,6 @@ static struct DRWShapeCache {
|
|||
GPUBatch *drw_quad;
|
||||
GPUBatch *drw_quad_wires;
|
||||
GPUBatch *drw_grid;
|
||||
GPUBatch *drw_sphere;
|
||||
GPUBatch *drw_plain_axes;
|
||||
GPUBatch *drw_single_arrow;
|
||||
GPUBatch *drw_cube;
|
||||
|
@ -140,6 +150,7 @@ static struct DRWShapeCache {
|
|||
GPUBatch *drw_particle_circle;
|
||||
GPUBatch *drw_particle_axis;
|
||||
GPUBatch *drw_gpencil_dummy_quad;
|
||||
GPUBatch *drw_sphere_lod[DRW_LOD_MAX];
|
||||
} SHC = {NULL};
|
||||
|
||||
void DRW_shape_cache_free(void)
|
||||
|
@ -473,11 +484,30 @@ static void sphere_lat_lon_vert(GPUVertBuf *vbo, int *v_ofs, float lat, float lo
|
|||
(*v_ofs)++;
|
||||
}
|
||||
|
||||
GPUBatch *DRW_cache_sphere_get(void)
|
||||
GPUBatch *DRW_cache_sphere_get(const eDRWLevelOfDetail level_of_detail)
|
||||
{
|
||||
if (!SHC.drw_sphere) {
|
||||
const int lat_res = 32;
|
||||
const int lon_res = 24;
|
||||
BLI_assert(level_of_detail >= DRW_LOD_LOW && level_of_detail < DRW_LOD_MAX);
|
||||
|
||||
if (!SHC.drw_sphere_lod[level_of_detail]) {
|
||||
int lat_res;
|
||||
int lon_res;
|
||||
|
||||
switch (level_of_detail) {
|
||||
case DRW_LOD_LOW:
|
||||
lat_res = DRW_SPHERE_SHAPE_LATITUDE_LOW;
|
||||
lon_res = DRW_SPHERE_SHAPE_LONGITUDE_LOW;
|
||||
break;
|
||||
case DRW_LOD_MEDIUM:
|
||||
lat_res = DRW_SPHERE_SHAPE_LATITUDE_MEDIUM;
|
||||
lon_res = DRW_SPHERE_SHAPE_LONGITUDE_MEDIUM;
|
||||
break;
|
||||
case DRW_LOD_HIGH:
|
||||
lat_res = DRW_SPHERE_SHAPE_LATITUDE_HIGH;
|
||||
lon_res = DRW_SPHERE_SHAPE_LONGITUDE_HIGH;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GPUVertFormat format = extra_vert_format();
|
||||
GPU_vertformat_attr_add(&format, "nor", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
|
||||
|
@ -508,9 +538,10 @@ GPUBatch *DRW_cache_sphere_get(void)
|
|||
}
|
||||
}
|
||||
|
||||
SHC.drw_sphere = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, NULL, GPU_BATCH_OWNS_VBO);
|
||||
SHC.drw_sphere_lod[level_of_detail] = GPU_batch_create_ex(
|
||||
GPU_PRIM_TRIS, vbo, NULL, GPU_BATCH_OWNS_VBO);
|
||||
}
|
||||
return SHC.drw_sphere;
|
||||
return SHC.drw_sphere_lod[level_of_detail];
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -32,6 +32,15 @@ struct Volume;
|
|||
struct VolumeGrid;
|
||||
struct bGPDstroke;
|
||||
|
||||
/* Shape resolution level of detail */
|
||||
typedef enum eDRWLevelOfDetail {
|
||||
DRW_LOD_LOW = 0,
|
||||
DRW_LOD_MEDIUM = 1,
|
||||
DRW_LOD_HIGH = 2,
|
||||
|
||||
DRW_LOD_MAX, /* Max number of level of detail */
|
||||
} eDRWLevelOfDetail;
|
||||
|
||||
void DRW_shape_cache_free(void);
|
||||
|
||||
/* 3D cursor */
|
||||
|
@ -44,9 +53,10 @@ struct GPUBatch *DRW_cache_fullscreen_quad_get(void);
|
|||
struct GPUBatch *DRW_cache_quad_get(void);
|
||||
struct GPUBatch *DRW_cache_quad_wires_get(void);
|
||||
struct GPUBatch *DRW_cache_cube_get(void);
|
||||
struct GPUBatch *DRW_cache_sphere_get(void);
|
||||
struct GPUBatch *DRW_cache_normal_arrow_get(void);
|
||||
|
||||
struct GPUBatch *DRW_cache_sphere_get(const eDRWLevelOfDetail level_of_detail);
|
||||
|
||||
/* Dummy VBOs */
|
||||
struct GPUBatch *DRW_gpencil_dummy_buffer_get(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue