From 363ab9625738b464d0023b11986054e62bbd6045 Mon Sep 17 00:00:00 2001 From: Ftps Date: Wed, 9 Apr 2025 15:51:30 +0900 Subject: [PATCH 1/2] update glsl func --- phy/cluster/views/trace.py | 2 +- phy/plot/base.py | 8 ++++---- phy/plot/gloo/program.py | 6 +++--- phy/plot/gloo/shader.py | 10 +++++----- phy/plot/gloo/texture.py | 2 +- phy/plot/gloo/uniforms.py | 2 +- phy/plot/gloo/variable.py | 2 +- phy/plot/glsl/histogram.frag | 5 +++-- phy/plot/glsl/histogram.vert | 10 +++++----- phy/plot/glsl/image.frag | 5 +++-- phy/plot/glsl/image.vert | 6 +++--- phy/plot/glsl/line.frag | 5 +++-- phy/plot/glsl/line.vert | 7 ++++--- phy/plot/glsl/line_agg_geom.frag | 16 +++++++++------- phy/plot/glsl/line_agg_geom.geom | 16 ++++++++-------- phy/plot/glsl/line_agg_geom.vert | 8 ++++---- phy/plot/glsl/msdf.frag | 10 ++++++---- phy/plot/glsl/msdf.vert | 22 ++++++++++++---------- phy/plot/glsl/patch.frag | 5 +++-- phy/plot/glsl/patch.vert | 6 +++--- phy/plot/glsl/plot.frag | 10 ++++++---- phy/plot/glsl/plot.vert | 14 +++++++------- phy/plot/glsl/plot_agg.frag | 16 +++++++++------- phy/plot/glsl/plot_agg.vert | 22 +++++++++++----------- phy/plot/glsl/polygon.frag | 2 +- phy/plot/glsl/polygon.vert | 2 +- phy/plot/glsl/scatter.frag | 10 ++++++---- phy/plot/glsl/scatter.vert | 10 +++++----- phy/plot/glsl/simple.frag | 2 +- phy/plot/glsl/simple.vert | 2 +- phy/plot/glsl/text.frag | 7 ++++--- phy/plot/glsl/text.vert | 14 +++++++------- phy/plot/glsl/uni_plot.frag | 8 +++++--- phy/plot/glsl/uni_plot.vert | 10 +++++----- phy/plot/glsl/uni_scatter.frag | 5 +++-- phy/plot/glsl/uni_scatter.vert | 6 +++--- phy/plot/glsl/utils.glsl | 4 ++-- phy/plot/interact.py | 6 +++--- phy/plot/tests/test_base.py | 6 +++--- phy/plot/tests/test_interact.py | 4 ++-- 40 files changed, 167 insertions(+), 146 deletions(-) diff --git a/phy/cluster/views/trace.py b/phy/cluster/views/trace.py index 07f4e6cc8..1fdfd4c93 100644 --- a/phy/cluster/views/trace.py +++ b/phy/cluster/views/trace.py @@ -207,7 +207,7 @@ def _create_visuals(self): # Gradient of color for the traces. if self.trace_color_0 and self.trace_color_1: self.trace_visual.inserter.insert_frag( - 'gl_FragColor.rgb = mix(vec3%s, vec3%s, (v_signal_index / %d));' % ( + 'FragColor.rgb = mix(vec3%s, vec3%s, (v_signal_index / %d));' % ( self.trace_color_0, self.trace_color_1, self.n_channels), 'end') self.canvas.add_visual(self.trace_visual) diff --git a/phy/plot/base.py b/phy/plot/base.py index e82f42002..486ff17c6 100644 --- a/phy/plot/base.py +++ b/phy/plot/base.py @@ -238,8 +238,8 @@ def __init__(self): def _init_insert(self): self.insert_vert('vec2 {{varout}} = {{varin}};', 'before_transforms', index=0) self.insert_vert('gl_Position = vec4({{varout}}, 0., 1.);', 'after_transforms', index=0) - self.insert_vert('varying vec2 v_{{varout}};\n', 'header', index=0) - self.insert_frag('varying vec2 v_{{varout}};\n', 'header', index=0) + self.insert_vert('out vec2 v_{{varout}};\n', 'header', index=0) + self.insert_frag('in vec2 v_{{varout}};\n', 'header', index=0) def _insert(self, shader_type, glsl, location, origin=None, index=None): assert location in ( @@ -289,8 +289,8 @@ def insert_frag(self, glsl, location=None, origin=None, index=None): def add_varying(self, vtype, name, value): """Add a varying variable.""" - self.insert_vert('varying %s %s;' % (vtype, name), 'header') - self.insert_frag('varying %s %s;' % (vtype, name), 'header') + self.insert_vert('out %s %s;' % (vtype, name), 'header') + self.insert_frag('in %s %s;' % (vtype, name), 'header') self.insert_vert('%s = %s;' % (name, value), 'end') def add_gpu_transforms(self, tc): diff --git a/phy/plot/gloo/program.py b/phy/plot/gloo/program.py index 242cab289..cf9c94203 100644 --- a/phy/plot/gloo/program.py +++ b/phy/plot/gloo/program.py @@ -50,7 +50,7 @@ class Program(GLObject): # --------------------------------- def __init__(self, vertex=None, fragment=None, geometry=None, - count=0, version="120"): + count=0, version="330"): """ Initialize the program and optionnaly buffer. """ @@ -427,7 +427,7 @@ def active_uniforms(self): uniform vec3 color; # Inactive void main() { - gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); + FragColor = vec4(1.0, 1.0, 1.0, 1.0); } """ @@ -470,7 +470,7 @@ def inactive_uniforms(self): uniform vec3 color; # Inactive void main() { - gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); + FragColor = vec4(1.0, 1.0, 1.0, 1.0); } """ diff --git a/phy/plot/gloo/shader.py b/phy/plot/gloo/shader.py index 4849cd7cd..559ac26d7 100644 --- a/phy/plot/gloo/shader.py +++ b/phy/plot/gloo/shader.py @@ -23,7 +23,7 @@ fragment = ''' void main(void) { - gl_FragColor = vec4(1.0,1.0,0.0,1.0); + FragColor = vec4(1.0,1.0,0.0,1.0); } ''' quad = gloo.Program(vertex, fragment, count=4) @@ -85,7 +85,7 @@ class Shader(GLObject): 'samplerCube': gl.GL_SAMPLER_CUBE, } - def __init__(self, target, code, version="120"): + def __init__(self, target, code, version="330"): """ Initialize the shader. """ @@ -338,7 +338,7 @@ def attributes(self): class VertexShader(Shader): """ Vertex shader class """ - def __init__(self, code=None, version="120"): + def __init__(self, code=None, version="330"): Shader.__init__(self, gl.GL_VERTEX_SHADER, code, version) @property @@ -354,7 +354,7 @@ def __repr__(self): class FragmentShader(Shader): """ Fragment shader class """ - def __init__(self, code=None, version="120"): + def __init__(self, code=None, version="330"): Shader.__init__(self, gl.GL_FRAGMENT_SHADER, code, version) @property @@ -387,7 +387,7 @@ class GeometryShader(Shader): """ def __init__(self, code=None, - vertices_out=None, input_type=None, output_type=None, version="120"): + vertices_out=None, input_type=None, output_type=None, version="330"): Shader.__init__(self, gl.GL_GEOMETRY_SHADER_EXT, code, version) self._vertices_out = vertices_out diff --git a/phy/plot/gloo/texture.py b/phy/plot/gloo/texture.py index 1d9964e0f..cb61c188d 100644 --- a/phy/plot/gloo/texture.py +++ b/phy/plot/gloo/texture.py @@ -19,7 +19,7 @@ varying vec2 v_texcoord; void main() { - gl_FragColor = texture2D(texture, v_texcoord); + FragColor = texture2D(texture, v_texcoord); } ''' ... diff --git a/phy/plot/gloo/uniforms.py b/phy/plot/gloo/uniforms.py index 53d2ff8e0..473911a30 100644 --- a/phy/plot/gloo/uniforms.py +++ b/phy/plot/gloo/uniforms.py @@ -226,7 +226,7 @@ def code(self, prefix="u_"): count, shift = _dtype[name], 0 while count: if store == 0: - body += "\n _uniform = texture2D(u_uniforms, vec2(float(i++)/size_x,ty));\n" + body += "\n _uniform = texture(u_uniforms, vec2(float(i++)/size_x,ty));\n" store = 4 if store == 4: a = "xyzw" diff --git a/phy/plot/gloo/variable.py b/phy/plot/gloo/variable.py index c3f4b6b8a..a6fc24816 100644 --- a/phy/plot/gloo/variable.py +++ b/phy/plot/gloo/variable.py @@ -50,7 +50,7 @@ uniform vec4 color; void main(void) { - gl_FragColor = color; + FragColor = color; } ''' program = gloo.Program(vertex, fragment, count=4) # program["position"] type is Attribute diff --git a/phy/plot/glsl/histogram.frag b/phy/plot/glsl/histogram.frag index 7c31f83aa..b20da3a9c 100644 --- a/phy/plot/glsl/histogram.frag +++ b/phy/plot/glsl/histogram.frag @@ -1,5 +1,6 @@ -varying vec4 v_color; +in vec4 v_color; +out vec4 FragColor; void main() { - gl_FragColor = v_color; + FragColor = v_color; } diff --git a/phy/plot/glsl/histogram.vert b/phy/plot/glsl/histogram.vert index 1889ca2f4..555cd5ab7 100644 --- a/phy/plot/glsl/histogram.vert +++ b/phy/plot/glsl/histogram.vert @@ -1,17 +1,17 @@ #include "utils.glsl" -attribute vec2 a_position; -attribute float a_hist_index; // 0..n_hists-1 +in vec2 a_position; +in float a_hist_index; // 0..n_hists-1 uniform sampler2D u_color; uniform float n_hists; -varying vec4 v_color; -varying float v_hist_index; +out vec4 v_color; +out float v_hist_index; void main() { gl_Position = transform(a_position); - v_color = fetch_texture(a_hist_index, u_color, n_hists); + v_color = texture(u_color, vec2(a_hist_index / n_hists, 0.0)); v_hist_index = a_hist_index; } diff --git a/phy/plot/glsl/image.frag b/phy/plot/glsl/image.frag index d0bfdbe7e..0ab853a94 100644 --- a/phy/plot/glsl/image.frag +++ b/phy/plot/glsl/image.frag @@ -1,6 +1,7 @@ uniform sampler2D u_tex; -varying vec2 v_tex_coords; +in vec2 v_tex_coords; +out vec4 FragColor void main() { - gl_FragColor = texture2D(u_tex, v_tex_coords); + FragColor = texture(u_tex, v_tex_coords); } diff --git a/phy/plot/glsl/image.vert b/phy/plot/glsl/image.vert index a378a1981..6aacb6ed8 100644 --- a/phy/plot/glsl/image.vert +++ b/phy/plot/glsl/image.vert @@ -1,7 +1,7 @@ -attribute vec2 a_position; -attribute vec2 a_tex_coords; +in vec2 a_position; +in vec2 a_tex_coords; -varying vec2 v_tex_coords; +out vec2 v_tex_coords; void main() { gl_Position = transform(a_position); diff --git a/phy/plot/glsl/line.frag b/phy/plot/glsl/line.frag index 7c31f83aa..5c1a69e1e 100644 --- a/phy/plot/glsl/line.frag +++ b/phy/plot/glsl/line.frag @@ -1,5 +1,6 @@ -varying vec4 v_color; +in vec4 v_color; +out vec4 FragColor; void main() { - gl_FragColor = v_color; + FragColor = v_color; } diff --git a/phy/plot/glsl/line.vert b/phy/plot/glsl/line.vert index a5c0c5474..336fadbf3 100644 --- a/phy/plot/glsl/line.vert +++ b/phy/plot/glsl/line.vert @@ -1,6 +1,7 @@ -attribute vec2 a_position; -attribute vec4 a_color; -varying vec4 v_color; +in vec2 a_position; +in vec4 a_color; + +out vec4 v_color; void main() { gl_Position = transform(a_position); diff --git a/phy/plot/glsl/line_agg_geom.frag b/phy/plot/glsl/line_agg_geom.frag index c4664b2e9..2b6c3aebd 100644 --- a/phy/plot/glsl/line_agg_geom.frag +++ b/phy/plot/glsl/line_agg_geom.frag @@ -47,10 +47,12 @@ uniform float antialias; uniform float linewidth; uniform float miter_limit; -varying float v_length; -varying vec2 v_caps; -varying vec2 v_texcoord; -varying vec2 v_bevel_distance; +in float v_length; +in vec2 v_caps; +in vec2 v_texcoord; +in vec2 v_bevel_distance; + +out vec4 FragColor; void main() { @@ -59,12 +61,12 @@ void main() if (v_caps.x < 0.0) { - gl_FragColor = cap(1, v_texcoord.x, v_texcoord.y, linewidth, antialias, color); + FragColor = cap(1, v_texcoord.x, v_texcoord.y, linewidth, antialias, color); return; } if (v_caps.y > v_length) { - gl_FragColor = cap(1, v_texcoord.x-v_length, v_texcoord.y, linewidth, antialias, color); + FragColor = cap(1, v_texcoord.x-v_length, v_texcoord.y, linewidth, antialias, color); return; } @@ -83,6 +85,6 @@ void main() { distance = v_bevel_distance.y - t; } - gl_FragColor = stroke(distance, linewidth, antialias, color); + FragColor = stroke(distance, linewidth, antialias, color); } diff --git a/phy/plot/glsl/line_agg_geom.geom b/phy/plot/glsl/line_agg_geom.geom index c779e2bcd..c143831eb 100644 --- a/phy/plot/glsl/line_agg_geom.geom +++ b/phy/plot/glsl/line_agg_geom.geom @@ -1,4 +1,4 @@ -#version 120 +#version 330 #extension GL_EXT_gpu_shader4 : enable #extension GL_EXT_geometry_shader4 : enable @@ -7,14 +7,14 @@ uniform mat4 projection; // uniform float linewidth; // uniform float miter_limit; -varying in float v_antialias[4][1]; -varying in float v_linewidth[4][1]; -varying in float v_miter_limit[4][1]; +in float v_antialias[4][1]; +in float v_linewidth[4][1]; +in float v_miter_limit[4][1]; -varying out vec2 v_caps; -varying out float v_length; -varying out vec2 v_texcoord; -varying out vec2 v_bevel_distance; +out vec2 v_caps; +out float v_length; +out vec2 v_texcoord; +out vec2 v_bevel_distance; float compute_u(vec2 p0, vec2 p1, vec2 p) { diff --git a/phy/plot/glsl/line_agg_geom.vert b/phy/plot/glsl/line_agg_geom.vert index 5c0f9c26e..cced1391e 100644 --- a/phy/plot/glsl/line_agg_geom.vert +++ b/phy/plot/glsl/line_agg_geom.vert @@ -2,11 +2,11 @@ uniform float antialias; uniform float linewidth; uniform float miter_limit; -attribute vec2 position; +in vec2 position; -varying float v_antialias[1]; -varying float v_linewidth[1]; -varying float v_miter_limit[1]; +out float v_antialias[1]; +out float v_linewidth[1]; +out float v_miter_limit[1]; void main() { diff --git a/phy/plot/glsl/msdf.frag b/phy/plot/glsl/msdf.frag index 7dd70f719..fa70220df 100644 --- a/phy/plot/glsl/msdf.frag +++ b/phy/plot/glsl/msdf.frag @@ -8,8 +8,10 @@ uniform vec4 u_color; uniform vec2 u_tex_size; uniform vec2 u_zoom; -varying vec2 v_tex_coords; -varying vec4 v_color; +in vec2 v_tex_coords; +in vec4 v_color; + +out vec4 FragColor; float median(float r, float g, float b) { @@ -24,7 +26,7 @@ float contour(float d, float w) { float get_alpha(vec2 uv) { vec2 msdfUnit = 4.0 / u_tex_size; - vec3 sample = texture2D(u_tex, uv).rgb; + vec3 sample = texture(u_tex, uv).rgb; float sigDist = median(sample.r, sample.g, sample.b) - 0.5; sigDist *= dot(msdfUnit, 0.5 / fwidth(uv)); sigDist += 0.5; @@ -65,5 +67,5 @@ void main() { // sigDist = exp(-20 * pow(sigDist - 1, 2)); // color = mix(vec3(1, 1, 1), u_color.rgb, sigDist); - gl_FragColor = vec4(v_color.rgb * alpha, v_color.a); + FragColor = vec4(v_color.rgb * alpha, v_color.a); } diff --git a/phy/plot/glsl/msdf.vert b/phy/plot/glsl/msdf.vert index d4510262a..d93a46401 100644 --- a/phy/plot/glsl/msdf.vert +++ b/phy/plot/glsl/msdf.vert @@ -1,20 +1,22 @@ -attribute vec2 a_position; // text position -attribute vec4 a_color; -attribute float a_glyph_index; // glyph index in the text -attribute float a_quad_index; // quad index in the glyph -attribute float a_char_index; // index of the glyph in the texture -attribute float a_lengths; -attribute float a_string_index; // index of the string +in vec2 a_position; // text position +in vec4 a_color; +in float a_glyph_index; // glyph index in the text +in float a_quad_index; // quad index in the glyph +in float a_char_index; // index of the glyph in the texture +in float a_lengths; +in float a_string_index; // index of the string // (1, 1) for lower left, (-1, 1) for lower right, // (1, -1) for upper left, (-1, -1) for upper right -attribute vec2 a_anchor; +in vec2 a_anchor; uniform vec2 u_glyph_size; // (w, h) +// uniform vec2 u_window_size; -varying vec4 v_color; -varying vec2 v_tex_coords; + +out vec4 v_color; +out vec2 v_tex_coords; const float rows = 6; const float cols = 16; diff --git a/phy/plot/glsl/patch.frag b/phy/plot/glsl/patch.frag index 3649a0883..5c7a478b4 100644 --- a/phy/plot/glsl/patch.frag +++ b/phy/plot/glsl/patch.frag @@ -1,6 +1,7 @@ -varying vec4 v_color; +in vec4 v_color; +out vec4 FragColor; void main() { - gl_FragColor = v_color; + FragColor = v_color; } diff --git a/phy/plot/glsl/patch.vert b/phy/plot/glsl/patch.vert index f03afe4f4..57c2c324c 100644 --- a/phy/plot/glsl/patch.vert +++ b/phy/plot/glsl/patch.vert @@ -1,7 +1,7 @@ -attribute vec3 a_position; -attribute vec4 a_color; +in vec3 a_position; +in vec4 a_color; -varying vec4 v_color; +out vec4 v_color; void main() { vec2 xy = a_position.xy; diff --git a/phy/plot/glsl/plot.frag b/phy/plot/glsl/plot.frag index c5547f7e8..57ebb756c 100644 --- a/phy/plot/glsl/plot.frag +++ b/phy/plot/glsl/plot.frag @@ -1,8 +1,10 @@ #include "utils.glsl" -varying vec4 v_color; -varying float v_signal_index; -varying float v_mask; +in vec4 v_color; +in float v_signal_index; +in float v_mask; + +out vec4 FragColor void main() { @@ -10,5 +12,5 @@ void main() { if (fract(v_signal_index) > 0.) discard; - gl_FragColor = apply_mask(v_color, v_mask); + FragColor = apply_mask(v_color, v_mask); } diff --git a/phy/plot/glsl/plot.vert b/phy/plot/glsl/plot.vert index bf7c34a1d..f5367b479 100644 --- a/phy/plot/glsl/plot.vert +++ b/phy/plot/glsl/plot.vert @@ -1,15 +1,15 @@ #include "utils.glsl" -attribute vec3 a_position; -attribute vec4 a_color; -attribute float a_signal_index; // 0..n_signals-1 -attribute float a_mask; +in vec3 a_position; +in vec4 a_color; +in float a_signal_index; // 0..n_signals-1 +in float a_mask; uniform float u_mask_max; -varying vec4 v_color; -varying float v_signal_index; -varying float v_mask; +out vec4 v_color; +out float v_signal_index; +out float v_mask; void main() { vec2 xy = a_position.xy; diff --git a/phy/plot/glsl/plot_agg.frag b/phy/plot/glsl/plot_agg.frag index 42a2da705..e20aad391 100644 --- a/phy/plot/glsl/plot_agg.frag +++ b/phy/plot/glsl/plot_agg.frag @@ -7,17 +7,19 @@ // Varyings // ------------------------------------ -varying vec4 v_color; -varying float v_distance; -varying float v_linewidth; -varying float v_antialias; -varying float v_mask; +in vec4 v_color; +in float v_distance; +in float v_linewidth; +in float v_antialias; +in float v_mask; + +out vec4 FragColor; // Main // ------------------------------------ void main() { if (v_color.a == 0) { discard; } - gl_FragColor = stroke(v_distance, v_linewidth, v_antialias, v_color); - gl_FragColor = apply_mask(gl_FragColor, v_mask); + FragColor = stroke(v_distance, v_linewidth, v_antialias, v_color); + FragColor = apply_mask(FragColor, v_mask); } diff --git a/phy/plot/glsl/plot_agg.vert b/phy/plot/glsl/plot_agg.vert index 592ca4328..a3cae2f27 100644 --- a/phy/plot/glsl/plot_agg.vert +++ b/phy/plot/glsl/plot_agg.vert @@ -6,13 +6,13 @@ // Externs // ------------------------------------ -attribute vec3 a_prev; -attribute vec3 a_curr; -attribute vec3 a_next; -attribute float a_id; -attribute vec4 a_color; -attribute float a_mask; -attribute float a_depth; +in vec3 a_prev; +in vec3 a_curr; +in vec3 a_next; +in float a_id; +in vec4 a_color; +in float a_mask; +in float a_depth; uniform float u_antialias; uniform float u_linewidth; @@ -20,10 +20,10 @@ uniform float u_mask_max; // Varyings // ------------------------------------ -varying float v_antialias; -varying float v_linewidth; -varying float v_distance; -varying vec4 v_color; +out float v_antialias; +out float v_linewidth; +out float v_distance; +out vec4 v_color; varying float v_mask; diff --git a/phy/plot/glsl/polygon.frag b/phy/plot/glsl/polygon.frag index 8df552c17..5aa670d5c 100644 --- a/phy/plot/glsl/polygon.frag +++ b/phy/plot/glsl/polygon.frag @@ -1,5 +1,5 @@ uniform vec4 u_color; void main() { - gl_FragColor = u_color; + FragColor = u_color; } diff --git a/phy/plot/glsl/polygon.vert b/phy/plot/glsl/polygon.vert index a82e7671b..0e21ad701 100644 --- a/phy/plot/glsl/polygon.vert +++ b/phy/plot/glsl/polygon.vert @@ -1,4 +1,4 @@ -attribute vec2 a_position; +in vec2 a_position; uniform vec4 u_color; void main() { diff --git a/phy/plot/glsl/scatter.frag b/phy/plot/glsl/scatter.frag index a17f606ff..3113ccb7d 100644 --- a/phy/plot/glsl/scatter.frag +++ b/phy/plot/glsl/scatter.frag @@ -1,9 +1,11 @@ #include "markers/%MARKER.glsl" #include "utils.glsl" -varying vec4 v_color; -varying float v_size; -uniform vec2 u_zoom; +in vec4 v_color; +in float v_size; +in vec2 u_zoom; + +out vec4 fragColor; void main() { @@ -11,5 +13,5 @@ void main() float point_size = v_size + 5.; %MARKER_SCALING float distance = marker_%MARKER(P * point_size, marker_size); - gl_FragColor = filled(distance, 1.0, 1.0, v_color); + fragColor = filled(distance, 1.0, 1.0, v_color); } diff --git a/phy/plot/glsl/scatter.vert b/phy/plot/glsl/scatter.vert index c241fca42..ea1e2029a 100644 --- a/phy/plot/glsl/scatter.vert +++ b/phy/plot/glsl/scatter.vert @@ -1,9 +1,9 @@ -attribute vec3 a_position; -attribute vec4 a_color; -attribute float a_size; +in vec3 a_position; +in vec4 a_color; +in float a_size; -varying vec4 v_color; -varying float v_size; +out vec4 v_color; +out float v_size; void main() { vec2 xy = a_position.xy; diff --git a/phy/plot/glsl/simple.frag b/phy/plot/glsl/simple.frag index 8df552c17..5aa670d5c 100644 --- a/phy/plot/glsl/simple.frag +++ b/phy/plot/glsl/simple.frag @@ -1,5 +1,5 @@ uniform vec4 u_color; void main() { - gl_FragColor = u_color; + FragColor = u_color; } diff --git a/phy/plot/glsl/simple.vert b/phy/plot/glsl/simple.vert index 2a59757e8..60eeb92f8 100644 --- a/phy/plot/glsl/simple.vert +++ b/phy/plot/glsl/simple.vert @@ -1,4 +1,4 @@ -attribute vec2 a_position; +in vec2 a_position; uniform vec4 u_color; void main() { diff --git a/phy/plot/glsl/text.frag b/phy/plot/glsl/text.frag index 6e4ba84ef..434adf980 100644 --- a/phy/plot/glsl/text.frag +++ b/phy/plot/glsl/text.frag @@ -5,10 +5,11 @@ uniform sampler2D u_tex; uniform vec4 u_color; uniform vec2 u_zoom; -varying vec2 v_tex_coords; +in vec2 v_tex_coords; +out vec4 FragColor void main() { // Texture scalar. - float c = texture2D(u_tex, v_tex_coords).x; - gl_FragColor = vec4(u_color.rgb * c, u_color.a); + float c = texture(u_tex, v_tex_coords).x; + FragColor = vec4(u_color.rgb * c, u_color.a); } diff --git a/phy/plot/glsl/text.vert b/phy/plot/glsl/text.vert index e54731b2f..653972555 100644 --- a/phy/plot/glsl/text.vert +++ b/phy/plot/glsl/text.vert @@ -1,19 +1,19 @@ // NOTE: NOT USED ANYMORE (see msdf.vert instead) -attribute vec2 a_position; // text position -attribute float a_glyph_index; // glyph index in the text -attribute float a_quad_index; // quad index in the glyph -attribute float a_char_index; // index of the glyph in the texture -attribute float a_lengths; +in vec2 a_position; // text position +in float a_glyph_index; // glyph index in the text +in float a_quad_index; // quad index in the glyph +in float a_char_index; // index of the glyph in the texture +in float a_lengths; // (1, 1) for lower left, (-1, 1) for lower right, // (1, -1) for upper left, (-1, -1) for upper right -attribute vec2 a_anchor; +in vec2 a_anchor; uniform vec2 u_glyph_size; // (w, h) -varying vec2 v_tex_coords; +out vec2 v_tex_coords; const float rows = 6; const float cols = 16; diff --git a/phy/plot/glsl/uni_plot.frag b/phy/plot/glsl/uni_plot.frag index 4ebbe9701..7549e941f 100644 --- a/phy/plot/glsl/uni_plot.frag +++ b/phy/plot/glsl/uni_plot.frag @@ -1,8 +1,10 @@ #include "utils.glsl" uniform vec4 u_color; -varying float v_signal_index; -varying float v_mask; +in float v_signal_index; +in float v_mask; + +out vec4 FragColor; void main() { @@ -10,5 +12,5 @@ void main() { if (fract(v_signal_index) > 0.) discard; - gl_FragColor = apply_mask(u_color, v_mask); + FragColor = apply_mask(u_color, v_mask); } diff --git a/phy/plot/glsl/uni_plot.vert b/phy/plot/glsl/uni_plot.vert index 3bac16626..6a9c3f8da 100644 --- a/phy/plot/glsl/uni_plot.vert +++ b/phy/plot/glsl/uni_plot.vert @@ -1,14 +1,14 @@ #include "utils.glsl" -attribute vec2 a_position; -attribute float a_signal_index; // 0..n_signals-1 -attribute float a_mask; +in vec2 a_position; +in float a_signal_index; // 0..n_signals-1 +in float a_mask; uniform vec4 u_color; uniform float u_mask_max; -varying float v_signal_index; -varying float v_mask; +out float v_signal_index; +out float v_mask; void main() { gl_Position = transform(a_position); diff --git a/phy/plot/glsl/uni_scatter.frag b/phy/plot/glsl/uni_scatter.frag index c9aa6c45b..323faca6b 100644 --- a/phy/plot/glsl/uni_scatter.frag +++ b/phy/plot/glsl/uni_scatter.frag @@ -4,7 +4,8 @@ uniform vec4 u_color; uniform float u_size; -varying float v_mask; +in float v_mask; +out vec4 FragColor; vec4 filled2(float distance, float linewidth, float antialias, vec4 bg_color) { @@ -36,5 +37,5 @@ void main() float point_size = u_size + 5.; float distance = marker_%MARKER(P * point_size, u_size); vec4 color = apply_mask(u_color, v_mask); - gl_FragColor = filled2(distance, 1.0, 1.0, color); + FragColor = filled2(distance, 1.0, 1.0, color); } diff --git a/phy/plot/glsl/uni_scatter.vert b/phy/plot/glsl/uni_scatter.vert index d7f263cc7..24ccc0817 100644 --- a/phy/plot/glsl/uni_scatter.vert +++ b/phy/plot/glsl/uni_scatter.vert @@ -1,13 +1,13 @@ #include "utils.glsl" -attribute vec2 a_position; -attribute float a_mask; +in vec2 a_position; +in float a_mask; uniform vec4 u_color; uniform float u_size; uniform float u_mask_max; -varying float v_mask; +out float v_mask; void main() { gl_Position = transform(a_position); diff --git a/phy/plot/glsl/utils.glsl b/phy/plot/glsl/utils.glsl index 3b2875911..9107e0073 100644 --- a/phy/plot/glsl/utils.glsl +++ b/phy/plot/glsl/utils.glsl @@ -18,8 +18,8 @@ vec3 rgb_to_hsv(vec3 c) } -vec4 fetch_texture(float index, sampler2D texture, float size) { - return texture2D(texture, vec2(index / (size - 1.), .5)); +vec4 fetch_texture(float index, sampler2D _texture, float size) { + return texture(_texture, vec2(index / (size - 1.0), 0.5)); } diff --git a/phy/plot/interact.py b/phy/plot/interact.py index c44957a97..5c4bb3897 100644 --- a/phy/plot/interact.py +++ b/phy/plot/interact.py @@ -80,7 +80,7 @@ def attach(self, canvas): canvas.gpu_transforms += self.gpu_transforms canvas.inserter.insert_vert( """ - attribute vec2 {}; + in vec2 {}; uniform vec2 {}; uniform vec2 u_grid_scaling; """.format(self.box_var, self.shape_var), @@ -204,7 +204,7 @@ def attach(self, canvas): canvas.gpu_transforms += self.gpu_transforms canvas.inserter.insert_vert(""" #include "utils.glsl" - attribute float {}; + in float {}; uniform sampler2D u_box_pos; uniform float n_boxes; uniform vec2 u_box_size; @@ -385,7 +385,7 @@ def attach(self, canvas): canvas.gpu_transforms += self.gpu_transforms canvas.inserter.insert_vert(""" #include "utils.glsl" - attribute float {}; + in float {}; uniform float n_boxes; uniform bool u_top_origin; uniform vec2 u_box_size; diff --git a/phy/plot/tests/test_base.py b/phy/plot/tests/test_base.py index 5382aa38b..abf18d069 100644 --- a/phy/plot/tests/test_base.py +++ b/phy/plot/tests/test_base.py @@ -28,7 +28,7 @@ @fixture def vertex_shader_nohook(): yield """ - attribute vec2 a_position; + in vec2 a_position; void main() { gl_Position = vec4(a_position.xy, 0, 1); } @@ -38,7 +38,7 @@ def vertex_shader_nohook(): @fixture def vertex_shader(): yield """ - attribute vec2 a_position; + in vec2 a_position; void main() { gl_Position = transform(a_position.xy); gl_PointSize = 2.0; @@ -50,7 +50,7 @@ def vertex_shader(): def fragment_shader(): yield """ void main() { - gl_FragColor = vec4(1, 1, 1, 1); + FragColor = vec4(1, 1, 1, 1); } """ diff --git a/phy/plot/tests/test_interact.py b/phy/plot/tests/test_interact.py index 2c6d97799..92b5bbe90 100644 --- a/phy/plot/tests/test_interact.py +++ b/phy/plot/tests/test_interact.py @@ -32,7 +32,7 @@ class MyTestVisual(BaseVisual): def __init__(self): super(MyTestVisual, self).__init__() self.vertex_shader = """ - attribute vec2 a_position; + in vec2 a_position; void main() { vec2 xy = a_position.xy; gl_Position = transform(xy); @@ -41,7 +41,7 @@ def __init__(self): """ self.fragment_shader = """ void main() { - gl_FragColor = vec4(1, 1, 1, 1); + FragColor = vec4(1, 1, 1, 1); } """ self.set_primitive_type('points') From 7b53a7f18e5efa378b2bb86c8ea8f6a7d796bdcc Mon Sep 17 00:00:00 2001 From: Ftps Date: Wed, 9 Apr 2025 23:32:20 +0900 Subject: [PATCH 2/2] fix modules(i.e. texture2d -> texture) --- phy/cluster/views/trace.py | 2 +- phy/plot/gloo/gl.py | 4 ---- phy/plot/gloo/program.py | 16 ++++++------- phy/plot/gloo/shader.py | 13 ++++++----- phy/plot/gloo/texture.py | 7 ++---- phy/plot/gloo/variable.py | 40 +++++++++++++++++++++++++------- phy/plot/glsl/histogram.frag | 3 ++- phy/plot/glsl/image.frag | 3 ++- phy/plot/glsl/line.frag | 3 ++- phy/plot/glsl/line_agg_geom.frag | 35 ++++++++++++++-------------- phy/plot/glsl/line_agg_geom.geom | 16 ++++++------- phy/plot/glsl/msdf.frag | 11 ++++----- phy/plot/glsl/msdf.vert | 2 -- phy/plot/glsl/patch.frag | 5 ++-- phy/plot/glsl/plot.frag | 4 ++-- phy/plot/glsl/plot_agg.frag | 6 ++--- phy/plot/glsl/plot_agg.vert | 4 ++-- phy/plot/glsl/polygon.frag | 4 +++- phy/plot/glsl/scatter.frag | 4 +++- phy/plot/glsl/simple.frag | 4 +++- phy/plot/glsl/text.frag | 5 ++-- phy/plot/glsl/uni_plot.frag | 5 ++-- phy/plot/glsl/uni_plot.vert | 2 +- phy/plot/glsl/uni_scatter.frag | 5 ++-- phy/plot/glsl/utils.glsl | 4 ++-- phy/plot/interact.py | 2 +- phy/plot/tests/test_base.py | 7 +++--- phy/plot/tests/test_interact.py | 5 ++-- 28 files changed, 123 insertions(+), 98 deletions(-) diff --git a/phy/cluster/views/trace.py b/phy/cluster/views/trace.py index 1fdfd4c93..bf6754f78 100644 --- a/phy/cluster/views/trace.py +++ b/phy/cluster/views/trace.py @@ -207,7 +207,7 @@ def _create_visuals(self): # Gradient of color for the traces. if self.trace_color_0 and self.trace_color_1: self.trace_visual.inserter.insert_frag( - 'FragColor.rgb = mix(vec3%s, vec3%s, (v_signal_index / %d));' % ( + 'fragColor.rgb = mix(vec3%s, vec3%s, (v_signal_index / %d));' % ( self.trace_color_0, self.trace_color_1, self.n_channels), 'end') self.canvas.add_visual(self.trace_visual) diff --git a/phy/plot/gloo/gl.py b/phy/plot/gloo/gl.py index 48c440fe0..d54a3e1c0 100644 --- a/phy/plot/gloo/gl.py +++ b/phy/plot/gloo/gl.py @@ -48,14 +48,10 @@ def enable_depth_mask(): glClearColor(0, 0, 0, 0) # noqa glClearDepth(1.) # noqa - glEnable(GL_BLEND) # noqa glDepthRange(0., 1.) # noqa glDepthFunc(GL_EQUAL) # noqa glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # noqa - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) # noqa - glEnable(GL_POINT_SPRITE) # noqa - # Patch: pythonize the glGetActiveAttrib _glGetActiveAttrib = glGetActiveAttrib # noqa diff --git a/phy/plot/gloo/program.py b/phy/plot/gloo/program.py index cf9c94203..b26499c33 100644 --- a/phy/plot/gloo/program.py +++ b/phy/plot/gloo/program.py @@ -50,7 +50,7 @@ class Program(GLObject): # --------------------------------- def __init__(self, vertex=None, fragment=None, geometry=None, - count=0, version="330"): + count=0, version="410"): """ Initialize the program and optionnaly buffer. """ @@ -141,7 +141,7 @@ def hooks(self): .. code:: C - attribute vec3 position; + in vec3 position; void main () { gl_Position = (position); # "transform" is a hook } @@ -427,7 +427,7 @@ def active_uniforms(self): uniform vec3 color; # Inactive void main() { - FragColor = vec4(1.0, 1.0, 1.0, 1.0); + gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } """ @@ -470,7 +470,7 @@ def inactive_uniforms(self): uniform vec3 color; # Inactive void main() { - FragColor = vec4(1.0, 1.0, 1.0, 1.0); + gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } """ @@ -506,8 +506,8 @@ def active_attributes(self): .. code:: - attribute vec3 normal; # Inactive - attribute vec3 position; # Active + in vec3 normal; # Inactive + in vec3 position; # Active void main() { gl_Position = vec4(position, 1.0); } @@ -552,8 +552,8 @@ def inactive_attributes(self): .. code:: - attribute vec3 normal; # Inactive - attribute vec3 position; # Active + in vec3 normal; # Inactive + in vec3 position; # Active void main() { gl_Position = vec4(position, 1.0); } diff --git a/phy/plot/gloo/shader.py b/phy/plot/gloo/shader.py index 559ac26d7..76ae7a96c 100644 --- a/phy/plot/gloo/shader.py +++ b/phy/plot/gloo/shader.py @@ -15,15 +15,16 @@ .. code:: python vertex = ''' - attribute vec2 position; + in vec2 position; void main (void) { gl_Position = vec4(0.85*position, 0.0, 1.0); } ''' fragment = ''' + out vec4 fragColor; void main(void) { - FragColor = vec4(1.0,1.0,0.0,1.0); + fragColor = vec4(1.0,1.0,0.0,1.0); } ''' quad = gloo.Program(vertex, fragment, count=4) @@ -85,7 +86,7 @@ class Shader(GLObject): 'samplerCube': gl.GL_SAMPLER_CUBE, } - def __init__(self, target, code, version="330"): + def __init__(self, target, code, version="410"): """ Initialize the shader. """ @@ -338,7 +339,7 @@ def attributes(self): class VertexShader(Shader): """ Vertex shader class """ - def __init__(self, code=None, version="330"): + def __init__(self, code=None, version="410"): Shader.__init__(self, gl.GL_VERTEX_SHADER, code, version) @property @@ -354,7 +355,7 @@ def __repr__(self): class FragmentShader(Shader): """ Fragment shader class """ - def __init__(self, code=None, version="330"): + def __init__(self, code=None, version="410"): Shader.__init__(self, gl.GL_FRAGMENT_SHADER, code, version) @property @@ -387,7 +388,7 @@ class GeometryShader(Shader): """ def __init__(self, code=None, - vertices_out=None, input_type=None, output_type=None, version="330"): + vertices_out=None, input_type=None, output_type=None, version="410"): Shader.__init__(self, gl.GL_GEOMETRY_SHADER_EXT, code, version) self._vertices_out = vertices_out diff --git a/phy/plot/gloo/texture.py b/phy/plot/gloo/texture.py index cb61c188d..c205484cf 100644 --- a/phy/plot/gloo/texture.py +++ b/phy/plot/gloo/texture.py @@ -15,11 +15,11 @@ ... fragment = ''' - uniform sampler2D texture; + uniform sampler2D tex; varying vec2 v_texcoord; void main() { - FragColor = texture2D(texture, v_texcoord); + gl_FragColor = texture(texture, v_texcoord); } ''' ... @@ -394,7 +394,6 @@ def _setup(self): """ Setup texture on GPU """ Texture._setup(self) - gl.glEnable(gl.GL_TEXTURE_CUBE_MAP) gl.glBindTexture(self.target, self._handle) targets = [gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X, gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, @@ -411,7 +410,6 @@ def _update(self): log.log(5, "GPU: Updating texture cube") if self.need_update: - gl.glEnable(gl.GL_TEXTURE_CUBE_MAP) gl.glBindTexture(self.target, self.handle) targets = [gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X, @@ -455,7 +453,6 @@ def _activate(self): """ Activate texture on GPU """ log.log(5, "GPU: Activate texture cube") - gl.glEnable(gl.GL_TEXTURE_CUBE_MAP) gl.glBindTexture(self.target, self._handle) if self._need_setup: self._setup() diff --git a/phy/plot/gloo/variable.py b/phy/plot/gloo/variable.py index a6fc24816..99c1616d5 100644 --- a/phy/plot/gloo/variable.py +++ b/phy/plot/gloo/variable.py @@ -41,16 +41,17 @@ .. code:: vertex = ''' - attribute vec3 position; + in vec3 position; void main (void) { gl_Position = vec4(position, 1.0); } ''' fragment = ''' uniform vec4 color; + out vec4 fragColor; void main(void) { - FragColor = color; + fragColor = color; } ''' program = gloo.Program(vertex, fragment, count=4) # program["position"] type is Attribute @@ -363,14 +364,35 @@ def set_data(self, data): self._generic = False def _activate(self): + """Activate the attribute ensuring proper GL state.""" + if not self._active: + return + if isinstance(self.data, (VertexBuffer, VertexArray)): - self.data.activate() - size, gtype, dtype = gl_typeinfo[self._gtype] - stride = self.data.stride - offset = ctypes.c_void_p(self.data.offset) - gl.glEnableVertexAttribArray(self.handle) - gl.glVertexAttribPointer( - self.handle, size, gtype, gl.GL_FALSE, stride, offset) + # Early validation + if self.handle < 0: + log.debug("Skipping activation of attribute %s (invalid handle)", self.name) + return + + try: + # 1. First bind the buffer + self.data.activate() + + # 2. Get the attribute information + size, gtype, dtype = gl_typeinfo[self._gtype] + stride = self.data.stride + offset = ctypes.c_void_p(self.data.offset) + + # 3. Set pointer before enabling + gl.glVertexAttribPointer( + self.handle, size, gtype, gl.GL_FALSE, stride, offset) + + # 4. Enable the attribute array + gl.glEnableVertexAttribArray(self.handle) + + except Exception as e: + log.error("Error activating attribute %s: %s", self.name, str(e)) + raise def _deactivate(self): if isinstance(self.data, VertexBuffer): diff --git a/phy/plot/glsl/histogram.frag b/phy/plot/glsl/histogram.frag index b20da3a9c..eb82f98f7 100644 --- a/phy/plot/glsl/histogram.frag +++ b/phy/plot/glsl/histogram.frag @@ -1,6 +1,7 @@ -in vec4 v_color; out vec4 FragColor; +in vec4 v_color; + void main() { FragColor = v_color; } diff --git a/phy/plot/glsl/image.frag b/phy/plot/glsl/image.frag index 0ab853a94..658dd00b3 100644 --- a/phy/plot/glsl/image.frag +++ b/phy/plot/glsl/image.frag @@ -1,6 +1,7 @@ uniform sampler2D u_tex; in vec2 v_tex_coords; -out vec4 FragColor + +out vec4 FragColor; void main() { FragColor = texture(u_tex, v_tex_coords); diff --git a/phy/plot/glsl/line.frag b/phy/plot/glsl/line.frag index 5c1a69e1e..eb82f98f7 100644 --- a/phy/plot/glsl/line.frag +++ b/phy/plot/glsl/line.frag @@ -1,5 +1,6 @@ +out vec4 FragColor; + in vec4 v_color; -out vec4 FragColor; void main() { FragColor = v_color; diff --git a/phy/plot/glsl/line_agg_geom.frag b/phy/plot/glsl/line_agg_geom.frag index 2b6c3aebd..b1b3b3f9a 100644 --- a/phy/plot/glsl/line_agg_geom.frag +++ b/phy/plot/glsl/line_agg_geom.frag @@ -1,3 +1,15 @@ +in vec2 v_texcoord; +in float v_length; +in vec2 v_caps; +in vec2 v_bevel_distance; + +out vec4 FragColor; + +uniform vec4 color; +uniform float antialias; +uniform float linewidth; +uniform float miter_limit; + vec4 stroke(float distance, float linewidth, float antialias, vec4 color) { vec4 frag_color; @@ -41,19 +53,6 @@ vec4 cap(int type, float dx, float dy, float linewidth, float antialias, vec4 co return stroke(d, linewidth, antialias, color); } - -uniform vec4 color; -uniform float antialias; -uniform float linewidth; -uniform float miter_limit; - -in float v_length; -in vec2 v_caps; -in vec2 v_texcoord; -in vec2 v_bevel_distance; - -out vec4 FragColor; - void main() { @@ -66,7 +65,7 @@ void main() } if (v_caps.y > v_length) { - FragColor = cap(1, v_texcoord.x-v_length, v_texcoord.y, linewidth, antialias, color); + FragColor = cap(1, v_texcoord.x - v_length, v_texcoord.y, linewidth, antialias, color); return; } @@ -75,16 +74,16 @@ void main() // else if(v_texcoord.x > v_length) { distance = length(v_texcoord - vec2(v_length, 0.0)); } // Miter limit - float t = (miter_limit-1.0)*(linewidth/2.0) + antialias; + float t = (miter_limit - 1.0) * (linewidth / 2.0) + antialias; - if( (v_texcoord.x < 0.0) && (v_bevel_distance.x > (abs(distance) + t)) ) + if ((v_texcoord.x < 0.0) && (v_bevel_distance.x > (abs(distance) + t))) { distance = v_bevel_distance.x - t; } - else if( (v_texcoord.x > v_length) && (v_bevel_distance.y > (abs(distance) + t)) ) + else if ((v_texcoord.x > v_length) && (v_bevel_distance.y > (abs(distance) + t))) { distance = v_bevel_distance.y - t; } - FragColor = stroke(distance, linewidth, antialias, color); + FragColor = stroke(distance, linewidth, antialias, color); } diff --git a/phy/plot/glsl/line_agg_geom.geom b/phy/plot/glsl/line_agg_geom.geom index c143831eb..e36b6403f 100644 --- a/phy/plot/glsl/line_agg_geom.geom +++ b/phy/plot/glsl/line_agg_geom.geom @@ -1,4 +1,4 @@ -#version 330 +#version 410 #extension GL_EXT_gpu_shader4 : enable #extension GL_EXT_geometry_shader4 : enable @@ -7,14 +7,14 @@ uniform mat4 projection; // uniform float linewidth; // uniform float miter_limit; -in float v_antialias[4][1]; -in float v_linewidth[4][1]; -in float v_miter_limit[4][1]; +in in float v_antialias[4][1]; +in in float v_linewidth[4][1]; +in in float v_miter_limit[4][1]; -out vec2 v_caps; -out float v_length; -out vec2 v_texcoord; -out vec2 v_bevel_distance; +out out vec2 v_caps; +out out float v_length; +out out vec2 v_texcoord; +out out vec2 v_bevel_distance; float compute_u(vec2 p0, vec2 p1, vec2 p) { diff --git a/phy/plot/glsl/msdf.frag b/phy/plot/glsl/msdf.frag index fa70220df..15e3655ad 100644 --- a/phy/plot/glsl/msdf.frag +++ b/phy/plot/glsl/msdf.frag @@ -11,8 +11,7 @@ uniform vec2 u_zoom; in vec2 v_tex_coords; in vec4 v_color; -out vec4 FragColor; - +out vec4 fragColor; float median(float r, float g, float b) { return max(min(r, g), min(max(r, g), b)); @@ -26,8 +25,8 @@ float contour(float d, float w) { float get_alpha(vec2 uv) { vec2 msdfUnit = 4.0 / u_tex_size; - vec3 sample = texture(u_tex, uv).rgb; - float sigDist = median(sample.r, sample.g, sample.b) - 0.5; + vec3 _sample = texture(u_tex, uv).rgb; + float sigDist = median(_sample.r, _sample.g, _sample.b) - 0.5; sigDist *= dot(msdfUnit, 0.5 / fwidth(uv)); sigDist += 0.5; return clamp(sigDist, 0.0, 1.0); @@ -62,10 +61,10 @@ void main() { alpha = supersample(alpha); // CONTOUR -- does not work well with small font sizes - // vec3 sample = texture2D(u_tex, v_tex_coords).rgb; + // vec3 sample = texture(u_tex, v_tex_coords).rgb; // float sigDist = median(sample.r, sample.g, sample.b); // sigDist = exp(-20 * pow(sigDist - 1, 2)); // color = mix(vec3(1, 1, 1), u_color.rgb, sigDist); - FragColor = vec4(v_color.rgb * alpha, v_color.a); + fragColor = vec4(v_color.rgb * alpha, v_color.a); } diff --git a/phy/plot/glsl/msdf.vert b/phy/plot/glsl/msdf.vert index d93a46401..a8448db05 100644 --- a/phy/plot/glsl/msdf.vert +++ b/phy/plot/glsl/msdf.vert @@ -12,8 +12,6 @@ in float a_string_index; // index of the string in vec2 a_anchor; uniform vec2 u_glyph_size; // (w, h) -// uniform vec2 u_window_size; - out vec4 v_color; out vec2 v_tex_coords; diff --git a/phy/plot/glsl/patch.frag b/phy/plot/glsl/patch.frag index 5c7a478b4..de6a5377e 100644 --- a/phy/plot/glsl/patch.frag +++ b/phy/plot/glsl/patch.frag @@ -1,7 +1,8 @@ in vec4 v_color; -out vec4 FragColor; + +out vec4 fragColor; void main() { - FragColor = v_color; + fragColor = v_color; } diff --git a/phy/plot/glsl/plot.frag b/phy/plot/glsl/plot.frag index 57ebb756c..9b08ae2c5 100644 --- a/phy/plot/glsl/plot.frag +++ b/phy/plot/glsl/plot.frag @@ -4,7 +4,7 @@ in vec4 v_color; in float v_signal_index; in float v_mask; -out vec4 FragColor +out vec4 fragColor; void main() { @@ -12,5 +12,5 @@ void main() { if (fract(v_signal_index) > 0.) discard; - FragColor = apply_mask(v_color, v_mask); + fragColor = apply_mask(v_color, v_mask); } diff --git a/phy/plot/glsl/plot_agg.frag b/phy/plot/glsl/plot_agg.frag index e20aad391..bac09bd72 100644 --- a/phy/plot/glsl/plot_agg.frag +++ b/phy/plot/glsl/plot_agg.frag @@ -13,13 +13,13 @@ in float v_linewidth; in float v_antialias; in float v_mask; -out vec4 FragColor; +out vec4 fragColor; // Main // ------------------------------------ void main() { if (v_color.a == 0) { discard; } - FragColor = stroke(v_distance, v_linewidth, v_antialias, v_color); - FragColor = apply_mask(FragColor, v_mask); + vec4 strokeColor = stroke(v_distance, v_linewidth, v_antialias, v_color); + fragColor = apply_mask(gl_FragColor, v_mask); } diff --git a/phy/plot/glsl/plot_agg.vert b/phy/plot/glsl/plot_agg.vert index a3cae2f27..8e06e84e0 100644 --- a/phy/plot/glsl/plot_agg.vert +++ b/phy/plot/glsl/plot_agg.vert @@ -18,14 +18,14 @@ uniform float u_antialias; uniform float u_linewidth; uniform float u_mask_max; -// Varyings +// outs // ------------------------------------ out float v_antialias; out float v_linewidth; out float v_distance; out vec4 v_color; -varying float v_mask; +out float v_mask; vec2 NDC_to_viewport(vec4 position, vec2 viewport) { diff --git a/phy/plot/glsl/polygon.frag b/phy/plot/glsl/polygon.frag index 5aa670d5c..ec82f252f 100644 --- a/phy/plot/glsl/polygon.frag +++ b/phy/plot/glsl/polygon.frag @@ -1,5 +1,7 @@ uniform vec4 u_color; +out vec4 fragColor; + void main() { - FragColor = u_color; + fragColor = u_color; } diff --git a/phy/plot/glsl/scatter.frag b/phy/plot/glsl/scatter.frag index 3113ccb7d..148e08285 100644 --- a/phy/plot/glsl/scatter.frag +++ b/phy/plot/glsl/scatter.frag @@ -3,7 +3,9 @@ in vec4 v_color; in float v_size; -in vec2 u_zoom; + +uniform vec2 u_zoom; + out vec4 fragColor; diff --git a/phy/plot/glsl/simple.frag b/phy/plot/glsl/simple.frag index 5aa670d5c..ec82f252f 100644 --- a/phy/plot/glsl/simple.frag +++ b/phy/plot/glsl/simple.frag @@ -1,5 +1,7 @@ uniform vec4 u_color; +out vec4 fragColor; + void main() { - FragColor = u_color; + fragColor = u_color; } diff --git a/phy/plot/glsl/text.frag b/phy/plot/glsl/text.frag index 434adf980..7883df42b 100644 --- a/phy/plot/glsl/text.frag +++ b/phy/plot/glsl/text.frag @@ -6,10 +6,11 @@ uniform vec4 u_color; uniform vec2 u_zoom; in vec2 v_tex_coords; -out vec4 FragColor + +out vec4 fragColor; void main() { // Texture scalar. float c = texture(u_tex, v_tex_coords).x; - FragColor = vec4(u_color.rgb * c, u_color.a); + fragColor = vec4(u_color.rgb * c, u_color.a); } diff --git a/phy/plot/glsl/uni_plot.frag b/phy/plot/glsl/uni_plot.frag index 7549e941f..f77f7e254 100644 --- a/phy/plot/glsl/uni_plot.frag +++ b/phy/plot/glsl/uni_plot.frag @@ -4,13 +4,12 @@ uniform vec4 u_color; in float v_signal_index; in float v_mask; -out vec4 FragColor; +out vec4 fragColor; void main() { // Discard pixels between signals. if (fract(v_signal_index) > 0.) discard; - - FragColor = apply_mask(u_color, v_mask); + fragColor = apply_mask(u_color, v_mask); } diff --git a/phy/plot/glsl/uni_plot.vert b/phy/plot/glsl/uni_plot.vert index 6a9c3f8da..9ef3e968b 100644 --- a/phy/plot/glsl/uni_plot.vert +++ b/phy/plot/glsl/uni_plot.vert @@ -16,4 +16,4 @@ void main() { v_signal_index = a_signal_index; v_mask = a_mask; -} +} \ No newline at end of file diff --git a/phy/plot/glsl/uni_scatter.frag b/phy/plot/glsl/uni_scatter.frag index 323faca6b..855999f3e 100644 --- a/phy/plot/glsl/uni_scatter.frag +++ b/phy/plot/glsl/uni_scatter.frag @@ -5,7 +5,8 @@ uniform vec4 u_color; uniform float u_size; in float v_mask; -out vec4 FragColor; + +out vec4 fragColor; vec4 filled2(float distance, float linewidth, float antialias, vec4 bg_color) { @@ -37,5 +38,5 @@ void main() float point_size = u_size + 5.; float distance = marker_%MARKER(P * point_size, u_size); vec4 color = apply_mask(u_color, v_mask); - FragColor = filled2(distance, 1.0, 1.0, color); + fragColor = filled2(distance, 1.0, 1.0, color); } diff --git a/phy/plot/glsl/utils.glsl b/phy/plot/glsl/utils.glsl index 9107e0073..c2e3a77d6 100644 --- a/phy/plot/glsl/utils.glsl +++ b/phy/plot/glsl/utils.glsl @@ -18,8 +18,8 @@ vec3 rgb_to_hsv(vec3 c) } -vec4 fetch_texture(float index, sampler2D _texture, float size) { - return texture(_texture, vec2(index / (size - 1.0), 0.5)); +vec4 fetch_texture(float index, sampler2D tex, float size) { + return texture(tex, vec2(index / (size - 1.), .5)); } diff --git a/phy/plot/interact.py b/phy/plot/interact.py index 5c4bb3897..2c2ad1b8a 100644 --- a/phy/plot/interact.py +++ b/phy/plot/interact.py @@ -80,7 +80,7 @@ def attach(self, canvas): canvas.gpu_transforms += self.gpu_transforms canvas.inserter.insert_vert( """ - in vec2 {}; + in vec2 {}; uniform vec2 {}; uniform vec2 u_grid_scaling; """.format(self.box_var, self.shape_var), diff --git a/phy/plot/tests/test_base.py b/phy/plot/tests/test_base.py index abf18d069..a2b9a062a 100644 --- a/phy/plot/tests/test_base.py +++ b/phy/plot/tests/test_base.py @@ -28,7 +28,7 @@ @fixture def vertex_shader_nohook(): yield """ - in vec2 a_position; + in vec2 a_position; void main() { gl_Position = vec4(a_position.xy, 0, 1); } @@ -38,7 +38,7 @@ def vertex_shader_nohook(): @fixture def vertex_shader(): yield """ - in vec2 a_position; + in vec2 a_position; void main() { gl_Position = transform(a_position.xy); gl_PointSize = 2.0; @@ -49,8 +49,9 @@ def vertex_shader(): @fixture def fragment_shader(): yield """ + out vec4 fragColor; void main() { - FragColor = vec4(1, 1, 1, 1); + fragColor = vec4(1, 1, 1, 1); } """ diff --git a/phy/plot/tests/test_interact.py b/phy/plot/tests/test_interact.py index 92b5bbe90..4050d4c52 100644 --- a/phy/plot/tests/test_interact.py +++ b/phy/plot/tests/test_interact.py @@ -32,7 +32,7 @@ class MyTestVisual(BaseVisual): def __init__(self): super(MyTestVisual, self).__init__() self.vertex_shader = """ - in vec2 a_position; + in vec2 a_position; void main() { vec2 xy = a_position.xy; gl_Position = transform(xy); @@ -40,8 +40,9 @@ def __init__(self): } """ self.fragment_shader = """ + out vec4 fragColor; void main() { - FragColor = vec4(1, 1, 1, 1); + fragColor = vec4(1, 1, 1, 1); } """ self.set_primitive_type('points')