Skip to content

Commit a2567e4

Browse files
committed
shaders: switch to f32 params
1 parent 32e0c93 commit a2567e4

File tree

5 files changed

+41
-35
lines changed

5 files changed

+41
-35
lines changed

editor/src/messages/portfolio/document/node_graph/node_properties.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ pub(crate) fn property_from_type(
149149
Type::Concrete(concrete_type) => {
150150
match concrete_type.alias.as_ref().map(|x| x.as_ref()) {
151151
// Aliased types (ambiguous values)
152-
Some("Percentage") => number_widget(default_info, number_input.percentage().min(min(0.)).max(max(100.))).into(),
153-
Some("SignedPercentage") => number_widget(default_info, number_input.percentage().min(min(-100.)).max(max(100.))).into(),
154-
Some("Angle") => number_widget(default_info, number_input.mode_range().min(min(-180.)).max(max(180.)).unit(unit.unwrap_or("°"))).into(),
152+
Some("Percentage") | Some("PercentageF32") => number_widget(default_info, number_input.percentage().min(min(0.)).max(max(100.))).into(),
153+
Some("SignedPercentage") | Some("SignedPercentageF32") => number_widget(default_info, number_input.percentage().min(min(-100.)).max(max(100.))).into(),
154+
Some("Angle") | Some("AngleF32") => number_widget(default_info, number_input.mode_range().min(min(-180.)).max(max(180.)).unit(unit.unwrap_or("°"))).into(),
155155
Some("Multiplier") => number_widget(default_info, number_input.unit(unit.unwrap_or("x"))).into(),
156156
Some("PixelLength") => number_widget(default_info, number_input.min(min(0.)).unit(unit.unwrap_or(" px"))).into(),
157157
Some("Length") => number_widget(default_info, number_input.min(min(0.))).into(),

node-graph/gbrush/src/brush.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub async fn create_brush_texture(brush_style: &BrushStyle) -> Raster<CPU> {
137137
}
138138

139139
pub fn blend_with_mode(background: TableRow<Raster<CPU>>, foreground: TableRow<Raster<CPU>>, blend_mode: BlendMode, opacity: f64) -> TableRow<Raster<CPU>> {
140-
let opacity = opacity / 100.;
140+
let opacity = opacity as f32 / 100.;
141141
match std::hint::black_box(blend_mode) {
142142
// Normal group
143143
BlendMode::Normal => blend_image_closure(foreground, background, |a, b| blend_colors(a, b, BlendMode::Normal, opacity)),

node-graph/gcore-shaders/src/registry.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
pub mod types {
22
/// 0% - 100%
33
pub type Percentage = f64;
4+
/// 0% - 100%
5+
pub type PercentageF32 = f32;
46
/// -100% - 100%
57
pub type SignedPercentage = f64;
8+
/// -100% - 100%
9+
pub type SignedPercentageF32 = f32;
610
/// -180° - 180°
711
pub type Angle = f64;
12+
/// -180° - 180°
13+
pub type AngleF32 = f32;
814
/// Ends in the unit of x
915
pub type Multiplier = f64;
1016
/// Non-negative integer with px unit

node-graph/graster-nodes/src/adjustments.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use graphene_core::raster_types::{CPU, Raster};
1010
use graphene_core::table::Table;
1111
use graphene_core_shaders::color::Color;
1212
use graphene_core_shaders::context::Ctx;
13-
use graphene_core_shaders::registry::types::{Angle, Percentage, SignedPercentage};
13+
use graphene_core_shaders::registry::types::{AngleF32, PercentageF32, SignedPercentageF32};
1414
#[cfg(not(feature = "std"))]
1515
use num_traits::float::Float;
1616

@@ -148,8 +148,8 @@ fn brightness_contrast<T: Adjust<Color>>(
148148
)]
149149
#[gpu_image]
150150
mut input: T,
151-
brightness: SignedPercentage,
152-
contrast: SignedPercentage,
151+
brightness: SignedPercentageF32,
152+
contrast: SignedPercentageF32,
153153
use_classic: bool,
154154
) -> T {
155155
if use_classic {
@@ -238,11 +238,11 @@ fn levels<T: Adjust<Color>>(
238238
)]
239239
#[gpu_image]
240240
mut image: T,
241-
#[default(0.)] shadows: Percentage,
242-
#[default(50.)] midtones: Percentage,
243-
#[default(100.)] highlights: Percentage,
244-
#[default(0.)] output_minimums: Percentage,
245-
#[default(100.)] output_maximums: Percentage,
241+
#[default(0.)] shadows: PercentageF32,
242+
#[default(50.)] midtones: PercentageF32,
243+
#[default(100.)] highlights: PercentageF32,
244+
#[default(0.)] output_minimums: PercentageF32,
245+
#[default(100.)] output_maximums: PercentageF32,
246246
) -> T {
247247
image.adjust(|color| {
248248
let color = color.to_gamma_srgb();
@@ -309,22 +309,22 @@ fn black_and_white<T: Adjust<Color>>(
309309
#[default(Color::BLACK)] tint: Color,
310310
#[default(40.)]
311311
#[range((-200., 300.))]
312-
reds: Percentage,
312+
reds: PercentageF32,
313313
#[default(60.)]
314314
#[range((-200., 300.))]
315-
yellows: Percentage,
315+
yellows: PercentageF32,
316316
#[default(40.)]
317317
#[range((-200., 300.))]
318-
greens: Percentage,
318+
greens: PercentageF32,
319319
#[default(60.)]
320320
#[range((-200., 300.))]
321-
cyans: Percentage,
321+
cyans: PercentageF32,
322322
#[default(20.)]
323323
#[range((-200., 300.))]
324-
blues: Percentage,
324+
blues: PercentageF32,
325325
#[default(80.)]
326326
#[range((-200., 300.))]
327-
magentas: Percentage,
327+
magentas: PercentageF32,
328328
) -> T {
329329
image.adjust(|color| {
330330
let color = color.to_gamma_srgb();
@@ -379,9 +379,9 @@ fn hue_saturation<T: Adjust<Color>>(
379379
)]
380380
#[gpu_image]
381381
mut input: T,
382-
hue_shift: Angle,
383-
saturation_shift: SignedPercentage,
384-
lightness_shift: SignedPercentage,
382+
hue_shift: AngleF32,
383+
saturation_shift: SignedPercentageF32,
384+
lightness_shift: SignedPercentageF32,
385385
) -> T {
386386
input.adjust(|color| {
387387
let color = color.to_gamma_srgb();
@@ -437,8 +437,8 @@ fn threshold<T: Adjust<Color>>(
437437
)]
438438
#[gpu_image]
439439
mut image: T,
440-
#[default(50.)] min_luminance: Percentage,
441-
#[default(100.)] max_luminance: Percentage,
440+
#[default(50.)] min_luminance: PercentageF32,
441+
#[default(100.)] max_luminance: PercentageF32,
442442
luminance_calc: LuminanceCalculation,
443443
) -> T {
444444
image.adjust(|color| {
@@ -483,7 +483,7 @@ fn vibrance<T: Adjust<Color>>(
483483
)]
484484
#[gpu_image]
485485
mut image: T,
486-
vibrance: SignedPercentage,
486+
vibrance: SignedPercentageF32,
487487
) -> T {
488488
image.adjust(|color| {
489489
let vibrance = vibrance as f32 / 100.;
@@ -955,21 +955,21 @@ fn exposure<T: Adjust<Color>>(
955955
)]
956956
#[gpu_image]
957957
mut input: T,
958-
exposure: f64,
959-
offset: f64,
958+
exposure: f32,
959+
offset: f32,
960960
#[default(1.)]
961961
#[range((0.01, 10.))]
962962
#[hard_min(0.0001)]
963-
gamma_correction: f64,
963+
gamma_correction: f32,
964964
) -> T {
965965
input.adjust(|color| {
966966
let adjusted = color
967967
// Exposure
968-
.map_rgb(|c: f32| c * 2_f32.powf(exposure as f32))
968+
.map_rgb(|c: f32| c * 2_f32.powf(exposure))
969969
// Offset
970-
.map_rgb(|c: f32| c + offset as f32)
970+
.map_rgb(|c: f32| c + offset)
971971
// Gamma correction
972-
.gamma(gamma_correction as f32);
972+
.gamma(gamma_correction);
973973

974974
adjusted.map_rgb(|c: f32| c.clamp(0., 1.))
975975
});

node-graph/graster-nodes/src/blending_nodes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use graphene_core::table::Table;
77
use graphene_core_shaders::Ctx;
88
use graphene_core_shaders::blending::BlendMode;
99
use graphene_core_shaders::color::{Color, Pixel};
10-
use graphene_core_shaders::registry::types::Percentage;
10+
use graphene_core_shaders::registry::types::{Percentage, PercentageF32};
1111

1212
pub trait Blend<P: Pixel> {
1313
fn blend(&self, under: &Self, blend_fn: impl Fn(P, P) -> P) -> Self;
@@ -71,7 +71,7 @@ mod blend_std {
7171
}
7272

7373
#[inline(always)]
74-
pub fn blend_colors(foreground: Color, background: Color, blend_mode: BlendMode, opacity: f64) -> Color {
74+
pub fn blend_colors(foreground: Color, background: Color, blend_mode: BlendMode, opacity: f32) -> Color {
7575
let target_color = match blend_mode {
7676
// Other utility blend modes (hidden from the normal list) - do not have alpha blend
7777
BlendMode::Erase => return background.alpha_subtract(foreground),
@@ -141,7 +141,7 @@ fn blend<T: Blend<Color> + Send>(
141141
#[gpu_image]
142142
under: T,
143143
blend_mode: BlendMode,
144-
#[default(100.)] opacity: Percentage,
144+
#[default(100.)] opacity: PercentageF32,
145145
) -> T {
146146
over.blend(&under, |a, b| blend_colors(a, b, blend_mode, opacity / 100.))
147147
}
@@ -158,7 +158,7 @@ fn color_overlay<T: Adjust<Color>>(
158158
mut image: T,
159159
#[default(Color::BLACK)] color: Color,
160160
blend_mode: BlendMode,
161-
#[default(100.)] opacity: Percentage,
161+
#[default(100.)] opacity: PercentageF32,
162162
) -> T {
163163
let opacity = (opacity as f32 / 100.).clamp(0., 1.);
164164

@@ -183,7 +183,7 @@ where
183183
{
184184
let blend_mode = blend_mode.eval(());
185185
let opacity = opacity.eval(());
186-
blend_colors(input.0, input.1, blend_mode, opacity / 100.)
186+
blend_colors(input.0, input.1, blend_mode, opacity as f32 / 100.)
187187
}
188188

189189
#[cfg(all(feature = "std", test))]

0 commit comments

Comments
 (0)