MacOS: Enable support for EDR rendering #105662

Merged
Brecht Van Lommel merged 26 commits from Jason-Fielder/blender:macos_EDR_support into main 2023-08-09 14:25:23 +02:00
11 changed files with 29 additions and 51 deletions
Showing only changes of commit b06504c153 - Show all commits

View File

@ -169,17 +169,15 @@ vec4 OCIO_ProcessColor(vec4 col, vec4 col_overlay)
* merge UI using alpha blending in the correct color space. */
if (parameters.use_overlay) {
col.rgb = pow(col.rgb, vec3(parameters.exponent * 2.2));
col = max(col, 0.0);
vec4 clamped_col = min(col, 1.0);
if (!parameters.use_extended) {
brecht marked this conversation as resolved Outdated

would still use clamp(col, 0.0, 1.0) here. and move the max inside the else-clause

would still use `clamp(col, 0.0, 1.0)` here. and move the `max` inside the else-clause

As would even go further and suggest to move all clamping inside the if-else clause for clarity.

if (!parameters.use_extended) {
  col = clamp(col, 0.0, 1.0);
}
else {
  col = mix(min(col, 0.0), clamp(col, 0.0, 1.0), col_overlay.a);
}

This way, the code is easier to refactor if we need to change the else clause.

As would even go further and suggest to move all clamping inside the if-else clause for clarity. ``` if (!parameters.use_extended) { col = clamp(col, 0.0, 1.0); } else { col = mix(min(col, 0.0), clamp(col, 0.0, 1.0), col_overlay.a); } ``` This way, the code is easier to refactor if we need to change the else clause.
/* if we're not using an extended colour space, clamp the color 0..1 */
col = clamped_col;
col = clamp(col, 0.0, 1.0);
}
fclem marked this conversation as resolved Outdated

Comment style: Capital + fullstop.

Comment style: Capital + fullstop.
else {
/* When using extended colorspace, interpolate towards clamped color to improve display of
* alpha-blended overlays. */
col = mix(col, clamped_col, col_overlay.a);
col = mix(max(col, 0.0), clamp(col, 0.0, 1.0), col_overlay.a);
}
col *= 1.0 - col_overlay.a;
col += col_overlay; /* Assumed unassociated alpha. */

View File

@ -1906,7 +1906,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph,
/* Determine desired offscreen format depending on HDR availability. */
bool use_hdr = false;
if (scene && ((scene->view_settings.flag & COLORMANAGE_VIEW_USE_HDR) != 0)) {
use_hdr = GPU_HDR_support();
use_hdr = GPU_hdr_support();
}
eGPUTextureFormat desired_format = (use_hdr) ? GPU_RGBA16F : GPU_RGBA8;

View File

@ -52,7 +52,7 @@ bool GPU_compute_shader_support(void);
bool GPU_shader_storage_buffer_objects_support(void);
bool GPU_shader_image_load_store_support(void);
bool GPU_shader_draw_parameters_support(void);
bool GPU_HDR_support(void);
bool GPU_hdr_support(void);
brecht marked this conversation as resolved Outdated

Would use GPU_hdr_support even if the style guide doesn't require it

Would use `GPU_hdr_support` even if the style guide doesn't require it
bool GPU_mem_stats_supported(void);
void GPU_mem_stats_get(int *totalmem, int *freemem);

View File

@ -654,8 +654,7 @@ int GPU_offscreen_height(const GPUOffScreen *offscreen);
struct GPUTexture *GPU_offscreen_color_texture(const GPUOffScreen *offscreen);
/**
* Return the color texture of a #GPUOffScreen. Does not give ownership.
* \note only to be used by viewport code!
* Return the texture format of a #GPUOffScreen.
brecht marked this conversation as resolved Outdated

Comment needs to be updated.

Comment needs to be updated.
*/
eGPUTextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen);

View File

@ -182,7 +182,7 @@ bool GPU_shader_draw_parameters_support()
return GCaps.shader_draw_parameters_support;
}
bool GPU_HDR_support()
bool GPU_hdr_support()
{
return GCaps.hdr_viewport_support;
}

View File

