Skip to content

Commit

Permalink
Add color scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturk committed Dec 10, 2024
1 parent 139d0af commit 1b16196
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions yt_idv/scene_components/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions yt_idv/scene_components/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions yt_idv/shaders/known_uniforms.inc.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion yt_idv/shaders/passthrough.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 1b16196

Please sign in to comment.