Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple views in a single window #137

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions yt_idv/rendering_contexts/pyglet_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def center_window(self):
self.set_position(0.5, 0.5)

def on_mouse_press(self, x, y, button, modifiers):
self._currently_clicked = True
self._do_update = True

def on_mouse_release(self, x, y, button, modifiers):
self._currently_clicked = False
self._do_update = True

def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
Expand Down
50 changes: 48 additions & 2 deletions yt_idv/scene_components/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ class SceneComponent(traitlets.HasTraits):

display_name = traitlets.Unicode(allow_none=True)

# These attributes are
final_pass_vertex = ShaderTrait(allow_none=True).tag(shader_type="vertex")
final_pass_fragment = ShaderTrait(allow_none=True).tag(shader_type="fragment")
_final_pass = traitlets.Instance(ShaderProgram, allow_none=True)
_final_pass_invalid = True

# These attributes are just for colormap application
cmap_min = traitlets.CFloat(None, allow_none=True)
cmap_max = traitlets.CFloat(None, allow_none=True)
cmap_log = traitlets.Bool(True)
scale = traitlets.CFloat(1.0)

# This attribute determines whether or not this component is "active"
active = traitlets.Bool(True)

@traitlets.observe("display_bounds")
def _change_display_bounds(self, change):
# We need to update the framebuffer if the width or height has changed
Expand Down Expand Up @@ -217,6 +225,14 @@ def _colormap_vertex_default(self):
def _colormap_fragment_default(self):
return component_shaders[self.name][self.render_method]["second_fragment"]

@traitlets.default("final_pass_vertex")
def _final_pass_vertex_default(self):
return "passthrough"

@traitlets.default("final_pass_fragment")
def _final_pass_fragment_default(self):
return "display_border"

@traitlets.default("base_quad")
def _default_base_quad(self):
bq = SceneData(
Expand Down Expand Up @@ -253,6 +269,16 @@ def program2(self):
self._program2_invalid = False
return self._program2

@property
def final_pass(self):
if self._final_pass_invalid:
if self._final_pass is not None:
self._final_pass.delete_program()
self._final_pass = ShaderProgram(
self.final_pass_vertex, self.final_pass_fragment
)
return self._final_pass

def _set_iso_uniforms(self, p):
# these could be handled better by watching traits.
p._set_uniform("iso_num_layers", int(len(self.iso_layers)))
Expand All @@ -268,6 +294,10 @@ def _set_iso_uniforms(self, p):
def run_program(self, scene):
# Store this info, because we need to render into a framebuffer that is the
# right size.
if self.display_bounds != (0.0, 1.0, 0.0, 1.0):
draw_boundary = 0.002
else:
draw_boundary = 0.0
x0, y0, w, h = GL.glGetIntegerv(GL.GL_VIEWPORT)
GL.glViewport(0, 0, w, h)
if not self.visible:
Expand Down Expand Up @@ -303,6 +333,18 @@ def run_program(self, scene):
GL.glViewport(x0, y0, w, h)
GL.glDrawArrays(GL.GL_TRIANGLES, 0, 6)

if draw_boundary > 0.0:
with self.final_pass.enable() as p3:
p3._set_uniform("draw_boundary", float(draw_boundary))
if self.active:
boundary_color = np.array([0.0, 0.0, 1.0, 1.0], dtype="float32")
else:
boundary_color = np.array([0.5, 0.5, 0.5, 1.0], dtype="float32")
p3._set_uniform("boundary_color", boundary_color)
with self.base_quad.vertex_array.bind(p3):
GL.glViewport(x0, y0, w, h)
GL.glDrawArrays(GL.GL_TRIANGLES, 0, 6)

def draw(self, scene, program):
raise NotImplementedError

Expand Down Expand Up @@ -373,12 +415,16 @@ def _recompile_shader(self) -> bool:
"fragment_shader",
"colormap_vertex",
"colormap_fragment",
"final_pass_vertex",
"final_pass_fragment",
)
for shader_name in shaders:
s = getattr(self, shader_name, None)
if s:
s.delete_shader()
self._program1_invalid = self._program2_invalid = True
self._program1_invalid = self._program2_invalid = self._final_pass_invalid = (
True
)
return True

def _render_isolayer_inputs(self, imgui) -> bool:
Expand Down
13 changes: 13 additions & 0 deletions yt_idv/shaders/display_border.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
in vec2 UV;

out vec4 color;

void main(){
color = texture(fb_tex, UV);
color.a = 1.0;
vec2 d = abs(UV - vec2(0.5));
if(0.5 - max(d.x, d.y) < draw_boundary) {
color = vec4(boundary_color);
}
gl_FragDepth = texture(db_tex, UV).r;
}
4 changes: 4 additions & 0 deletions yt_idv/shaders/known_uniforms.inc.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ uniform int iso_num_layers;
uniform float iso_layers[32];
uniform float iso_layer_tol[32];
uniform float iso_alphas[32];

