Merge branch 'blender-v3.1-release'
# Conflicts: # intern/opencolorio/ocio_shader_shared.hh
This commit is contained in:
commit
e81dda4f38
|
@ -7,7 +7,6 @@ set(INC
|
||||||
../guardedalloc
|
../guardedalloc
|
||||||
../../source/blender/blenlib
|
../../source/blender/blenlib
|
||||||
../../source/blender/gpu
|
../../source/blender/gpu
|
||||||
../../source/blender/gpu/intern
|
|
||||||
../../source/blender/makesdna
|
../../source/blender/makesdna
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +20,6 @@ set(SRC
|
||||||
|
|
||||||
ocio_capi.h
|
ocio_capi.h
|
||||||
ocio_impl.h
|
ocio_impl.h
|
||||||
ocio_shader_shared.hh
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIB
|
set(LIB
|
||||||
|
@ -58,38 +56,8 @@ if(WITH_OPENCOLORIO)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(GLSL_SRC
|
data_to_c_simple(gpu_shader_display_transform.glsl SRC)
|
||||||
gpu_shader_display_transform_vert.glsl
|
data_to_c_simple(gpu_shader_display_transform_vertex.glsl SRC)
|
||||||
gpu_shader_display_transform_frag.glsl
|
|
||||||
|
|
||||||
ocio_shader_shared.hh
|
|
||||||
)
|
|
||||||
|
|
||||||
set(GLSL_C)
|
|
||||||
foreach(GLSL_FILE ${GLSL_SRC})
|
|
||||||
data_to_c_simple(${GLSL_FILE} GLSL_C)
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
blender_add_lib(bf_ocio_shaders "${GLSL_C}" "" "" "")
|
|
||||||
|
|
||||||
list(APPEND LIB
|
|
||||||
bf_ocio_shaders
|
|
||||||
)
|
|
||||||
|
|
||||||
set(GLSL_SOURCE_CONTENT "")
|
|
||||||
foreach(GLSL_FILE ${GLSL_SRC})
|
|
||||||
get_filename_component(GLSL_FILE_NAME ${GLSL_FILE} NAME)
|
|
||||||
string(REPLACE "." "_" GLSL_FILE_NAME_UNDERSCORES ${GLSL_FILE_NAME})
|
|
||||||
string(APPEND GLSL_SOURCE_CONTENT "SHADER_SOURCE\(datatoc_${GLSL_FILE_NAME_UNDERSCORES}, \"${GLSL_FILE_NAME}\", \"${GLSL_FILE}\"\)\n")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
set(glsl_source_list_file "${CMAKE_CURRENT_BINARY_DIR}/glsl_ocio_source_list.h")
|
|
||||||
file(GENERATE OUTPUT ${glsl_source_list_file} CONTENT "${GLSL_SOURCE_CONTENT}")
|
|
||||||
list(APPEND SRC ${glsl_source_list_file})
|
|
||||||
list(APPEND INC ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
|
|
||||||
target_include_directories(bf_ocio_shaders PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,39 @@
|
||||||
/* Blender OpenColorIO implementation */
|
/* Blender OpenColorIO implementation */
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
uniform sampler2D image_texture;
|
||||||
/** \name Curve Mapping Implementation
|
uniform sampler2D overlay_texture;
|
||||||
* \{ */
|
|
||||||
|
uniform float dither;
|
||||||
|
uniform float scale;
|
||||||
|
uniform float exponent;
|
||||||
|
uniform bool predivide;
|
||||||
|
uniform bool overlay;
|
||||||
|
|
||||||
#ifdef USE_CURVE_MAPPING
|
#ifdef USE_CURVE_MAPPING
|
||||||
|
uniform sampler1D curve_mapping_texture;
|
||||||
|
|
||||||
|
layout(std140) uniform OCIO_GPUCurveMappingParameters
|
||||||
|
{
|
||||||
|
/* Curve mapping parameters
|
||||||
|
*
|
||||||
|
* See documentation for OCIO_CurveMappingSettings to get fields descriptions.
|
||||||
|
* (this ones pretty much copies stuff from C structure.)
|
||||||
|
*/
|
||||||
|
vec4 curve_mapping_mintable;
|
||||||
|
vec4 curve_mapping_range;
|
||||||
|
vec4 curve_mapping_ext_in_x;
|
||||||
|
vec4 curve_mapping_ext_in_y;
|
||||||
|
vec4 curve_mapping_ext_out_x;
|
||||||
|
vec4 curve_mapping_ext_out_y;
|
||||||
|
vec4 curve_mapping_first_x;
|
||||||
|
vec4 curve_mapping_first_y;
|
||||||
|
vec4 curve_mapping_last_x;
|
||||||
|
vec4 curve_mapping_last_y;
|
||||||
|
vec4 curve_mapping_black;
|
||||||
|
vec4 curve_mapping_bwmul;
|
||||||
|
int curve_mapping_lut_size;
|
||||||
|
int curve_mapping_use_extend_extrapolate;
|
||||||
|
};
|
||||||
|
|
||||||
float read_curve_mapping(int table, int index)
|
float read_curve_mapping(int table, int index)
|
||||||
{
|
{
|
||||||
|
@ -14,27 +43,27 @@ float read_curve_mapping(int table, int index)
|
||||||
float curvemap_calc_extend(int table, float x, vec2 first, vec2 last)
|
float curvemap_calc_extend(int table, float x, vec2 first, vec2 last)
|
||||||
{
|
{
|
||||||
if (x <= first[0]) {
|
if (x <= first[0]) {
|
||||||
if (curve_mapping.use_extend_extrapolate == 0) {
|
if (curve_mapping_use_extend_extrapolate == 0) {
|
||||||
/* horizontal extrapolation */
|
/* horizontal extrapolation */
|
||||||
return first[1];
|
return first[1];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
float fac = (curve_mapping.ext_in_x[table] != 0.0) ?
|
float fac = (curve_mapping_ext_in_x[table] != 0.0) ?
|
||||||
((x - first[0]) / curve_mapping.ext_in_x[table]) :
|
((x - first[0]) / curve_mapping_ext_in_x[table]) :
|
||||||
10000.0;
|
10000.0;
|
||||||
return first[1] + curve_mapping.ext_in_y[table] * fac;
|
return first[1] + curve_mapping_ext_in_y[table] * fac;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (x >= last[0]) {
|
else if (x >= last[0]) {
|
||||||
if (curve_mapping.use_extend_extrapolate == 0) {
|
if (curve_mapping_use_extend_extrapolate == 0) {
|
||||||
/* horizontal extrapolation */
|
/* horizontal extrapolation */
|
||||||
return last[1];
|
return last[1];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
float fac = (curve_mapping.ext_out_x[table] != 0.0) ?
|
float fac = (curve_mapping_ext_out_x[table] != 0.0) ?
|
||||||
((x - last[0]) / curve_mapping.ext_out_x[table]) :
|
((x - last[0]) / curve_mapping_ext_out_x[table]) :
|
||||||
-10000.0;
|
-10000.0;
|
||||||
return last[1] + curve_mapping.ext_out_y[table] * fac;
|
return last[1] + curve_mapping_ext_out_y[table] * fac;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
@ -42,10 +71,10 @@ float curvemap_calc_extend(int table, float x, vec2 first, vec2 last)
|
||||||
|
|
||||||
float curvemap_evaluateF(int table, float value)
|
float curvemap_evaluateF(int table, float value)
|
||||||
{
|
{
|
||||||
float mintable_ = curve_mapping.mintable[table];
|
float mintable_ = curve_mapping_mintable[table];
|
||||||
float range = curve_mapping.range[table];
|
float range = curve_mapping_range[table];
|
||||||
float mintable = 0.0;
|
float mintable = 0.0;
|
||||||
int CM_TABLE = curve_mapping.lut_size - 1;
|
int CM_TABLE = curve_mapping_lut_size - 1;
|
||||||
|
|
||||||
float fi;
|
float fi;
|
||||||
int i;
|
int i;
|
||||||
|
@ -58,8 +87,8 @@ float curvemap_evaluateF(int table, float value)
|
||||||
if (fi < 0.0 || fi > float(CM_TABLE)) {
|
if (fi < 0.0 || fi > float(CM_TABLE)) {
|
||||||
return curvemap_calc_extend(table,
|
return curvemap_calc_extend(table,
|
||||||
value,
|
value,
|
||||||
vec2(curve_mapping.first_x[table], curve_mapping.first_y[table]),
|
vec2(curve_mapping_first_x[table], curve_mapping_first_y[table]),
|
||||||
vec2(curve_mapping.last_x[table], curve_mapping.last_y[table]));
|
vec2(curve_mapping_last_x[table], curve_mapping_last_y[table]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
|
@ -77,7 +106,7 @@ float curvemap_evaluateF(int table, float value)
|
||||||
|
|
||||||
vec4 curvemapping_evaluate_premulRGBF(vec4 col)
|
vec4 curvemapping_evaluate_premulRGBF(vec4 col)
|
||||||
{
|
{
|
||||||
col.rgb = (col.rgb - curve_mapping.black.rgb) * curve_mapping.bwmul.rgb;
|
col.rgb = (col.rgb - curve_mapping_black.rgb) * curve_mapping_bwmul.rgb;
|
||||||
|
|
||||||
vec4 result;
|
vec4 result;
|
||||||
result.r = curvemap_evaluateF(0, col.r);
|
result.r = curvemap_evaluateF(0, col.r);
|
||||||
|
@ -86,15 +115,8 @@ vec4 curvemapping_evaluate_premulRGBF(vec4 col)
|
||||||
result.a = col.a;
|
result.a = col.a;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* USE_CURVE_MAPPING */
|
#endif /* USE_CURVE_MAPPING */
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
/** \name Dithering
|
|
||||||
* \{ */
|
|
||||||
|
|
||||||
/* Using a triangle distribution which gives a more final uniform noise.
|
/* Using a triangle distribution which gives a more final uniform noise.
|
||||||
* See Banding in Games:A Noisy Rant(revision 5) Mikkel Gjøl, Playdead (slide 27) */
|
* See Banding in Games:A Noisy Rant(revision 5) Mikkel Gjøl, Playdead (slide 27) */
|
||||||
/* GPUs are rounding before writing to framebuffer so we center the distribution around 0.0. */
|
/* GPUs are rounding before writing to framebuffer so we center the distribution around 0.0. */
|
||||||
|
@ -113,33 +135,23 @@ float dither_random_value(vec2 co)
|
||||||
|
|
||||||
vec2 round_to_pixel(sampler2D tex, vec2 uv)
|
vec2 round_to_pixel(sampler2D tex, vec2 uv)
|
||||||
{
|
{
|
||||||
vec2 size = vec2(textureSize(tex, 0));
|
vec2 size = textureSize(tex, 0);
|
||||||
return floor(uv * size) / size;
|
return vec2(ivec2(uv * size)) / size;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 apply_dither(vec4 col, vec2 uv)
|
vec4 apply_dither(vec4 col, vec2 uv)
|
||||||
{
|
{
|
||||||
col.rgb += dither_random_value(uv) * 0.0033 * parameters.dither;
|
col.rgb += dither_random_value(uv) * 0.0033 * dither;
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \} */
|
vec4 OCIO_ProcessColor(vec4 col, vec4 col_overlay, vec2 noise_uv)
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
/** \name Main Processing
|
|
||||||
* \{ */
|
|
||||||
|
|
||||||
/* Prototypes: Implementation is generaterd and defined after. */
|
|
||||||
vec4 OCIO_to_scene_linear(vec4 pixel);
|
|
||||||
vec4 OCIO_to_display(vec4 pixel);
|
|
||||||
|
|
||||||
vec4 OCIO_ProcessColor(vec4 col, vec4 col_overlay)
|
|
||||||
{
|
{
|
||||||
#ifdef USE_CURVE_MAPPING
|
#ifdef USE_CURVE_MAPPING
|
||||||
col = curvemapping_evaluate_premulRGBF(col);
|
col = curvemapping_evaluate_premulRGBF(col);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (parameters.use_predivide) {
|
if (predivide) {
|
||||||
if (col.a > 0.0 && col.a < 1.0) {
|
if (col.a > 0.0 && col.a < 1.0) {
|
||||||
col.rgb *= 1.0 / col.a;
|
col.rgb *= 1.0 / col.a;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +166,7 @@ vec4 OCIO_ProcessColor(vec4 col, vec4 col_overlay)
|
||||||
col = OCIO_to_scene_linear(col);
|
col = OCIO_to_scene_linear(col);
|
||||||
|
|
||||||
/* Apply exposure in scene linear. */
|
/* Apply exposure in scene linear. */
|
||||||
col.rgb *= parameters.scale;
|
col.rgb *= scale;
|
||||||
|
|
||||||
/* Convert to display space. */
|
/* Convert to display space. */
|
||||||
col = OCIO_to_display(col);
|
col = OCIO_to_display(col);
|
||||||
|
@ -165,31 +177,34 @@ vec4 OCIO_ProcessColor(vec4 col, vec4 col_overlay)
|
||||||
* i.e: The linear color space w.r.t. display chromaticity and radiometry.
|
* i.e: The linear color space w.r.t. display chromaticity and radiometry.
|
||||||
* We separate the colormanagement process into two steps to be able to
|
* We separate the colormanagement process into two steps to be able to
|
||||||
* merge UI using alpha blending in the correct color space. */
|
* merge UI using alpha blending in the correct color space. */
|
||||||
if (parameters.use_overlay) {
|
if (overlay) {
|
||||||
col.rgb = pow(col.rgb, vec3(parameters.exponent * 2.2));
|
col.rgb = pow(col.rgb, vec3(exponent * 2.2));
|
||||||
col = clamp(col, 0.0, 1.0);
|
col = clamp(col, 0.0, 1.0);
|
||||||
col *= 1.0 - col_overlay.a;
|
col *= 1.0 - col_overlay.a;
|
||||||
col += col_overlay; /* Assumed unassociated alpha. */
|
col += col_overlay; /* Assumed unassociated alpha. */
|
||||||
col.rgb = pow(col.rgb, vec3(1.0 / 2.2));
|
col.rgb = pow(col.rgb, vec3(1.0 / 2.2));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
col.rgb = pow(col.rgb, vec3(parameters.exponent));
|
col.rgb = pow(col.rgb, vec3(exponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parameters.dither > 0.0) {
|
if (dither > 0.0) {
|
||||||
vec2 noise_uv = round_to_pixel(image_texture, texCoord_interp.st);
|
|
||||||
col = apply_dither(col, noise_uv);
|
col = apply_dither(col, noise_uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \} */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
in vec2 texCoord_interp;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 col = texture(image_texture, texCoord_interp.st);
|
vec4 col = texture(image_texture, texCoord_interp.st);
|
||||||
vec4 col_overlay = texture(overlay_texture, texCoord_interp.st);
|
vec4 col_overlay = texture(overlay_texture, texCoord_interp.st);
|
||||||
|
vec2 noise_uv = round_to_pixel(image_texture, texCoord_interp.st);
|
||||||
|
|
||||||
fragColor = OCIO_ProcessColor(col, col_overlay);
|
fragColor = OCIO_ProcessColor(col, col_overlay, noise_uv);
|
||||||
}
|
}
|
|
@ -1,4 +1,10 @@
|
||||||
|
|
||||||
|
uniform mat4 ModelViewProjectionMatrix;
|
||||||
|
|
||||||
|
in vec2 texCoord;
|
||||||
|
in vec2 pos;
|
||||||
|
out vec2 texCoord_interp;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f);
|
gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f);
|
|
@ -21,14 +21,14 @@
|
||||||
#include "GPU_shader.h"
|
#include "GPU_shader.h"
|
||||||
#include "GPU_uniform_buffer.h"
|
#include "GPU_uniform_buffer.h"
|
||||||
|
|
||||||
#include "gpu_shader_create_info.hh"
|
|
||||||
|
|
||||||
using namespace OCIO_NAMESPACE;
|
using namespace OCIO_NAMESPACE;
|
||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
#include "ocio_impl.h"
|
#include "ocio_impl.h"
|
||||||
#include "ocio_shader_shared.hh"
|
|
||||||
|
extern "C" char datatoc_gpu_shader_display_transform_glsl[];
|
||||||
|
extern "C" char datatoc_gpu_shader_display_transform_vertex_glsl[];
|
||||||
|
|
||||||
/* **** OpenGL drawing routines using GLSL for color space transform ***** */
|
/* **** OpenGL drawing routines using GLSL for color space transform ***** */
|
||||||
|
|
||||||
|
@ -39,19 +39,41 @@ enum OCIO_GPUTextureSlots {
|
||||||
TEXTURE_SLOT_LUTS_OFFSET = 3,
|
TEXTURE_SLOT_LUTS_OFFSET = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OCIO_GPUUniformBufSlots {
|
/* Curve mapping parameters
|
||||||
UNIFORMBUF_SLOT_DISPLAY = 0,
|
*
|
||||||
UNIFORMBUF_SLOT_CURVEMAP = 1,
|
* See documentation for OCIO_CurveMappingSettings to get fields descriptions.
|
||||||
UNIFORMBUF_SLOT_LUTS = 2,
|
* (this ones pretty much copies stuff from C structure.)
|
||||||
|
*/
|
||||||
|
struct OCIO_GPUCurveMappingParameters {
|
||||||
|
float curve_mapping_mintable[4];
|
||||||
|
float curve_mapping_range[4];
|
||||||
|
float curve_mapping_ext_in_x[4];
|
||||||
|
float curve_mapping_ext_in_y[4];
|
||||||
|
float curve_mapping_ext_out_x[4];
|
||||||
|
float curve_mapping_ext_out_y[4];
|
||||||
|
float curve_mapping_first_x[4];
|
||||||
|
float curve_mapping_first_y[4];
|
||||||
|
float curve_mapping_last_x[4];
|
||||||
|
float curve_mapping_last_y[4];
|
||||||
|
float curve_mapping_black[4];
|
||||||
|
float curve_mapping_bwmul[4];
|
||||||
|
int curve_mapping_lut_size;
|
||||||
|
int curve_mapping_use_extend_extrapolate;
|
||||||
|
int _pad[2];
|
||||||
|
/** WARNING: Needs to be 16byte aligned. Used as UBO data. */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OCIO_GPUShader {
|
struct OCIO_GPUShader {
|
||||||
/* GPU shader. */
|
/* GPU shader. */
|
||||||
struct GPUShader *shader = nullptr;
|
struct GPUShader *shader = nullptr;
|
||||||
|
|
||||||
/** Uniform parameters. */
|
/** Uniform locations. */
|
||||||
OCIO_GPUParameters parameters = {};
|
int scale_loc = 0;
|
||||||
GPUUniformBuf *parameters_buffer = nullptr;
|
int exponent_loc = 0;
|
||||||
|
int dither_loc = 0;
|
||||||
|
int overlay_loc = 0;
|
||||||
|
int predivide_loc = 0;
|
||||||
|
int ubo_bind = 0;
|
||||||
|
|
||||||
/* Destructor. */
|
/* Destructor. */
|
||||||
~OCIO_GPUShader()
|
~OCIO_GPUShader()
|
||||||
|
@ -59,9 +81,6 @@ struct OCIO_GPUShader {
|
||||||
if (shader) {
|
if (shader) {
|
||||||
GPU_shader_free(shader);
|
GPU_shader_free(shader);
|
||||||
}
|
}
|
||||||
if (parameters_buffer) {
|
|
||||||
GPU_uniformbuf_free(parameters_buffer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,7 +103,6 @@ struct OCIO_GPUTextures {
|
||||||
|
|
||||||
/* Uniforms */
|
/* Uniforms */
|
||||||
std::vector<OCIO_GPUUniform> uniforms;
|
std::vector<OCIO_GPUUniform> uniforms;
|
||||||
GPUUniformBuf *uniforms_buffer = nullptr;
|
|
||||||
|
|
||||||
/* Destructor. */
|
/* Destructor. */
|
||||||
~OCIO_GPUTextures()
|
~OCIO_GPUTextures()
|
||||||
|
@ -95,9 +113,6 @@ struct OCIO_GPUTextures {
|
||||||
if (dummy) {
|
if (dummy) {
|
||||||
GPU_texture_free(dummy);
|
GPU_texture_free(dummy);
|
||||||
}
|
}
|
||||||
if (uniforms_buffer) {
|
|
||||||
GPU_uniformbuf_free(uniforms_buffer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -150,134 +165,97 @@ static bool createGPUShader(OCIO_GPUShader &shader,
|
||||||
const GpuShaderDescRcPtr &shaderdesc_to_display,
|
const GpuShaderDescRcPtr &shaderdesc_to_display,
|
||||||
const bool use_curve_mapping)
|
const bool use_curve_mapping)
|
||||||
{
|
{
|
||||||
using namespace blender::gpu::shader;
|
std::ostringstream os;
|
||||||
|
|
||||||
std::string source;
|
|
||||||
source += shaderdesc_to_scene_linear->getShaderText();
|
|
||||||
source += "\n";
|
|
||||||
source += shaderdesc_to_display->getShaderText();
|
|
||||||
source += "\n";
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Replace all uniform declarations by a comment.
|
/* Fragment shader */
|
||||||
* This avoids double declarations from the backend. */
|
|
||||||
size_t index = 0;
|
/* Work around OpenColorIO not supporting latest GLSL yet. */
|
||||||
while (true) {
|
os << "#define texture2D texture\n";
|
||||||
index = source.find("uniform ", index);
|
os << "#define texture3D texture\n";
|
||||||
if (index == -1) {
|
|
||||||
break;
|
if (use_curve_mapping) {
|
||||||
}
|
os << "#define USE_CURVE_MAPPING\n";
|
||||||
source.replace(index, 2, "//");
|
|
||||||
index += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os << shaderdesc_to_scene_linear->getShaderText() << "\n";
|
||||||
|
os << shaderdesc_to_display->getShaderText() << "\n";
|
||||||
|
|
||||||
|
os << datatoc_gpu_shader_display_transform_glsl;
|
||||||
}
|
}
|
||||||
|
|
||||||
StageInterfaceInfo iface("OCIO_Interface", "");
|
shader.shader = GPU_shader_create(datatoc_gpu_shader_display_transform_vertex_glsl,
|
||||||
iface.smooth(Type::VEC2, "texCoord_interp");
|
os.str().c_str(),
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
"OCIOShader");
|
||||||
|
|
||||||
ShaderCreateInfo info("OCIO_Display");
|
if (shader.shader == nullptr) {
|
||||||
/* Work around OpenColorIO not supporting latest GLSL yet. */
|
return false;
|
||||||
info.define("texture2D", "texture");
|
}
|
||||||
info.define("texture3D", "texture");
|
|
||||||
info.typedef_source("ocio_shader_shared.hh");
|
shader.scale_loc = GPU_shader_get_uniform(shader.shader, "scale");
|
||||||
info.sampler(TEXTURE_SLOT_IMAGE, ImageType::FLOAT_2D, "image_texture");
|
shader.exponent_loc = GPU_shader_get_uniform(shader.shader, "exponent");
|
||||||
info.sampler(TEXTURE_SLOT_OVERLAY, ImageType::FLOAT_2D, "overlay_texture");
|
shader.dither_loc = GPU_shader_get_uniform(shader.shader, "dither");
|
||||||
info.uniform_buf(UNIFORMBUF_SLOT_DISPLAY, "OCIO_GPUParameters", "parameters");
|
shader.overlay_loc = GPU_shader_get_uniform(shader.shader, "overlay");
|
||||||
info.push_constant(Type::MAT4, "ModelViewProjectionMatrix");
|
shader.predivide_loc = GPU_shader_get_uniform(shader.shader, "predivide");
|
||||||
info.vertex_in(0, Type::VEC2, "pos");
|
shader.ubo_bind = GPU_shader_get_uniform_block_binding(shader.shader,
|
||||||
info.vertex_in(1, Type::VEC2, "texCoord");
|
"OCIO_GPUCurveMappingParameters");
|
||||||
info.vertex_out(iface);
|
|
||||||
info.fragment_out(0, Type::VEC4, "fragColor");
|
GPU_shader_bind(shader.shader);
|
||||||
info.vertex_source("gpu_shader_display_transform_vert.glsl");
|
|
||||||
info.fragment_source("gpu_shader_display_transform_frag.glsl");
|
/* Set texture bind point uniform once. This is saved by the shader. */
|
||||||
info.fragment_source_generated = source;
|
GPUShader *sh = shader.shader;
|
||||||
|
GPU_shader_uniform_int(sh, GPU_shader_get_uniform(sh, "image_texture"), TEXTURE_SLOT_IMAGE);
|
||||||
|
GPU_shader_uniform_int(sh, GPU_shader_get_uniform(sh, "overlay_texture"), TEXTURE_SLOT_OVERLAY);
|
||||||
|
|
||||||
if (use_curve_mapping) {
|
if (use_curve_mapping) {
|
||||||
info.define("USE_CURVE_MAPPING");
|
GPU_shader_uniform_int(
|
||||||
info.uniform_buf(UNIFORMBUF_SLOT_CURVEMAP, "OCIO_GPUCurveMappingParameters", "curve_mapping");
|
sh, GPU_shader_get_uniform(sh, "curve_mapping_texture"), TEXTURE_SLOT_CURVE_MAPPING);
|
||||||
info.sampler(TEXTURE_SLOT_CURVE_MAPPING, ImageType::FLOAT_1D, "curve_mapping_texture");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set LUT textures. */
|
/* Set LUT textures. */
|
||||||
int slot = TEXTURE_SLOT_LUTS_OFFSET;
|
for (int i = 0; i < textures.luts.size(); i++) {
|
||||||
for (OCIO_GPULutTexture &texture : textures.luts) {
|
GPU_shader_uniform_int(sh,
|
||||||
ImageType type = GPU_texture_dimensions(texture.texture) == 2 ? ImageType::FLOAT_2D :
|
GPU_shader_get_uniform(sh, textures.luts[i].sampler_name.c_str()),
|
||||||
ImageType::FLOAT_3D;
|
TEXTURE_SLOT_LUTS_OFFSET + i);
|
||||||
info.sampler(slot++, type, texture.sampler_name.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set LUT uniforms. */
|
/* Set uniforms. */
|
||||||
if (!textures.uniforms.empty()) {
|
for (OCIO_GPUUniform &uniform : textures.uniforms) {
|
||||||
/* NOTE: For simplicity, we pad everything to size of vec4 avoiding sorting and alignment
|
const GpuShaderDesc::UniformData &data = uniform.data;
|
||||||
* issues. It is unlikely that this becomes a real issue. */
|
const char *name = uniform.name.c_str();
|
||||||
size_t ubo_size = textures.uniforms.size() * sizeof(float) * 4;
|
|
||||||
void *ubo_data_buf = malloc(ubo_size);
|
|
||||||
|
|
||||||
uint32_t *ubo_data = reinterpret_cast<uint32_t *>(ubo_data_buf);
|
if (data.m_getDouble) {
|
||||||
|
GPU_shader_uniform_1f(sh, name, (float)data.m_getDouble());
|
||||||
std::stringstream ss;
|
}
|
||||||
ss << "struct OCIO_GPULutParameters {\n";
|
else if (data.m_getBool) {
|
||||||
|
GPU_shader_uniform_1f(sh, name, (float)(data.m_getBool() ? 1.0f : 0.0f));
|
||||||
int index = 0;
|
}
|
||||||
for (OCIO_GPUUniform &uniform : textures.uniforms) {
|
else if (data.m_getFloat3) {
|
||||||
index += 1;
|
GPU_shader_uniform_3f(sh,
|
||||||
const GpuShaderDesc::UniformData &data = uniform.data;
|
name,
|
||||||
const char *name = uniform.name.c_str();
|
(float)data.m_getFloat3()[0],
|
||||||
char prefix = ' ';
|
(float)data.m_getFloat3()[1],
|
||||||
int vec_len;
|
(float)data.m_getFloat3()[2]);
|
||||||
switch (data.m_type) {
|
}
|
||||||
case UNIFORM_DOUBLE: {
|
else if (data.m_vectorFloat.m_getSize && data.m_vectorFloat.m_getVector) {
|
||||||
vec_len = 1;
|
GPU_shader_uniform_vector(sh,
|
||||||
float value = float(data.m_getDouble());
|
GPU_shader_get_uniform(sh, name),
|
||||||
memcpy(ubo_data, &value, sizeof(float));
|
(int)data.m_vectorFloat.m_getSize(),
|
||||||
break;
|
1,
|
||||||
}
|
(float *)data.m_vectorFloat.m_getVector());
|
||||||
case UNIFORM_BOOL: {
|
}
|
||||||
prefix = 'b';
|
else if (data.m_vectorInt.m_getSize && data.m_vectorInt.m_getVector) {
|
||||||
vec_len = 1;
|
GPU_shader_uniform_vector_int(sh,
|
||||||
int value = int(data.m_getBool());
|
GPU_shader_get_uniform(sh, name),
|
||||||
memcpy(ubo_data, &value, sizeof(int));
|
(int)data.m_vectorInt.m_getSize(),
|
||||||
break;
|
1,
|
||||||
}
|
(int *)data.m_vectorInt.m_getVector());
|
||||||
case UNIFORM_FLOAT3:
|
|
||||||
vec_len = 3;
|
|
||||||
memcpy(ubo_data, data.m_getFloat3().data(), sizeof(float) * 3);
|
|
||||||
break;
|
|
||||||
case UNIFORM_VECTOR_FLOAT:
|
|
||||||
vec_len = data.m_vectorFloat.m_getSize();
|
|
||||||
memcpy(ubo_data, data.m_vectorFloat.m_getVector(), sizeof(float) * vec_len);
|
|
||||||
break;
|
|
||||||
case UNIFORM_VECTOR_INT:
|
|
||||||
prefix = 'i';
|
|
||||||
vec_len = data.m_vectorInt.m_getSize();
|
|
||||||
memcpy(ubo_data, data.m_vectorInt.m_getVector(), sizeof(int) * vec_len);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Align every member to 16bytes. */
|
|
||||||
ubo_data += 4;
|
|
||||||
/* Use a generic variable name because some GLSL compilers can interpret the preprocessor
|
|
||||||
* define as recursive. */
|
|
||||||
ss << " " << prefix << "vec4 var" << index << ";\n";
|
|
||||||
/* Use a define to keep the generated code working. */
|
|
||||||
blender::StringRef suffix = blender::StringRefNull("xyzw").substr(0, vec_len);
|
|
||||||
ss << "#define " << name << " lut_parameters.var" << index << "." << suffix << "\n";
|
|
||||||
}
|
}
|
||||||
ss << "};\n";
|
|
||||||
info.typedef_source_generated = ss.str();
|
|
||||||
|
|
||||||
info.uniform_buf(UNIFORMBUF_SLOT_LUTS, "OCIO_GPULutParameters", "lut_parameters");
|
|
||||||
|
|
||||||
textures.uniforms_buffer = GPU_uniformbuf_create_ex(
|
|
||||||
ubo_size, ubo_data_buf, "OCIO_LutParameters");
|
|
||||||
|
|
||||||
free(ubo_data_buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shader.shader = GPU_shader_create_from_info(reinterpret_cast<GPUShaderCreateInfo *>(&info));
|
return true;
|
||||||
|
|
||||||
return (shader.shader != nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
@ -460,65 +438,27 @@ static void updateGPUCurveMapping(OCIO_GPUCurveMappping &curvemap,
|
||||||
/* Update uniforms. */
|
/* Update uniforms. */
|
||||||
OCIO_GPUCurveMappingParameters data;
|
OCIO_GPUCurveMappingParameters data;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
data.range[i] = curve_mapping_settings->range[i];
|
data.curve_mapping_range[i] = curve_mapping_settings->range[i];
|
||||||
data.mintable[i] = curve_mapping_settings->mintable[i];
|
data.curve_mapping_mintable[i] = curve_mapping_settings->mintable[i];
|
||||||
data.ext_in_x[i] = curve_mapping_settings->ext_in_x[i];
|
data.curve_mapping_ext_in_x[i] = curve_mapping_settings->ext_in_x[i];
|
||||||
data.ext_in_y[i] = curve_mapping_settings->ext_in_y[i];
|
data.curve_mapping_ext_in_y[i] = curve_mapping_settings->ext_in_y[i];
|
||||||
data.ext_out_x[i] = curve_mapping_settings->ext_out_x[i];
|
data.curve_mapping_ext_out_x[i] = curve_mapping_settings->ext_out_x[i];
|
||||||
data.ext_out_y[i] = curve_mapping_settings->ext_out_y[i];
|
data.curve_mapping_ext_out_y[i] = curve_mapping_settings->ext_out_y[i];
|
||||||
data.first_x[i] = curve_mapping_settings->first_x[i];
|
data.curve_mapping_first_x[i] = curve_mapping_settings->first_x[i];
|
||||||
data.first_y[i] = curve_mapping_settings->first_y[i];
|
data.curve_mapping_first_y[i] = curve_mapping_settings->first_y[i];
|
||||||
data.last_x[i] = curve_mapping_settings->last_x[i];
|
data.curve_mapping_last_x[i] = curve_mapping_settings->last_x[i];
|
||||||
data.last_y[i] = curve_mapping_settings->last_y[i];
|
data.curve_mapping_last_y[i] = curve_mapping_settings->last_y[i];
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
data.black[i] = curve_mapping_settings->black[i];
|
data.curve_mapping_black[i] = curve_mapping_settings->black[i];
|
||||||
data.bwmul[i] = curve_mapping_settings->bwmul[i];
|
data.curve_mapping_bwmul[i] = curve_mapping_settings->bwmul[i];
|
||||||
}
|
}
|
||||||
data.lut_size = curve_mapping_settings->lut_size;
|
data.curve_mapping_lut_size = curve_mapping_settings->lut_size;
|
||||||
data.use_extend_extrapolate = curve_mapping_settings->use_extend_extrapolate;
|
data.curve_mapping_use_extend_extrapolate = curve_mapping_settings->use_extend_extrapolate;
|
||||||
|
|
||||||
GPU_uniformbuf_update(curvemap.buffer, &data);
|
GPU_uniformbuf_update(curvemap.buffer, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateGPUDisplayParameters(OCIO_GPUShader &shader,
|
|
||||||
float scale,
|
|
||||||
float exponent,
|
|
||||||
float dither,
|
|
||||||
bool use_predivide,
|
|
||||||
bool use_overlay)
|
|
||||||
{
|
|
||||||
bool do_update = false;
|
|
||||||
if (shader.parameters_buffer == nullptr) {
|
|
||||||
shader.parameters_buffer = GPU_uniformbuf_create(sizeof(OCIO_GPUParameters));
|
|
||||||
do_update = true;
|
|
||||||
}
|
|
||||||
OCIO_GPUParameters &data = shader.parameters;
|
|
||||||
if (data.scale != scale) {
|
|
||||||
data.scale = scale;
|
|
||||||
do_update = true;
|
|
||||||
}
|
|
||||||
if (data.exponent != exponent) {
|
|
||||||
data.exponent = exponent;
|
|
||||||
do_update = true;
|
|
||||||
}
|
|
||||||
if (data.dither != dither) {
|
|
||||||
data.dither = dither;
|
|
||||||
do_update = true;
|
|
||||||
}
|
|
||||||
if (data.use_predivide != use_predivide) {
|
|
||||||
data.use_predivide = use_predivide;
|
|
||||||
do_update = true;
|
|
||||||
}
|
|
||||||
if (data.use_overlay != use_overlay) {
|
|
||||||
data.use_overlay = use_overlay;
|
|
||||||
do_update = true;
|
|
||||||
}
|
|
||||||
if (do_update) {
|
|
||||||
GPU_uniformbuf_update(shader.parameters_buffer, &data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
@ -669,7 +609,7 @@ bool OCIOImpl::gpuDisplayShaderBind(OCIO_ConstConfigRcPtr *config,
|
||||||
/* Update and bind curve mapping data. */
|
/* Update and bind curve mapping data. */
|
||||||
if (curve_mapping_settings) {
|
if (curve_mapping_settings) {
|
||||||
updateGPUCurveMapping(curvemap, curve_mapping_settings);
|
updateGPUCurveMapping(curvemap, curve_mapping_settings);
|
||||||
GPU_uniformbuf_bind(curvemap.buffer, UNIFORMBUF_SLOT_CURVEMAP);
|
GPU_uniformbuf_bind(curvemap.buffer, shader.ubo_bind);
|
||||||
GPU_texture_bind(curvemap.texture, TEXTURE_SLOT_CURVE_MAPPING);
|
GPU_texture_bind(curvemap.texture, TEXTURE_SLOT_CURVE_MAPPING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,16 +623,17 @@ bool OCIOImpl::gpuDisplayShaderBind(OCIO_ConstConfigRcPtr *config,
|
||||||
GPU_texture_bind(textures.luts[i].texture, TEXTURE_SLOT_LUTS_OFFSET + i);
|
GPU_texture_bind(textures.luts[i].texture, TEXTURE_SLOT_LUTS_OFFSET + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textures.uniforms_buffer) {
|
|
||||||
GPU_uniformbuf_bind(textures.uniforms_buffer, UNIFORMBUF_SLOT_LUTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateGPUDisplayParameters(shader, scale, exponent, dither, use_predivide, use_overlay);
|
|
||||||
GPU_uniformbuf_bind(shader.parameters_buffer, UNIFORMBUF_SLOT_DISPLAY);
|
|
||||||
|
|
||||||
/* TODO(fclem): remove remains of IMM. */
|
/* TODO(fclem): remove remains of IMM. */
|
||||||
immBindShader(shader.shader);
|
immBindShader(shader.shader);
|
||||||
|
|
||||||
|
/* Bind Shader and set uniforms. */
|
||||||
|
// GPU_shader_bind(shader.shader);
|
||||||
|
GPU_shader_uniform_float(shader.shader, shader.scale_loc, scale);
|
||||||
|
GPU_shader_uniform_float(shader.shader, shader.exponent_loc, exponent);
|
||||||
|
GPU_shader_uniform_float(shader.shader, shader.dither_loc, dither);
|
||||||
|
GPU_shader_uniform_int(shader.shader, shader.overlay_loc, use_overlay);
|
||||||
|
GPU_shader_uniform_int(shader.shader, shader.predivide_loc, use_predivide);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
* Copyright 2022 Blender Foundation. All rights reserved. */
|
|
||||||
|
|
||||||
#ifndef GPU_SHADER
|
|
||||||
# include "GPU_shader_shared_utils.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct OCIO_GPUCurveMappingParameters {
|
|
||||||
/* Curve mapping parameters
|
|
||||||
*
|
|
||||||
* See documentation for OCIO_CurveMappingSettings to get fields descriptions.
|
|
||||||
* (this ones pretty much copies stuff from C structure.)
|
|
||||||
*/
|
|
||||||
float4 mintable;
|
|
||||||
float4 range;
|
|
||||||
float4 ext_in_x;
|
|
||||||
float4 ext_in_y;
|
|
||||||
float4 ext_out_x;
|
|
||||||
float4 ext_out_y;
|
|
||||||
float4 first_x;
|
|
||||||
float4 first_y;
|
|
||||||
float4 last_x;
|
|
||||||
float4 last_y;
|
|
||||||
float4 black;
|
|
||||||
float4 bwmul;
|
|
||||||
int lut_size;
|
|
||||||
int use_extend_extrapolate;
|
|
||||||
int _pad0;
|
|
||||||
int _pad1;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct OCIO_GPUParameters {
|
|
||||||
float dither;
|
|
||||||
float scale;
|
|
||||||
float exponent;
|
|
||||||
bool1 use_predivide;
|
|
||||||
bool1 use_overlay;
|
|
||||||
int _pad0;
|
|
||||||
int _pad1;
|
|
||||||
int _pad2;
|
|
||||||
};
|
|
|
@ -452,21 +452,12 @@ if(WITH_IMAGE_DDS)
|
||||||
add_definitions(-DWITH_DDS)
|
add_definitions(-DWITH_DDS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WITH_OPENCOLORIO)
|
|
||||||
add_definitions(-DWITH_OCIO)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
blender_add_lib(bf_gpu "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
|
blender_add_lib(bf_gpu "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
|
||||||
target_link_libraries(bf_gpu PUBLIC
|
target_link_libraries(bf_gpu PUBLIC
|
||||||
bf_draw_shaders
|
bf_draw_shaders
|
||||||
bf_gpu_shaders
|
bf_gpu_shaders
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WITH_OPENCOLORIO)
|
|
||||||
target_link_libraries(bf_gpu PUBLIC bf_ocio_shaders)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
if(CXX_WARN_NO_SUGGEST_OVERRIDE)
|
if(CXX_WARN_NO_SUGGEST_OVERRIDE)
|
||||||
target_compile_options(bf_gpu PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override>)
|
target_compile_options(bf_gpu PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override>)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -21,9 +21,6 @@ extern "C" {
|
||||||
#define SHADER_SOURCE(datatoc, filename, filepath) extern char datatoc[];
|
#define SHADER_SOURCE(datatoc, filename, filepath) extern char datatoc[];
|
||||||
#include "glsl_draw_source_list.h"
|
#include "glsl_draw_source_list.h"
|
||||||
#include "glsl_gpu_source_list.h"
|
#include "glsl_gpu_source_list.h"
|
||||||
#ifdef WITH_OCIO
|
|
||||||
# include "glsl_ocio_source_list.h"
|
|
||||||
#endif
|
|
||||||
#undef SHADER_SOURCE
|
#undef SHADER_SOURCE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,9 +348,6 @@ void gpu_shader_dependency_init()
|
||||||
g_sources->add_new(filename, new GPUSource(filepath, filename, datatoc));
|
g_sources->add_new(filename, new GPUSource(filepath, filename, datatoc));
|
||||||
#include "glsl_draw_source_list.h"
|
#include "glsl_draw_source_list.h"
|
||||||
#include "glsl_gpu_source_list.h"
|
#include "glsl_gpu_source_list.h"
|
||||||
#ifdef WITH_OCIO
|
|
||||||
# include "glsl_ocio_source_list.h"
|
|
||||||
#endif
|
|
||||||
#undef SHADER_SOURCE
|
#undef SHADER_SOURCE
|
||||||
|
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
|
Loading…
Reference in New Issue