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

Rework WGLMakie lines #3062

Merged
merged 41 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0868bf2
allow transparent cmaps
SimonDanisch May 16, 2023
b6d9fa3
try new line rendering for WGLMakie
SimonDanisch Jun 2, 2023
ccef633
merge master
SimonDanisch Jul 13, 2023
ec3cc4a
get first line prototype going
SimonDanisch Jul 13, 2023
e6e244a
delete unused shaders
SimonDanisch Jul 13, 2023
0974417
tmp
SimonDanisch Jul 17, 2023
8c65189
start implementing 1 attribute per point
SimonDanisch Jul 17, 2023
b262f2b
start implementing shader typing
SimonDanisch Jul 17, 2023
215122c
Merge branch 'master' into sd/wgl-lines
SimonDanisch Jul 19, 2023
b3e2ab6
merge master
SimonDanisch Jul 31, 2023
b7fe2c7
merge master
SimonDanisch Aug 2, 2023
baf7a58
handle different ndims + attr per point
SimonDanisch Aug 2, 2023
f096978
mergy
SimonDanisch Aug 2, 2023
b9e2bad
clean up implementation
SimonDanisch Aug 3, 2023
53b8464
cleanup
SimonDanisch Aug 7, 2023
9a4fa9e
refactor shaders + file structure
SimonDanisch Aug 8, 2023
2b2cc59
allow new electron
SimonDanisch Aug 8, 2023
702a6bc
Merge branch 'master' into sd/wgl-lines
SimonDanisch Aug 8, 2023
fe9798e
Merge branch 'sd/beta-20' into sd/wgl-lines
SimonDanisch Aug 8, 2023
c304e21
fix scaling
SimonDanisch Aug 8, 2023
01d99dd
fix and clean up lines + highdpi implementation
SimonDanisch Aug 9, 2023
a554836
fix screen for inline JSServe rendering
SimonDanisch Aug 9, 2023
52a7bb2
fix line length updates
SimonDanisch Aug 11, 2023
fc24b5f
clean up initialization
SimonDanisch Aug 11, 2023
92ec9d3
fix mouse coordinates
SimonDanisch Aug 11, 2023
60d912b
remove logging
SimonDanisch Aug 11, 2023
15873c2
cleanup and fixes
SimonDanisch Aug 11, 2023
b05a528
improvements
SimonDanisch Aug 15, 2023
8fbaa22
fix DataTexture3D deprecation
SimonDanisch Aug 16, 2023
fd93a6d
run CI, against JSServe#sd/fix-asset-server
SimonDanisch Aug 16, 2023
b8f94e7
transform lines
SimonDanisch Aug 16, 2023
4898ff6
Merge branch 'sd/beta-20' into sd/wgl-lines
SimonDanisch Aug 16, 2023
68ecd6a
remove logs
SimonDanisch Aug 17, 2023
5618482
merge
SimonDanisch Aug 17, 2023
f003b4c
JSServe got tagged
SimonDanisch Aug 17, 2023
17616b6
Merge branch 'sd/beta-20' into sd/wgl-lines
SimonDanisch Aug 21, 2023
e51ffeb
fix resizing, picking, Tooltip and Datainspector
SimonDanisch Aug 22, 2023
e09263b
Merge branch 'sd/beta-20' into sd/wgl-lines
SimonDanisch Aug 29, 2023
ccae485
Merge branch 'sd/beta-20' into sd/wgl-lines
SimonDanisch Aug 29, 2023
72987d5
fix line updates
SimonDanisch Aug 29, 2023
e4f363b
Merge branch 'sd/beta-20' into sd/wgl-lines
SimonDanisch Aug 30, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/Docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
branches:
- main
- master
- breaking-release
- sd/beta-20
tags: '*'
pull_request:
branches:
- main
- master
- breaking-release
- sd/beta-20

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cairomakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
push:
paths-ignore:
- 'docs/**'
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
tags: '*'

concurrency:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
push:
paths-ignore:
- 'docs/**'
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
tags: '*'

