Skip to content

Commit

Permalink
[Text] added option to disable sample shading in the shader at all & …
Browse files Browse the repository at this point in the history
…version bump
  • Loading branch information
haraldsteinlechner committed Dec 21, 2023
1 parent c28d488 commit 500bec9
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 5.4.10-prerelease0005
- [Text] added option to disable sample shading

### 5.4.10-prerelease0004
- [GL] added flag to disable multidraw (experimental)

Expand Down
22 changes: 17 additions & 5 deletions src/Aardvark.Rendering.Text/Font.fs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ type Font private(impl : FontImpl, family : string) =

new(family : string) = Font(family, 400, false)


module FontRenderingSettings =
let mutable DisableSampleShading = false


type ShapeCache(r : IRuntime) =
static let cache = ConcurrentDictionary<IRuntime, ShapeCache>()

Expand All @@ -519,19 +524,26 @@ type ShapeCache(r : IRuntime) =
let boundarySurfaceCache = ConcurrentDictionary<IFramebufferSignature, IBackendSurface>()
let billboardSurfaceCache = ConcurrentDictionary<IFramebufferSignature, IBackendSurface>()


let pathShader =
if FontRenderingSettings.DisableSampleShading then
Path.Shader.pathFragmentNoSampleShading |> toEffect
else
Path.Shader.pathFragment |> toEffect

let effect =
FShade.Effect.compose [
Path.Shader.pathVertex |> toEffect
//Path.Shader.pathTrafo |> toEffect
Path.Shader.depthBiasVs |> toEffect
Path.Shader.pathFragment |> toEffect
pathShader
]

let instancedEffect =
FShade.Effect.compose [
Path.Shader.pathVertexInstanced |> toEffect
Path.Shader.depthBiasVs |> toEffect
Path.Shader.pathFragment |> toEffect
pathShader
]

let boundaryEffect =
Expand All @@ -551,22 +563,22 @@ type ShapeCache(r : IRuntime) =
FShade.Effect.compose [
Path.Shader.pathVertexBillboard |> toEffect
Path.Shader.depthBiasVs |> toEffect
Path.Shader.pathFragment |> toEffect
pathShader
]

let instancedBillboardEffect =
FShade.Effect.compose [
Path.Shader.pathVertexInstancedBillboard |> toEffect
Path.Shader.depthBiasVs |> toEffect
Path.Shader.pathFragment |> toEffect
pathShader
]

let surface (s : IFramebufferSignature) =
surfaceCache.GetOrAdd(s, fun s ->
r.PrepareEffect(
s, [
Path.Shader.pathVertex |> toEffect
Path.Shader.pathFragment |> toEffect
pathShader
]
)
)
Expand Down
55 changes: 55 additions & 0 deletions src/Aardvark.Rendering.Text/Path.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ module Path =
[<DepthLayer>] layer : float


[<TrafoOffsetAndScale>] instanceTrafo : M34d
}

type VertexNoSampleShading =
{
[<Position>] p : V4d
[<KLMKind>] klmKind : V4d
[<ShapeTrafoR0>] tr0 : V4d
[<ShapeTrafoR1>] tr1 : V4d
[<PathColor>] color : V4d

[<SamplePosition>] samplePos : V2d

[<DepthLayer>] layer : float


[<TrafoOffsetAndScale>] instanceTrafo : M34d
}

Expand Down Expand Up @@ -240,6 +256,45 @@ module Path =

}

let pathFragmentNoSampleShading(v : VertexNoSampleShading) =
fragment {
let kind = v.klmKind.W

let mutable color = v.color

if uniform.FillGlyphs then
if kind > 1.5 && kind < 3.5 then
// bezier2
let ci = v.klmKind.XYZ
let f = (ci.X * ci.X - ci.Y) * ci.Z
if f > 0.0 then
discard()

elif kind > 3.5 && kind < 5.5 then
// arc
let ci = v.klmKind.XYZ
let f = ((ci.X * ci.X + ci.Y*ci.Y) - 1.0) * ci.Z

if f > 0.0 then
discard()

elif kind > 5.5 then
let ci = v.klmKind.XYZ
let f = ci.X * ci.X * ci.X - ci.Y * ci.Z
if f > 0.0 then
discard()
else
if kind > 1.5 && kind < 3.5 then
color <- V4d.IOOI
elif kind > 3.5 && kind < 5.5 then
color <- V4d.OIOI
elif kind > 5.5 then
color <- V4d.OOII

return color

}

let boundaryVertex (v : Vertex) =
vertex {
return { v with p = uniform.ModelViewProjTrafo * v.p }
Expand Down

0 comments on commit 500bec9

Please sign in to comment.