This commit is contained in:
firedef 2022-07-21 23:47:52 +03:00
Родитель 5335358883
Коммит c5d2c109cd
13 изменённых файлов: 121 добавлений и 74 удалений

Просмотреть файл

@ -1,3 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

Просмотреть файл

@ -6,6 +6,6 @@ namespace SomeChartsAvaloniaExamples;
internal class Program {
[STAThread]
public static void Main(string[] args) {
ScatterChartExample.Run();
LineChartExample.Run();
}
}

Просмотреть файл

@ -54,6 +54,15 @@
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.12" />
<PackageReference Include="MathStuff" Version="1.0.0" />
<PackageReference Include="runtime.any.System.Collections" Version="4.3.0" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.IO" Version="4.3.0" />
<PackageReference Include="System.Resources.ResourceManager" Version="4.3.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
<PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SomeChartsUiAvalonia\SomeChartsUiAvalonia.csproj" />

Просмотреть файл

@ -48,7 +48,7 @@ public static class LineChartExample {
// amount of points in current line
// this value will not affect line length, because it`s using culling (generate mesh and render only visible parts)
// you can also use collections by 'ArrayChartData<T>()' and 'CollectionChartData<T>()'
const int lineLength = 8192;
const int lineLength = 81920;
IChartData<float> data = new FuncChartData<float>(j => LineChartFunc(j, i * 10), lineLength);
// colors of line

Просмотреть файл

@ -28,7 +28,7 @@ public class LineChart : RenderableBase, IDownsample {
}
public LineChart(IChartData<float> values, indexedColor color, ChartsCanvas c) : this(values, new ConstChartData<indexedColor>(color), c) { }
public float downsampleMultiplier { get; set; } = .5f;
public float downsampleMultiplier { get; set; } = .25f;
public float elementScale { get; set; } = 100;
protected override unsafe void GenerateMesh() {

Просмотреть файл

@ -40,14 +40,15 @@ public class Ruler : RenderableBase {
public bool useStyledText = false;
private readonly TextMesh _textMesh;
private Font _font;
private Font? _font;
public Ruler(ChartsCanvas owner) : base(owner) {
_textMesh = owner.factory.CreateTextMesh(this);
uint resolution = 32;
_font = Font.LoadFromPath("data/FiraCode-VariableFont_wght.ttf", renderer.owner, resolution);
Font fallbackFont = Font.LoadFromPath("data/NotoSansJP-Regular.otf", renderer.owner, resolution);
_font.fallbacks.Add(fallbackFont);
_font = canvas.GetDefaultFont();
//Font fallbackFont = Font.LoadFromPath("data/NotoSansJP-Regular.otf", renderer.owner, resolution);
//_font.fallbacks.Add(fallbackFont);
updateFrameSkip = 1;
}
@ -79,7 +80,7 @@ public class Ruler : RenderableBase {
//DrawText(txt, positions, font, labelColor.GetColor(), screenSpaceLabels ? fontSize * scaleVal : fontSize, skipLabels..);
_textMesh.ClearMeshes();
for (int i = 0; i < txt.Length; i++) {
_textMesh.GenerateMesh(txt[i], _font, screenSpaceLabels ? fontSize * scaleVal : fontSize, labelColor.GetColor(), new(positions[i]));
_textMesh.GenerateMesh(txt[i], _font ?? canvas.GetDefaultFont(), screenSpaceLabels ? fontSize * scaleVal : fontSize, labelColor.GetColor(), new(positions[i]));
}
}

Просмотреть файл

@ -14,64 +14,10 @@
</PropertyGroup>
<ItemGroup>
<None Remove=".gitignore" />
<None Update="data\shaders\basic.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\basic.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\basicTextured.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\basicTextured.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\bloom.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\bloom.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\diffuse.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\diffuse.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\fxaa.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\fxaa.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\text.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\text.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\shapes.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\shapes.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\smooth.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\smooth.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="src\impl\opengl\GlInterfaceGen.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>GlInterfaceGen.cs</LastGenOutput>
</None>
<None Update="data\shaders\uberPostFx.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\shaders\uberPostFx.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.12" />
@ -95,4 +41,78 @@
<DependentUpon>GlInterfaceGen.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Remove="data\shaders\basic.frag" />
<Content Include="data\shaders\basic.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\basic.vert" />
<Content Include="data\shaders\basic.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\basicTextured.frag" />
<Content Include="data\shaders\basicTextured.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\basicTextured.vert" />
<Content Include="data\shaders\basicTextured.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\bloom.frag" />
<Content Include="data\shaders\bloom.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\bloom.vert" />
<Content Include="data\shaders\bloom.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\diffuse.frag" />
<Content Include="data\shaders\diffuse.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\diffuse.vert" />
<Content Include="data\shaders\diffuse.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\fxaa.frag" />
<Content Include="data\shaders\fxaa.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\fxaa.vert" />
<Content Include="data\shaders\fxaa.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\shapes.frag" />
<Content Include="data\shaders\shapes.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\shapes.vert" />
<Content Include="data\shaders\shapes.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\smooth.frag" />
<Content Include="data\shaders\smooth.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\smooth.vert" />
<Content Include="data\shaders\smooth.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\text.frag" />
<Content Include="data\shaders\text.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\text.vert" />
<Content Include="data\shaders\text.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\uberPostFx.frag" />
<Content Include="data\shaders\uberPostFx.frag">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="data\shaders\uberPostFx.vert" />
<Content Include="data\shaders\uberPostFx.vert">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

Просмотреть файл

@ -6,6 +6,7 @@ in vec3 fragNormal;
in vec2 fragUv;
in vec4 fragCol;
in vec2 texCoord;
in vec2 subPixelSize;
// uniforms
uniform float u_gamma = 0.3;
@ -32,17 +33,25 @@ float sample(vec2 coord, float gammaAdd) {
return alpha;
}
vec4 sampleSubpixel(vec2 coord, float gammaAdd, float offset) {
float r = sample(coord - vec2(offset, 0), gammaAdd);
float g = sample(coord, gammaAdd);
float b = sample(coord + vec2(offset, 0), gammaAdd);
float a = (r + g + b) * .333333;
return vec4(r,g,b,a);
}
void main() {
const float rA = .4;
const float bA = .4;
float shift_ = fract(gl_FragCoord.x);
float shift_ = fract(subPixelSize.x);
float fragGamma = (fragCol.x + fragCol.y + fragCol.z) * .02;
float s = -dFdx(texCoord.x) / 3.0;
if (textQuality == 1) {
vec4 col0 = vec4(sample(texCoord, fragGamma));
vec4 col1 = vec4(sample(texCoord + vec2(-s,0), fragGamma));
vec4 col0 = sampleSubpixel(texCoord, fragGamma, s);
vec4 col1 = sampleSubpixel(texCoord + vec2(s,0), fragGamma, s);
vec4 curCol = col0;
if (shift_ <= 1/3.0) {

Просмотреть файл

@ -8,6 +8,7 @@ in vec4 col;
// uniforms
uniform mat4 mvp;
uniform vec2 screenSize;
// outputs
out vec3 fragPos;
@ -16,13 +17,16 @@ out vec2 fragUv;
out vec4 fragCol;
out vec2 texCoord;
out vec2 subPixelSize;
#extension GL_ARB_gpu_shader5 : enable
void main() {
float scale = 1.0;
vec3 scaledPos = pos * scale;
gl_Position = mvp * vec4(pos, 1.0);
subPixelSize = 0.33333 / screenSize;
vec2 posXy = floor(gl_Position.xy / subPixelSize) * subPixelSize;
gl_Position = vec4(posXy, gl_Position.zw);
gl_Position = mvp * vec4(scaledPos, 1.0);
fragPos = gl_Position.xyz;
fragUv = uv;
fragCol = col;

Просмотреть файл

@ -103,7 +103,9 @@ public class AvaloniaGlChartsCanvas : CustomGlControlBase {
ch.stickRange = isVertical ? new(0, 0, length, 0) : new(0, 0, 0, length);
return ch;
}
}
public Ruler AddRuler(Orientation orientation, int length, Func<int, string> names) => AddRuler(orientation, length, new FuncChartManagedData<string>(names, 1));
public Ruler AddRulerWithoutLabels(Orientation orientation, int length) {
bool isVertical = (orientation & Orientation.vertical) != 0;

Просмотреть файл

@ -98,10 +98,10 @@ public class GlMesh : Mesh {
#region rendering
public void Render(Material? material, Matrix4x4 mvp, float3 cameraPos) {
public void Render(Material? material, Matrix4x4 mvp, float3 cameraPos, float2 screenSize) {
if (material is {shader: not GlShader}) return;
if (!PrepareBuffers()) return;
PrepareShader(material, mvp, cameraPos);
PrepareShader(material, mvp, cameraPos, screenSize);
GlInfo.CheckError("after uniforms");
GlInfo.gl!.DrawElements(GL_TRIANGLES, indexes.count, GL_UNSIGNED_SHORT, IntPtr.Zero);
@ -121,7 +121,7 @@ public class GlMesh : Mesh {
return true;
}
private static void PrepareShader(Material? material, Matrix4x4 mvp, float3 cameraPos) {
private static void PrepareShader(Material? material, Matrix4x4 mvp, float3 cameraPos, float2 screenSize) {
GlShader shader = material == null || ChartsRenderSettings.useDefaultMat ? GlShaders.basic : (GlShader)material.shader;
if (shader.shaderProgram == 0) shader.TryCompile();
if (shader.shaderProgram == 0) return;
@ -132,6 +132,7 @@ public class GlMesh : Mesh {
shader.TrySetUniform("mvp", mvp);
shader.TrySetUniform("cameraPos", cameraPos);
shader.TrySetUniform("time", (float)DateTime.Now.TimeOfDay.TotalMilliseconds);
shader.TrySetUniform("screenSize", screenSize);
if (material == null) return;
shader.TryApplyMaterial(material);

Просмотреть файл

@ -41,6 +41,6 @@ public class GlChartsBackend : ChartsBackendBase {
Matrix4x4 mvp = transform.modelMatrix * owner.transform.viewMatrix * owner.transform.projectionMatrix;
obj.Render(material, mvp, camPos);
obj.Render(material, mvp, camPos, owner.transform.screenBounds.widthHeight);
}
}

Просмотреть файл

@ -22,7 +22,7 @@ public class GlPostProcessor : PostProcessor {
GlMesh glMesh = (GlMesh) mesh;
UpdateVertices();
glMesh.Render(material, mvp, float3.zero);
glMesh.Render(material, mvp, float3.zero, owner.transform.screenBounds.widthHeight);
//owner.renderer.backend.DrawMesh(glMesh, material, new(0));
}
}