Python BGL Colors are broken since 2.83 : Brighter and Low Constrast #79788
Labels
No Label
Meta
Good First Issue
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Eevee & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds, Tests & Devices
Module
Python API
Module
Rendering & Cycles
Module
Sculpt, Paint & Texture
Module
User Interface
Module
VFX & Video
Priority
High
Priority
Low
Priority
Normal
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Information from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
11 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-manual#79788
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Linux-4.15.0-112-generic-x86_64-with-debian-buster-sid 64 Bits
Graphics card: GeForce RTX 2080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 440.64
Blender Version
Broken: version: 2.91.0 Alpha, branch: master, commit date: 2020-08-13 18:18, hash:
blender/blender@275f1039d2
Broken: version: 2.83.4, branch: master, commit date: 2020-08-05 06:00, hash:
blender/blender@c113af8288
Worked: version: 2.82 (sub 7), branch: master, commit date: 2020-02-12 16:20, hash:
blender/blender@77d23b0bd7
bgl_2.83_bug_example_.blend
Short description of error
Colors are not "True" colors in BGL renders (viewport or any other screen in UI)
They are much brighter and less contrasted.
See attached PNG images for comparaison.
See attached GIF file for an animated comparaison between 2.82 and 2.83
The problem remains in 2.91 as well
I tried to change the color management settings if the bpy.data.image object on loading images, but it does not fix the problem.
Anyway the colors are different as well for text (BLF) and plain color polygons.
Exact steps for others to reproduce the error
Basically, error is reproduced by doing any kind of display in UI using python and BGL : lines, surfaces, or even 2D images
Colors are not the "right" ones.
The .blend file is ready to be launched "Run Script" to reproduce the bug, and contains both image and python script.
bgl_2.83_bug_example_.blend
If external python file is prefered, python file is attached as well for reproducing. Same than the .blend except the path to image is external.
The car image for example is attached as well
color_issue_2.83_bgl_example.py
The code to reproduce issue is inspired from official examples available here :
https://docs.blender.org/api/blender2.8/gpu.html
https://docs.blender.org/api/blender2.8/blf.html
Added subscriber: @Tricotou
Added subscribers: @brecht, @rjg
@brecht I vaguely remember (might be misremembering) that the color management approach for OpenGL / viewport drawing was changed between versions in the overlay refactor. Could this be an issue of outdated documentation, e.g. a missing command that is now required to use the correct color management on an image buffer, or is this a bug?
Found the relevant changes:
Added subscriber: @EAW
Relevant part in the release notes:
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Python_API
It is also at the bottom of:
https://www.blender.org/download/releases/2-83/
@EAW thanks for your advice, indeed I did not see this note in the 2.83 release.
A few things :
I was not using absolute "custom" shaders, but the default ones from gpu.shader.from_builtin( ).
I had a look in the GLSL code of all the default builtin shaders, using gpu.shader.code_from_builtin( ) with '2D_UNIFORM_COLOR', '2D_FLAT_COLOR', '2D_SMOOTH_COLOR', '2D_IMAGE', '3D_UNIFORM_COLOR', '3D_FLAT_COLOR', '3D_SMOOTH_COLOR' ... In fact the blender_srgb_to_framebuffer_space function is already used in all of them, EXCEPT the 2D_IMAGE that I was actually using for the image in my example, which is not normal, I suppose.
So, one bug is the lack of blender_srgb_to_framebuffer_space function in the default 2D_IMAGE builtin fragment shader :
Current state :
Fix proposal :
The above solution works fine for image rending in BGL.
That said :
Added subscriber: @fclem
CC @fclem.
Changed status from 'Needs Triage' to: 'Confirmed'
Added subscriber: @Jeroen-Bakker
I will report this as a Bug due to API limitations and confusion
Added subscriber: @VilemDuha
Not sure this is related, but alpha in bgl is broken in 2.91 -
Added subscriber: @lichtwerk
Without exactly knowing your code, but this could be the fact that you need to call
glClearColor
prior toglClear
in 2.9?see blender/blender#79491 (GL_BLEND ignores texture alpha channel)
These functions tend to clear too much (actually the whole viewport) and I'm using code from these basic samples:
https://docs.blender.org/api/current/gpu.html
for both image and rectangle. Pasting here the image draw example:
Dont you have to enable GL_BLEND?
(in the middle of something else, can check later, too...)
Checked on the alpha issue, enabling GL_BLEND works, but only to a degree (looks wrong), reported separately to not hijack this task, see blender/blender#81289 (Python gpu bgl image drawing alpha problem)
Added subscriber: @ideasman42
Can this be resolved by updating docs?
Added subscriber: @JacobMerrill-1
will gpu module be getting all it's own approximations of these functions for vulkan etc?
I seem to remember bgl was being depreciated ?
Added subscriber: @letg
(The image is the exported png) (1)
When I loaded an image as texture with shader.uniform_sampler or with glTexImage2D or glBindTexture, it is always not represented correctly, mostly a bit too bright. (3) (my draw function is draw_handler_add(drawf, (), 'WINDOW', 'POST_VIEW'))
I tried already to use GL_SRGB8_ALPHA8 (with glTexImage2D) and blender_srgb_to_framebuffer_space. These both made it too dark and a bit saturated. (2) (Both look very similar)
I even tried a Gamma Correction in the GLSL Shader.
I tried to tweak some of the blender_srgb_to_framebuffer_space glsl code when I used my own version of this source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl implementation.
Perhaps the location where the image editor loads its image could be helpful too. Then I can see how this part displays the color correctly even for different display devices.
Thank you in Advance.