Class SkiaShaderEffect
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
CompiledShader
protected SKRuntimeEffect CompiledShader
Field Value
FilterModeProperty
public static readonly BindableProperty FilterModeProperty
Field Value
MipmapModeProperty
public static readonly BindableProperty MipmapModeProperty
Field Value
PaintWithShader
protected SKPaint PaintWithShader
Field Value
ShaderCodeProperty
public static readonly BindableProperty ShaderCodeProperty
Field Value
ShaderSourceProperty
public static readonly BindableProperty ShaderSourceProperty
Field Value
ShaderTemplateProperty
public static readonly BindableProperty ShaderTemplateProperty
Field Value
TileModeProperty
public static readonly BindableProperty TileModeProperty
Field Value
UseContextProperty
public static readonly BindableProperty UseContextProperty
Field Value
_template
protected string _template
Field Value
_templatePlacehodler
protected string _templatePlacehodler
Field Value
_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
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
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
FilterMode
public SKFilterMode FilterMode { get; set; }
Property Value
LoadedCode
public string LoadedCode { get; set; }
Property Value
MipmapMode
public SKMipmapMode MipmapMode { get; set; }
Property Value
MouseCurrent
Shadertoy conventions current mouse position (or drag position)
public PointF MouseCurrent { get; set; }
Property Value
MouseInitial
Shadertoy conventions where click/drag started. If zero could mean not dragging.
public PointF MouseInitial { get; set; }
Property Value
NeedApply
public override bool NeedApply { get; }
Property Value
ShaderCode
Changing this directly will force the shader to recompile
public string ShaderCode { get; set; }
Property Value
ShaderSource
FIlename from resources, ex: @"Shaders\blit.sksl"
public string ShaderSource { get; set; }
Property Value
ShaderTemplate
public string ShaderTemplate { get; set; }
Property Value
TileMode
Tile mode for input textures
public SKShaderTileMode TileMode { get; set; }
Property Value
TimeSeconds
Normally will be automatically set in Render method from context FrameTimeNanos
public float TimeSeconds { get; set; }
Property Value
UseBackground
Controls how/when the background texture is captured. Default is Always.
public PostRendererEffectUseBackgroud UseBackground { get; set; }
Property Value
UseContext
Use either context or global Superview background, default is True.
public bool UseContext { get; set; }
Property Value
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
CreatePrimaryTextureShader(SKImage)
protected virtual SKShader CreatePrimaryTextureShader(SKImage source)
Parameters
sourceSKImage
Returns
CreateShader(DrawingContext, SKImage)
Creates shader fresh each time - no caching of GPU resources
public virtual SKShader CreateShader(DrawingContext ctx, SKImage source)
Parameters
ctxDrawingContextsourceSKImage
Returns
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
ctxSkiaDrawingContextdestinationSKRect
Returns
CreateTexturesUniforms(SkiaDrawingContext, SKRect, SKShader)
Creates texture uniforms fresh each time
protected virtual SKRuntimeEffectChildren CreateTexturesUniforms(SkiaDrawingContext ctx, SKRect destination, SKShader primaryTexture)
Parameters
ctxSkiaDrawingContextdestinationSKRectprimaryTextureSKShader
Returns
CreateUniforms(SKRect)
Creates uniforms fresh each time
protected virtual SKRuntimeEffectUniforms CreateUniforms(SKRect destination)
Parameters
destinationSKRect
Returns
Flush(SkiaDrawingContext)
protected void Flush(SkiaDrawingContext ctx)
Parameters
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
ctxSkiaDrawingContextdestinationSKRect
Returns
NeedChangeSource(BindableObject, object, object)
protected static void NeedChangeSource(BindableObject bindable, object oldvalue, object newvalue)
Parameters
bindableBindableObjectoldvalueobjectnewvalueobject
NormalizeShaderCode(string)
public string NormalizeShaderCode(string shaderText)
Parameters
shaderTextstring
Returns
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
ctxDrawingContext
SendError(string)
protected void SendError(string error)
Parameters
errorstring
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
imageSKImage
Returns
Events
OnCompilationError
public event EventHandler<string> OnCompilationError