Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement mask for ticks with the stencil buffer #389

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ public record struct SliderTexturedVertex2D : IVertex
private Vector2 drawSize;
private float radius;
private IShader shader;
private IShader maskShader;

private IUniformBuffer<SliderUniform> shaderData;
private IUniformBuffer<MaskUniform> maskData;

[StructLayout(LayoutKind.Sequential, Pack = 1)]
private record struct SliderUniform
Expand All @@ -79,14 +77,6 @@ private record struct SliderUniform
private UniformPadding4 _p4;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
private record struct MaskUniform
{
public UniformBool WriteDepth;

private UniformPadding12 _p1;
}

// We multiply the size param by 3 such that the amount of vertices is a multiple of the amount of vertices
// per primitive (triangles in this case). Otherwise overflowing the batch will result in wrong
// grouping of vertices into primitives.
Expand Down Expand Up @@ -128,7 +118,6 @@ public override void ApplyState()
drawSize = Source.DrawSize;
radius = Source.PathRadius;
shader = Source.hitFadeTextureShader;
maskShader = Source.depthMaskShader;

var center = Source.PositionInBoundingBox(Vector2.Zero);
var edge = Source.PositionInBoundingBox(new Vector2(Source.PathDistance, 0));
Expand Down Expand Up @@ -360,55 +349,47 @@ public override void Draw(IRenderer renderer)
Reverse = reverse
};

maskData ??= renderer.CreateUniformBuffer<MaskUniform>();
//maskData ??= renderer.CreateUniformBuffer<MaskUniform>();

halfCircleBatch ??= renderer.CreateLinearBatch<SliderTexturedVertex2D>(max_resolution * 100 * 3, 10, PrimitiveTopology.Triangles);
quadBatch ??= renderer.CreateQuadBatch<SliderTexturedVertex2D>(200, 10);

if (texture?.Available != true || segments.Length == 0)
return;

renderer.PushDepthInfo(new DepthInfo(depthTest: true, writeDepth: true, function: BufferTestFunction.Always));
maskData.Data = maskData.Data with { WriteDepth = true };
maskShader.Bind();
maskShader.BindUniformBlock("m_maskParameters", maskData);
shader.Bind();
shader.BindUniformBlock("m_sliderParameters", shaderData);

renderer.PushStencilInfo(new StencilInfo(stencilTest: true, testValue: 255, testFunction: BufferTestFunction.Always, passed: StencilOperation.Replace));

foreach (var i in innerTicks)
{
renderer.DrawQuad(renderer.WhitePixel, i, Color4.Transparent);
}

maskShader.Unbind();
renderer.PopDepthInfo();
renderer.PopStencilInfo();
renderer.PushStencilInfo(new StencilInfo(stencilTest: true, testValue: 255, testFunction: BufferTestFunction.NotEqual, passed: StencilOperation.Keep));

shader.Bind();
shader.BindUniformBlock("m_sliderParameters", shaderData);
texture.Bind();

updateVertexBuffer();

shader.Unbind();

renderer.PushDepthInfo(new DepthInfo(depthTest: true, writeDepth: true, function: BufferTestFunction.Always));
maskData.Data = maskData.Data with { WriteDepth = false };
maskShader.Bind();
maskShader.BindUniformBlock("m_maskParameters", maskData);

// not needed right now, but it clears the stencil mask
renderer.PushStencilInfo(new StencilInfo(stencilTest: true, testValue: 0, testFunction: BufferTestFunction.Always, passed: StencilOperation.Replace));
foreach (var i in innerTicks)
{
renderer.DrawQuad(renderer.WhitePixel, i, Color4.Transparent);
}
renderer.PopStencilInfo();

maskShader.Unbind();
renderer.PopDepthInfo();
renderer.PopStencilInfo();
shader.Unbind();
}

protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

shaderData?.Dispose();
maskData?.Dispose();
halfCircleBatch?.Dispose();
quadBatch?.Dispose();
segments.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ private static Texture generateSmoothPathTexture(IRenderer renderer, float radiu
public partial class SliderPath : Drawable
{
public IEnumerable<DrawableSliderRepeat> Ticks = Array.Empty<DrawableSliderRepeat>();
private IShader depthMaskShader { get; set; }
private IShader hitFadeTextureShader { get; set; }

private readonly List<Vector3> vertices = new();
Expand Down Expand Up @@ -220,7 +219,6 @@ private void load(IRenderer renderer, ShaderManager shaders)
{
texture = renderer.WhitePixel;

depthMaskShader = shaders.Load("DepthMask", "DepthMask");
hitFadeTextureShader = shaders.Load("SliderPositionAndColour", "Slider");
}

Expand Down
32 changes: 0 additions & 32 deletions osu.Game.Rulesets.Tau/Resources/Shaders/sh_DepthMask.fs

This file was deleted.

6 changes: 0 additions & 6 deletions osu.Game.Rulesets.Tau/Resources/Shaders/sh_DepthMask.vs

This file was deleted.

4 changes: 0 additions & 4 deletions osu.Game.Rulesets.Tau/osu.Game.Rulesets.Tau.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
<DependentUpon>UI.resx</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Remove="Resources\Shaders\sh_DepthMask.fs" />
<None Remove="Resources\Shaders\sh_DepthMask.vs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Game" Version="2023.717.0" />
</ItemGroup>
Expand Down