Skip to content

Commit

Permalink
fix: hide bloom effect checkbox on Blender 4.3 or later
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Dec 5, 2024
1 parent b387fc6 commit d804a4f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 15 deletions.
5 changes: 5 additions & 0 deletions doc/modules/ROOT/pages/panels/leds/led_control.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ Ties are broken according to the order of the drones in the `Drones` collection.

== Enabling or disabling the bloom effect

NOTE: Blender 4.3 removed support for the bloom effect built into the EEVEE
renderer, therefore this option is not available on Blender 4.3 and later.
Use the https://docs.blender.org/manual/en/latest/compositing/index.html[Compositor]
in Blender 4.3 or later to achieve a similar effect.

The btn:[Use bloom effect] checkbox allows you to enable or disable the bloom
effect that is applied to the 3D view. The bloom effect adds a not-so-subtle
glow around the drones (and all other bright meshes), but it comes with a caveat:
Expand Down
10 changes: 6 additions & 4 deletions src/modules/sbstudio/plugin/panels/led_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sbstudio.plugin.operators import (
ApplyColorsToSelectedDronesOperator as ApplyColors,
)
from sbstudio.plugin.utils.bloom import bloom_effect_supported


class LEDControlPanel(Panel):
Expand Down Expand Up @@ -57,8 +58,9 @@ def draw(self, context):
params.color = "SECONDARY"
params.fade = True

layout.separator()
if bloom_effect_supported():
layout.separator()

row = layout.row()
row.prop(scene.skybrush.settings, "use_bloom_effect")
row.prop(scene.skybrush.settings, "emission_strength")
row = layout.row()
row.prop(scene.skybrush.settings, "use_bloom_effect")
row.prop(scene.skybrush.settings, "emission_strength")
60 changes: 49 additions & 11 deletions src/modules/sbstudio/plugin/utils/bloom.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Functions to enable or disable a bloom effect on the 3D view."""

from functools import lru_cache
import bpy

from sbstudio.plugin.constants import Collections, Templates
Expand All @@ -10,13 +11,24 @@
from sbstudio.plugin.views import find_all_3d_views

__all__ = (
"bloom_effect_supported",
"disable_bloom_effect",
"enable_bloom_effect",
"enable_bloom_effect_if_needed",
"set_bloom_effect_enabled",
"update_emission_strength",
)


def bloom_effect_supported() -> bool:
"""Returns whether the bloom effect is supported in the current version of
Blender.
"""
# Bloom effect from Blender 4.3 requires setting up a compositor node tree
# and we have not implemented that yet
return not _bloom_requires_compositor()


def enable_bloom_effect() -> None:
"""Enables the bloom effect on the 3D view."""
set_bloom_effect_enabled(True)
Expand All @@ -40,20 +52,19 @@ def disable_bloom_effect() -> None:

def set_bloom_effect_enabled(value: bool) -> None:
"""Enables or disables the bloom effect on the 3D view."""
if not hasattr(bpy.context.scene.eevee, "use_bloom"):
# Blender 4.3 and later
# TODO(ntamas): set up the bloom effect with compositor somehow
return

if value:
bpy.context.scene.eevee.use_bloom = True
bpy.context.scene.eevee.bloom_radius = 4
bpy.context.scene.eevee.bloom_intensity = 0.2
for space in find_all_3d_views():
space.shading.type = "MATERIAL"
if _bloom_requires_compositor():
# TODO(ntamas)
pass
else:
_enable_bloom_with_eevee_renderer()

else:
bpy.context.scene.eevee.use_bloom = False
if _bloom_requires_compositor():
# TODO(ntamas)
pass
else:
_disable_bloom_with_eevee_renderer()


def update_emission_strength(value: float) -> None:
Expand All @@ -69,3 +80,30 @@ def update_emission_strength(value: float) -> None:
if template:
material = get_material_for_led_light_color(template)
set_emission_strength_of_material(material, value)


@lru_cache(maxsize=1)
def _bloom_requires_compositor() -> bool:
"""Returns whether the bloom effect requires the usage of compositor nodes
in the current version of Blender.
"""
scene = bpy.context.scene
return not hasattr(scene, "eevee") or not hasattr(scene.eevee, "use_bloom")


def _enable_bloom_with_eevee_renderer() -> None:
"""Enables the bloom effect for older versions of Blender where the EEVEE
renderer has explicit properties for the bloom effect.
"""
bpy.context.scene.eevee.use_bloom = True
bpy.context.scene.eevee.bloom_radius = 4
bpy.context.scene.eevee.bloom_intensity = 0.2
for space in find_all_3d_views():
space.shading.type = "MATERIAL"


def _disable_bloom_with_eevee_renderer() -> None:
"""Disables the bloom effect for older versions of Blender where the EEVEE
renderer provides this effect.
"""
bpy.context.scene.eevee.use_bloom = False
10 changes: 10 additions & 0 deletions typings/bpy/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,17 @@ class Scene:
frame_subframe: float

collection: Collection
eevee: SceneEEVEE
render: RenderSettings
skybrush: DroneShowAddonProperties

def frame_set(self, frame: int, subframe: float = 0.0) -> None: ...

class SceneEEVEE(bpy_struct):
bloom_radius: float # only for Blender <4.3
bloom_intensity: float # only for Blender <4.3
use_bloom: bool # only for Blender <4.3

class Context(bpy_struct):
area: Area
scene: Scene
Expand Down Expand Up @@ -220,6 +226,10 @@ class Region(bpy_struct):

class SpaceView3D(Space):
overlay: View3DOverlay
shading: View3DShading

class View3DOverlay(bpy_struct):
show_overlays: bool

class View3DShading(bpy_struct):
type: Literal["WIREFRAME", "SOLID", "MATERIAL", "RENDERED"]

0 comments on commit d804a4f

Please sign in to comment.