@ -441,7 +441,7 @@ static void gpu_viewport_draw_colormanaged(GPUViewport *viewport,
GPUTexture *color_overlay = viewport->color_overlay_tx[view];
bool use_ocio = false;
bool use_hdr = GPU_HDR_support() &&
bool use_hdr = GPU_hdr_support() &&
((viewport->view_settings.flag & COLORMANAGE_VIEW_USE_HDR) != 0);
if (viewport->do_color_management && display_colorspace) {

View File

@ -36,16 +36,14 @@ void main()
vec4 overlay_col = texture(overlays_texture, texCoord_interp.xy);
if (overlay) {
fragColor = max(fragColor, 0.0);
vec4 clamped_col = min(fragColor, 1.0);
if (!use_extended) {
brecht marked this conversation as resolved Outdated

Same here as in the OCIO shader.

Same here as in the OCIO shader.
/* Only clamp color if we are not using an extended display colorspace. */
fragColor = clamped_col;
/* if we're not using an extended colour space, clamp the color 0..1 */
fragColor = clamp(fragColor, 0.0, 1.0);
}
else {
/* When using extended colorspace, interpolate towards clamped color to avoid over-brightened
* overlays. */
fragColor = mix(fragColor, clamped_col, overlay_col.a);
/* When using extended colorspace, interpolate towards clamped color to improve display of
* alpha-blended overlays. */
fragColor = mix(max(fragColor, 0.0), clamp(fragColor, 0.0, 1.0), overlay_col.a);
}
fragColor *= 1.0 - overlay_col.a;
fragColor += overlay_col;

View File

@ -4107,7 +4107,7 @@ bool IMB_colormanagement_setup_glsl_draw_from_space(
const float gamma = applied_view_settings->gamma;
const float scale = (exposure == 0.0f) ? 1.0f : powf(2.0f, exposure);
const float exponent = (gamma == 1.0f) ? 1.0f : 1.0f / max_ff(FLT_EPSILON, gamma);
const bool use_extended = GPU_HDR_support() &&
const bool use_extended = GPU_hdr_support() &&
(applied_view_settings->flag & COLORMANAGE_VIEW_USE_HDR) != 0;
OCIO_ConstConfigRcPtr *config = OCIO_getCurrentConfig();

View File

@ -506,18 +506,6 @@ static void rna_ColorManagedViewSettings_look_set(PointerRNA *ptr, int value)
}
}
static void rna_ColorManagedViewSettings_use_hdr_set(PointerRNA *ptr, bool value)
{
ColorManagedViewSettings *view_settings = (ColorManagedViewSettings *)ptr->data;
if (value) {
view_settings->flag |= COLORMANAGE_VIEW_USE_HDR;
}
else {
view_settings->flag &= ~COLORMANAGE_VIEW_USE_HDR;
}
}
static const EnumPropertyItem *rna_ColorManagedViewSettings_look_itemf(bContext * /*C*/,
PointerRNA *ptr,
PropertyRNA * /*prop*/,
@ -1287,7 +1275,6 @@ static void rna_def_colormanage(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_hdr_view", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", COLORMANAGE_VIEW_USE_HDR);
RNA_def_property_boolean_funcs(prop, NULL, "rna_ColorManagedViewSettings_use_hdr_set");
RNA_def_property_ui_text(prop,
"High Dynamic Range",
"Enable high dynamic range with extended colorspace in viewport, "

View File

@ -238,7 +238,7 @@ PyDoc_STRVAR(pygpu_hdr_support_get_doc,
" :rtype: bool\n");
static PyObject *pygpu_hdr_support_get(PyObject * /*self*/)
{
return PyBool_FromLong(GPU_HDR_support());
return PyBool_FromLong(GPU_hdr_support());
}
/** \} */

View File

@ -663,18 +663,24 @@ static void wm_draw_offscreen_texture_parameters(GPUOffScreen *offscreen)
GPU_texture_mipmap_mode(texture, false, false);
}
static eGPUTextureFormat get_hdr_framebuffer_format(const Scene *scene)
{
bool use_hdr = false;
if (scene && ((scene->view_settings.flag & COLORMANAGE_VIEW_USE_HDR) != 0)) {
use_hdr = GPU_hdr_support();
}
eGPUTextureFormat desired_format = (use_hdr) ? GPU_RGBA16F : GPU_RGBA8;
return desired_format;
}
static void wm_draw_region_buffer_create(Scene *scene,
ARegion *region,
bool stereo,
bool use_viewport)
{
/* Determine desired offscreen format. */
bool use_hdr = false;
if (scene && ((scene->view_settings.flag & COLORMANAGE_VIEW_USE_HDR) != 0)) {
use_hdr = GPU_HDR_support();
}
eGPUTextureFormat desired_format = (use_hdr) ? GPU_RGBA16F : GPU_RGBA8;
/* Determine desired offscreen format depending on HDR availability. */
eGPUTextureFormat desired_format = get_hdr_framebuffer_format(scene);
if (region->draw_buffer) {
if (region->draw_buffer->stereo != stereo) {
@ -1177,13 +1183,8 @@ static void wm_draw_window(bContext *C, wmWindow *win)
wm_draw_window_onscreen(C, win, -1);
}
else {
/* Determine desired offscreen format. */
bool use_hdr = false;
Scene *scene = WM_window_get_active_scene(win);
if (scene && ((scene->view_settings.flag & COLORMANAGE_VIEW_USE_HDR) != 0)) {
use_hdr = GPU_HDR_support();
}
eGPUTextureFormat desired_format = (use_hdr) ? GPU_RGBA16F : GPU_RGBA8;
/* Determine desired offscreen format depending on HDR availability. */
eGPUTextureFormat desired_format = get_hdr_framebuffer_format(WM_window_get_active_scene(win));
/* For side-by-side and top-bottom, we need to render each view to an
* an off-screen texture and then draw it. This used to happen for all
@ -1343,12 +1344,7 @@ uint8_t *WM_window_pixels_read_from_offscreen(bContext *C, wmWindow *win, int r_
r_size[1] = WM_window_pixels_y(win);
/* Determine desired offscreen format depending on HDR availability. */
bool use_hdr = false;
Scene *scene = WM_window_get_active_scene(win);
if (scene && ((scene->view_settings.flag & COLORMANAGE_VIEW_USE_HDR) != 0)) {
use_hdr = GPU_HDR_support();
}
eGPUTextureFormat desired_format = (use_hdr) ? GPU_RGBA16F : GPU_RGBA8;
eGPUTextureFormat desired_format = get_hdr_framebuffer_format(WM_window_get_active_scene(win));
GPUOffScreen *offscreen = GPU_offscreen_create(
r_size[0], r_size[1], false, desired_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);