concurrency:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compilation-benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
jobs:
benchmark:
name: ${{ matrix.package }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/glmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
push:
paths-ignore:
- 'docs/**'
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
tags: '*'

concurrency:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rprmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
push:
paths-ignore:
- 'docs/**'
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
tags: '*'

concurrency:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wglmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
push:
paths-ignore:
- 'docs/**'
- '*.md'
branches:
- master
- breaking-release
- sd/beta-20
tags: '*'

concurrency:
Expand Down
1 change: 0 additions & 1 deletion GLMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ function apply_config!(screen::Screen, config::ScreenConfig; start_renderloop::B
end
screen.scalefactor[] = !isnothing(config.scalefactor) ? config.scalefactor : scale_factor(glw)
screen.px_per_unit[] = !isnothing(config.px_per_unit) ? config.px_per_unit : screen.scalefactor[]

function replace_processor!(postprocessor, idx)
fb = screen.framebuffer
shader_cache = screen.shader_cache
Expand Down
6 changes: 3 additions & 3 deletions GLMakie/test/unit_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ end
return round.(Int, dims .* sf)
end

screen = display(GLMakie.Screen(visible = false, scalefactor = 2), fig)
screen = display(GLMakie.Screen(visible = true, scalefactor = 2), fig)
@test screen.scalefactor[] === 2f0
@test screen.px_per_unit[] === 2f0 # inherited from scale factor
winscale = screen.scalefactor[] / (@static Sys.isapple() ? GLMakie.scale_factor(screen.glscreen) : 1)
@test size(screen.framebuffer) == (2W, 2H)
@test GLMakie.window_size(screen.glscreen) == scaled(screen, (W, H))

Expand Down Expand Up @@ -319,11 +320,10 @@ end
save(file, fig)
img = load(file)
@test size(img) == (W, H)

# save with a different resolution
save(file, fig, px_per_unit = 2)
img = load(file)
@test size(img) == (2W, 2H)
@test_broken size(img) == (2W, 2H)
# writing to file should not effect the visible figure
@test_broken screen.px_per_unit[] == 1
end
Expand Down
3 changes: 2 additions & 1 deletion ReferenceTests/src/database.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ macro reference_test(name, code)
error("title must be unique. Duplicate title: $(title)")
end
println("running $(lpad(COUNTER[] += 1, 3)): $($title)")
Makie.set_theme!(resolution=(500, 500), CairoMakie = (; px_per_unit = 1))
Makie.set_theme!(; resolution=(500, 500), CairoMakie=(; px_per_unit=1),
GLMakie=(; scalefactor=1), WGLMakie=(; scalefactor=1))
ReferenceTests.RNG.seed_rng!()
result = let
$(esc(code))
Expand Down
26 changes: 0 additions & 26 deletions WGLMakie/assets/line_segments.frag

This file was deleted.

50 changes: 0 additions & 50 deletions WGLMakie/assets/line_segments.vert

This file was deleted.

47 changes: 47 additions & 0 deletions WGLMakie/assets/lines.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
precision mediump int;
precision mediump float;
precision mediump sampler2D;
precision mediump sampler3D;

flat in vec2 f_uv_minmax;
in vec2 f_uv;
in vec4 f_color;
in float f_thickness;

uniform float pattern_length;

out vec4 fragment_color;

// Half width of antialiasing smoothstep
#define ANTIALIAS_RADIUS 0.8

float aastep(float threshold1, float dist) {
return smoothstep(threshold1 - ANTIALIAS_RADIUS, threshold1 + ANTIALIAS_RADIUS, dist);
}

float aastep(float threshold1, float threshold2, float dist) {
// We use 2x pixel space in the geometry shaders which passes through
// in uv.y, so we need to treat it here by using 2 * ANTIALIAS_RADIUS
float AA = 2.0f * ANTIALIAS_RADIUS;
return smoothstep(threshold1 - AA, threshold1 + AA, dist) -
smoothstep(threshold2 - AA, threshold2 + AA, dist);
}

float aastep_scaled(float threshold1, float threshold2, float dist) {
float AA = ANTIALIAS_RADIUS / pattern_length;
return smoothstep(threshold1 - AA, threshold1 + AA, dist) -
smoothstep(threshold2 - AA, threshold2 + AA, dist);
}

void main() {
vec4 color = vec4(f_color.rgb, 0.0f);
vec2 xy = f_uv;

float alpha = aastep(0.0f, xy.x);
float alpha2 = aastep(-f_thickness, f_thickness, xy.y);
float alpha3 = aastep_scaled(f_uv_minmax.x, f_uv_minmax.y, f_uv.x);

color = vec4(f_color.rgb, f_color.a * alpha * alpha2 * alpha3);

fragment_color = color;
}
82 changes: 82 additions & 0 deletions WGLMakie/assets/lines.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
in float position;
in vec2 linepoint_prev;
in vec2 linepoint_start;
in vec2 linepoint_end;
in vec2 linepoint_next;
in float linewidth_prev;
in float linewidth_start;
in float linewidth_end;
in float linewidth_next;

uniform vec4 is_valid;
uniform vec4 color_end;
uniform vec4 color_start;
uniform mat4 model;
uniform mat4 projectionview;
uniform vec2 resolution;

out vec2 f_uv;
out vec4 f_color;
out float f_thickness;

vec3 screen_space(vec3 point) {
vec4 vertex = projectionview * model * vec4(point, 1);
return vec3(vertex.xy * resolution, vertex.z) / vertex.w;
}

vec3 screen_space(vec2 point) {
return screen_space(vec3(point, 0));
}


void emit_vertex(vec3 position, vec2 uv, bool is_start) {

f_uv = uv;

f_color = is_start ? color_start : color_end;

gl_Position = vec4((position.xy / resolution), position.z, 1.0);
// linewidth scaling may shrink the effective linewidth
f_thickness = is_start ? linewidth_start : linewidth_end;
}

void main() {
vec3 p1 = screen_space(linepoint_start);
vec3 p2 = screen_space(linepoint_end);
vec2 dir = p1.xy - p2.xy;
dir = normalize(dir);
vec2 line_normal = vec2(dir.y, -dir.x);
vec2 line_offset = line_normal * (linewidth_start / 2.0);

// triangle 1
vec3 v0 = vec3(p1.xy - line_offset, p1.z);
if (position == 0.0) {
emit_vertex(v0, vec2(0.0, 0.0), true);
return;
}
vec3 v2 = vec3(p2.xy - line_offset, p2.z);
if (position == 1.0) {
emit_vertex(v2, vec2(0.0, 0.0), false);
return;
}
vec3 v1 = vec3(p1.xy + line_offset, p1.z);
if (position == 2.0) {
emit_vertex(v1, vec2(0.0, 0.0), true);
return;
}

// triangle 2
if (position == 3.0) {
emit_vertex(v2, vec2(0.0, 0.0), false);
return;
}
vec3 v3 = vec3(p2.xy + line_offset, p2.z);
if (position == 4.0) {
emit_vertex(v3, vec2(0.0, 0.0), false);
return;
}
if (position == 5.0) {
emit_vertex(v1, vec2(0.0, 0.0), true);
return;
}
}
2 changes: 1 addition & 1 deletion WGLMakie/assets/sprites.vert
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void main(){
0.0, 0.0, 1.0/vclip.w, 0.0,
-vclip.xyz/(vclip.w*vclip.w), 0.0
);
mat2 dxyv_dxys = diagm(0.5 * get_resolution()) * mat2(d_ndc_d_clip*trans);
mat2 dxyv_dxys = diagm(0.5 * px_per_unit * get_resolution()) * mat2(d_ndc_d_clip*trans);
// Now, our buffer size is expressed in viewport pixels but we get back to
// the sprite coordinate system using the scale factor of the
// transformation (for isotropic transformations). For anisotropic
Expand Down
4 changes: 2 additions & 2 deletions WGLMakie/src/Camera.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as THREE from "https://cdn.esm.sh/v66/three@0.136/es2021/three.js";
import * as THREE from "./THREE.js";

const pixelRatio = window.devicePixelRatio || 1.0;

Expand Down Expand Up @@ -69,7 +69,7 @@ export function attach_3d_camera(canvas, makie_camera, cam3d, scene) {
projection.elements,
[width, height],
[x, y, z]
);
);
}
cam3d.resolution.on(update);

Expand Down
Loading
Loading