Skip to content

Commit

Permalink
skiasharp 3 update
Browse files Browse the repository at this point in the history
  • Loading branch information
kikipoulet committed Feb 20, 2025
1 parent 948cff3 commit 5672b0e
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 188 deletions.
26 changes: 13 additions & 13 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Avalonia.AvaloniaEdit" Version="11.1.0" />
<PackageVersion Include="Avalonia.Controls.ColorPicker" Version="11.2.1" />
<PackageVersion Include="Avalonia.Desktop" Version="11.2.1" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.2.1" />
<PackageVersion Include="Avalonia.Controls.ColorPicker" Version="11.2.4" />
<PackageVersion Include="Avalonia.Desktop" Version="11.2.4" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.2.4" />
<PackageVersion Include="Avalonia.Diagnostics" Version="11.2.1" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.2.1" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.2.4" />
<PackageVersion Include="AvaloniaEdit.TextMate" Version="11.1.0" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageVersion Include="Dock.Model" Version="11.2.0" />
<PackageVersion Include="Dock.Model.Mvvm" Version="11.2.0" />
<PackageVersion Include="Dock.Serializer" Version="11.2.0" />
<PackageVersion Include="Material.Icons.Avalonia" Version="2.1.10" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Material.Icons.Avalonia" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
<PackageVersion Include="ShowMeTheXaml.Avalonia" Version="1.5.1" />
<PackageVersion Include="ShowMeTheXaml.Avalonia.Generator" Version="1.5.1" />
<PackageVersion Include="Avalonia" Version="11.2.1" />
<PackageVersion Include="Avalonia.Skia" Version="11.2.1" />
<PackageVersion Include="SkiaSharp" Version="2.88.8" />
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.2.1" />
<PackageVersion Include="Avalonia.Themes.Simple" Version="11.2.1" />
<PackageVersion Include="Avalonia" Version="11.2.4" />
<PackageVersion Include="Avalonia.Skia" Version="11.2.4" />
<PackageVersion Include="SkiaSharp" Version="3.118.0-preview.2.3" />
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.2.4" />
<PackageVersion Include="Avalonia.Themes.Simple" Version="11.2.4" />
<PackageVersion Include="Dock.Avalonia" Version="11.2.0" />
<PackageVersion Include="Dock.Model.Avalonia" Version="11.2.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
</ItemGroup>
</Project>
7 changes: 0 additions & 7 deletions SukiUI.Demo/Assets/space.sksl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ const float darkmatter =0.300;
const float distfading =0.730;
const float saturation =0.850;

float mod(float x, float y) {
return x - y * floor(x / y);
}

vec3 mod(vec3 x, vec3 y) {
return vec3(mod(x.x,y.x), mod(x.y,y.y), mod(x.z,y.z));
}

half4 main( vec2 fragCoord )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void OpenMessageBoxStyleDialog()
.OfType(SelectedType)
.WithTitle("MessageBox style dialog.")
.WithContent("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.")
.WithActionButton("Close " + SelectedType.ToString(), _ => { }, true, "Flat", "Accent")
.WithActionButton("Close " + SelectedType.ToString(), _ => { }, true, "Flat")
.Dismiss().ByClickingBackground()
.TryShow();
}
Expand Down
5 changes: 1 addition & 4 deletions SukiUI/Content/Shaders/Background/backgroundshadcn.sksl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}


vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(
Expand Down
5 changes: 1 addition & 4 deletions SukiUI/Content/Shaders/Background/bubble.sksl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}


vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(
Expand Down
5 changes: 1 addition & 4 deletions SukiUI/Content/Shaders/Background/bubblestrong.sksl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}


vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(
Expand Down
5 changes: 1 addition & 4 deletions SukiUI/Content/Shaders/Background/gradient.sksl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}


vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(
Expand Down
5 changes: 1 addition & 4 deletions SukiUI/Content/Shaders/Background/gradientdarker.sksl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}


vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(
Expand Down
74 changes: 27 additions & 47 deletions SukiUI/Content/Shaders/Background/gradientsoft.sksl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}


vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(
Expand All @@ -13,10 +10,10 @@ vec3 blendOverlay(vec3 base, vec3 blend) {

vec3 blendOverlayDark(vec3 base, vec3 blend) {
vec3 result;
result.r = (base.r < 0.5) ? (2 * base.r * blend.r) : (4 - 1.5 * (3 - base.r) * (4 - blend.r));
result.g = (base.g < 0.5) ? (2* base.g * blend.g) : (4 - 1.5 * (3 - base.g) * (4 - blend.g));
result.b = (base.b < 0.5) ? (2 * base.b * blend.b) : (4 - 1.5 * (3 - base.b) * (4 - blend.b));
return mix(base, clamp(result, 0.0, 1.0), 0.5); // Mélange avec la couleur de base pour réduire l'assombrissement
result.r = (base.r < 0.5) ? (2.0 * base.r * blend.r) : (4.0 - 1.5 * (3.0 - base.r) * (4.0 - blend.r));
result.g = (base.g < 0.5) ? (2.0 * base.g * blend.g) : (4.0 - 1.5 * (3.0 - base.g) * (4.0 - blend.g));
result.b = (base.b < 0.5) ? (2.0 * base.b * blend.b) : (4.0 - 1.5 * (3.0 - base.b) * (4.0 - blend.b));
return mix(base, clamp(result, 0.0, 1.0), 0.5);
}

mat2 Rot(float a) {
Expand All @@ -30,10 +27,9 @@ vec2 hash(vec2 p) {
return fract(sin(p) * 43758.5453);
}

float noise(in vec2 p) {
float noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);

vec2 u = f * f * (3.0 - 2.0 * f);

float n = mix(mix(dot(-1.0 + 2.0 * hash(i + vec2(0.0, 0.0)), f - vec2(0.0, 0.0)),
Expand All @@ -45,57 +41,41 @@ float noise(in vec2 p) {

vec4 main(vec2 fragCoord) {

vec3 grayBase = vec3(0.11,0.11,0.11);

vec3 grayBase = vec3(0.11, 0.11, 0.11);
vec2 uv = fragCoord / iResolution.xy;
float ratio = iResolution.x / iResolution.y;

vec2 tuv = uv;
tuv -= .5;

float degree = noise(vec2(iTime * .15, tuv.x * tuv.y));
vec2 tuv = uv - 0.5;
float degree = noise(vec2(iTime * 0.15, tuv.x * tuv.y));

tuv.y *= 0.7 / ratio;
tuv *= Rot(radians((degree - .5) * 720. + 180.));
tuv *= Rot(radians((degree - 0.5) * 720.0 + 180.0));
tuv.y *= ratio;

float frequency = 1.;
float amplitude = 155.;
float frequency = 1.0;
float amplitude = 155.0;
float speed = iTime * 0.1;
tuv.x += sin(tuv.y * frequency + speed) / amplitude;
tuv.y += sin(tuv.x * frequency * 1.5 + speed) / (amplitude * .5);
tuv.y += sin(tuv.x * frequency * 1.5 + speed) / (amplitude * 0.5);

float opacityLayer1 = 0.95;
float opacityLayer2 = 0.85 - (iDark / 2);
float opacityLayer2 = 0.85 - (iDark / 2.0);


float iPrimaryOpacity = 1.5; // Exemple de nouvelle opacité pour iPrimary
if (iDark == 1) {
iPrimaryOpacity = 0.6;
}
float iPrimaryOpacity = (iDark == 1.0) ? 0.6 : 1.5;
vec3 iPrimaryWithOpacity = iPrimary * iPrimaryOpacity;


float iAccentOpacity = -1.05;
if (iDark == 1) {
iAccentOpacity = 4.5;
}
float iAccentOpacity = (iDark == 1.0) ? 4.5 : -1.05;
vec3 iAccentWithOpacity = iPrimary * iAccentOpacity;

vec3 layer1Color = mix(vec3(0.0), iPrimaryWithOpacity, opacityLayer1);
vec3 layer1 = mix(layer1Color, iAccentWithOpacity * 0.85, smoothstep(-.3, .4, (tuv * Rot(radians(-5.))).x));
vec3 layer1 = mix(layer1Color, iAccentWithOpacity * 0.85, smoothstep(-0.3, 0.4, (tuv * Rot(radians(-5.0))).x));

vec3 layer2Color = mix(vec3(0.0), iAccentWithOpacity, opacityLayer2);
vec3 layer2 = mix(layer2Color, iPrimaryWithOpacity * 0.65, smoothstep(-.2, .3, (tuv * Rot(radians(-5.))).x));

vec3 finalComp = mix(layer1, layer2, smoothstep(.8, -.5, tuv.y));

vec3 col;
if (iDark == 0) {
col = blendOverlay( iBase * 1.02, finalComp);
} else {
col = blendOverlayDark(grayBase, finalComp);
}

return vec4(col, iAlpha);
}
vec3 layer2 = mix(layer2Color, iPrimaryWithOpacity * 0.65, smoothstep(-0.2, 0.3, (tuv * Rot(radians(-5.0))).x));

vec3 finalComp = mix(layer1, layer2, smoothstep(0.8, -0.5, tuv.y));

vec3 col = (iDark == 0.0) ? blendOverlay(iBase * 1.02, finalComp) : blendOverlayDark(grayBase, finalComp);

return half4(col, iAlpha);
}
4 changes: 0 additions & 4 deletions SukiUI/Content/Shaders/Background/waves.sksl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ float mod(float x, float y) {
return x - y * floor(x / y);
}

float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}

vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(
Expand Down
43 changes: 0 additions & 43 deletions SukiUI/Content/Shaders/Loading/glow.sksl
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,6 @@ uniform vec3 iForeground;

const float pi = 3.14159265358979323846;

float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}

float atan(float y, float x) {
// Constants for the series expansion
const float pi_2 = pi / 2.0;

// Handle special cases
if (x == 0.0) {
if (y > 0.0) return pi_2;
if (y < 0.0) return -pi_2;
return 0.0; // Undefined, but return 0
}

float abs_y = abs(y) + 1e-10; // Avoid division by zero

// Compute the arctangent of y/x
float angle;
if (abs(x) > abs_y) {
float z = y / x;
float zz = z * z;
angle = z * (0.999866 + zz * (-0.3302995 + zz * (0.180141 + zz * (-0.085133 + zz * 0.020835))));
if (x < 0.0) {
if (y < 0.0) {
angle -= pi;
} else {
angle += pi;
}
}
} else {
float z = x / y;
float zz = z * z;
angle = pi_2 - z * (0.999866 + zz * (-0.3302995 + zz * (0.180141 + zz * (-0.085133 + zz * 0.020835))));
if (y < 0.0) {
angle -= pi;
}
}

return angle;
}

vec4 main(vec2 fragCoord) {
float radius = 0.3;
float lineWidth = 2.0; // in pixels
Expand Down
13 changes: 5 additions & 8 deletions SukiUI/Content/Shaders/Loading/pellets.sksl
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
uniform vec3 iForeground;

float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}


float A(vec2 p, float a) {
a *= 3.14159;\
a *= 3.14159;
vec2 s = vec2(sin(a), cos(a));
p.x = abs(p.x);
return ((s.y * p.x > s.x * p.y) ? length(p - s * .6) :
abs(length(p) - .6)) - .07;
}

mat2 D(float a) {
a *= 3.14159;\
a *= 3.14159;
vec2 s = vec2(sin(a), cos(a));
return mat2(s.y, -s.x, s.x, s.y);
}
Expand All @@ -23,8 +20,8 @@ vec4 main(vec2 fragCoord) {
vec2 r = iResolution.xy, p = (2. * fragCoord - r) / r.y;
float T = iTime * 1.0;
float d = A(p * D(1. - 0.125 * floor(T)), 0.4375); // distance to longest arc
float i;
for (i = 0.0; i < 1.0; i += 0.5)

for (float i = 0.0; i < 1.0; i += 0.5)
d = min(A(p * D(mix(-0.5, 0.625, fract(T / 2.0 + i)) - 0.125 * T), 0.0625), d); // distance to shorter arcs ("pellets")

// Ajustement de la largeur de la ligne
Expand Down
42 changes: 0 additions & 42 deletions SukiUI/Content/Shaders/Loading/simple.sksl
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,6 @@ uniform vec3 iForeground;

const float pi = 3.14159265358979323846;

float smoothstep(float a, float b, float x) {
float t = clamp((x - a) / (b - a), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}

float atan(float y, float x) {
// Constants for the series expansion
const float pi_2 = pi / 2.0;

// Handle special cases
if (x == 0.0) {
if (y > 0.0) return pi_2;
if (y < 0.0) return -pi_2;
return 0.0; // Undefined, but return 0
}

float abs_y = abs(y) + 1e-10; // Avoid division by zero

// Compute the arctangent of y/x
float angle;
if (abs(x) > abs_y) {
float z = y / x;
float zz = z * z;
angle = z * (0.999866 + zz * (-0.3302995 + zz * (0.180141 + zz * (-0.085133 + zz * 0.020835))));
if (x < 0.0) {
if (y < 0.0) {
angle -= pi;
} else {
angle += pi;
}
}
} else {
float z = x / y;
float zz = z * z;
angle = pi_2 - z * (0.999866 + zz * (-0.3302995 + zz * (0.180141 + zz * (-0.085133 + zz * 0.020835))));
if (y < 0.0) {
angle -= pi;
}
}

return angle;
}

vec4 main(vec2 fragCoord) {
float radius = 0.3;
Expand Down
7 changes: 4 additions & 3 deletions SukiUI/Utilities/Effects/SukiEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private SukiEffect(string shaderString, string rawShaderString)
{
_shaderString = shaderString;
_rawShaderString = rawShaderString;
var compiledEffect = SKRuntimeEffect.Create(_shaderString, out var errors);
var compiledEffect = SKRuntimeEffect.CreateShader(_shaderString, out var errors);
Effect = compiledEffect ?? throw new ShaderCompilationException(errors);
}

Expand Down Expand Up @@ -160,7 +160,8 @@ internal SKShader ToShaderWithUniforms(float timeSeconds, ThemeVariant activeVar
{ "iDark", activeVariant == ThemeVariant.Dark ? 1f : 0f },
{ "iAlpha", alpha }
};
return Effect.ToShader(false, inputs);

return Effect.ToShader(inputs);
}

internal SKShader ToShaderWithCustomUniforms(Func<SKRuntimeEffect,SKRuntimeEffectUniforms> uniformFactory, float timeSeconds, Rect bounds,
Expand All @@ -170,7 +171,7 @@ internal SKShader ToShaderWithCustomUniforms(Func<SKRuntimeEffect,SKRuntimeEffec
uniforms.Add("iResolution", new[] { (float)bounds.Width, (float)bounds.Height, 0f });
uniforms.Add("iTime", timeSeconds * animationScale);
uniforms.Add("iAlpha", alpha);
return Effect.ToShader(false, uniforms);
return Effect.ToShader(uniforms);
}

/// <summary>
Expand Down

0 comments on commit 5672b0e

Please sign in to comment.