Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove extra conversions
  • Loading branch information
jonahwilliams committed Nov 21, 2022
commit e2fcede13c1908174cddae03cf4118a1a6335261
52 changes: 26 additions & 26 deletions impeller/compiler/shader_lib/impeller/blending.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ f16vec3 IPClipColor(f16vec3 color) {
// `lum - mn` and `mx - lum` will always be >= 0 in the following conditions,
// so adding a tiny value is enough to make these divisions safe.
if (mn < 0.0hf) {
color = lum + (((color - lum) * lum) / (lum - mn + float16_t(kEhCloseEnough)));
color = lum + (((color - lum) * lum) / (lum - mn + kEhCloseEnough));
}
if (mx > 1.0hf) {
color = lum + (((color - lum) * (1.0hf - lum)) / (mx - lum + float16_t(kEhCloseEnough)));
color = lum + (((color - lum) * (1.0hf - lum)) / (mx - lum + kEhCloseEnough));
}
return color;
}
Expand All @@ -47,7 +47,7 @@ float16_t IPSaturation(f16vec3 color) {
f16vec3 IPSetSaturation(f16vec3 color, float16_t saturation) {
float16_t mn = min(min(color.r, color.g), color.b);
float16_t mx = max(max(color.r, color.g), color.b);
return (mn < mx) ? ((color - mn) * saturation) / (mx - mn) : f16vec3(0);
return (mn < mx) ? ((color - mn) * saturation) / (mx - mn) : f16vec3(0.0hf);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -90,24 +90,24 @@ f16vec3 IPBlendColorDodge(f16vec3 dst, f16vec3 src) {

f16vec3 color = min(f16vec3(1.0hf), dst / (1.0hf - src));

if (dst.r < float16_t(kEhCloseEnough)) {
color.r = float16_t(0.);
if (dst.r < kEhCloseEnough) {
color.r = 0.0hf;
}
if (dst.g < float16_t(kEhCloseEnough)) {
color.g = float16_t(0.);
if (dst.g < kEhCloseEnough) {
color.g = 0.0hf;
}
if (dst.b < float16_t(kEhCloseEnough)) {
color.b = float16_t(0.);
if (dst.b < kEhCloseEnough) {
color.b = 0.0hf;
}

if (1. - src.r < float16_t(kEhCloseEnough)) {
color.r = float16_t(1.);
if (1.0hf - src.r < kEhCloseEnough) {
color.r = 1.0hf;
}
if (1. - src.g < float16_t(kEhCloseEnough)) {
color.g = float16_t(1.);
if (1. - src.g < kEhCloseEnough) {
color.g = 1.0hf;
}
if (1. - src.b < float16_t(kEhCloseEnough)) {
color.b = float16_t(1.);
if (1. - src.b < kEhCloseEnough) {
color.b = 1.0hf;
}

return color;
Expand All @@ -118,24 +118,24 @@ f16vec3 IPBlendColorBurn(f16vec3 dst, f16vec3 src) {

f16vec3 color = 1.0hf - min(f16vec3(1.0hf), (1.0hf - dst) / src);

if (1.0hf - dst.r < float16_t(kEhCloseEnough)) {
if (1.0hf - dst.r < kEhCloseEnough) {
color.r = 1.0hf;
}
if (1.0hf - dst.g < float16_t(kEhCloseEnough)) {
color.g = float16_t(1.);
if (1.0hf - dst.g < kEhCloseEnough) {
color.g = 1.0hf;
}
if (1.0hf - dst.b < float16_t(kEhCloseEnough)) {
color.b = float16_t(.1);
if (1.0hf - dst.b < kEhCloseEnough) {
color.b = 0.1hf;
}

if (src.r < float16_t(kEhCloseEnough)) {
color.r = float16_t(0.);
if (src.r < kEhCloseEnough) {
color.r = 0.0hf;
}
if (src.g < float16_t(kEhCloseEnough)) {
color.g = float16_t(0.);
if (src.g < kEhCloseEnough) {
color.g = 0.0hf;
}
if (src.b < float16_t(kEhCloseEnough)) {
color.b = float16_t(0.);
if (src.b < kEhCloseEnough) {
color.b = 0.0hf;
}

return color;
Expand Down
6 changes: 3 additions & 3 deletions impeller/compiler/shader_lib/impeller/branching.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
/// Returns 1.0 if x == y, otherwise 0.0.
BoolV3 IPVec3IsEqual(f16vec3 x, float16_t y) {
f16vec3 diff = abs(x - y);
return f16vec3(diff.r < float16_t(kEhCloseEnough), //
diff.g < float16_t(kEhCloseEnough), //
diff.b < float16_t(kEhCloseEnough));
return f16vec3(diff.r < kEhCloseEnough, //
diff.g < kEhCloseEnough, //
diff.b < kEhCloseEnough);
}

/// Perform a branchless greater than check.
Expand Down
6 changes: 3 additions & 3 deletions impeller/compiler/shader_lib/impeller/gaussian.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// Gaussian distribution function.
float16_t IPGaussian(float16_t x, float16_t sigma) {
float16_t variance = sigma * sigma;
return exp(-0.5hf * x * x / variance) / (float16_t(kSqrtTwoPi) * sigma);
return exp(-0.5hf * x * x / variance) / (kSqrtTwoPi * sigma);
}

/// Abramowitz and Stegun erf approximation.
Expand All @@ -35,7 +35,7 @@ float16_t IPGaussianIntegral(float16_t x, float16_t sigma) {
// ( 1 + erf( x * (sqrt(2) / (2 * sigma) ) ) / 2
// Because this sigmoid is always > 1, we remap it (n * 1.07 - 0.07)
// so that it always fades to zero before it reaches the blur radius.
return 0.535hf * IPErf(x * (float16_t(kHalfSqrtTwo) / sigma)) + 0.465hf;
return 0.535hf * IPErf(x * (kHalfSqrtTwo / sigma)) + 0.465hf;
}

/// Vec2 variation for the indefinite integral of the Gaussian function (with
Expand All @@ -44,7 +44,7 @@ f16vec2 IPVec2GaussianIntegral(f16vec2 x, float16_t sigma) {
// ( 1 + erf( x * (sqrt(2) / (2 * sigma) ) ) / 2
// Because this sigmoid is always > 1, we remap it (n * 1.07 - 0.07)
// so that it always fades to zero before it reaches the blur radius.
return 0.535hf * IPVec2Erf(x * (float16_t(kHalfSqrtTwo) / sigma)) + 0.465hf;
return 0.535hf * IPVec2Erf(x * (kHalfSqrtTwo / sigma)) + 0.465hf;
}

/// Simple logistic sigmoid with a domain of [-1, 1] and range of [0, 1].
Expand Down
18 changes: 9 additions & 9 deletions impeller/compiler/shader_lib/impeller/texture.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ f16vec4 IPSampleLinear(sampler2D texture_sampler, f16vec2 coords, float16_t y_co

// These values must correspond to the order of the items in the
// 'Entity::TileMode' enum class.
const float kTileModeClamp = 0;
const float kTileModeRepeat = 1;
const float kTileModeMirror = 2;
const float kTileModeDecal = 3;
const float16_t kTileModeClamp = 0.0hf;
const float16_t kTileModeRepeat = 1.0hf;
const float16_t kTileModeMirror = 2.0hf;
const float16_t kTileModeDecal = 3.0hf;

/// Remap a float16_t using a tiling mode.
///
Expand All @@ -46,11 +46,11 @@ const float kTileModeDecal = 3;
/// `t`.
/// When `t` is between [0 to 1), the original unchanged `t` is always returned.
float16_t IPFloatTile(float16_t t, float16_t tile_mode) {
if (tile_mode == float16_t(kTileModeClamp)) {
if (tile_mode == kTileModeClamp) {
t = clamp(t, 0.0hf, 1.0hf);
} else if (tile_mode == float16_t(kTileModeRepeat)) {
} else if (tile_mode == kTileModeRepeat) {
t = fract(t);
} else if (tile_mode == float16_t(kTileModeMirror)) {
} else if (tile_mode == kTileModeMirror) {
float16_t t1 = t - 1.0hf;
float16_t t2 = t1 - 2.0hf * floor(t1 * 0.5hf) - 1.0hf;
t = abs(t2);
Expand Down Expand Up @@ -105,8 +105,8 @@ f16vec4 IPSampleLinearWithTileMode(sampler2D tex,
f16vec2 half_texel,
float16_t x_tile_mode,
float16_t y_tile_mode) {
if (x_tile_mode == float16_t(kTileModeDecal) && (coords.x < 0.0hf || coords.x >= 1.0hf) ||
y_tile_mode == float16_t(kTileModeDecal) && (coords.y < 0.0hf || coords.y >= 1.0hf)) {
if (x_tile_mode == kTileModeDecal && (coords.x < 0.0hf || coords.x >= 1.0hf) ||
y_tile_mode == kTileModeDecal && (coords.y < 0.0hf || coords.y >= 1.0hf)) {
return f16vec4(0.0hf);
}

Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/shaders/blending/advanced_blend.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main() {
IPSampleWithTileMode(texture_sampler_dst, // sampler
v_dst_texture_coords, // texture coordinates
blend_info.dst_y_coord_scale, // y coordinate scale
float16_t(kTileModeDecal) // tile mode
kTileModeDecal // tile mode
) * blend_info.dst_input_alpha;

f16vec4 dst = IPUnpremultiply(dst_sample);
Expand All @@ -38,7 +38,7 @@ void main() {
texture_sampler_src, // sampler
v_src_texture_coords, // texture coordinates
blend_info.src_y_coord_scale, // y coordinate scale
float16_t(kTileModeDecal) // tile mode
kTileModeDecal // tile mode
));

f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a;
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/shaders/morphology_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void main() {
texture_sampler, // sampler
texture_coords, // texture coordinates
frag_info.texture_sampler_y_coord_scale, // y coordinate scale
float16_t(kTileModeDecal) // tile mode
kTileModeDecal // tile mode
);
if (frag_info.morph_type == float16_t(kMorphTypeDilate)) {
if (frag_info.morph_type == kMorphTypeDilate) {
result = max(color, result);
} else {
result = min(color, result);
Expand Down