7#if defined(WITH_OPENCOLORIO)
22using namespace OCIO_NAMESPACE;
24static ConstProcessorRcPtr create_to_scene_linear_processor(
27 return create_ocio_processor(
28 ocio_config, display_shader.from_colorspace.c_str(), ROLE_SCENE_LINEAR);
31static ConstProcessorRcPtr create_to_display_processor(
36 display_parameters.view = display_shader.view;
37 display_parameters.display = display_shader.display;
38 display_parameters.look = display_shader.look;
39 display_parameters.use_hdr_buffer = display_shader.use_hdr_buffer;
40 display_parameters.use_display_emulation = display_shader.use_display_emulation;
41 return create_ocio_display_processor(config, display_parameters);
45 const GpuShaderDescRcPtr &shader_desc,
49 uniform.
name = shader_desc->getUniform(index, uniform.data);
50 if (uniform.data.m_type == UNIFORM_UNKNOWN) {
54 textures.uniforms.append(uniform);
59 const GpuShaderDescRcPtr &shader_desc,
62 const char *texture_name =
nullptr;
63 const char *sampler_name =
nullptr;
67 GpuShaderCreator::TextureType channel = GpuShaderCreator::TEXTURE_RGB_CHANNEL;
71 static_assert(OCIO_VERSION_HEX >= 0x02030000);
72 GpuShaderDesc::TextureDimensions dimensions = GpuShaderDesc::TEXTURE_2D;
73 shader_desc->getTexture(
74 index, texture_name, sampler_name, width, height, channel, dimensions, interpolation);
77 shader_desc->getTextureValues(index, values);
78 if (texture_name ==
nullptr || sampler_name ==
nullptr || width == 0 || height == 0 ||
85 blender::gpu::TextureFormat::SFLOAT_16_16_16 :
93 std::string sampler1D_name = std::string(
"sampler1D ") + sampler_name;
94 if (strstr(shader_desc->getShaderText(), sampler1D_name.c_str()) !=
nullptr) {
102 if (lut.texture ==
nullptr) {
109 lut.sampler_name = sampler_name;
111 textures.luts.append(lut);
117 const GpuShaderDescRcPtr &shader_desc,
120 const char *texture_name =
nullptr;
121 const char *sampler_name =
nullptr;
124 shader_desc->get3DTexture(index, texture_name, sampler_name, edgelen, interpolation);
127 shader_desc->get3DTextureValues(index, values);
128 if (texture_name ==
nullptr || sampler_name ==
nullptr || edgelen == 0 || values ==
nullptr) {
138 blender::gpu::TextureFormat::SFLOAT_16_16_16,
141 if (lut.texture ==
nullptr) {
148 lut.sampler_name = sampler_name;
150 textures.luts.append(lut);
155 const GpuShaderDescRcPtr &shader_desc)
157 for (
int index = 0; index < shader_desc->getNumUniforms(); index++) {
158 if (!add_gpu_uniform(textures, shader_desc, index)) {
162 for (
int index = 0; index < shader_desc->getNumTextures(); index++) {
163 if (!add_gpu_lut_1D2D(textures, shader_desc, index)) {
167 for (
int index = 0; index < shader_desc->getNum3DTextures(); index++) {
168 if (!add_gpu_lut_3D(textures, shader_desc, index)) {
178void LibOCIOGPUShaderBinder::construct_shader_for_processors(
180 const ConstProcessorRcPtr &processor_to_scene_linear,
181 const ConstProcessorRcPtr &processor_to_display,
182 const Span<std::array<StringRefNull, 2>> additional_defines)
const
184 std::string fragment_source;
186 GpuShaderDescRcPtr shaderdesc_to_scene_linear;
187 if (processor_to_scene_linear) {
188 shaderdesc_to_scene_linear = GpuShaderDesc::CreateShaderDesc();
189 shaderdesc_to_scene_linear->setLanguage(GPU_LANGUAGE_GLSL_1_3);
190 shaderdesc_to_scene_linear->setFunctionName(
"OCIO_to_scene_linear");
191 shaderdesc_to_scene_linear->setResourcePrefix(
"to_scene");
192 processor_to_scene_linear->getDefaultGPUProcessor()->extractGpuShaderInfo(
193 shaderdesc_to_scene_linear);
194 shaderdesc_to_scene_linear->finalize();
196 if (!create_gpu_textures(display_shader.textures, shaderdesc_to_scene_linear)) {
197 display_shader.is_valid =
false;
201 fragment_source += shaderdesc_to_scene_linear->getShaderText();
202 fragment_source +=
"\n";
205 GpuShaderDescRcPtr shaderdesc_to_display;
206 if (processor_to_display) {
207 shaderdesc_to_display = GpuShaderDesc::CreateShaderDesc();
208 shaderdesc_to_display->setLanguage(GPU_LANGUAGE_GLSL_1_3);
209 shaderdesc_to_display->setFunctionName(
"OCIO_to_display");
210 shaderdesc_to_display->setResourcePrefix(
"to_display");
211 processor_to_display->getDefaultGPUProcessor()->extractGpuShaderInfo(shaderdesc_to_display);
212 shaderdesc_to_display->finalize();
214 if (!create_gpu_textures(display_shader.textures, shaderdesc_to_display)) {
215 display_shader.is_valid =
false;
219 fragment_source += shaderdesc_to_display->getShaderText();
220 fragment_source +=
"\n";
223 if (!create_gpu_shader(display_shader, fragment_source, additional_defines)) {
224 display_shader.is_valid =
false;
228 display_shader.is_valid =
true;
231void LibOCIOGPUShaderBinder::construct_display_shader(
234 const LibOCIOConfig &config =
static_cast<const LibOCIOConfig &
>(config_);
235 const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config = config.get_ocio_config();
237 ConstProcessorRcPtr processor_to_scene_linear = create_to_scene_linear_processor(ocio_config,
239 ConstProcessorRcPtr processor_to_display = create_to_display_processor(config, display_shader);
241 if (!processor_to_scene_linear || !processor_to_display) {
242 display_shader.is_valid =
false;
246 construct_shader_for_processors(
247 display_shader, processor_to_scene_linear, processor_to_display, {});
250void LibOCIOGPUShaderBinder::construct_scene_linear_shader(
253 const LibOCIOConfig &config =
static_cast<const LibOCIOConfig &
>(config_);
254 const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config = config.get_ocio_config();
256 ConstProcessorRcPtr processor_to_scene_linear = create_to_scene_linear_processor(ocio_config,
258 if (!processor_to_scene_linear) {
259 display_shader.is_valid =
false;
263 construct_shader_for_processors(
265 processor_to_scene_linear,
267 {{
"USE_TO_SCENE_LINEAR_ONLY",
""}, {
"OUTPUT_PREMULTIPLIED",
""}});
void GPU_texture_extend_mode(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
blender::gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
blender::gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
StringRefNull from_colorspace
blender::gpu::Texture * texture