Skip to content

Instantly share code, notes, and snippets.

@chikatoike
Created July 28, 2013 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chikatoike/6097450 to your computer and use it in GitHub Desktop.
Save chikatoike/6097450 to your computer and use it in GitHub Desktop.
F# WPF HLSL Shader
// http://blogs.msdn.com/b/hiroyuk/archive/2010/09/28/10068491.aspx
open System
open System.Windows
open System.Windows.Controls
open System.Windows.Media.Imaging
open System.Windows.Media.Effects
type MyEffect() as this =
inherit ShaderEffect()
let InputProperty =
ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typedefof<MyEffect>, 0)
let ps = new PixelShader()
do ps.UriSource <- new Uri("..\\..\\Gray.ps", UriKind.Relative)
this.PixelShader <- ps
this.UpdateShaderValue(InputProperty)
// dependency property?
member this.Input
with get () = this.GetValue(InputProperty)
and set value = this.SetValue(InputProperty, value)
let w = new Window(Title = "title", Width = 300., Height = 300.)
w.Loaded.Add(fun _ ->
let b = new Button(Content = "button", Width = 110., Height = 23.)
b.Click.Add(fun _ -> MessageBox.Show("hello") |> ignore)
w.Content <- b
let img = new Image()
img.Source <- new BitmapImage(new Uri(@"..\..\image.png", UriKind.Relative))
img.Effect <- new MyEffect()
w.Content <- img
()
)
[<EntryPoint>][<STAThread>]
let main _ = (Application()).Run w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment