From 1b16196106fd74577261e27e159dff3b873731a0 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Tue, 10 Dec 2024 14:35:51 -0600 Subject: [PATCH] Add color scaling --- yt_idv/scene_components/base_component.py | 7 +++++++ yt_idv/scene_components/blocks.py | 9 +++++++++ yt_idv/shaders/known_uniforms.inc.glsl | 3 +++ yt_idv/shaders/passthrough.frag.glsl | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/yt_idv/scene_components/base_component.py b/yt_idv/scene_components/base_component.py index 1c60f03..dac3d2f 100644 --- a/yt_idv/scene_components/base_component.py +++ b/yt_idv/scene_components/base_component.py @@ -78,6 +78,9 @@ class SceneComponent(traitlets.HasTraits): cmap_log = traitlets.Bool(True) scale = traitlets.CFloat(1.0) + # These attributes are for when we aren't applying the colormap + color_scale = traitlets.CFloat(1.0) + # This attribute determines whether or not this component is "active" active = traitlets.Bool(True) @@ -354,6 +357,7 @@ def run_program(self, scene): with self.fb.bind(True): with self.program1.enable() as p: scene.camera._set_uniforms(scene, p) + # This is for passthrough shaders. self._set_uniforms(scene, p) if self.render_method == "isocontours": self._set_iso_uniforms(p) @@ -367,6 +371,9 @@ def run_program(self, scene): with self.fb.input_bind(1, 2): with self.program2.enable() as p2: with scene.bind_buffer(): + # For passthroughs, we set this + p2._set_uniform("color_factor", self.color_scale) + # Now for colormaps... p2._set_uniform("cmap", 0) p2._set_uniform("fb_tex", 1) p2._set_uniform("db_tex", 2) diff --git a/yt_idv/scene_components/blocks.py b/yt_idv/scene_components/blocks.py index 1b5d2fe..f179ccf 100644 --- a/yt_idv/scene_components/blocks.py +++ b/yt_idv/scene_components/blocks.py @@ -83,6 +83,15 @@ def render_gui(self, imgui, renderer, scene): imgui.image_button( self.transfer_function.texture_name, 256, 32, frame_padding=0 ) + _, value = imgui.input_float( + "Scale Output", + self.color_scale, + format="%0.2f", + flags=imgui.INPUT_TEXT_ENTER_RETURNS_TRUE, + ) + if _: + self.color_scale = value + changed = True imgui.text("Right click and drag to change") update = False data = self.transfer_function.data.astype("f4") / 255 diff --git a/yt_idv/shaders/known_uniforms.inc.glsl b/yt_idv/shaders/known_uniforms.inc.glsl index 3a9bf89..8112f74 100644 --- a/yt_idv/shaders/known_uniforms.inc.glsl +++ b/yt_idv/shaders/known_uniforms.inc.glsl @@ -65,3 +65,6 @@ uniform float iso_alphas[32]; // draw outline control uniform float draw_boundary; uniform vec4 boundary_color; + +// factor for the color passthrough +uniform float color_factor; \ No newline at end of file diff --git a/yt_idv/shaders/passthrough.frag.glsl b/yt_idv/shaders/passthrough.frag.glsl index 63b0d77..9f570fc 100644 --- a/yt_idv/shaders/passthrough.frag.glsl +++ b/yt_idv/shaders/passthrough.frag.glsl @@ -3,7 +3,7 @@ in vec2 UV; out vec4 color; void main(){ - color = texture(fb_tex, UV); + color = texture(fb_tex, UV) * color_factor; color.a = 1.0; gl_FragDepth = texture(db_tex, UV).r; }