Skip to content

Commit c59d598

Browse files
committed
Merge branch 'ir/ref-v3' of github.com:GraphiteEditor/Graphite into ir/ref-v3
2 parents 8052c1b + 3b22ea7 commit c59d598

24 files changed

Lines changed: 104 additions & 76 deletions

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

desktop/src/render/composite_shader.wgsl

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,60 @@ var s_diffuse: sampler;
4444

4545
@fragment
4646
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
47-
let ui = textureSample(t_ui, s_diffuse, in.tex_coords);
48-
if (ui.a >= 0.999) {
49-
return ui;
47+
let ui_linear = textureSample(t_ui, s_diffuse, in.tex_coords);
48+
if (ui_linear.a >= 0.999) {
49+
return ui_linear;
5050
}
5151

5252
let viewport_coordinate = (in.tex_coords - constants.viewport_offset) * constants.viewport_scale;
5353

54-
// Vello renders its values to an `RgbaUnorm` texture, but if we try to use this in the main rendering pipeline
55-
// which renders to an `Srgb` surface, gamma mapping is applied twice. This converts back to linear to compensate.
56-
let overlay_raw = textureSample(t_overlays, s_diffuse, viewport_coordinate);
57-
let overlay = vec4<f32>(srgb_to_linear(overlay_raw.rgb), overlay_raw.a);
58-
let viewport_raw = textureSample(t_viewport, s_diffuse, viewport_coordinate);
59-
let viewport = vec4<f32>(srgb_to_linear(viewport_raw.rgb), viewport_raw.a);
54+
let overlay_srgb = textureSample(t_overlays, s_diffuse, viewport_coordinate);
55+
let viewport_srgb = textureSample(t_viewport, s_diffuse, viewport_coordinate);
6056

61-
if (overlay.a < 0.001) {
62-
return blend(ui, viewport);
57+
// UI texture is premultiplied, we need to unpremultiply before blending
58+
let ui_srgb = linear_to_srgb(unpremultiply(ui_linear));
59+
60+
if (overlay_srgb.a < 0.001) {
61+
if (ui_srgb.a < 0.001) {
62+
return srgb_to_linear(viewport_srgb);
63+
} else {
64+
return srgb_to_linear(blend(ui_srgb, viewport_srgb));
65+
}
6366
}
6467

65-
let composite = blend(overlay, viewport);
66-
return blend(ui, composite);
67-
}
68+
let composite_linear = blend(srgb_to_linear(overlay_srgb), srgb_to_linear(viewport_srgb));
6869

69-
fn srgb_to_linear(srgb: vec3<f32>) -> vec3<f32> {
70-
return select(
71-
pow((srgb + 0.055) / 1.055, vec3<f32>(2.4)),
72-
srgb / 12.92,
73-
srgb <= vec3<f32>(0.04045)
74-
);
70+
if (ui_srgb.a < 0.001) {
71+
return composite_linear;
72+
}
73+
74+
return srgb_to_linear(blend(ui_srgb, linear_to_srgb(composite_linear)));
7575
}
7676

7777
fn blend(fg: vec4<f32>, bg: vec4<f32>) -> vec4<f32> {
7878
let a = fg.a + bg.a * (1.0 - fg.a);
7979
let rgb = fg.rgb * fg.a + bg.rgb * bg.a * (1.0 - fg.a);
8080
return vec4<f32>(rgb, a);
8181
}
82+
83+
fn linear_to_srgb(in: vec4<f32>) -> vec4<f32> {
84+
let cutoff = vec3<f32>(0.0031308);
85+
let lo = in.rgb * 12.92;
86+
let hi = 1.055 * pow(max(in.rgb, vec3<f32>(0.0)), vec3<f32>(1.0/2.4)) - 0.055;
87+
return vec4<f32>(select(lo, hi, in.rgb > cutoff), in.a);
88+
}
89+
90+
fn srgb_to_linear(in: vec4<f32>) -> vec4<f32> {
91+
let cutoff = vec3<f32>(0.04045);
92+
let lo = in.rgb / 12.92;
93+
let hi = pow((in.rgb + 0.055) / 1.055, vec3<f32>(2.4));
94+
return vec4<f32>(select(lo, hi, in.rgb > cutoff), in.a);
95+
}
96+
97+
fn unpremultiply(in: vec4<f32>) -> vec4<f32> {
98+
if (in.a > 0.0) {
99+
return vec4<f32>((in.rgb / in.a), in.a);
100+
} else {
101+
return vec4<f32>(0.0);
102+
}
103+
}

editor/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ ron = ["dep:ron"]
2323
graphite-proc-macros = { workspace = true }
2424
graph-craft = { workspace = true }
2525
interpreted-executor = { workspace = true }
26-
graphene-std = { workspace = true }
27-
graphene-core = { workspace = true }
26+
graphene-std = { workspace = true } # NOTE: `graphene-core` should not be added here because `graphene-std` re-exports its contents
2827
preprocessor = { workspace = true }
2928

3029
# Workspace dependencies

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ use crate::node_graph_executor::NodeGraphExecutor;
3030
use glam::{DAffine2, DVec2, IVec2};
3131
use graph_craft::document::value::TaggedValue;
3232
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
33-
use graphene_core::subpath::Subpath;
3433
use graphene_std::math::quad::Quad;
3534
use graphene_std::path_bool::{boolean_intersect, path_bool_lib};
3635
use graphene_std::raster::BlendMode;
3736
use graphene_std::raster_types::Raster;
37+
use graphene_std::subpath::Subpath;
3838
use graphene_std::table::Table;
3939
use graphene_std::vector::PointId;
4040
use graphene_std::vector::click_target::{ClickTarget, ClickTargetType};

editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use crate::messages::portfolio::document::utility_types::network_interface::Node
44
use crate::messages::prelude::*;
55
use glam::{DAffine2, IVec2};
66
use graph_craft::document::NodeId;
7-
use graphene_core::subpath::Subpath;
87
use graphene_std::Artboard;
98
use graphene_std::brush::brush_stroke::BrushStroke;
109
use graphene_std::raster::BlendMode;
1110
use graphene_std::raster_types::{CPU, Raster};
11+
use graphene_std::subpath::Subpath;
1212
use graphene_std::table::Table;
1313
use graphene_std::text::{Font, TypesettingConfig};
1414
use graphene_std::vector::PointId;

editor/src/messages/portfolio/document/graph_operation/transform_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::messages::portfolio::document::utility_types::network_interface::{Inp
22
use glam::{DAffine2, DVec2};
33
use graph_craft::document::value::TaggedValue;
44
use graph_craft::document::{NodeId, NodeInput};
5-
use graphene_core::subpath::Subpath;
5+
use graphene_std::subpath::Subpath;
66
use graphene_std::vector::PointId;
77

88
/// Convert an affine transform into the tuple `(scale, angle, translation, shear)` assuming `shear.y = 0`.

editor/src/messages/portfolio/document/graph_operation/utility_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use glam::{DAffine2, IVec2};
77
use graph_craft::concrete;
88
use graph_craft::document::value::TaggedValue;
99
use graph_craft::document::{NodeId, NodeInput};
10-
use graphene_core::subpath::Subpath;
1110
use graphene_std::Artboard;
1211
use graphene_std::brush::brush_stroke::BrushStroke;
1312
use graphene_std::raster::BlendMode;
1413
use graphene_std::raster_types::{CPU, Raster};
14+
use graphene_std::subpath::Subpath;
1515
use graphene_std::table::Table;
1616
use graphene_std::text::{Font, TypesettingConfig};
1717
use graphene_std::vector::Vector;

editor/src/messages/portfolio/document/overlays/utility_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::messages::portfolio::document::utility_types::network_interface::Node
44
use crate::messages::tool::common_functionality::shape_editor::{SelectedLayerState, ShapeState};
55
use crate::messages::tool::tool_messages::tool_prelude::{DocumentMessageHandler, PreferencesMessageHandler};
66
use glam::{DAffine2, DVec2};
7-
use graphene_core::subpath::{Bezier, BezierHandles};
7+
use graphene_std::subpath::{Bezier, BezierHandles};
88
use graphene_std::vector::misc::ManipulatorPointId;
99
use graphene_std::vector::{PointId, SegmentId};
1010
use wasm_bindgen::JsCast;

editor/src/messages/portfolio/document/overlays/utility_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::messages::prelude::Message;
88
use core::borrow::Borrow;
99
use core::f64::consts::{FRAC_PI_2, PI, TAU};
1010
use glam::{DAffine2, DVec2};
11-
use graphene_core::subpath::Subpath;
1211
use graphene_std::Color;
1312
use graphene_std::math::quad::Quad;
13+
use graphene_std::subpath::Subpath;
1414
use graphene_std::vector::click_target::ClickTargetType;
1515
use graphene_std::vector::misc::{dvec2_to_point, point_to_dvec2};
1616
use graphene_std::vector::{PointId, SegmentId, Vector};

editor/src/messages/portfolio/document/overlays/utility_types_vello.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use crate::messages::prelude::Message;
77
use core::borrow::Borrow;
88
use core::f64::consts::{FRAC_PI_2, PI, TAU};
99
use glam::{DAffine2, DVec2};
10-
use graphene_core::subpath::{self, Subpath};
1110
use graphene_std::Color;
1211
use graphene_std::math::quad::Quad;
12+
use graphene_std::subpath::{self, Subpath};
1313
use graphene_std::table::Table;
1414
use graphene_std::text::{TextAlign, TypesettingConfig, load_font, to_path};
1515
use graphene_std::vector::click_target::ClickTargetType;

0 commit comments

Comments
 (0)