// draw outline control
uniform float draw_boundary;
uniform vec4 boundary_color;
151 changes: 83 additions & 68 deletions yt_idv/shaders/shaderlist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,138 +4,153 @@ shader_definitions:
info: A constant value applied
source: constant.frag.glsl
blend_func:
- one
- one
- one
- one
blend_equation: func add
constant_rgba:
info: A constant, specified RGBa value applied
source: constant_rgba.frag.glsl
blend_func:
- one
- one
blend_equation: func add
info: A constant, specified RGBa value applied
source: constant_rgba.frag.glsl
blend_func:
- one
- one
blend_equation: func add
apply_colormap:
info: A second pass fragment shader used to apply a colormap to the result of
info:
A second pass fragment shader used to apply a colormap to the result of
the first pass rendering
source: apply_colormap.frag.glsl
blend_func:
- src alpha
- dst alpha
- src alpha
- dst alpha
blend_equation: func add
expand_1d:
info: This expands a 1D texture along the y dimension
source: expand_1d.frag.glsl
blend_func:
- one
- zero
- one
- zero
blend_equation: func add
draw_blocks:
info: A first pass fragment shader that performs ray casting using transfer function.
info:
A first pass fragment shader that performs ray casting using transfer function.
See :ref:`volume-rendering-method` for more details.
source: block_outline.frag.glsl
blend_func:
- src alpha
- one minus src alpha
- src alpha
- one minus src alpha
blend_equation: func add
isocontour:
info: A first pass fragment shader that renders isocontour layers.
source: isocontour.frag.glsl
blend_func:
- src alpha
- one minus src alpha
- src alpha
- one minus src alpha
blend_equation: func add
max_intensity:
info: A first pass fragment shader that computes Maximum Intensity Projection
info:
A first pass fragment shader that computes Maximum Intensity Projection
of the data. See :ref:`projection-types` for more information.
source:
- ray_tracing.frag.glsl
- max_intensity.frag.glsl
- ray_tracing.frag.glsl
- max_intensity.frag.glsl
blend_func:
- one
- one
- one
- one
blend_equation: max
mesh:
info: A vertex shader used for unstructured mesh rendering.
source: mesh.frag.glsl
depth_test: less
blend_func:
- one
- zero
- one
- zero
blend_equation: func add
noop:
info: A second pass fragment shader that performs no operation. Usually used
info:
A second pass fragment shader that performs no operation. Usually used
if the first pass already took care of applying proper color to the data
source: noop.frag.glsl
passthrough:
info: A first pass fragment shader that performs no operation. Used for debug
info:
A first pass fragment shader that performs no operation. Used for debug
puproses. It's distinct from NoOpFragmentShader, because of the number of uniforms
source: passthrough.frag.glsl
blend_func:
- src alpha
- dst alpha
- src alpha
- dst alpha
blend_equation: func add
display_border:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new shader -- the rest are whitespace changes.

info: Draws a border around the display area
source: display_border.frag.glsl
blend_func:
- src alpha
- dst alpha
blend_equation: func add
draw_lines:
info: A line drawing fragment shader
source: draw_lines.frag.glsl
blend_func:
- one
- zero
- one
- zero
blend_equation: func add
projection:
info: A first pass fragment shader that performs unweighted integration of the
info:
A first pass fragment shader that performs unweighted integration of the
data along the line of sight. See :ref:`projection-types` for more information.
source:
- ray_tracing.frag.glsl
- projection.frag.glsl
- ray_tracing.frag.glsl
- projection.frag.glsl
blend_func:
- one
- one
- one
- one
blend_equation: func add
text_overlay:
info: A simple text overlay shader
source: textoverlay.frag.glsl
blend_func:
- src alpha
- one minus src alpha
- src alpha
- one minus src alpha
blend_equation: func add
transfer_function:
info: A first pass fragment shader that performs ray casting using transfer function.
info:
A first pass fragment shader that performs ray casting using transfer function.
See :ref:`volume-rendering-method` for more details.
source:
- ray_tracing.frag.glsl
- transfer_function.frag.glsl
- ray_tracing.frag.glsl
- transfer_function.frag.glsl
blend_func_separate:
- one minus dst alpha
- one
- one minus dst alpha
- one
- one minus dst alpha
- one
- one minus dst alpha
- one
blend_equation_separate:
- func add
- func add
- func add
- func add
sph_kernel:
info: Sample pre-integrated SPH kernel
source: sph_kernel.frag.glsl
blend_func:
- one
- one
- one
- one
blend_equation: func add
field_value:
info: Use field values as input
source: field_value.frag.glsl
blend_func:
- one
- one
- one
- one
slice_sample:
info: Slice through a block collection
source: slice_sample.frag.glsl
depth_test: less
blend_func:
- one
- zero
- one
- zero
blend_equation: func add
vertex:
default:
info: A first pass vertex shader that tranlates the location of vertices from
info:
A first pass vertex shader that tranlates the location of vertices from
the world coordinates to the viewing plane coordinates
source: default.vert.glsl
mesh:
Expand Down Expand Up @@ -169,21 +184,21 @@ shader_definitions:
source: particle_expand.geom.glsl
component_shaders:
curve_rendering:
default_value: default
default:
description: Default
first_vertex: mesh
first_fragment: constant_rgba
second_vertex: passthrough
second_fragment: passthrough
default_value: default
default:
description: Default
first_vertex: mesh
first_fragment: constant_rgba
second_vertex: passthrough
second_fragment: passthrough
multi_curve_rendering:
default_value: default
default:
description: Default
first_vertex: mesh
first_fragment: constant_rgba
second_vertex: passthrough
second_fragment: passthrough
default_value: default
default:
description: Default
first_vertex: mesh
first_fragment: constant_rgba
second_vertex: passthrough
second_fragment: passthrough
block_rendering:
default_value: max_intensity
max_intensity:
Expand Down