GPUShader: Implement workaround for gizmo drawing on sRGB framebuffer

This solution involves adding a uniform to each fragment shader that is
used by gizmo drawing and use the framebuffer state to set this uniform
accordingly.

This solution can also be carried to external shaders (addons).
A single line of code would then be enough to fix the issue.

The only trickery here is the dummy define:
`#define srgb_to_framebuffer_space(a)`
This is in order to avoid breaking other DRW shaders that use the same
fragment shader code but do not need the tranformation.

Related to T74139

Reviewed By: brecht, campbellbarton

Differential Revision: https://developer.blender.org/D7261
This commit is contained in:
2020-04-14 20:44:45 +02:00
parent bf49bb354f
commit 21c658b718
20 changed files with 104 additions and 12 deletions

View File

@@ -120,8 +120,8 @@ static PyObject *bpygpu_shader_new(PyTypeObject *UNUSED(type), PyObject *args, P
return NULL;
}
GPUShader *shader = GPU_shader_create(
params.vertexcode, params.fragcode, params.geocode, params.libcode, params.defines, NULL);
GPUShader *shader = GPU_shader_create_from_python(
params.vertexcode, params.fragcode, params.geocode, params.libcode, params.defines);
if (shader == NULL) {
PyErr_SetString(PyExc_Exception, "Shader Compile Error, see console for more details");
@@ -609,6 +609,10 @@ PyDoc_STRVAR(
" To debug shaders, use the --debug-gpu-shaders command line option"
" to see full GLSL shader compilation and linking errors.\n"
"\n"
" For drawing user interface elements and gizmos, use "
" ``fragOutput = blender_srgb_to_framebuffer_space(fragOutput)``"
" to transform the output sRGB colors to the framebuffer colorspace."
"\n"
" :param vertexcode: Vertex shader code.\n"
" :type vertexcode: str\n"
" :param fragcode: Fragment shader code.\n"