Table of Contents

Class SkiaShaderEffect

Namespace
DrawnUi.Draw
Assembly
DrawnUi.Maui.dll

IPostRendererEffect

public class SkiaShaderEffect : SkiaEffect, INotifyPropertyChanged, IDisposable, IPostRendererEffect, ISkiaEffect, ICanBeUpdatedWithContext, ICanBeUpdated
Inheritance
SkiaShaderEffect
Implements
Derived
Inherited Members
Extension Methods

Fields

AutoCreateInputTextureProperty

public static readonly BindableProperty AutoCreateInputTextureProperty

Field Value

BindableProperty

CompiledShader

protected SKRuntimeEffect CompiledShader

Field Value

SKRuntimeEffect

FilterModeProperty

public static readonly BindableProperty FilterModeProperty

Field Value

BindableProperty

MipmapModeProperty

public static readonly BindableProperty MipmapModeProperty

Field Value

BindableProperty

PaintWithShader

protected SKPaint PaintWithShader

Field Value

SKPaint

ShaderCodeProperty

public static readonly BindableProperty ShaderCodeProperty

Field Value

BindableProperty

ShaderSourceProperty

public static readonly BindableProperty ShaderSourceProperty

Field Value

BindableProperty

ShaderTemplateProperty

public static readonly BindableProperty ShaderTemplateProperty

Field Value

BindableProperty

TileModeProperty

public static readonly BindableProperty TileModeProperty

Field Value

BindableProperty

UseContextProperty

public static readonly BindableProperty UseContextProperty

Field Value

BindableProperty

_template

protected string _template

Field Value

string

_templatePlacehodler

protected string _templatePlacehodler

Field Value

string

_uniformImageResolution

protected readonly float[] _uniformImageResolution

Field Value

float[]

Properties

AquiredBackground

True once the Once-mode snapshot has been captured. Reset to false to re-capture.

public bool AquiredBackground { get; set; }

Property Value

bool

AutoCreateInputTexture

Should create a texture from the current drawing to pass to shader as uniform shader iImage1, default is True. You need this set to False only if your shader is output-only.

public bool AutoCreateInputTexture { get; set; }

Property Value

bool

BlendMode

Blend mode used when drawing the shader effect on the canvas. Default is SrcOver. For generative overlay effects (UseBackground = Never), use Plus for additive blending.

public SKBlendMode BlendMode { get; set; }

Property Value

SKBlendMode

FilterMode

public SKFilterMode FilterMode { get; set; }

Property Value

SKFilterMode

LoadedCode

public string LoadedCode { get; set; }

Property Value

string

MipmapMode

public SKMipmapMode MipmapMode { get; set; }

Property Value

SKMipmapMode

MouseCurrent

Shadertoy conventions current mouse position (or drag position)

public PointF MouseCurrent { get; set; }

Property Value

PointF

MouseInitial

Shadertoy conventions where click/drag started. If zero could mean not dragging.

public PointF MouseInitial { get; set; }

Property Value

PointF

NeedApply

public override bool NeedApply { get; }

Property Value

bool

ShaderCode

Changing this directly will force the shader to recompile

public string ShaderCode { get; set; }

Property Value

string

ShaderSource

FIlename from resources, ex: @"Shaders\blit.sksl"

public string ShaderSource { get; set; }

Property Value

string

ShaderTemplate

public string ShaderTemplate { get; set; }

Property Value

string

TileMode

Tile mode for input textures

public SKShaderTileMode TileMode { get; set; }

Property Value

SKShaderTileMode

TimeSeconds

Normally will be automatically set in Render method from context FrameTimeNanos

public float TimeSeconds { get; set; }

Property Value

float

UseBackground

Controls how/when the background texture is captured. Default is Always.

public PostRendererEffectUseBackgroud UseBackground { get; set; }

Property Value

PostRendererEffectUseBackgroud

UseContext

Use either context or global Superview background, default is True.

public bool UseContext { get; set; }

Property Value

bool

Methods

ApplyShaderSource()

protected virtual void ApplyShaderSource()

CompileShader()

Compiles the shader code - only CPU-side compilation

protected virtual void CompileShader()

CompileShader(string, bool, Action<string>)

protected virtual void CompileShader(string shaderCode, bool useCache = true, Action<string> onError = null)

Parameters

shaderCode string
useCache bool
onError Action<string>

CreatePrimaryTextureShader(SKImage)

protected virtual SKShader CreatePrimaryTextureShader(SKImage source)

Parameters

source SKImage

Returns

SKShader

CreateShader(DrawingContext, SKImage)

Creates shader fresh each time - no caching of GPU resources

public virtual SKShader CreateShader(DrawingContext ctx, SKImage source)

Parameters

ctx DrawingContext
source SKImage

Returns

SKShader

CreateSnapshot(SkiaDrawingContext, SKRect)

Create snapshot from the current parent control drawing state to use as input texture for the shader

protected virtual SKImage CreateSnapshot(SkiaDrawingContext ctx, SKRect destination)

Parameters

ctx SkiaDrawingContext
destination SKRect

Returns

SKImage

CreateTexturesUniforms(SkiaDrawingContext, SKRect, SKShader)

Creates texture uniforms fresh each time

protected virtual SKRuntimeEffectChildren CreateTexturesUniforms(SkiaDrawingContext ctx, SKRect destination, SKShader primaryTexture)

Parameters

ctx SkiaDrawingContext
destination SKRect
primaryTexture SKShader

Returns

SKRuntimeEffectChildren

CreateUniforms(SKRect)

Creates uniforms fresh each time

protected virtual SKRuntimeEffectUniforms CreateUniforms(SKRect destination)

Parameters

destination SKRect

Returns

SKRuntimeEffectUniforms

Flush(SkiaDrawingContext)

protected void Flush(SkiaDrawingContext ctx)

Parameters

ctx SkiaDrawingContext

GetPrimaryTextureImage(SkiaDrawingContext, SKRect)

Returns the background texture according to the current UseBackground mode. Always — live snapshot (or parent cache) every frame. Once — snapshot taken on first call, frozen thereafter; reset AquiredBackground to re-capture. Never — returns null; shader must not require iImage1.

protected virtual SKImage GetPrimaryTextureImage(SkiaDrawingContext ctx, SKRect destination)

Parameters

ctx SkiaDrawingContext
destination SKRect

Returns

SKImage

NeedChangeSource(BindableObject, object, object)

protected static void NeedChangeSource(BindableObject bindable, object oldvalue, object newvalue)

Parameters

bindable BindableObject
oldvalue object
newvalue object

NormalizeShaderCode(string)

public string NormalizeShaderCode(string shaderText)

Parameters

shaderText string

Returns

string

OnDisposing()

Simplified dispose - only CPU-side resources

protected override void OnDisposing()

ReleaseFrozenSnapshot()

public void ReleaseFrozenSnapshot()

Render(DrawingContext)

EffectPostRenderer

public virtual void Render(DrawingContext ctx)

Parameters

ctx DrawingContext

SendError(string)

protected void SendError(string error)

Parameters

error string

ShouldDisposePreviousTexture(SKImage)

Checks if image is a new snapshot that needs disposal this frame. Frozen snapshots are managed by ReleaseFrozenSnapshot; parent cache is never owned.

protected virtual bool ShouldDisposePreviousTexture(SKImage image)

Parameters

image SKImage

Returns

bool

Events

OnCompilationError

public event EventHandler<string> OnCompilationError

Event Type

EventHandler<string>