<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>bling Wiki &amp; Documentation Rss Feed</title><link>http://www.codeplex.com/bling/Wiki/View.aspx?title=Home</link><description>bling Wiki Rss Description</description><item><title>Updated Wiki: Home</title><link>http://bling.codeplex.com/wikipage?version=53</link><description>&lt;div class="wikidoc"&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=Tutorial&amp;referringTitle=Home"&gt;Tutorial Manual&lt;/a&gt; | &lt;a href="http://bling.codeplex.com/wikipage?title=FAQ&amp;referringTitle=Home"&gt;FAQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Bling is a C#-based library for easily programming images, animations, interactions, and visualizations on Microsoft's WPF/.NET. Bling is oriented towards design technologists, i.e., designers who sometimes program, to aid in the rapid prototyping of rich UI design ideas.  Students, artists, researchers, and hobbyists will also find Bling useful as a tool for quickly expressing ideas or visualizations. Bling's APIs and constructs are optimized for the fast programming of throw away code as opposed to the careful programming of production code. &lt;br /&gt;&lt;br /&gt;Bling as the following features that aid in the rapid prototyping of rich UIs:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home"&gt;Declarative constraints&lt;/a&gt;&lt;/b&gt; that maintain dynamic relationships in the UI without the need for complex event handling.  For example, &lt;i&gt;button.Width = 100 - slider.Value&lt;/i&gt; causes button to shrink as the slider thumb is moved to the right, or grow as it is moved to the left. Constraints have many benefits: they allow rich custom layouts to be expressed with very little code, they are easy animate, and they support UIs with lots of dynamic behavior. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home&amp;ANCHOR#animation"&gt;Simplified animation&lt;/a&gt;&lt;/b&gt; with one line of code. For example, &lt;i&gt;button.Left.Animate().Duration(500).To = label.Right&lt;/i&gt; will cause button to move to the right of label in 500 milliseconds. &lt;/li&gt;
&lt;li&gt;High-level &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=fungraphics&amp;referringTitle=Home"&gt;functional programming constructs&lt;/a&gt;&lt;/b&gt; for graphics programming including abstractions for &lt;a href="http://bling.codeplex.com/wikipage?title=texture&amp;referringTitle=Home"&gt;textures&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=pixel%20effect&amp;referringTitle=Home"&gt;pixel effects&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=transition&amp;referringTitle=Home"&gt;transitions&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=curve&amp;referringTitle=Home"&gt;curves&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=surface&amp;referringTitle=Home"&gt;surfaces&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=height%20field&amp;referringTitle=Home"&gt;height fields&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=normal%20map&amp;referringTitle=Home"&gt;normal maps&lt;/a&gt;, and 3D/2.5D &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=lighting&amp;referringTitle=Home"&gt;lighting&lt;/a&gt;&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;Experimental support for &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=DirectX&amp;referringTitle=Home"&gt;Direct3D 10&lt;/a&gt;&lt;/b&gt; surfaces that are defined by pixel, vertex, and geometry shaders.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=shader&amp;referringTitle=Home"&gt;Pixel shader effects&lt;/a&gt;&lt;/b&gt; without the need to write HLSL code or boilerplate code! For example, &lt;i&gt;canvas.Effect.Custom = (input, uv) =&amp;gt; new ColorBl(1d - input[uv].ScRGB, input[uv].ScA);&lt;/i&gt; defines and installs a pixel shader on a canvas that inverts the canvas's colors.  Pixel shading in Bling takes advantage of your graphics card to create rich, pixel-level effects. &lt;/li&gt;
&lt;li&gt;An experimental &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=physics&amp;referringTitle=Home"&gt;UI physics engine&lt;/a&gt;&lt;/b&gt; for integrating physics into user interfaces! The physics supported by Bling is flexible, controllable, and easy to program.  &lt;/li&gt;
&lt;li&gt;A rich library of &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=geometry&amp;referringTitle=Home"&gt;geometry routines&lt;/a&gt;&lt;/b&gt;; e.g., finding where two lines intersect, the base of a triangle, the area of triangle, or a point on Bezier curve. These routines are compatible with all of Bling's features; e.g., they can be used in express constraints, pixel shaders, or physical constraints. Bling also provides a rich API for manipulating angles in both degrees and radians.&lt;/li&gt;
&lt;li&gt;And many &lt;b&gt;smaller things&lt;/b&gt;; e.g., a frame-based background animation manager and slide presentation system.&lt;/li&gt;
&lt;li&gt;As a &lt;b&gt;lightweight wrapper&lt;/b&gt; around WPF, Bling code is completely compatible with conventional WPF code written in C#, XAML, or other .NET languages.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Bling is an open source project created by &lt;a href="mailto:sean.mcdirmid@gmail.com" class="externalLink"&gt;Sean McDirmid&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and friends to aid in design rapid prototyping. We used Bling to enhance our productivity and would like to share it with other WPF UI design prototypers.&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
Requirments: Visual Studio 2008 full or &lt;a href="http://www.microsoft.com/express/download/" class="externalLink"&gt;Express&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6" class="externalLink"&gt;.NET 3.5&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7" class="externalLink"&gt;.NET 3.5 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" class="externalLink"&gt;Visual Studio 2008 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (may not be necessary, comes with VS 2008 Express). To support WPF pixel shaders, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=c1367bc3-4676-481a-bfaa-5c15d1d7199d" class="externalLink"&gt;DirectX August 2008 runtime&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is sometimes required, although this is often already installed on your machine.&lt;br /&gt;&lt;br /&gt;As of Bling 3, DirectX 10 is also supported for Windows Vista and Windows 7 (sorry XP users!). If you want to use DirectX 10, you'll have to install the latest redistrutable; e.g., the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;amp;displaylang=en" class="externalLink"&gt;web installer&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Bling also depends on the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fcode.msdn.microsoft.com%2fWindowsAPICodePack&amp;referringTitle=Home"&gt;Windows API Code Pack&lt;/a&gt; and the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fwww.codeplex.com%2fdlr&amp;referringTitle=Home"&gt;DLR&lt;/a&gt;, but both DLLs are included in the distribution.&lt;br /&gt;&lt;br /&gt;Download the source release from the web page. An example comes with the release. To include in your own project for WPF development, simply add the Bling.Core and Bling.WPF projects to your solution, and then add a reference to the Bling project from your own project. For DirectX 10 development, add and refer to the Bling.Core, Bling.WPF, and Bling.D3D10 projects.&lt;br /&gt;
&lt;h3&gt;Example&lt;/h3&gt;
The code used in this getting started example is located in the GettingStarted.cs file of the GettingStarted project in the release. We start of this example by creating a &lt;b&gt;thumb&lt;/b&gt; and &lt;b&gt;label&lt;/b&gt; on a &lt;b&gt;canvas&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  CenterPosition = canvas.Size - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(20,20),
  ZIndex = 1,
};
LabelBl label = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LabelBl(canvas) {
  Content = &lt;span style="color:#A31515;"&gt;&amp;quot;Hello World: &amp;quot;&lt;/span&gt;.Bl() + thumb.CenterPosition.ToStringBl(),
  Font = { Weight = FontWeights.SemiBold, Size = 80, },
  CenterPosition = canvas.CenterSize,
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The first statement creates a red &lt;b&gt;thumb&lt;/b&gt; that can be dragged (&lt;i&gt;CanDrag = true&lt;/i&gt;).  The initial location of the &lt;b&gt;thumb&lt;/b&gt; is in the right hand bottom corner of the &lt;b&gt;canvas&lt;/b&gt;,&lt;br /&gt;while its Z index is set to one.  The second statement creates a &lt;b&gt;label&lt;/b&gt; whose content is bound to &amp;quot;Hello World&amp;quot; prepended to the current location of the &lt;b&gt;thumb&lt;/b&gt;.  By default,&lt;br /&gt;assignments to properties in Bling are &lt;i&gt;contraints&lt;/i&gt; where the bound to property will change as the bound-to expression changes.  In our example, the &lt;b&gt;label&lt;/b&gt;'s content will change&lt;br /&gt;to always reflect the location of the &lt;b&gt;thumb&lt;/b&gt;, which you can experience this by moving the &lt;b&gt;thumb&lt;/b&gt;. Likewise, the center position of the &lt;b&gt;label&lt;/b&gt; is bound to the center of its containing canvas. As the window that contains the canvas is resized, the label is repositioned so that it always remains in the center. &lt;br /&gt;&lt;br /&gt;Constraints are ubiquitous and incredibly expressive in Bling. Consider another constraint:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
label.RenderTransform.Rotate = 
  (thumb.CenterPosition - label.CenterPosition).Angle.ToDegrees();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This code rotates the &lt;b&gt;label&lt;/b&gt; according to the position of the &lt;b&gt;thumb&lt;/b&gt; with respect to the center of the &lt;b&gt;label&lt;/b&gt;. A vector from the center of the &lt;b&gt;label&lt;/b&gt; is first computed using subtraction, where the vector is then converted into a radian angle (via &lt;i&gt;Angle&lt;/i&gt;), which itself is turned into a degree angle (&lt;i&gt;ToDegrees&lt;/i&gt;).  The result is that the &lt;b&gt;label&lt;/b&gt; rotates as the &lt;b&gt;thumb&lt;/b&gt; is moved in a circle around its center.  This example demonstrates the power of Bling constraints: properties can be bound to many kinds of expressions including those that operate over angles.&lt;br /&gt;&lt;br /&gt;The next piece of code demonstrates how a UI widget can easily undergo custom pixel shading: &lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumbB = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Blue, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(0,0), CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt; 
};
label.Effect.Custom = (input, uv) =&amp;gt; {
  &lt;span style="color:Green;"&gt;/*L1*/&lt;/span&gt; PointBl p = label.RenderTransform.Inverse.
   Transform(thumbB.CenterPosition - label.LeftTop);
  &lt;span style="color:Green;"&gt;/*L2*/&lt;/span&gt; PointBl q = uv * label.Size;
  &lt;span style="color:Green;"&gt;/*L3*/&lt;/span&gt; DoubleBl d = (p - q).Length;
  &lt;span style="color:Green;"&gt;/*L4*/&lt;/span&gt; d = 1 - (d / 500).Min(1);
  &lt;span style="color:Green;"&gt;/*L5*/&lt;/span&gt; ColorBl clr = (d).Lerp(Colors.Black, Colors.Blue);
  &lt;span style="color:Green;"&gt;/*L6*/&lt;/span&gt; &lt;span style="color:Blue;"&gt;return&lt;/span&gt; ColorBl.FromScRgb
    ((input[uv].ScA).Min((1 - (d * d)).Max(.4)), clr.ScRGB);
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;We want to shade the &lt;b&gt;label&lt;/b&gt; with respect to the position of &lt;b&gt;thumbB&lt;/b&gt;. However, pixel shader effects are applied before render transforms, so we have to transform the position of &lt;b&gt;thumbB&lt;/b&gt; with respect to &lt;b&gt;label&lt;/b&gt;'s inverse transform, which happens on the first line of the shader (below &lt;i&gt;(input,uv) =&amp;gt; {&lt;/i&gt;). Since transforms are relative to the widgets they are applied, we also subtract &lt;b&gt;label&lt;/b&gt;'s left top position from &lt;b&gt;thumbB&lt;/b&gt;'s center position. &lt;b&gt;uv&lt;/b&gt; identifies the  position of the pixel being shaded in term of a percentage rather than in pixels.  So that we can compare &lt;b&gt;uv&lt;/b&gt; to the position of &lt;b&gt;thumbB&lt;/b&gt;, we multiple it by the size of the label (line two) and then we can find the distance between the two points (line three).  Line four specifies that the circle we care about is 500 pixels in radius, which we then invert so that closer distances are higher in value. Line five uses the result &lt;b&gt;d&lt;/b&gt; to interpolate between black and blue colors, which is then used on line six to create the color of the pixel with some modifications to its alpha. &lt;br /&gt;&lt;br /&gt;The resulting pixel shader executes on the GPU with performance similar to a DirectX pixel shader, and in fact, it is a DirectX pixel shader. Pixel shaders can refer to many UI objects and properties  directly, such as positions, although there are limitations. For example, a pixel shader can refer to a point property but not an enum property, and can refer to an image brush but not a solid color brush (due to limitations enforced by WPF). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 26 Oct 2009 06:22:40 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20091026062240A</guid></item><item><title>Updated Wiki: Home</title><link>http://bling.codeplex.com/wikipage?version=52</link><description>&lt;div class="wikidoc"&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=Tutorial&amp;referringTitle=Home"&gt;Tutorial Manual&lt;/a&gt; | &lt;a href="http://bling.codeplex.com/wikipage?title=FAQ&amp;referringTitle=Home"&gt;FAQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Bling is a C#-based library for easily programming images, animations, interactions, and visualizations on Microsoft's WPF/.NET. Bling is oriented towards design technologists, i.e., designers who sometimes program, to aid in the rapid prototyping of rich UI design ideas.  Students, artists, researchers, and hobbyists will also find Bling useful as a tool for quickly expressing ideas or visualizations. Bling's APIs and constructs are optimized for the fast programming of throw away code as opposed to the careful programming of production code. &lt;br /&gt;&lt;br /&gt;Bling as the following features that aid in the rapid prototyping of rich UIs:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home"&gt;Declarative constraints&lt;/a&gt;&lt;/b&gt; that maintain dynamic relationships in the UI without the need for complex event handling.  For example, &lt;i&gt;button.Width = 100 - slider.Value&lt;/i&gt; causes button to shrink as the slider thumb is moved to the right, or grow as it is moved to the left. Constraints have many benefits: they allow rich custom layouts to be expressed with very little code, they are easy animate, and they support UIs with lots of dynamic behavior. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home&amp;ANCHOR#animation"&gt;Simplified animation&lt;/a&gt;&lt;/b&gt; with one line of code. For example, &lt;i&gt;button.Left.Animate().Duration(500).To = label.Right&lt;/i&gt; will cause button to move to the right of label in 500 milliseconds. &lt;/li&gt;
&lt;li&gt;High-level &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=fungraphics&amp;referringTitle=Home"&gt;functional programming constructs&lt;/a&gt;&lt;/b&gt; for graphics programming including abstractions for &lt;a href="http://bling.codeplex.com/wikipage?title=texture&amp;referringTitle=Home"&gt;textures&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=pixel%20effect&amp;referringTitle=Home"&gt;pixel effects&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=transition&amp;referringTitle=Home"&gt;transitions&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=curve&amp;referringTitle=Home"&gt;curves&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=surface&amp;referringTitle=Home"&gt;surfaces&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=height%20field&amp;referringTitle=Home"&gt;height fields&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=normal%20map&amp;referringTitle=Home"&gt;normal maps&lt;/a&gt;, and 3D/2.5D &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=lighting&amp;referringTitle=Home"&gt;lighting&lt;/a&gt;&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;Experimental support for &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=DirectX&amp;referringTitle=Home"&gt;Direct3D 10&lt;/a&gt;&lt;/b&gt; surfaces that are defined by pixel, vertex, and geometry shaders.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=shader&amp;referringTitle=Home"&gt;Pixel shader effects&lt;/a&gt;&lt;/b&gt; without the need to write HLSL code or boilerplate code! For example, &lt;i&gt;canvas.Effect.Custom = (input, uv) =&amp;gt; new ColorBl(1d - input[uv].ScRGB, input[uv].ScA);&lt;/i&gt; defines and installs a pixel shader on a canvas that inverts the canvas's colors.  Pixel shading in Bling takes advantage of your graphics card to create rich, pixel-level effects. &lt;/li&gt;
&lt;li&gt;An experimental &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=physics&amp;referringTitle=Home"&gt;UI physics engine&lt;/a&gt;&lt;/b&gt; for integrating physics into user interfaces! The physics supported by Bling is flexible, controllable, and easy to program.  &lt;/li&gt;
&lt;li&gt;A rich library of &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=geometry&amp;referringTitle=Home"&gt;geometry routines&lt;/a&gt;&lt;/b&gt;; e.g., finding where two lines intersect, the base of a triangle, the area of triangle, or a point on Bezier curve. These routines are compatible with all of Bling's features; e.g., they can be used in express constraints, pixel shaders, or physical constraints. Bling also provides a rich API for manipulating angles in both degrees and radians.&lt;/li&gt;
&lt;li&gt;And many &lt;b&gt;smaller things&lt;/b&gt;; e.g., a frame-based background animation manager and slide presentation system.&lt;/li&gt;
&lt;li&gt;As a &lt;b&gt;lightweight wrapper&lt;/b&gt; around WPF, Bling code is completely compatible with conventional WPF code written in C#, XAML, or other .NET languages.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Bling is an open source project created by &lt;a href="mailto:sean.mcdirmid@gmail.com" class="externalLink"&gt;Sean McDirmid&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and friends to aid in design rapid prototyping. We used Bling to enhance our productivity and would like to share it with other WPF UI design prototypers.&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
Requirments: Visual Studio 2008 full or &lt;a href="http://www.microsoft.com/express/download/" class="externalLink"&gt;Express&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6" class="externalLink"&gt;.NET 3.5&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7" class="externalLink"&gt;.NET 3.5 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" class="externalLink"&gt;Visual Studio 2008 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (may not be necessary, comes with VS 2008 Express). To support WPF pixel shaders, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=c1367bc3-4676-481a-bfaa-5c15d1d7199d" class="externalLink"&gt;DirectX August 2008 runtime&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is sometimes required, although this is often already installed on your machine.&lt;br /&gt;&lt;br /&gt;As of Bling 3, DirectX 10 is also supported for Windows Vista and Windows 7 (sorry XP users!). If you want to use DirectX 10, you'll have to install the latest redistrutable; e.g., the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;amp;displaylang=en" class="externalLink"&gt;web installer&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Bling also depends on the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fcode.msdn.microsoft.com%2fWindowsAPICodePack&amp;referringTitle=Home"&gt;Windows API Code Pack&lt;/a&gt; and the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fwww.codeplex.com%2fdlr&amp;referringTitle=Home"&gt;DLR&lt;/a&gt;, but both DLLs are included in the distribution.&lt;br /&gt;&lt;br /&gt;Download the source release from the web page. An example comes with the release. To include in your own project for WPF development, simply add the Bling.Core and Bling.WPF projects to your solution, and then add a reference to the Bling project from your own project. For DirectX 10 development, add and refer to the Bling.Core, Bling.WPF, and Bling.D3D10 projects.&lt;br /&gt;
&lt;h3&gt;Example&lt;/h3&gt;
The code used in this getting started example is located in the GettingStarted.cs file of the GettingStarted project in the release. We start of this example by creating a &lt;b&gt;thumb&lt;/b&gt; and &lt;b&gt;label&lt;/b&gt; on a &lt;b&gt;canvas&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  CenterPosition = canvas.Size - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(20,20),
  ZIndex = 1,
};
LabelBl label = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LabelBl(canvas) {
  Content = &lt;span style="color:#A31515;"&gt;&amp;quot;Hello World: &amp;quot;&lt;/span&gt;.Bl() + thumb.CenterPosition.ToStringBl(),
  Font = { Weight = FontWeights.SemiBold, Size = 80, },
  CenterPosition = canvas.CenterSize,
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The first statement creates a red &lt;b&gt;thumb&lt;/b&gt; that can be dragged (&lt;i&gt;CanDrag = true&lt;/i&gt;).  The initial location of the &lt;b&gt;thumb&lt;/b&gt; is in the right hand bottom corner of the &lt;b&gt;canvas&lt;/b&gt;,&lt;br /&gt;while its Z index is set to one.  The second statement creates a &lt;b&gt;label&lt;/b&gt; whose content is bound to &amp;quot;Hello World&amp;quot; prepended to the current location of the &lt;b&gt;thumb&lt;/b&gt;.  By default,&lt;br /&gt;assignments to properties in Bling are &lt;i&gt;contraints&lt;/i&gt; where the bound to property will change as the bound-to expression changes.  In our example, the &lt;b&gt;label&lt;/b&gt;'s content will change&lt;br /&gt;to always reflect the location of the &lt;b&gt;thumb&lt;/b&gt;, which you can experience this by moving the &lt;b&gt;thumb&lt;/b&gt;. Likewise, the center position of the &lt;b&gt;label&lt;/b&gt; is bound to the center of its containing canvas. As the window that contains the canvas is resized, the label is repositioned so that it always remains in the center. &lt;br /&gt;&lt;br /&gt;Constraints are ubiquitous and incredibly expressive in Bling. Consider another constraint:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
label.RenderTransform.Rotate = 
  (thumb.CenterPosition - label.CenterPosition).Angle.ToDegrees();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This code rotates the &lt;b&gt;label&lt;/b&gt; according to the position of the &lt;b&gt;thumb&lt;/b&gt; with respect to the center of the &lt;b&gt;label&lt;/b&gt;. A vector from the center of the &lt;b&gt;label&lt;/b&gt; is first computed using subtraction, where the vector is then converted into a radian angle (via &lt;i&gt;Angle&lt;/i&gt;), which itself is turned into a degree angle (&lt;i&gt;ToDegrees&lt;/i&gt;).  The result is that the &lt;b&gt;label&lt;/b&gt; rotates as the &lt;b&gt;thumb&lt;/b&gt; is moved in a circle around its center.  This example demonstrates the power of Bling constraints: properties can be bound to many kinds of expressions including those that operate over angles.&lt;br /&gt;&lt;br /&gt;The next piece of code demonstrates how a UI widget can easily undergo custom pixel shading: &lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumbB = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Blue, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(0,0), CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt; 
};
label.Effect.Custom = (input, uv) =&amp;gt; {
  &lt;span style="color:Green;"&gt;/*L1*/&lt;/span&gt; PointBl p = label.RenderTransform.Inverse.
   Transform(thumbB.CenterPosition - label.LeftTop);
  &lt;span style="color:Green;"&gt;/*L2*/&lt;/span&gt; PointBl q = uv * label.Size;
  &lt;span style="color:Green;"&gt;/*L3*/&lt;/span&gt; DoubleBl d = (p - q).Length;
  &lt;span style="color:Green;"&gt;/*L4*/&lt;/span&gt; d = 1 - (d / 500).Min(1);
  &lt;span style="color:Green;"&gt;/*L5*/&lt;/span&gt; ColorBl clr = (d).Lerp(Colors.Black, Colors.Blue);
  &lt;span style="color:Green;"&gt;/*L6*/&lt;/span&gt; &lt;span style="color:Blue;"&gt;return&lt;/span&gt; 
    ColorBl.FromScRgb((input[uv].ScA).Min((1 - (d * d)).Max(.4)), clr.ScRGB);
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;We want to shade the &lt;b&gt;label&lt;/b&gt; with respect to the position of &lt;b&gt;thumbB&lt;/b&gt;. However, pixel shader effects are applied before render transforms, so we have to transform the position of &lt;b&gt;thumbB&lt;/b&gt; with respect to &lt;b&gt;label&lt;/b&gt;'s inverse transform, which happens on the first line of the shader (below &lt;i&gt;(input,uv) =&amp;gt; {&lt;/i&gt;). Since transforms are relative to the widgets they are applied, we also subtract &lt;b&gt;label&lt;/b&gt;'s left top position from &lt;b&gt;thumbB&lt;/b&gt;'s center position. &lt;b&gt;uv&lt;/b&gt; identifies the  position of the pixel being shaded in term of a percentage rather than in pixels.  So that we can compare &lt;b&gt;uv&lt;/b&gt; to the position of &lt;b&gt;thumbB&lt;/b&gt;, we multiple it by the size of the label (line two) and then we can find the distance between the two points (line three).  Line four specifies that the circle we care about is 500 pixels in radius, which we then invert so that closer distances are higher in value. Line five uses the result &lt;b&gt;d&lt;/b&gt; to interpolate between black and blue colors, which is then used on line six to create the color of the pixel with some modifications to its alpha. &lt;br /&gt;&lt;br /&gt;The resulting pixel shader executes on the GPU with performance similar to a DirectX pixel shader, and in fact, it is a DirectX pixel shader. Pixel shaders can refer to many UI objects and properties  directly, such as positions, although there are limitations. For example, a pixel shader can refer to a point property but not an enum property, and can refer to an image brush but not a solid color brush (due to limitations enforced by WPF). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 26 Oct 2009 06:22:15 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20091026062215A</guid></item><item><title>Updated Wiki: Home</title><link>http://bling.codeplex.com/wikipage?version=51</link><description>&lt;div class="wikidoc"&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=Tutorial&amp;referringTitle=Home"&gt;Tutorial Manual&lt;/a&gt; | &lt;a href="http://bling.codeplex.com/wikipage?title=FAQ&amp;referringTitle=Home"&gt;FAQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Bling is a C#-based library for easily programming images, animations, interactions, and visualizations on Microsoft's WPF/.NET. Bling is oriented towards design technologists, i.e., designers who sometimes program, to aid in the rapid prototyping of rich UI design ideas.  Students, artists, researchers, and hobbyists will also find Bling useful as a tool for quickly expressing ideas or visualizations. Bling's APIs and constructs are optimized for the fast programming of throw away code as opposed to the careful programming of production code. &lt;br /&gt;&lt;br /&gt;Bling as the following features that aid in the rapid prototyping of rich UIs:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home"&gt;Declarative constraints&lt;/a&gt;&lt;/b&gt; that maintain dynamic relationships in the UI without the need for complex event handling.  For example, &lt;i&gt;button.Width = 100 - slider.Value&lt;/i&gt; causes button to shrink as the slider thumb is moved to the right, or grow as it is moved to the left. Constraints have many benefits: they allow rich custom layouts to be expressed with very little code, they are easy animate, and they support UIs with lots of dynamic behavior. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home&amp;ANCHOR#animation"&gt;Simplified animation&lt;/a&gt;&lt;/b&gt; with one line of code. For example, &lt;i&gt;button.Left.Animate().Duration(500).To = label.Right&lt;/i&gt; will cause button to move to the right of label in 500 milliseconds. &lt;/li&gt;
&lt;li&gt;High-level &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=fungraphics&amp;referringTitle=Home"&gt;functional programming constructs&lt;/a&gt;&lt;/b&gt; for graphics programming including abstractions for &lt;a href="http://bling.codeplex.com/wikipage?title=texture&amp;referringTitle=Home"&gt;textures&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=pixel%20effect&amp;referringTitle=Home"&gt;pixel effects&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=transition&amp;referringTitle=Home"&gt;transitions&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=curve&amp;referringTitle=Home"&gt;curves&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=surface&amp;referringTitle=Home"&gt;surfaces&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=height%20field&amp;referringTitle=Home"&gt;height fields&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=normal%20map&amp;referringTitle=Home"&gt;normal maps&lt;/a&gt;, and 3D/2.5D &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=lighting&amp;referringTitle=Home"&gt;lighting&lt;/a&gt;&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;Experimental support for &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=DirectX&amp;referringTitle=Home"&gt;Direct3D 10&lt;/a&gt;&lt;/b&gt; surfaces that are defined by pixel, vertex, and geometry shaders.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=shader&amp;referringTitle=Home"&gt;Pixel shader effects&lt;/a&gt;&lt;/b&gt; without the need to write HLSL code or boilerplate code! For example, &lt;i&gt;canvas.Effect.Custom = (input, uv) =&amp;gt; new ColorBl(1d - input[uv].ScRGB, input[uv].ScA);&lt;/i&gt; defines and installs a pixel shader on a canvas that inverts the canvas's colors.  Pixel shading in Bling takes advantage of your graphics card to create rich, pixel-level effects. &lt;/li&gt;
&lt;li&gt;An experimental &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=physics&amp;referringTitle=Home"&gt;UI physics engine&lt;/a&gt;&lt;/b&gt; for integrating physics into user interfaces! The physics supported by Bling is flexible, controllable, and easy to program.  &lt;/li&gt;
&lt;li&gt;A rich library of &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=geometry&amp;referringTitle=Home"&gt;geometry routines&lt;/a&gt;&lt;/b&gt;; e.g., finding where two lines intersect, the base of a triangle, the area of triangle, or a point on Bezier curve. These routines are compatible with all of Bling's features; e.g., they can be used in express constraints, pixel shaders, or physical constraints. Bling also provides a rich API for manipulating angles in both degrees and radians.&lt;/li&gt;
&lt;li&gt;And many &lt;b&gt;smaller things&lt;/b&gt;; e.g., a frame-based background animation manager and slide presentation system.&lt;/li&gt;
&lt;li&gt;As a &lt;b&gt;lightweight wrapper&lt;/b&gt; around WPF, Bling code is completely compatible with conventional WPF code written in C#, XAML, or other .NET languages.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Bling is an open source project created by &lt;a href="mailto:sean.mcdirmid@gmail.com" class="externalLink"&gt;Sean McDirmid&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and friends to aid in design rapid prototyping. We used Bling to enhance our productivity and would like to share it with other WPF UI design prototypers.&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
Requirments: Visual Studio 2008 full or &lt;a href="http://www.microsoft.com/express/download/" class="externalLink"&gt;Express&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6" class="externalLink"&gt;.NET 3.5&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7" class="externalLink"&gt;.NET 3.5 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" class="externalLink"&gt;Visual Studio 2008 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (may not be necessary, comes with VS 2008 Express). To support WPF pixel shaders, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=c1367bc3-4676-481a-bfaa-5c15d1d7199d" class="externalLink"&gt;DirectX August 2008 runtime&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is sometimes required, although this is often already installed on your machine.&lt;br /&gt;&lt;br /&gt;As of Bling 3, DirectX 10 is also supported for Windows Vista and Windows 7 (sorry XP users!). If you want to use DirectX 10, you'll have to install the latest redistrutable; e.g., the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;amp;displaylang=en" class="externalLink"&gt;web installer&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Bling also depends on the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fcode.msdn.microsoft.com%2fWindowsAPICodePack&amp;referringTitle=Home"&gt;Windows API Code Pack&lt;/a&gt; and the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fwww.codeplex.com%2fdlr&amp;referringTitle=Home"&gt;DLR&lt;/a&gt;, but both DLLs are included in the distribution.&lt;br /&gt;&lt;br /&gt;Download the source release from the web page. An example comes with the release. To include in your own project for WPF development, simply add the Bling.Core and Bling.WPF projects to your solution, and then add a reference to the Bling project from your own project. For DirectX 10 development, add and refer to the Bling.Core, Bling.WPF, and Bling.D3D10 projects.&lt;br /&gt;
&lt;h3&gt;Example&lt;/h3&gt;
The code used in this getting started example is located in the GettingStarted.cs file of the GettingStarted project in the release. We start of this example by creating a &lt;b&gt;thumb&lt;/b&gt; and &lt;b&gt;label&lt;/b&gt; on a &lt;b&gt;canvas&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  CenterPosition = canvas.Size - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(20,20),
  ZIndex = 1,
};
LabelBl label = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LabelBl(canvas) {
  Content = &lt;span style="color:#A31515;"&gt;&amp;quot;Hello World: &amp;quot;&lt;/span&gt;.Bl() + thumb.CenterPosition.ToStringBl(),
  Font = { Weight = FontWeights.SemiBold, Size = 80, },
  CenterPosition = canvas.CenterSize,
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The first statement creates a red &lt;b&gt;thumb&lt;/b&gt; that can be dragged (&lt;i&gt;CanDrag = true&lt;/i&gt;).  The initial location of the &lt;b&gt;thumb&lt;/b&gt; is in the right hand bottom corner of the &lt;b&gt;canvas&lt;/b&gt;,&lt;br /&gt;while its Z index is set to one.  The second statement creates a &lt;b&gt;label&lt;/b&gt; whose content is bound to &amp;quot;Hello World&amp;quot; prepended to the current location of the &lt;b&gt;thumb&lt;/b&gt;.  By default,&lt;br /&gt;assignments to properties in Bling are &lt;i&gt;contraints&lt;/i&gt; where the bound to property will change as the bound-to expression changes.  In our example, the &lt;b&gt;label&lt;/b&gt;'s content will change&lt;br /&gt;to always reflect the location of the &lt;b&gt;thumb&lt;/b&gt;, which you can experience this by moving the &lt;b&gt;thumb&lt;/b&gt;. Likewise, the center position of the &lt;b&gt;label&lt;/b&gt; is bound to the center of its containing canvas. As the window that contains the canvas is resized, the label is repositioned so that it always remains in the center. &lt;br /&gt;&lt;br /&gt;Constraints are ubiquitous and incredibly expressive in Bling. Consider another constraint:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
label.RenderTransform.Rotate = 
  (thumb.CenterPosition - label.CenterPosition).Angle.ToDegrees();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This code rotates the &lt;b&gt;label&lt;/b&gt; according to the position of the &lt;b&gt;thumb&lt;/b&gt; with respect to the center of the &lt;b&gt;label&lt;/b&gt;. A vector from the center of the &lt;b&gt;label&lt;/b&gt; is first computed using subtraction, where the vector is then converted into a radian angle (via &lt;i&gt;Angle&lt;/i&gt;), which itself is turned into a degree angle (&lt;i&gt;ToDegrees&lt;/i&gt;).  The result is that the &lt;b&gt;label&lt;/b&gt; rotates as the &lt;b&gt;thumb&lt;/b&gt; is moved in a circle around its center.  This example demonstrates the power of Bling constraints: properties can be bound to many kinds of expressions including those that operate over angles.&lt;br /&gt;&lt;br /&gt;The next piece of code demonstrates how a UI widget can easily undergo custom pixel shading: &lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumbB = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Blue, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(0,0), CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt; 
};
label.Effect.Custom = (input, uv) =&amp;gt; {
  &lt;span style="color:Green;"&gt;/*L1*/&lt;/span&gt; PointBl p = 
    label.RenderTransform.Inverse.Transform(thumbB.CenterPosition - label.LeftTop);
  &lt;span style="color:Green;"&gt;/*L2*/&lt;/span&gt; PointBl q = uv * label.Size;
  &lt;span style="color:Green;"&gt;/*L3*/&lt;/span&gt; DoubleBl d = (p - q).Length;
  &lt;span style="color:Green;"&gt;/*L4*/&lt;/span&gt; d = 1 - (d / 500).Min(1);
  &lt;span style="color:Green;"&gt;/*L5*/&lt;/span&gt; ColorBl clr = (d).Lerp(Colors.Black, Colors.Blue);
  &lt;span style="color:Green;"&gt;/*L6*/&lt;/span&gt; &lt;span style="color:Blue;"&gt;return&lt;/span&gt; 
    ColorBl.FromScRgb((input[uv].ScA).Min((1 - (d * d)).Max(.4)), clr.ScRGB);
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;We want to shade the &lt;b&gt;label&lt;/b&gt; with respect to the position of &lt;b&gt;thumbB&lt;/b&gt;. However, pixel shader effects are applied before render transforms, so we have to transform the position of &lt;b&gt;thumbB&lt;/b&gt; with respect to &lt;b&gt;label&lt;/b&gt;'s inverse transform, which happens on the first line of the shader (below &lt;i&gt;(input,uv) =&amp;gt; {&lt;/i&gt;). Since transforms are relative to the widgets they are applied, we also subtract &lt;b&gt;label&lt;/b&gt;'s left top position from &lt;b&gt;thumbB&lt;/b&gt;'s center position. &lt;b&gt;uv&lt;/b&gt; identifies the  position of the pixel being shaded in term of a percentage rather than in pixels.  So that we can compare &lt;b&gt;uv&lt;/b&gt; to the position of &lt;b&gt;thumbB&lt;/b&gt;, we multiple it by the size of the label (line two) and then we can find the distance between the two points (line three).  Line four specifies that the circle we care about is 500 pixels in radius, which we then invert so that closer distances are higher in value. Line five uses the result &lt;b&gt;d&lt;/b&gt; to interpolate between black and blue colors, which is then used on line six to create the color of the pixel with some modifications to its alpha. &lt;br /&gt;&lt;br /&gt;The resulting pixel shader executes on the GPU with performance similar to a DirectX pixel shader, and in fact, it is a DirectX pixel shader. Pixel shaders can refer to many UI objects and properties  directly, such as positions, although there are limitations. For example, a pixel shader can refer to a point property but not an enum property, and can refer to an image brush but not a solid color brush (due to limitations enforced by WPF). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 26 Oct 2009 06:21:44 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20091026062144A</guid></item><item><title>Updated Wiki: Home</title><link>http://bling.codeplex.com/wikipage?version=50</link><description>&lt;div class="wikidoc"&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=Tutorial&amp;referringTitle=Home"&gt;Tutorial Manual&lt;/a&gt; | &lt;a href="http://bling.codeplex.com/wikipage?title=FAQ&amp;referringTitle=Home"&gt;FAQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Bling is a C#-based library for easily programming images, animations, interactions, and visualizations on Microsoft's WPF/.NET. Bling is oriented towards design technologists, i.e., designers who sometimes program, to aid in the rapid prototyping of rich UI design ideas.  Students, artists, researchers, and hobbyists will also find Bling useful as a tool for quickly expressing ideas or visualizations. Bling's APIs and constructs are optimized for the fast programming of throw away code as opposed to the careful programming of production code. &lt;br /&gt;&lt;br /&gt;Bling as the following features that aid in the rapid prototyping of rich UIs:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home"&gt;Declarative constraints&lt;/a&gt;&lt;/b&gt; that maintain dynamic relationships in the UI without the need for complex event handling.  For example, &lt;i&gt;button.Width = 100 - slider.Value&lt;/i&gt; causes button to shrink as the slider thumb is moved to the right, or grow as it is moved to the left. Constraints have many benefits: they allow rich custom layouts to be expressed with very little code, they are easy animate, and they support UIs with lots of dynamic behavior. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home&amp;ANCHOR#animation"&gt;Simplified animation&lt;/a&gt;&lt;/b&gt; with one line of code. For example, &lt;i&gt;button.Left.Animate().Duration(500).To = label.Right&lt;/i&gt; will cause button to move to the right of label in 500 milliseconds. &lt;/li&gt;
&lt;li&gt;High-level &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=fungraphics&amp;referringTitle=Home"&gt;functional programming constructs&lt;/a&gt;&lt;/b&gt; for graphics programming including abstractions for &lt;a href="http://bling.codeplex.com/wikipage?title=texture&amp;referringTitle=Home"&gt;textures&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=pixel%20effect&amp;referringTitle=Home"&gt;pixel effects&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=transition&amp;referringTitle=Home"&gt;transitions&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=curve&amp;referringTitle=Home"&gt;curves&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=surface&amp;referringTitle=Home"&gt;surfaces&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=height%20field&amp;referringTitle=Home"&gt;height fields&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=normal%20map&amp;referringTitle=Home"&gt;normal maps&lt;/a&gt;, and 3D/2.5D &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=lighting&amp;referringTitle=Home"&gt;lighting&lt;/a&gt;&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;Experimental support for &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=DirectX&amp;referringTitle=Home"&gt;Direct3D 10&lt;/a&gt;&lt;/b&gt; surfaces that are defined by pixel, vertex, and geometry shaders.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=shader&amp;referringTitle=Home"&gt;Pixel shader effects&lt;/a&gt;&lt;/b&gt; without the need to write HLSL code or boilerplate code! For example, &lt;i&gt;canvas.Effect.Custom = (input, uv) =&amp;gt; new ColorBl(1d - input[uv].ScRGB, input[uv].ScA);&lt;/i&gt; defines and installs a pixel shader on a canvas that inverts the canvas's colors.  Pixel shading in Bling takes advantage of your graphics card to create rich, pixel-level effects. &lt;/li&gt;
&lt;li&gt;An experimental &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=physics&amp;referringTitle=Home"&gt;UI physics engine&lt;/a&gt;&lt;/b&gt; for integrating physics into user interfaces! The physics supported by Bling is flexible, controllable, and easy to program.  &lt;/li&gt;
&lt;li&gt;A rich library of &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=geometry&amp;referringTitle=Home"&gt;geometry routines&lt;/a&gt;&lt;/b&gt;; e.g., finding where two lines intersect, the base of a triangle, the area of triangle, or a point on Bezier curve. These routines are compatible with all of Bling's features; e.g., they can be used in express constraints, pixel shaders, or physical constraints. Bling also provides a rich API for manipulating angles in both degrees and radians.&lt;/li&gt;
&lt;li&gt;And many &lt;b&gt;smaller things&lt;/b&gt;; e.g., a frame-based background animation manager and slide presentation system.&lt;/li&gt;
&lt;li&gt;As a &lt;b&gt;lightweight wrapper&lt;/b&gt; around WPF, Bling code is completely compatible with conventional WPF code written in C#, XAML, or other .NET languages.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Bling is an open source project created by &lt;a href="mailto:sean.mcdirmid@gmail.com" class="externalLink"&gt;Sean McDirmid&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and friends to aid in design rapid prototyping. We used Bling to enhance our productivity and would like to share it with other WPF UI design prototypers.&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
Requirments: Visual Studio 2008 full or &lt;a href="http://www.microsoft.com/express/download/" class="externalLink"&gt;Express&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6" class="externalLink"&gt;.NET 3.5&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7" class="externalLink"&gt;.NET 3.5 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" class="externalLink"&gt;Visual Studio 2008 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (may not be necessary, comes with VS 2008 Express). To support WPF pixel shaders, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=c1367bc3-4676-481a-bfaa-5c15d1d7199d" class="externalLink"&gt;DirectX August 2008 runtime&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is sometimes required, although this is often already installed on your machine.&lt;br /&gt;&lt;br /&gt;As of Bling 3, DirectX 10 is also supported for Windows Vista and Windows 7 (sorry XP users!). If you want to use DirectX 10, you'll have to install the latest redistrutable; e.g., the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;amp;displaylang=en" class="externalLink"&gt;web installer&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Bling also depends on the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fcode.msdn.microsoft.com%2fWindowsAPICodePack&amp;referringTitle=Home"&gt;Windows API Code Pack&lt;/a&gt; and the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fwww.codeplex.com%2fdlr&amp;referringTitle=Home"&gt;DLR&lt;/a&gt;, but both DLLs are included in the distribution.&lt;br /&gt;&lt;br /&gt;Download the source release from the web page. An example comes with the release. To include in your own project for WPF development, simply add the Bling.Core and Bling.WPF projects to your solution, and then add a reference to the Bling project from your own project. For DirectX 10 development, add and refer to the Bling.Core, Bling.WPF, and Bling.D3D10 projects.&lt;br /&gt;
&lt;h3&gt;Example&lt;/h3&gt;
The code used in this getting started example is located in the GettingStarted.cs file of the GettingStarted project in the release. We start of this example by creating a &lt;b&gt;thumb&lt;/b&gt; and &lt;b&gt;label&lt;/b&gt; on a &lt;b&gt;canvas&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  CenterPosition = canvas.Size - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(20,20),
  ZIndex = 1,
};
LabelBl label = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LabelBl(canvas) {
  Content = &lt;span style="color:#A31515;"&gt;&amp;quot;Hello World: &amp;quot;&lt;/span&gt;.Bl() + thumb.CenterPosition.ToStringBl(),
  Font = { Weight = FontWeights.SemiBold, Size = 80, },
  CenterPosition = canvas.CenterSize,
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The first statement creates a red &lt;b&gt;thumb&lt;/b&gt; that can be dragged (&lt;i&gt;CanDrag = true&lt;/i&gt;).  The initial location of the &lt;b&gt;thumb&lt;/b&gt; is in the right hand bottom corner of the &lt;b&gt;canvas&lt;/b&gt;,&lt;br /&gt;while its Z index is set to one.  The second statement creates a &lt;b&gt;label&lt;/b&gt; whose content is bound to &amp;quot;Hello World&amp;quot; prepended to the current location of the &lt;b&gt;thumb&lt;/b&gt;.  By default,&lt;br /&gt;assignments to properties in Bling are &lt;i&gt;contraints&lt;/i&gt; where the bound to property will change as the bound-to expression changes.  In our example, the &lt;b&gt;label&lt;/b&gt;'s content will change&lt;br /&gt;to always reflect the location of the &lt;b&gt;thumb&lt;/b&gt;, which you can experience this by moving the &lt;b&gt;thumb&lt;/b&gt;. Likewise, the center position of the &lt;b&gt;label&lt;/b&gt; is bound to the center of its containing canvas. As the window that contains the canvas is resized, the label is repositioned so that it always remains in the center. &lt;br /&gt;&lt;br /&gt;Constraints are ubiquitous and incredibly expressive in Bling. Consider another constraint:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
label.RenderTransform.Rotate = 
  (thumb.CenterPosition - label.CenterPosition).Angle.ToDegrees();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This code rotates the &lt;b&gt;label&lt;/b&gt; according to the position of the &lt;b&gt;thumb&lt;/b&gt; with respect to the center of the &lt;b&gt;label&lt;/b&gt;. A vector from the center of the &lt;b&gt;label&lt;/b&gt; is first computed using subtraction, where the vector is then converted into a radian angle (via &lt;i&gt;Angle&lt;/i&gt;), which itself is turned into a degree angle (&lt;i&gt;ToDegrees&lt;/i&gt;).  The result is that the &lt;b&gt;label&lt;/b&gt; rotates as the &lt;b&gt;thumb&lt;/b&gt; is moved in a circle around its center.  This example demonstrates the power of Bling constraints: properties can be bound to many kinds of expressions including those that operate over angles.&lt;br /&gt;&lt;br /&gt;The next piece of code demonstrates how a UI widget can easily undergo custom pixel shading: &lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumbB = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Blue, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(0,0), CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt; 
};
label.Effect.Custom = (input, uv) =&amp;gt; {
  &lt;span style="color:Green;"&gt;/*L1*/&lt;/span&gt; PointBl p = label.RenderTransform.Inverse.Transform(thumbB.CenterPosition - label.LeftTop);
  &lt;span style="color:Green;"&gt;/*L2*/&lt;/span&gt; PointBl q = uv * label.Size;
  &lt;span style="color:Green;"&gt;/*L3*/&lt;/span&gt; DoubleBl d = (p - q).Length;
  &lt;span style="color:Green;"&gt;/*L4*/&lt;/span&gt; d = 1 - (d / 500).Min(1);
  &lt;span style="color:Green;"&gt;/*L5*/&lt;/span&gt; ColorBl clr = (d).Lerp(Colors.Black, Colors.Blue);
  &lt;span style="color:Green;"&gt;/*L6*/&lt;/span&gt; &lt;span style="color:Blue;"&gt;return&lt;/span&gt; ColorBl.FromScRgb((input[uv].ScA).Min((1 - (d * d)).Max(.4)), clr.ScRGB);
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;We want to shade the &lt;b&gt;label&lt;/b&gt; with respect to the position of &lt;b&gt;thumbB&lt;/b&gt;. However, pixel shader effects are applied before render transforms, so we have to transform the position of &lt;b&gt;thumbB&lt;/b&gt; with respect to &lt;b&gt;label&lt;/b&gt;'s inverse transform, which happens on the first line of the shader (below &lt;i&gt;(input,uv) =&amp;gt; {&lt;/i&gt;). Since transforms are relative to the widgets they are applied, we also subtract &lt;b&gt;label&lt;/b&gt;'s left top position from &lt;b&gt;thumbB&lt;/b&gt;'s center position. &lt;b&gt;uv&lt;/b&gt; identifies the  position of the pixel being shaded in term of a percentage rather than in pixels.  So that we can compare &lt;b&gt;uv&lt;/b&gt; to the position of &lt;b&gt;thumbB&lt;/b&gt;, we multiple it by the size of the label (line two) and then we can find the distance between the two points (line three).  Line four specifies that the circle we care about is 500 pixels in radius, which we then invert so that closer distances are higher in value. Line five uses the result &lt;b&gt;d&lt;/b&gt; to interpolate between black and blue colors, which is then used on line six to create the color of the pixel with some modifications to its alpha. &lt;br /&gt;&lt;br /&gt;The resulting pixel shader executes on the GPU with performance similar to a DirectX pixel shader, and in fact, it is a DirectX pixel shader. Pixel shaders can refer to many UI objects and properties  directly, such as positions, although there are limitations. For example, a pixel shader can refer to a point property but not an enum property, and can refer to an image brush but not a solid color brush (due to limitations enforced by WPF). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 26 Oct 2009 06:21:00 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20091026062100A</guid></item><item><title>Updated Wiki: Home</title><link>http://bling.codeplex.com/wikipage?version=49</link><description>&lt;div class="wikidoc"&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=Tutorial&amp;referringTitle=Home"&gt;Tutorial Manual&lt;/a&gt; | &lt;a href="http://bling.codeplex.com/wikipage?title=FAQ&amp;referringTitle=Home"&gt;FAQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Bling is a C#-based library for easily programming images, animations, interactions, and visualizations on Microsoft's WPF/.NET. Bling is oriented towards design technologists, i.e., designers who sometimes program, to aid in the rapid prototyping of rich UI design ideas.  Students, artists, researchers, and hobbyists will also find Bling useful as a tool for quickly expressing ideas or visualizations. Bling's APIs and constructs are optimized for the fast programming of throw away code as opposed to the careful programming of production code. &lt;br /&gt;&lt;br /&gt;Bling as the following features that aid in the rapid prototyping of rich UIs:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home"&gt;Declarative constraints&lt;/a&gt;&lt;/b&gt; that maintain dynamic relationships in the UI without the need for complex event handling.  For example, &lt;i&gt;button.Width = 100 - slider.Value&lt;/i&gt; causes button to shrink as the slider thumb is moved to the right, or grow as it is moved to the left. Constraints have many benefits: they allow rich custom layouts to be expressed with very little code, they are easy animate, and they support UIs with lots of dynamic behavior. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home&amp;ANCHOR#animation"&gt;Simplified animation&lt;/a&gt;&lt;/b&gt; with one line of code. For example, &lt;i&gt;button.Left.Animate().Duration(500).To = label.Right&lt;/i&gt; will cause button to move to the right of label in 500 milliseconds. &lt;/li&gt;
&lt;li&gt;High-level &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=fungraphics&amp;referringTitle=Home"&gt;functional programming constructs&lt;/a&gt;&lt;/b&gt; for graphics programming including abstractions for &lt;a href="http://bling.codeplex.com/wikipage?title=texture&amp;referringTitle=Home"&gt;textures&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=pixel%20effect&amp;referringTitle=Home"&gt;pixel effects&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=transition&amp;referringTitle=Home"&gt;transitions&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=curve&amp;referringTitle=Home"&gt;curves&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=surface&amp;referringTitle=Home"&gt;surfaces&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=height%20field&amp;referringTitle=Home"&gt;height fields&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=normal%20map&amp;referringTitle=Home"&gt;normal maps&lt;/a&gt;, and 3D/2.5D &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=lighting&amp;referringTitle=Home"&gt;lighting&lt;/a&gt;&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;Experimental support for &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=DirectX&amp;referringTitle=Home"&gt;Direct3D 10&lt;/a&gt;&lt;/b&gt; surfaces that are defined by pixel, vertex, and geometry shaders.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=shader&amp;referringTitle=Home"&gt;Pixel shader effects&lt;/a&gt;&lt;/b&gt; without the need to write HLSL code or boilerplate code! For example, &lt;i&gt;canvas.Effect.Custom = (input, uv) =&amp;gt; new ColorBl(1d - input[uv].ScRGB, input[uv].ScA);&lt;/i&gt; defines and installs a pixel shader on a canvas that inverts the canvas's colors.  Pixel shading in Bling takes advantage of your graphics card to create rich, pixel-level effects. &lt;/li&gt;
&lt;li&gt;An experimental &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=physics&amp;referringTitle=Home"&gt;UI physics engine&lt;/a&gt;&lt;/b&gt; for integrating physics into user interfaces! The physics supported by Bling is flexible, controllable, and easy to program.  &lt;/li&gt;
&lt;li&gt;A rich library of &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=geometry&amp;referringTitle=Home"&gt;geometry routines&lt;/a&gt;&lt;/b&gt;; e.g., finding where two lines intersect, the base of a triangle, the area of triangle, or a point on Bezier curve. These routines are compatible with all of Bling's features; e.g., they can be used in express constraints, pixel shaders, or physical constraints. Bling also provides a rich API for manipulating angles in both degrees and radians.&lt;/li&gt;
&lt;li&gt;And many &lt;b&gt;smaller things&lt;/b&gt;; e.g., a frame-based background animation manager and slide presentation system.&lt;/li&gt;
&lt;li&gt;As a &lt;b&gt;lightweight wrapper&lt;/b&gt; around WPF, Bling code is completely compatible with conventional WPF code written in C#, XAML, or other .NET languages.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Bling is an open source project created by &lt;a href="mailto:sean.mcdirmid@gmail.com" class="externalLink"&gt;Sean McDirmid&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and friends to aid in design rapid prototyping. We used Bling to enhance our productivity and would like to share it with other WPF UI design prototypers.&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
Requirments: Visual Studio 2008 full or &lt;a href="http://www.microsoft.com/express/download/" class="externalLink"&gt;Express&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6" class="externalLink"&gt;.NET 3.5&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7" class="externalLink"&gt;.NET 3.5 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" class="externalLink"&gt;Visual Studio 2008 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (may not be necessary, comes with VS 2008 Express). To support WPF pixel shaders, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=c1367bc3-4676-481a-bfaa-5c15d1d7199d" class="externalLink"&gt;DirectX August 2008 runtime&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is sometimes required, although this is often already installed on your machine.&lt;br /&gt;&lt;br /&gt;As of Bling 3, DirectX 10 is also supported for Windows Vista and Windows 7 (sorry XP users!). If you want to use DirectX 10, you'll have to install the latest redistrutable; e.g., the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;amp;displaylang=en" class="externalLink"&gt;web installer&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Bling also depends on the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fcode.msdn.microsoft.com%2fWindowsAPICodePack&amp;referringTitle=Home"&gt;Windows API Code Pack&lt;/a&gt; and the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fwww.codeplex.com%2fdlr&amp;referringTitle=Home"&gt;DLR&lt;/a&gt;, but both DLLs are included in the distribution.&lt;br /&gt;&lt;br /&gt;Download the source release from the web page. An example comes with the release. To include in your own project for WPF development, simply add the Bling.Core and Bling.WPF projects to your solution, and then add a reference to the Bling project from your own project. For DirectX 10 development, add and refer to the Bling.Core, Bling.WPF, and Bling.D3D10 projects.&lt;br /&gt;
&lt;h3&gt;Example&lt;/h3&gt;
The code used in this getting started example is located in the GettingStarted.cs file of the GettingStarted project in the release. We start of this example by creating a &lt;b&gt;thumb&lt;/b&gt; and &lt;b&gt;label&lt;/b&gt; on a &lt;b&gt;canvas&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  CenterPosition = canvas.Size - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(20,20),
  ZIndex = 1,
};
LabelBl label = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LabelBl(canvas) {
  Content = &lt;span style="color:#A31515;"&gt;&amp;quot;Hello World: &amp;quot;&lt;/span&gt;.Bl() + thumb.CenterPosition.ToStringBl(),
  Font = { Weight = FontWeights.SemiBold, Size = 80, },
  CenterPosition = canvas.CenterSize,
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The first statement creates a red &lt;b&gt;thumb&lt;/b&gt; that can be dragged (&lt;i&gt;CanDrag = true&lt;/i&gt;).  The initial location of the &lt;b&gt;thumb&lt;/b&gt; is in the right hand bottom corner of the &lt;b&gt;canvas&lt;/b&gt;,&lt;br /&gt;while its Z index is set to one.  The second statement creates a &lt;b&gt;label&lt;/b&gt; whose content is bound to &amp;quot;Hello World&amp;quot; prepended to the current location of the &lt;b&gt;thumb&lt;/b&gt;.  By default,&lt;br /&gt;assignments to properties in Bling are &lt;i&gt;contraints&lt;/i&gt; where the bound to property will change as the bound-to expression changes.  In our example, the &lt;b&gt;label&lt;/b&gt;'s content will change&lt;br /&gt;to always reflect the location of the &lt;b&gt;thumb&lt;/b&gt;, which you can experience this by moving the &lt;b&gt;thumb&lt;/b&gt;. Likewise, the center position of the &lt;b&gt;label&lt;/b&gt; is bound to the center of its containing canvas. As the window that contains the canvas is resized, the label is repositioned so that it always remains in the center. &lt;br /&gt;&lt;br /&gt;Constraints are ubiquitous and incredibly expressive in Bling. Consider another constraint:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
label.RenderTransform.Rotate = (thumb.CenterPosition - label.CenterPosition).Angle.ToDegrees();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This code rotates the &lt;b&gt;label&lt;/b&gt; according to the position of the &lt;b&gt;thumb&lt;/b&gt; with respect to the center of the &lt;b&gt;label&lt;/b&gt;. A vector from the center of the &lt;b&gt;label&lt;/b&gt; is first computed using subtraction, where the vector is then converted into a radian angle (via &lt;i&gt;Angle&lt;/i&gt;), which itself is turned into a degree angle (&lt;i&gt;ToDegrees&lt;/i&gt;).  The result is that the &lt;b&gt;label&lt;/b&gt; rotates as the &lt;b&gt;thumb&lt;/b&gt; is moved in a circle around its center.  This example demonstrates the power of Bling constraints: properties can be bound to many kinds of expressions including those that operate over angles.&lt;br /&gt;&lt;br /&gt;The next piece of code demonstrates how a UI widget can easily undergo custom pixel shading: &lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumbB = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Blue, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(0,0), CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt; 
};
label.Effect.Custom = (input, uv) =&amp;gt; {
  &lt;span style="color:Green;"&gt;/*L1*/&lt;/span&gt; PointBl p = label.RenderTransform.Inverse.Transform(thumbB.CenterPosition - label.LeftTop);
  &lt;span style="color:Green;"&gt;/*L2*/&lt;/span&gt; PointBl q = uv * label.Size;
  &lt;span style="color:Green;"&gt;/*L3*/&lt;/span&gt; DoubleBl d = (p - q).Length;
  &lt;span style="color:Green;"&gt;/*L4*/&lt;/span&gt; d = 1 - (d / 500).Min(1);
  &lt;span style="color:Green;"&gt;/*L5*/&lt;/span&gt; ColorBl clr = (d).Lerp(Colors.Black, Colors.Blue);
  &lt;span style="color:Green;"&gt;/*L6*/&lt;/span&gt; &lt;span style="color:Blue;"&gt;return&lt;/span&gt; ColorBl.FromScRgb((input[uv].ScA).Min((1 - (d * d)).Max(.4)), clr.ScRGB);
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;We want to shade the &lt;b&gt;label&lt;/b&gt; with respect to the position of &lt;b&gt;thumbB&lt;/b&gt;. However, pixel shader effects are applied before render transforms, so we have to transform the position of &lt;b&gt;thumbB&lt;/b&gt; with respect to &lt;b&gt;label&lt;/b&gt;'s inverse transform, which happens on the first line of the shader (below &lt;i&gt;(input,uv) =&amp;gt; {&lt;/i&gt;). Since transforms are relative to the widgets they are applied, we also subtract &lt;b&gt;label&lt;/b&gt;'s left top position from &lt;b&gt;thumbB&lt;/b&gt;'s center position. &lt;b&gt;uv&lt;/b&gt; identifies the  position of the pixel being shaded in term of a percentage rather than in pixels.  So that we can compare &lt;b&gt;uv&lt;/b&gt; to the position of &lt;b&gt;thumbB&lt;/b&gt;, we multiple it by the size of the label (line two) and then we can find the distance between the two points (line three).  Line four specifies that the circle we care about is 500 pixels in radius, which we then invert so that closer distances are higher in value. Line five uses the result &lt;b&gt;d&lt;/b&gt; to interpolate between black and blue colors, which is then used on line six to create the color of the pixel with some modifications to its alpha. &lt;br /&gt;&lt;br /&gt;The resulting pixel shader executes on the GPU with performance similar to a DirectX pixel shader, and in fact, it is a DirectX pixel shader. Pixel shaders can refer to many UI objects and properties  directly, such as positions, although there are limitations. For example, a pixel shader can refer to a point property but not an enum property, and can refer to an image brush but not a solid color brush (due to limitations enforced by WPF). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Fri, 23 Oct 2009 00:38:57 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20091023123857A</guid></item><item><title>Updated Wiki: lighting</title><link>http://bling.codeplex.com/wikipage?title=lighting&amp;version=11</link><description>&lt;div class="wikidoc"&gt;The code for the UI lighting tutorial is located in the LightingTutorial project of the distribution. You can find different materials with their own lighting effects. &lt;br /&gt;&lt;br /&gt;Bling's support for lighting is based on simple or local lighting model in computer graphics. Here we implement the diffuse reflection, the specular reflection, the one-time refraction and the simple diffraction. Basically, we use normal mapping to make the 2D object looks like in a 3D environment with more realistic lighting effect. Bling supports most of the lights and materials specified by &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fcc500324.aspx&amp;referringTitle=lighting"&gt;WPF 3D&lt;/a&gt;. The documentation for these classes in WPF 3D applies to Bling. &lt;br /&gt;
&lt;h2&gt;Light Sources&lt;/h2&gt;
As we know, without light, we can't see any color. One of the light source we used in Bling is point light, like the light bulb. The class “SpotLight” defines the point light, it has properties like position, direction, color, and inner and outer cone angles. The higher the light is, the bigger range it can illuminate, but the brightness would be weaker. We consider the diffuse color and the specular color of light are the same which is realistic for the most, which is defined by the. Usually we set the color of light to be white. In fact, the spot light also has the property called &amp;quot;attenuation quotient&amp;quot;, but we set it as the parameter of the lighting shader to adjust the lighting effect more freely. Another kind of the light source is direction light like the sunshine. usually this means the light source is very very far from all the object, so the directions from any object to source are the same,  that's why one of the property of direction light that lacks a position and only relies on direction for its effect. &lt;br /&gt;
&lt;h3&gt;Simple lighting of paper&lt;/h3&gt;First, we can implement the simplest lighting only with diffuse color of the flat surface, like a piece of paper, the surface of desk, etc. We just need to add sentences in the pixel shader like this:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
DiffuseMaterialCl diffMaterial = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; DiffuseMaterialCl();
SplotLightCl light = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; SpotLightCl() {
  Position = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(thumbB.CenterPosition - UseImage.LeftTop, 170),
  Direction = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(1, 0, -0.8).Normalize,
  InnerConeAngle = 5.ToDegrees(), OuterConeAngle = 15.ToDegrees(),
};
Point3DBl eyePosition = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(eyeThumb.CenterPosition - UseImage.LeftTop, 100);
MyCanvas.Background = Colors.CornflowerBlue;
MyCanvas.Effect.Custom = (input, uv) =&amp;gt; diffMaterial.Apply(light)
  [&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(uv * MyCanvas.Size, 0), &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(0, 0, 1), eyePosition][input, uv];
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The &lt;br /&gt;&lt;br /&gt;All the shaders to calculate lighting is in the class LightingTechniques, including this one. You can find these codes in light.cs, the function LightTest_Paper() in the class LightTest.&lt;br /&gt;Here CornflowerBlue means the color of the paper or anything you think it is. LightSource0 is the lightsource to brighten the world. We use the lefttop position and the size of the current object you’re drawing in the shader to do some transformation. Because usually many objects share one light source, we should uniform their coordinate systems and also the light source’s. Finally the point3DBl(X, Y, Z) gives the setting of attenuation Quotient, which is described as a quadratic equation like &amp;quot;1.0/(X * d^2 &lt;u&gt; Y * d &lt;/u&gt; Z), where d is the distance between the lightSource and the point&amp;quot;. The numbers are bigger, the attenuation goes bigger with the distance, so the darker the object is. Usually the number X,Y,Z are between 0 and 1, but you can adjust them as you wish to get a good vision effect. &lt;br /&gt;&lt;br /&gt;Here, with this simplest case, you can see how two kinds of light source effect the different results:&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64663" alt="difflight.jpg" title="difflight.jpg" /&gt;&lt;br /&gt;On the left is a spot light with the color white, on the right is a direction light with the color Ivory, and the color of paper itself is CornflowerBlue. Because the normal of the paper is only straight up, so the color is the same. Relatively, different attenuation and different direcion from point to light source make the lighting effct has a obvious change on the paper.&lt;br /&gt;&lt;br /&gt;The diffuse color of object is set similar to the paper, just add more inrfomation like normal, height and so on. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Specular color&lt;/b&gt;&lt;br /&gt;Specular color comes from the reflection of the light on the smooth surface like mirror, glass, some kind of metal, etc. Or you will more familiar with the word “highlight”.  In fact little object only has the specular color, but we still implement this interface to simplify some calculation in UI but with effect as good. For example, we made the 2.5D bubble wrap on some image just with specular color:&lt;br /&gt;          &lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64004" alt="bubblewrap.jpg" title="bubblewrap.jpg" /&gt;          &lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64005" alt="bubblewrap-bump.jpg" title="bubblewrap-bump.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;We use these codes to finish it:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
newCanvas.CustomEffect = (input, uv) =&amp;gt; {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; LightingTechniques.SpecularColor(uv, normalMap, heightMap, 20.0, LightSource0, 
    eyePos, newCanvas.LeftTop, newCanvas.Size, 10, 1.0) + baseMap[uv];
};
&lt;/pre&gt;&lt;/div&gt;Here, the normalMap defines the normal of every pixel point, in the lase case, the normal of paper is thought to be (0, 0, 1), a default value. In the 2D window, all the object have the same height:0, but with Heightmap, you can define the height of pixel in a fake 3D space. As the height saved in HeightMap must be between 0 and 1(from black to white), use the next parameter to scale the height as you want, here we enlarge the height to 20 times. You can see the normalMap and HeightMap above. These two maps help to calculate the lighting more realistic. The next parameter , a double value 20, is the reflective index,usually from 1 to 2000. The higher this number is, the surface looks more smoother, so that the highlight spot smaller and brighter. The last one is often between 0 ans 1, is called specularity factor which can control the entire strength of the specular color. And you’ll find that the specular color just relative to the light source’s color, so we add baseMap&lt;a href="http://bling.codeplex.com/wikipage?title=uv&amp;referringTitle=lighting"&gt;uv&lt;/a&gt; to adjust the whole effect.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Both diffuse and Specular color&lt;/b&gt;&lt;br /&gt;Most things in real world have both diffuse and specular color, so we provide the function to get the both, just like this:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
newCanvas.CustomEffect = (input, uv) =&amp;gt; {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; LightingTechniques.DiffuseSpecularColor(uv, baseMap, normalMap, LightSource0, eyePos, newCanvas.LeftTop, 
              newCanvas.Size, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(4e-6, 2e-3, 0.5), 2, 0.8);
}; 
&lt;/pre&gt;&lt;/div&gt;It’s just the combination of the above two functions. Here we omit heightmap and heightScale with the overloaded function. We can also use some color to instead of the image baseMap. Below is the effect of this funciton of a brick wall, compare with the ordinary texture on the right.&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64011" alt="wall.jpg" title="wall.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Simulate the glass&lt;/b&gt;&lt;br /&gt;The glass only has specular color because of its smooth surface. And it also generates refraction as its transparency. So we add a background behind our glass to show these effects. &lt;br /&gt;Here is the code of pixel shader:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
newCanvas.CustomEffect = (input, uv) =&amp;gt; {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; LightingTechniques.GlassColor(uv, Colors.LightBlue, backgroundMap, normalMap, LightSource0, eyePos, 
     newCanvas.LeftTop, newCanvas.Size, 1.0, 0.9, 1.5, 2.5,  newBackgound.LeftTop, newBackgound.Size, slider.Value);
 }; 
&lt;/pre&gt;&lt;/div&gt;The second parameter defines the color of glass itself. The next one describes the background image behind the glass. Then a series of similar parameters we’ve ever seen. After the reflective index (1.0) and the specularity factor(0.9), there are some new things: 1.5 is the relative refractive index (RI). “Relative” means this one equals to RI of refracting medium /  RI of incident medium, here 1.5 is a value we often used to describe glass’s relative RI, means:  RI of glass(1.5~1.9,generally)  / RI of air(1.0). The nest one is the thickness of glass, usually between 1 and 100, it determine the level of refraction. The thicker the glass is, the effect of refraction is more obvious.  The next two parameter give us the location of background image. The last one defines the transparency of glass, usually from 0.0 to 1.0,  the bigger transparency means the more light can across the glass and brighten the background. If the transparency is 0, you can only see the color of glass. Here are pictures with different transparency(0.2 → 0.6 → 1.0):&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64019" alt="glass.jpg" title="glass.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Simulate the diffraction of CD surface&lt;/b&gt;&lt;br /&gt;For surfaces with small-scale detail such as a CD, the small-scale surface detail causes the reflected waves to interfere with one another. This phenomenon is known as diffraction. Diffraction causes the reflected light from these surfaces to exhibit many colorful patterns, as you can see in the subtle reflections from a CD. We simulate it using the method in the book &lt;i&gt;GPU Gems&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;In the calculation of diffraction, the tangent vectors are needed to supply the local direction of the narrow bands on the surface. For a CD, they are in the direction of the tracks, so we can get them in the pixel shader.  If you want more complicated tangent vectors, more calculation or a texture should be helpful.&lt;br /&gt;Here is our code:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
newCanvas.CustomEffect = (input, uv) =&amp;gt; {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; LightingTechniques.DiffractionCD(uv, input, rainbow, LightSource0, eyePos, 
    newCanvas.LeftTop, newCanvas.Size);
}; 
&lt;/pre&gt;&lt;/div&gt;If you just want to render a CD only with diffraction, just call the function in shader like this simple way. We just meet two strange parameters: the second one ”input” supplies the basic image of a piece of CD, and the “rainbow” is a 1D texture in which we can map the color corresponding to a given wavelength, we use a simple approximation of a rainbow map that range from violet to red and include most colors in the rainbow. And we assume that the normal of surface is (0, 0.5, 0.866) with a little lean to show the diffraction better.&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64024" alt="cd-screenshot.jpg" title="cd-screenshot.jpg" /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Fri, 23 Oct 2009 00:37:04 GMT</pubDate><guid isPermaLink="false">Updated Wiki: lighting 20091023123704A</guid></item><item><title>Updated Wiki: lighting</title><link>http://bling.codeplex.com/wikipage?title=lighting&amp;version=10</link><description>&lt;div class="wikidoc"&gt;The code for the UI lighting tutorial is located in the LightingTutorial project of the distribution. You can find different materials with their own lighting effects. &lt;br /&gt;&lt;br /&gt;Bling's support for lighting is based on simple or local lighting model in computer graphics. Here we implement the diffuse reflection, the specular reflection, the one-time refraction and the simple diffraction. Basically, we use normal mapping to make the 2D object looks like in a 3D environment with more realistic lighting effect.&lt;br /&gt;&lt;br /&gt;As we know, without light, we can't see any color. One of the light source we used in Bling is point light, like the light bulb. The class “SpotLight” defines the point light, it has 3 properties: &lt;i&gt;Position&lt;/i&gt;, &lt;i&gt;Height&lt;/i&gt;, and &lt;i&gt;Color&lt;/i&gt;. &lt;i&gt;Position&lt;/i&gt; shows the 2D position of the light, and the property &lt;i&gt;Height&lt;/i&gt; help to locate the light in 3D space. The higher the light is, the bigger range it can illuminate, but the brightness would be weaker. We consider the diffuse color and the specular color of light are the same which is realistic for the most. So the property &lt;i&gt;Color&lt;/i&gt; defines this. Usually we set the color of light to be white. In fact, the spot light also has the property called &amp;quot;attenuation quotient&amp;quot;, but we set it as the parameter of the lighting shader to adjust the lighting effect more freely.&lt;br /&gt;&lt;br /&gt;Another kind of the light source is direction light like the sunshine. usually this means the light source is very very far from all the object, so the directions from any object to source are the same,  that's why one of the property of &amp;quot;DirectionLight&amp;quot; is &lt;i&gt;Direction&lt;/i&gt; instead of the &lt;i&gt;Position&lt;/i&gt; and &lt;i&gt;height&lt;/i&gt;. The other one is also the &lt;i&gt;Color&lt;/i&gt;. When in the calculation of lighting, it is similar to spot light, just change the parameter &amp;quot;SpotLight&amp;quot; to &amp;quot;DirectionLight&amp;quot;, and without &amp;quot;attenuation quotient&amp;quot;. Certainly it is realistic, for example, the color of everything in the sunshine are the same degree of attenuation, cause the difference of thier distances to the sun are nearly the same. So when you choose the direction light, the difference between color of things is smaller than point light.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Simple lighting of paper&lt;/b&gt;&lt;br /&gt;First, we can implement the simplest lighting only with diffuse color of the flat surface, like a piece of paper, the surface of desk, etc. We just need to add sentences in the pixel shader like this:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Point3DBl eyePosition = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(eyeThumb.CenterPosition - UseImage.LeftTop, 100);
DiffuseMaterialCl diffMaterial = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; DiffuseMaterialCl();
PointLightBl light = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointLightBl() { 
  Position = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(thumbA.CenterPosition - MyCanvas.LeftTop, 170)
};
MyCanvas.Background = Colors.CornflowerBlue;
MyCanvas.Effect.Custom = (input, uv) =&amp;gt; diffMaterial.Apply(light)
  [&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(uv * MyCanvas.Size, 0), &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(0, 0, 1), eyePosition][input, uv];
&lt;/pre&gt;&lt;/div&gt;All the shaders to calculate lighting is in the class LightingTechniques, including this one. You can find these codes in light.cs, the function LightTest_Paper() in the class LightTest.&lt;br /&gt;Here CornflowerBlue means the color of the paper or anything you think it is. LightSource0 is the lightsource to brighten the world. We use the lefttop position and the size of the current object you’re drawing in the shader to do some transformation. Because usually many objects share one light source, we should uniform their coordinate systems and also the light source’s. Finally the point3DBl(X, Y, Z) gives the setting of attenuation Quotient, which is described as a quadratic equation like &amp;quot;1.0/(X * d^2 &lt;u&gt; Y * d &lt;/u&gt; Z), where d is the distance between the lightSource and the point&amp;quot;. The numbers are bigger, the attenuation goes bigger with the distance, so the darker the object is. Usually the number X,Y,Z are between 0 and 1, but you can adjust them as you wish to get a good vision effect. &lt;br /&gt;&lt;br /&gt;Here, with this simplest case, you can see how two kinds of light source effect the different results:&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64663" alt="difflight.jpg" title="difflight.jpg" /&gt;&lt;br /&gt;On the left is a spot light with the color white, on the right is a direction light with the color Ivory, and the color of paper itself is CornflowerBlue. Because the normal of the paper is only straight up, so the color is the same. Relatively, different attenuation and different direcion from point to light source make the lighting effct has a obvious change on the paper.&lt;br /&gt;&lt;br /&gt;The diffuse color of object is set similar to the paper, just add more inrfomation like normal, height and so on. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Specular color&lt;/b&gt;&lt;br /&gt;Specular color comes from the reflection of the light on the smooth surface like mirror, glass, some kind of metal, etc. Or you will more familiar with the word “highlight”.  In fact little object only has the specular color, but we still implement this interface to simplify some calculation in UI but with effect as good. For example, we made the 2.5D bubble wrap on some image just with specular color:&lt;br /&gt;          &lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64004" alt="bubblewrap.jpg" title="bubblewrap.jpg" /&gt;          &lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64005" alt="bubblewrap-bump.jpg" title="bubblewrap-bump.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;We use these codes to finish it:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
newCanvas.CustomEffect = (input, uv) =&amp;gt; {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; LightingTechniques.SpecularColor(uv, normalMap, heightMap, 20.0, LightSource0, 
    eyePos, newCanvas.LeftTop, newCanvas.Size, 10, 1.0) + baseMap[uv];
};
&lt;/pre&gt;&lt;/div&gt;Here, the normalMap defines the normal of every pixel point, in the lase case, the normal of paper is thought to be (0, 0, 1), a default value. In the 2D window, all the object have the same height:0, but with Heightmap, you can define the height of pixel in a fake 3D space. As the height saved in HeightMap must be between 0 and 1(from black to white), use the next parameter to scale the height as you want, here we enlarge the height to 20 times. You can see the normalMap and HeightMap above. These two maps help to calculate the lighting more realistic. The next parameter , a double value 20, is the reflective index,usually from 1 to 2000. The higher this number is, the surface looks more smoother, so that the highlight spot smaller and brighter. The last one is often between 0 ans 1, is called specularity factor which can control the entire strength of the specular color. And you’ll find that the specular color just relative to the light source’s color, so we add baseMap&lt;a href="http://bling.codeplex.com/wikipage?title=uv&amp;referringTitle=lighting"&gt;uv&lt;/a&gt; to adjust the whole effect.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Both diffuse and Specular color&lt;/b&gt;&lt;br /&gt;Most things in real world have both diffuse and specular color, so we provide the function to get the both, just like this:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
newCanvas.CustomEffect = (input, uv) =&amp;gt; {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; LightingTechniques.DiffuseSpecularColor(uv, baseMap, normalMap, LightSource0, eyePos, newCanvas.LeftTop, 
              newCanvas.Size, &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point3DBl(4e-6, 2e-3, 0.5), 2, 0.8);
}; 
&lt;/pre&gt;&lt;/div&gt;It’s just the combination of the above two functions. Here we omit heightmap and heightScale with the overloaded function. We can also use some color to instead of the image baseMap. Below is the effect of this funciton of a brick wall, compare with the ordinary texture on the right.&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64011" alt="wall.jpg" title="wall.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Simulate the glass&lt;/b&gt;&lt;br /&gt;The glass only has specular color because of its smooth surface. And it also generates refraction as its transparency. So we add a background behind our glass to show these effects. &lt;br /&gt;Here is the code of pixel shader:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
newCanvas.CustomEffect = (input, uv) =&amp;gt; {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; LightingTechniques.GlassColor(uv, Colors.LightBlue, backgroundMap, normalMap, LightSource0, eyePos, 
     newCanvas.LeftTop, newCanvas.Size, 1.0, 0.9, 1.5, 2.5,  newBackgound.LeftTop, newBackgound.Size, slider.Value);
 }; 
&lt;/pre&gt;&lt;/div&gt;The second parameter defines the color of glass itself. The next one describes the background image behind the glass. Then a series of similar parameters we’ve ever seen. After the reflective index (1.0) and the specularity factor(0.9), there are some new things: 1.5 is the relative refractive index (RI). “Relative” means this one equals to RI of refracting medium /  RI of incident medium, here 1.5 is a value we often used to describe glass’s relative RI, means:  RI of glass(1.5~1.9,generally)  / RI of air(1.0). The nest one is the thickness of glass, usually between 1 and 100, it determine the level of refraction. The thicker the glass is, the effect of refraction is more obvious.  The next two parameter give us the location of background image. The last one defines the transparency of glass, usually from 0.0 to 1.0,  the bigger transparency means the more light can across the glass and brighten the background. If the transparency is 0, you can only see the color of glass. Here are pictures with different transparency(0.2 → 0.6 → 1.0):&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64019" alt="glass.jpg" title="glass.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Simulate the diffraction of CD surface&lt;/b&gt;&lt;br /&gt;For surfaces with small-scale detail such as a CD, the small-scale surface detail causes the reflected waves to interfere with one another. This phenomenon is known as diffraction. Diffraction causes the reflected light from these surfaces to exhibit many colorful patterns, as you can see in the subtle reflections from a CD. We simulate it using the method in the book &lt;i&gt;GPU Gems&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;In the calculation of diffraction, the tangent vectors are needed to supply the local direction of the narrow bands on the surface. For a CD, they are in the direction of the tracks, so we can get them in the pixel shader.  If you want more complicated tangent vectors, more calculation or a texture should be helpful.&lt;br /&gt;Here is our code:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
newCanvas.CustomEffect = (input, uv) =&amp;gt; {
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; LightingTechniques.DiffractionCD(uv, input, rainbow, LightSource0, eyePos, 
    newCanvas.LeftTop, newCanvas.Size);
}; 
&lt;/pre&gt;&lt;/div&gt;If you just want to render a CD only with diffraction, just call the function in shader like this simple way. We just meet two strange parameters: the second one ”input” supplies the basic image of a piece of CD, and the “rainbow” is a 1D texture in which we can map the color corresponding to a given wavelength, we use a simple approximation of a rainbow map that range from violet to red and include most colors in the rainbow. And we assume that the normal of surface is (0, 0.5, 0.866) with a little lean to show the diffraction better.&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=64024" alt="cd-screenshot.jpg" title="cd-screenshot.jpg" /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Fri, 23 Oct 2009 00:26:32 GMT</pubDate><guid isPermaLink="false">Updated Wiki: lighting 20091023122632A</guid></item><item><title>Updated Wiki: Home</title><link>http://bling.codeplex.com/wikipage?version=48</link><description>&lt;div class="wikidoc"&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=Tutorial&amp;referringTitle=Home"&gt;Tutorial Manual&lt;/a&gt; | &lt;a href="http://bling.codeplex.com/wikipage?title=FAQ&amp;referringTitle=Home"&gt;FAQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Bling is a C#-based library for easily programming images, animations, interactions, and visualizations on Microsoft's WPF/.NET. Bling is oriented towards design technologists, i.e., designers who sometimes program, to aid in the rapid prototyping of rich UI design ideas.  Students, artists, researchers, and hobbyists will also find Bling useful as a tool for quickly expressing ideas or visualizations. Bling's APIs and constructs are optimized for the fast programming of throw away code as opposed to the careful programming of production code. &lt;br /&gt;&lt;br /&gt;Bling as the following features that aid in the rapid prototyping of rich UIs:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home"&gt;Declarative constraints&lt;/a&gt;&lt;/b&gt; that maintain dynamic relationships in the UI without the need for complex event handling.  For example, &lt;i&gt;button.Width = 100 - slider.Value&lt;/i&gt; causes button to shrink as the slider thumb is moved to the right, or grow as it is moved to the left. Constraints have many benefits: they allow rich custom layouts to be expressed with very little code, they are easy animate, and they support UIs with lots of dynamic behavior. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=constraints&amp;referringTitle=Home&amp;ANCHOR#animation"&gt;Simplified animation&lt;/a&gt;&lt;/b&gt; with one line of code. For example, &lt;i&gt;button.Left.Animate().Duration(500).To = label.Right&lt;/i&gt; will cause button to move to the right of label in 500 milliseconds. &lt;/li&gt;
&lt;li&gt;High-level &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=fungraphics&amp;referringTitle=Home"&gt;functional programming constructs&lt;/a&gt;&lt;/b&gt; for graphics programming including abstractions for &lt;a href="http://bling.codeplex.com/wikipage?title=texture&amp;referringTitle=Home"&gt;textures&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=pixel%20effect&amp;referringTitle=Home"&gt;pixel effects&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=transition&amp;referringTitle=Home"&gt;transitions&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=curve&amp;referringTitle=Home"&gt;curves&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=surface&amp;referringTitle=Home"&gt;surfaces&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=height%20field&amp;referringTitle=Home"&gt;height fields&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/wikipage?title=normal%20map&amp;referringTitle=Home"&gt;normal maps&lt;/a&gt;, and 3D/2.5D &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=lighting&amp;referringTitle=Home"&gt;lighting&lt;/a&gt;&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;Experimental support for &lt;a href="http://bling.codeplex.com/wikipage?title=DirectX&amp;referringTitle=Home"&gt;Direct3D 10&lt;/a&gt; surfaces that are defined by pixel, vertex, and geometry shaders.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=shader&amp;referringTitle=Home"&gt;Pixel shader effects&lt;/a&gt;&lt;/b&gt; without the need to write HLSL code or boilerplate code! For example, &lt;i&gt;canvas.Effect.Custom = (input, uv) =&amp;gt; new ColorBl(1d - input[uv].ScRGB, input[uv].ScA);&lt;/i&gt; defines and installs a pixel shader on a canvas that inverts the canvas's colors.  Pixel shading in Bling takes advantage of your graphics card to create rich, pixel-level effects. &lt;/li&gt;
&lt;li&gt;An experimental &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=physics&amp;referringTitle=Home"&gt;UI physics engine&lt;/a&gt;&lt;/b&gt; for integrating physics into user interfaces! The physics supported by Bling is flexible, controllable, and easy to program.  &lt;/li&gt;
&lt;li&gt;A rich library of &lt;b&gt;&lt;a href="http://bling.codeplex.com/wikipage?title=geometry&amp;referringTitle=Home"&gt;geometry routines&lt;/a&gt;&lt;/b&gt;; e.g., finding where two lines intersect, the base of a triangle, the area of triangle, or a point on Bezier curve. These routines are compatible with all of Bling's features; e.g., they can be used in express constraints, pixel shaders, or physical constraints. Bling also provides a rich API for manipulating angles in both degrees and radians.&lt;/li&gt;
&lt;li&gt;And many &lt;b&gt;smaller things&lt;/b&gt;; e.g., a frame-based background animation manager and slide presentation system.&lt;/li&gt;
&lt;li&gt;As a &lt;b&gt;lightweight wrapper&lt;/b&gt; around WPF, Bling code is completely compatible with conventional WPF code written in C#, XAML, or other .NET languages.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Bling is an open source project created by &lt;a href="mailto:sean.mcdirmid@gmail.com" class="externalLink"&gt;Sean McDirmid&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and friends to aid in design rapid prototyping. We used Bling to enhance our productivity and would like to share it with other WPF UI design prototypers.&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
Requirments: Visual Studio 2008 full or &lt;a href="http://www.microsoft.com/express/download/" class="externalLink"&gt;Express&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6" class="externalLink"&gt;.NET 3.5&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7" class="externalLink"&gt;.NET 3.5 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" class="externalLink"&gt;Visual Studio 2008 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (may not be necessary, comes with VS 2008 Express). To support WPF pixel shaders, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=c1367bc3-4676-481a-bfaa-5c15d1d7199d" class="externalLink"&gt;DirectX August 2008 runtime&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is sometimes required, although this is often already installed on your machine.&lt;br /&gt;&lt;br /&gt;As of Bling 3, DirectX 10 is also supported for Windows Vista and Windows 7 (sorry XP users!). If you want to use DirectX 10, you'll have to install the latest redistrutable; e.g., the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;amp;displaylang=en" class="externalLink"&gt;web installer&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Bling also depends on the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fcode.msdn.microsoft.com%2fWindowsAPICodePack&amp;referringTitle=Home"&gt;Windows API Code Pack&lt;/a&gt; and the &lt;a href="http://bling.codeplex.com/wikipage?title=http%3a%2f%2fwww.codeplex.com%2fdlr&amp;referringTitle=Home"&gt;DLR&lt;/a&gt;, but both DLLs are included in the distribution.&lt;br /&gt;&lt;br /&gt;Download the source release from the web page. An example comes with the release. To include in your own project for WPF development, simply add the Bling.Core and Bling.WPF projects to your solution, and then add a reference to the Bling project from your own project. For DirectX 10 development, add and refer to the Bling.Core, Bling.WPF, and Bling.D3D10 projects.&lt;br /&gt;
&lt;h3&gt;Example&lt;/h3&gt;
The code used in this getting started example is located in the GettingStarted.cs file of the GettingStarted project in the release. We start of this example by creating a &lt;b&gt;thumb&lt;/b&gt; and &lt;b&gt;label&lt;/b&gt; on a &lt;b&gt;canvas&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  CenterPosition = canvas.Size - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(20,20),
  ZIndex = 1,
};
LabelBl label = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LabelBl(canvas) {
  Content = &lt;span style="color:#A31515;"&gt;&amp;quot;Hello World: &amp;quot;&lt;/span&gt;.Bl() + thumb.CenterPosition.ToStringBl(),
  Font = { Weight = FontWeights.SemiBold, Size = 80, },
  CenterPosition = canvas.CenterSize,
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The first statement creates a red &lt;b&gt;thumb&lt;/b&gt; that can be dragged (&lt;i&gt;CanDrag = true&lt;/i&gt;).  The initial location of the &lt;b&gt;thumb&lt;/b&gt; is in the right hand bottom corner of the &lt;b&gt;canvas&lt;/b&gt;,&lt;br /&gt;while its Z index is set to one.  The second statement creates a &lt;b&gt;label&lt;/b&gt; whose content is bound to &amp;quot;Hello World&amp;quot; prepended to the current location of the &lt;b&gt;thumb&lt;/b&gt;.  By default,&lt;br /&gt;assignments to properties in Bling are &lt;i&gt;contraints&lt;/i&gt; where the bound to property will change as the bound-to expression changes.  In our example, the &lt;b&gt;label&lt;/b&gt;'s content will change&lt;br /&gt;to always reflect the location of the &lt;b&gt;thumb&lt;/b&gt;, which you can experience this by moving the &lt;b&gt;thumb&lt;/b&gt;. Likewise, the center position of the &lt;b&gt;label&lt;/b&gt; is bound to the center of its containing canvas. As the window that contains the canvas is resized, the label is repositioned so that it always remains in the center. &lt;br /&gt;&lt;br /&gt;Constraints are ubiquitous and incredibly expressive in Bling. Consider another constraint:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
label.RenderTransform.Rotate = (thumb.CenterPosition - label.CenterPosition).Angle.ToDegrees();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This code rotates the &lt;b&gt;label&lt;/b&gt; according to the position of the &lt;b&gt;thumb&lt;/b&gt; with respect to the center of the &lt;b&gt;label&lt;/b&gt;. A vector from the center of the &lt;b&gt;label&lt;/b&gt; is first computed using subtraction, where the vector is then converted into a radian angle (via &lt;i&gt;Angle&lt;/i&gt;), which itself is turned into a degree angle (&lt;i&gt;ToDegrees&lt;/i&gt;).  The result is that the &lt;b&gt;label&lt;/b&gt; rotates as the &lt;b&gt;thumb&lt;/b&gt; is moved in a circle around its center.  This example demonstrates the power of Bling constraints: properties can be bound to many kinds of expressions including those that operate over angles.&lt;br /&gt;&lt;br /&gt;The next piece of code demonstrates how a UI widget can easily undergo custom pixel shading: &lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumbB = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Blue, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(0,0), CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt; 
};
label.Effect.Custom = (input, uv) =&amp;gt; {
  &lt;span style="color:Green;"&gt;/*L1*/&lt;/span&gt; PointBl p = label.RenderTransform.Inverse.Transform(thumbB.CenterPosition - label.LeftTop);
  &lt;span style="color:Green;"&gt;/*L2*/&lt;/span&gt; PointBl q = uv * label.Size;
  &lt;span style="color:Green;"&gt;/*L3*/&lt;/span&gt; DoubleBl d = (p - q).Length;
  &lt;span style="color:Green;"&gt;/*L4*/&lt;/span&gt; d = 1 - (d / 500).Min(1);
  &lt;span style="color:Green;"&gt;/*L5*/&lt;/span&gt; ColorBl clr = (d).Lerp(Colors.Black, Colors.Blue);
  &lt;span style="color:Green;"&gt;/*L6*/&lt;/span&gt; &lt;span style="color:Blue;"&gt;return&lt;/span&gt; ColorBl.FromScRgb((input[uv].ScA).Min((1 - (d * d)).Max(.4)), clr.ScRGB);
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;We want to shade the &lt;b&gt;label&lt;/b&gt; with respect to the position of &lt;b&gt;thumbB&lt;/b&gt;. However, pixel shader effects are applied before render transforms, so we have to transform the position of &lt;b&gt;thumbB&lt;/b&gt; with respect to &lt;b&gt;label&lt;/b&gt;'s inverse transform, which happens on the first line of the shader (below &lt;i&gt;(input,uv) =&amp;gt; {&lt;/i&gt;). Since transforms are relative to the widgets they are applied, we also subtract &lt;b&gt;label&lt;/b&gt;'s left top position from &lt;b&gt;thumbB&lt;/b&gt;'s center position. &lt;b&gt;uv&lt;/b&gt; identifies the  position of the pixel being shaded in term of a percentage rather than in pixels.  So that we can compare &lt;b&gt;uv&lt;/b&gt; to the position of &lt;b&gt;thumbB&lt;/b&gt;, we multiple it by the size of the label (line two) and then we can find the distance between the two points (line three).  Line four specifies that the circle we care about is 500 pixels in radius, which we then invert so that closer distances are higher in value. Line five uses the result &lt;b&gt;d&lt;/b&gt; to interpolate between black and blue colors, which is then used on line six to create the color of the pixel with some modifications to its alpha. &lt;br /&gt;&lt;br /&gt;The resulting pixel shader executes on the GPU with performance similar to a DirectX pixel shader, and in fact, it is a DirectX pixel shader. Pixel shaders can refer to many UI objects and properties  directly, such as positions, although there are limitations. For example, a pixel shader can refer to a point property but not an enum property, and can refer to an image brush but not a solid color brush (due to limitations enforced by WPF). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Fri, 23 Oct 2009 00:15:13 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20091023121513A</guid></item><item><title>Updated Wiki: Pixel effect</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Pixel effect&amp;version=4</link><description>&lt;div class="wikidoc"&gt;A pixel effect is a texture to texture transformation that defines a pixel shader. Example of a pixel effect is a ripple:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; PixelEffect Ripple(&lt;span style="color:Blue;"&gt;this&lt;/span&gt; PointBl Center, DoubleBl Amplitude, 
                                            DoubleBl Frequency, DoubleBl Phase) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PixelEffect(Input =&amp;gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(UV =&amp;gt; {
  PointBl ToPoint = UV - Center;
  DoubleBl Distance = ToPoint.Length;
  PointBl Direction = ToPoint / Distance;
  PointBl Wave = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Angle2DBl(Frequency * Distance + Phase).ToPoint;
  DoubleBl Falloff = (1d - Distance).Saturate.Square;
  DoubleBl Lighting = (Wave.Y * Falloff).Saturate * 0.2 + 0.8;
  PointBl Distance2 = Distance + Amplitude * Wave.X * Falloff;
  ColorBl Color = Input[Center + Distance2 * Direction];
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; ColorBl.FromScRGB(Color.ScA, Color.ScRGB * Amplitude.Lerp(1d, Lighting));
 }));
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The effect is self contained, and leads to the following result:&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=75929" alt="ripple.PNG" title="ripple.PNG" /&gt;&lt;br /&gt;&lt;br /&gt;As with textures, pixel effects can be composed via basic arithmetic operators such as addition or multiplication, or through interpolation (lerp), clamping, and so on. Pixel effects can also be composed using a circle operator of sorts via array indexing notation where e&lt;sub&gt;0&lt;/sub&gt;[e&lt;sub&gt;1&lt;/sub&gt;] is equivalent to input =&amp;gt; e&lt;sub&gt;0&lt;/sub&gt;[e&lt;sub&gt;1&lt;/sub&gt;[input]].&lt;br /&gt;
&lt;h2&gt;Related&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=transition&amp;referringTitle=Home"&gt;Transitions&lt;/a&gt; yield pixel effects when their progress, random seed, and next texture arguments are provided. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=Lighting&amp;referringTitle=Home"&gt;Lighting&lt;/a&gt; results yield pixel effects when normal maps or height fields (normals are approximated) are provided. This forms the basis for bump mapping in pixel shaders.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Tue, 21 Jul 2009 03:38:42 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Pixel effect 20090721033842A</guid></item><item><title>Updated Wiki: shader</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=shader&amp;version=10</link><description>&lt;div class="wikidoc"&gt;All examples in this section are located in Shaders.cs of the Tutorial project.&lt;br /&gt;&lt;br /&gt;A pixel shader is installed on a UI object by assigning function to the &lt;i&gt;Effect.Custom&lt;/i&gt; defined by its bling object. The type of a pixel shader is &lt;i&gt;Func&amp;lt;Texture, PointBl, ColorBl&amp;gt;&lt;/i&gt;, where the first argument is the input texture, the second argument is the pixel being shaded, and the return value is the resulting color of the pixel. A &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=pixel%20effect&amp;referringTitle=Tutorial"&gt;pixel effect&lt;/a&gt; is automatically coercible into a pixel shader.&lt;br /&gt;&lt;br /&gt;As an example consider the following code:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ImageBl image = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBl(canvas) { 
  Source = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; BitmapImage(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Autumn.jpg&amp;quot;&lt;/span&gt;.MakePackUri(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(Shaders))),
};
image.Effect.Custom = (input,uv) =&amp;gt; input[uv];
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This custom effect merely returns the original color of the pixel, leading to no change in the pixel.&lt;br /&gt;The current pixel, &lt;b&gt;uv&lt;/b&gt;, represents the pixel's coordinate as a percentage offset in the &lt;b&gt;input&lt;/b&gt; texture; e.g., the coordinate &lt;i&gt;(.25,.75)&lt;/i&gt; represents a pixel whose X pixel value is 25% the texture's width and whose Y pixel value is 75% the texture's height. We can mirror flip the image horizontally by reversing the accessed pixel's X coordinate:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
image.Effect.Custom = (input,uv) =&amp;gt; input[&lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(1 - uv.X, uv.Y)];
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The expression 1 - n addresses an opposing percent of n; e.g., if n is .33, 1 - n is .66. We can also flip the image vertically by reversing the accessed pixel's Y coordinate:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
image.Effect.Custom = (input,uv) =&amp;gt;  input[&lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(uv.X, 1 - uv.Y)];
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The following is the result of the last shaders. The first image has no effect applied, the second one flips horizontally, the last one flips vertically.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=58740" alt="a.jpg" title="a.jpg" /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=58741" alt="a_flipX.jpg" title="a_flipX.jpg" /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=58742" alt="a_flipY.jpg" title="a_flipY.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;For more fun, we can distort the image according to a draggable thumb. Consider:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  CenterPosition = canvas.CenterSize, ZIndex = 1,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;, Background = Brushes.Red
};
image.Effect.Custom = (input,uv) =&amp;gt; {
  PointBl v = ((uv * image.Size) - (thumb - image.LeftTop));
  DoubleBl l = (v.Length / 100);
  l = l.Pow(3);
  l = (l &amp;gt;= 1).Condition(0, l);
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; input[uv + l * v.Normal * .1];
};
&lt;/pre&gt;&lt;/div&gt;This code draws a lense around the current position of the thumb. Because we want to compare the current pixel being shaded (&lt;b&gt;uv&lt;/b&gt;) to the thumb's position, we multiply &lt;b&gt;uv&lt;/b&gt; by the size of the image and subtract the image's position from thumb (coerced to a position). This gives us a vector that we can then used to find the pixel distance between the current pixel and the thumb, which we divide by 100 so the lense's radius is 100 pixels. We take this length, raise it to the third power (so that the lense looks curvy) and use a condition to filter any length at one or greater to zero to create a clear border for the length. This value is then used to displace pixels in the lense according to l and the normal vector of the pixel from the thumb thumb. Result:&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=58743" alt="a_distort.jpg" title="a_distort.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;The pixel shaders shown so far operate by displacing pixels. Pixel shaders can also manipulate colors. Taking our last example, we can interpolate gray into the distorted part of the lense for a more realistic effect:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
image.Effect.Custom = (input,uv) =&amp;gt; {
  PointBl v = ((uv * image.Size) - (thumb - image.LeftTop));
  DoubleBl l = (v.Length / 100);
  l = l.Pow(3);
  l = (l &amp;gt;= 1).Condition(0, l);
  ColorBl clr = input[uv + l * v.Normal * .1];
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; l.Lerp(clr, Colors.Gray);
};
&lt;/pre&gt;&lt;/div&gt;The last line interpolates (&amp;quot;lerp&amp;quot;) between the computed color and gray based on the &lt;b&gt;l&lt;/b&gt; value. Result:&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=58744" alt="a_distortB.jpg" title="a_distortB.jpg" /&gt;&lt;br /&gt;
&lt;h3&gt;MetaBalls&lt;/h3&gt;
Pixel shaders that compute colors based on distances are very powerful. One example application of such a shader is to create &lt;a href="http://en.wikipedia.org/wiki/Metaballs" class="externalLink"&gt;MetaBalls&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, which are used to simulate organic objects. The MetaBall example in the tutorial is located in MetaBalls.cs. First, we create a second canvas in the main canvas to hold the meta-ball effect; we'll add thumbs in the main canvas on top of this second canvas to control the positions of the metaballs:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;new&lt;/span&gt; CanvasBl(canvas) {
  Size = canvas.Size, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(0, 0),
  Background = Brushes.Black,
}.Effect.Custom = (input, uv) =&amp;gt; {
&lt;/pre&gt;&lt;/div&gt;We don't bother assigning the canvas to a variable as we don't need to refer to it again (its just there to hold the effect). The rest of the metaball code takes place inside the custom effect function. Each metaball has its own primary color, which we store in a &lt;b&gt;colors&lt;/b&gt; array.  Each pixel has a &lt;b&gt;color&lt;/b&gt; that depends on how close the pixel is collectively to the metaball centers, which we express as &lt;b&gt;metaball&lt;/b&gt;. Code:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Random r = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Random();
ColorBl[] colors = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ColorBl[] {
  Colors.Red, Colors.Blue,
  Colors.Green, Colors.Cyan,
  Colors.Orange, Colors.Yellow,
};
ColorBl color = Colors.Black;
DoubleBl metaball = 0;
&lt;/pre&gt;&lt;/div&gt;Now, the metaball algorithm measures the distance and color of each pixel through a basic loop. We also create the WPF thumbs in this loop, as the loop will only be executed once when the pixel shader is generated. This behavior sounds a bit weird as the loop is only building an abstract value that is compiled into the pixel shader; even if it directly appears to be computing the pixel's color. Here is the loop:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;foreach&lt;/span&gt; (Color primary &lt;span style="color:Blue;"&gt;in&lt;/span&gt; colors) {
  PointBl point = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
    Background = primary,
    ZIndex = 1,
    CenterPosition = canvas.CenterSize - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(150, 150) +
                              r.NextPoint() * &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(300, 300),
    CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  }.CenterPosition;
  &lt;span style="color:Blue;"&gt;var&lt;/span&gt; v = (uv * canvas.Size - point);
  v = v * v;
  &lt;span style="color:Blue;"&gt;var&lt;/span&gt; at = 3d / (v.X + v.Y);
  color += primary * at;
  metaball += at;
}
&lt;/pre&gt;&lt;/div&gt;The first statement creates the thumb at a random location (&lt;i&gt;r.NextPoint()&lt;/i&gt;) in the canvas with a z-index of one so that the thumb appears above the effect. The current location of the thumb is then compared to the pixel using a tuned metaball distance function. The resulting &lt;b&gt;at&lt;/b&gt; value is then used to accumulate the pixel's color (weighted) and &lt;b&gt;metaball&lt;/b&gt; values. Finally, we compute and return the color: &lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; useColor = color / metaball;
&lt;span style="color:Blue;"&gt;return&lt;/span&gt; (metaball &amp;gt; .0016).Condition(useColor, Colors.White);
&lt;/pre&gt;&lt;/div&gt;We use a threshholding value of .0016 found via tuning, leading to a ball-like organization of the meta-balls. The result looks like this:&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=58836" alt="metaball.jpg" title="metaball.jpg" /&gt;&lt;br /&gt;
&lt;h3&gt;Limitations&lt;/h3&gt;
A pixel shader in Bling is translated into a conventional WPF pixel shader. As a result, they run on the GPU and are subject to various restrictions. Pixel shaders must be simple: they can only contain around 96 instructions and use 32 registers, where instruction and register are defined according to the {url:HLSL|http://en.wikipedia.org/wiki/High_Level_Shader_Language} specification. If you try to build a shader that is too complicated, Bling will throw an exception. Bling will attempt to optimize your pixel shaders (basic common sub-expression elimination), and the HLSL compiler will optimize more, but there are many cases where you'll have to hand tune your shader to make it fit. &lt;br /&gt;&lt;br /&gt;Only simple computations that touch textures or the coordinate of the current pixel will occur in the pixel shader. All other computations occur outside the pixel shader and their results are brought in via registers. To save instructions, you can try to re-arrange your pixel shader so that as many computations occur as possible before textures and the current pixel coordinate is touched.  Additionally, many computations cannot occur in shaders; e.g., if it involves creating a widget (as in the metaball example) or if it involves a transform matrix. In these cases, a &lt;i&gt;NotSupportedOperationException&lt;/i&gt; is thrown. &lt;br /&gt;&lt;br /&gt;A pixel shader does not support real looping. Instead, loops are unrolled so must be fixed in length. For example, the loop in the meta-ball example is only of size six. Unrolling is an important consideration since it will cause instructions to be consumed faster. Likewise, &amp;quot;if&amp;quot; is not supported in a pixel shader, and you must use Condition instead ({url:constraints|Constraints} share this limitation). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Tue, 21 Jul 2009 03:37:37 GMT</pubDate><guid isPermaLink="false">Updated Wiki: shader 20090721033737A</guid></item><item><title>Updated Wiki: Home</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Home&amp;version=47</link><description>&lt;div class="wikidoc"&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=Tutorial"&gt;Tutorial Manual&lt;/a&gt; | &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=FAQ"&gt;FAQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Bling is a C#-based library for easily programming images, animations, interactions, and visualizations on Microsoft's WPF/.NET. Bling is oriented towards design technologists, i.e., designers who sometimes program, to aid in the rapid prototyping of rich UI design ideas.  Students, artists, researchers, and hobbyists will also find Bling useful as a tool for quickly expressing ideas or visualizations. Bling's APIs and constructs are optimized for the fast programming of throw away code as opposed to the careful programming of production code. &lt;br /&gt;&lt;br /&gt;Bling as the following features that aid in the rapid prototyping of rich UIs:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=constraints"&gt;Declarative constraints&lt;/a&gt;&lt;/b&gt; that maintain dynamic relationships in the UI without the need for complex event handling.  For example, &lt;i&gt;button.Width = 100 - slider.Value&lt;/i&gt; causes button to shrink as the slider thumb is moved to the right, or grow as it is moved to the left. Constraints have many benefits: they allow rich custom layouts to be expressed with very little code, they are easy animate, and they support UIs with lots of dynamic behavior. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=constraints&amp;ANCHOR#animation"&gt;Simplified animation&lt;/a&gt;&lt;/b&gt; with one line of code. For example, &lt;i&gt;button.Left.Animate().Duration(500).To = label.Right&lt;/i&gt; will cause button to move to the right of label in 500 milliseconds. &lt;/li&gt;
&lt;li&gt;High-level &lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=fungraphics"&gt;functional programming constructs&lt;/a&gt;&lt;/b&gt; for graphics programming including abstractions for &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=texture"&gt;textures&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=pixel%20effect"&gt;pixel effects&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=transition"&gt;transitions&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=curve"&gt;curves&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=surface"&gt;surfaces&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=height%20field"&gt;height fields&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=normal%20map"&gt;normal maps&lt;/a&gt;, and 3D/2.5D &lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=lighting"&gt;lighting&lt;/a&gt;&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;Experimental support for Direct3D 10 pixel/vertex shaders.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=shader"&gt;Pixel shader effects&lt;/a&gt;&lt;/b&gt; without the need to write HLSL code or boilerplate code! For example, &lt;i&gt;canvas.Effect.Custom = (input, uv) =&amp;gt; new ColorBl(new Point3DBl(1,1,1) - input[uv].ScRGB, input[uv].ScA);&lt;/i&gt; defines and installs a pixel shader on a canvas that inverts the canvas's colors.  Pixel shading in Bling takes advantage of your graphics card to create rich, pixel-level effects. &lt;/li&gt;
&lt;li&gt;An experimental &lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=physics"&gt;UI physics engine&lt;/a&gt;&lt;/b&gt; for integrating physics into user interfaces! The physics supported by Bling is flexible, controllable, and easy to program.  &lt;/li&gt;
&lt;li&gt;A rich library of &lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=geometry"&gt;geometry routines&lt;/a&gt;&lt;/b&gt;; e.g., finding where two lines intersect, the base of a triangle, the area of triangle, or a point on Bezier curve. These routines are compatible with all of Bling's features; e.g., they can be used in express constraints, pixel shaders, or physical constraints. Bling also provides a rich API for manipulating angles in both degrees and radians.&lt;/li&gt;
&lt;li&gt;And many &lt;b&gt;smaller things&lt;/b&gt;; e.g., a frame-based background animation manager and slide presentation system.&lt;/li&gt;
&lt;li&gt;As a &lt;b&gt;lightweight wrapper&lt;/b&gt; around WPF, Bling code is completely compatible with conventional WPF code written in C#, XAML, or other .NET languages.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Bling is an open source project created by &lt;a href="mailto:sean.mcdirmid@gmail.com" class="externalLink"&gt;Sean McDirmid&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and friends to aid in design rapid prototyping. We used Bling to enhance our productivity and would like to share it with other WPF UI design prototypers.&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
Requirments: Visual Studio 2008 full or &lt;a href="http://www.microsoft.com/express/download/" class="externalLink"&gt;Express&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6" class="externalLink"&gt;.NET 3.5&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7" class="externalLink"&gt;.NET 3.5 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" class="externalLink"&gt;Visual Studio 2008 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (may not be necessary, comes with VS 2008 Express). To support WPF pixel shaders, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=c1367bc3-4676-481a-bfaa-5c15d1d7199d" class="externalLink"&gt;DirectX August 2008 runtime&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is sometimes required, although this is often already installed on your machine.&lt;br /&gt;&lt;br /&gt;As of Bling 3, DirectX 10 is also supported for Windows Vista and Windows 7 (sorry XP users!). If you want to use DirectX 10, you'll have to install the latest redistrutable; e.g., the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;amp;displaylang=en" class="externalLink"&gt;web installer&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Bling also depends on the WindowsAPICodePack and the DLR, but both DLLs are included in the distribution.&lt;br /&gt;&lt;br /&gt;Download the source release from the web page. An example comes with the release. To include in your own project for WPF development, simply add the Bling.Core and Bling.WPF projects to your solution, and then add a reference to the Bling project from your own project. For DirectX 10 development, add and refer to the Bling.Core, Bling.WPF, and Bling.D3D10 projects.&lt;br /&gt;
&lt;h3&gt;Example&lt;/h3&gt;
The code used in this getting started example is located in the GettingStarted.cs file of the GettingStarted project in the release. We start of this example by creating a &lt;b&gt;thumb&lt;/b&gt; and &lt;b&gt;label&lt;/b&gt; on a &lt;b&gt;canvas&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  CenterPosition = canvas.Size - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(20,20),
  ZIndex = 1,
};
LabelBl label = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LabelBl(canvas) {
  Content = &lt;span style="color:#A31515;"&gt;&amp;quot;Hello World: &amp;quot;&lt;/span&gt;.Bl() + thumb.CenterPosition.ToStringBl(),
  Font = { Weight = FontWeights.SemiBold, Size = 80, },
  CenterPosition = canvas.CenterSize,
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The first statement creates a red &lt;b&gt;thumb&lt;/b&gt; that can be dragged (&lt;i&gt;CanDrag = true&lt;/i&gt;).  The initial location of the &lt;b&gt;thumb&lt;/b&gt; is in the right hand bottom corner of the &lt;b&gt;canvas&lt;/b&gt;,&lt;br /&gt;while its Z index is set to one.  The second statement creates a &lt;b&gt;label&lt;/b&gt; whose content is bound to &amp;quot;Hello World&amp;quot; prepended to the current location of the &lt;b&gt;thumb&lt;/b&gt;.  By default,&lt;br /&gt;assignments to properties in Bling are &lt;i&gt;contraints&lt;/i&gt; where the bound to property will change as the bound-to expression changes.  In our example, the &lt;b&gt;label&lt;/b&gt;'s content will change&lt;br /&gt;to always reflect the location of the &lt;b&gt;thumb&lt;/b&gt;, which you can experience this by moving the &lt;b&gt;thumb&lt;/b&gt;. Likewise, the center position of the &lt;b&gt;label&lt;/b&gt; is bound to the center of its containing canvas. As the window that contains the canvas is resized, the label is repositioned so that it always remains in the center. &lt;br /&gt;&lt;br /&gt;Constraints are ubiquitous and incredibly expressive in Bling. Consider another constraint:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
label.RenderTransform.Rotate = (thumb.CenterPosition - label.CenterPosition).Angle.ToDegrees();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This code rotates the &lt;b&gt;label&lt;/b&gt; according to the position of the &lt;b&gt;thumb&lt;/b&gt; with respect to the center of the &lt;b&gt;label&lt;/b&gt;. A vector from the center of the &lt;b&gt;label&lt;/b&gt; is first computed using subtraction, where the vector is then converted into a radian angle (via &lt;i&gt;Angle&lt;/i&gt;), which itself is turned into a degree angle (&lt;i&gt;ToDegrees&lt;/i&gt;).  The result is that the &lt;b&gt;label&lt;/b&gt; rotates as the &lt;b&gt;thumb&lt;/b&gt; is moved in a circle around its center.  This example demonstrates the power of Bling constraints: properties can be bound to many kinds of expressions including those that operate over angles.&lt;br /&gt;&lt;br /&gt;The next piece of code demonstrates how a UI widget can easily undergo custom pixel shading: &lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumbB = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Blue, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(0,0), CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt; 
};
label.Effect.Custom = (input, uv) =&amp;gt; {
  &lt;span style="color:Green;"&gt;/*L1*/&lt;/span&gt; PointBl p = label.RenderTransform.Inverse.Transform(thumbB.CenterPosition - label.LeftTop);
  &lt;span style="color:Green;"&gt;/*L2*/&lt;/span&gt; PointBl q = uv * label.Size;
  &lt;span style="color:Green;"&gt;/*L3*/&lt;/span&gt; DoubleBl d = (p - q).Length;
  &lt;span style="color:Green;"&gt;/*L4*/&lt;/span&gt; d = 1 - (d / 500).Min(1);
  &lt;span style="color:Green;"&gt;/*L5*/&lt;/span&gt; ColorBl clr = (d).Lerp(Colors.Black, Colors.Blue);
  &lt;span style="color:Green;"&gt;/*L6*/&lt;/span&gt; &lt;span style="color:Blue;"&gt;return&lt;/span&gt; ColorBl.FromScRgb((input[uv].ScA).Min((1 - (d * d)).Max(.4)), clr.ScRGB);
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;We want to shade the &lt;b&gt;label&lt;/b&gt; with respect to the position of &lt;b&gt;thumbB&lt;/b&gt;. However, pixel shader effects are applied before render transforms, so we have to transform the position of &lt;b&gt;thumbB&lt;/b&gt; with respect to &lt;b&gt;label&lt;/b&gt;'s inverse transform, which happens on the first line of the shader (below &lt;i&gt;(input,uv) =&amp;gt; {&lt;/i&gt;). Since transforms are relative to the widgets they are applied, we also subtract &lt;b&gt;label&lt;/b&gt;'s left top position from &lt;b&gt;thumbB&lt;/b&gt;'s center position. &lt;b&gt;uv&lt;/b&gt; identifies the  position of the pixel being shaded in term of a percentage rather than in pixels.  So that we can compare &lt;b&gt;uv&lt;/b&gt; to the position of &lt;b&gt;thumbB&lt;/b&gt;, we multiple it by the size of the label (line two) and then we can find the distance between the two points (line three).  Line four specifies that the circle we care about is 500 pixels in radius, which we then invert so that closer distances are higher in value. Line five uses the result &lt;b&gt;d&lt;/b&gt; to interpolate between black and blue colors, which is then used on line six to create the color of the pixel with some modifications to its alpha. &lt;br /&gt;&lt;br /&gt;The resulting pixel shader executes on the GPU with performance similar to a DirectX pixel shader, and in fact, it is a DirectX pixel shader. Pixel shaders can refer to many UI objects and properties  directly, such as positions, although there are limitations. For example, a pixel shader can refer to a point property but not an enum property, and can refer to an image brush but not a solid color brush (due to limitations enforced by WPF). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Tue, 21 Jul 2009 03:35:29 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20090721033529A</guid></item><item><title>Updated Wiki: transition</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=transition&amp;version=2</link><description>&lt;div class="wikidoc"&gt;A transition is a function from a progress value (R&lt;sup&gt;1&lt;/sup&gt;), random seed (R&lt;sup&gt;1&lt;/sup&gt;) and next &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=texture&amp;referringTitle=Home"&gt;texture&lt;/a&gt; to a &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=pixel%20effect&amp;referringTitle=Home"&gt;pixel effect&lt;/a&gt; that implements the transition. Transitions encapsulate pixel-level slide transitions that you might see in presentation programs such as PowerPoint. Example encoding of a crumple transition:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;readonly&lt;/span&gt; Transition Crumple = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Transition((Progress, RandomSeed, NextInput) =&amp;gt;
 &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PixelEffect(Input =&amp;gt; {
   DoubleBl p = Progress * 2d;
   p = (p &amp;gt; 1.0).Condition(1.0 - (p - 1.0), p);
   ColorBl t1 = CloudPoint(Input, 10, RandomSeed, p);
   ColorBl t2 = CloudPoint(NextInput, 10, RandomSeed, p);
   &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Progress.Lerp(t1, t2);
}));
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;&lt;br /&gt;&lt;i&gt;CloudPoint&lt;/i&gt; is a method that distorts based on a cloud texture, implemented in three one line methods:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; Texture CloudPointT(DoubleBl Div, DoubleBl RandomSeed) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Driver.CloudImage.Distort((uv =&amp;gt; (uv / Div).MapY(y =&amp;gt; (y + 0.9.Bl().Min(RandomSeed)).Frac)));
}
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; PointBl CloudPoint(PointBl uv, DoubleBl div, DoubleBl RandomSeed) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; CloudPointT(div, RandomSeed)[uv].XY() * 2.0 - 1.0.Bl();
}
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; Texture CloudPoint(&lt;span style="color:Blue;"&gt;this&lt;/span&gt; Texture Input, DoubleBl Div, DoubleBl RandomSeed, PointBl Progress) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Input.Distort(uv =&amp;gt;  (uv + CloudPoint(uv, Div, RandomSeed) * Progress).Frac);
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Result of an intermediate crumple:&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=75936" alt="crumple.PNG" title="crumple.PNG" /&gt;&lt;br /&gt;&lt;br /&gt;As with pixel effects, transitions can be composed, where Max and Min and Lerp are the most useful composition functions.&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 15:18:17 GMT</pubDate><guid isPermaLink="false">Updated Wiki: transition 20090720031817P</guid></item><item><title>Updated Wiki: transition</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=transition&amp;version=1</link><description>&lt;div class="wikidoc"&gt;A transition is a function from a progress value (R&lt;sup&gt;1&lt;/sup&gt;), random seed (R&lt;sup&gt;1&lt;/sup&gt;) and next &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=texture&amp;referringTitle=Home"&gt;texture&lt;/a&gt; to a &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=pixel%20effect&amp;referringTitle=Home"&gt;pixel effect&lt;/a&gt; that implements the transition. Transitions encapsulate pixel-level slide transitions that you might see in presentation programs such as PowerPoint. Example encoding of a crumple transition:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;readonly&lt;/span&gt; Transition Crumple = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Transition((Progress, RandomSeed, NextInput) =&amp;gt;
 &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PixelEffect(Input =&amp;gt; {
   DoubleBl p = Progress * 2d;
   p = (p &amp;gt; 1.0).Condition(1.0 - (p - 1.0), p);
   ColorBl t1 = CloudPoint(Input, 10, RandomSeed, p);
   ColorBl t2 = CloudPoint(NextInput, 10, RandomSeed, p);
   &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Progress.Lerp(t1, t2);
}));
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;&lt;br /&gt;&lt;i&gt;CloudPoint&lt;/i&gt; is a method that distorts based on a cloud texture, implemented in three one line methods:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; Texture CloudPointT(DoubleBl Div, DoubleBl RandomSeed) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Driver.CloudImage.Distort((uv =&amp;gt; (uv / Div).MapY(y =&amp;gt; (y + 0.9.Bl().Min(RandomSeed)).Frac)));
}
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; PointBl CloudPoint(PointBl uv, DoubleBl div, DoubleBl RandomSeed) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; CloudPointT(div, RandomSeed)[uv].XY() * 2.0 - 1.0.Bl();
}
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; Texture CloudPoint(&lt;span style="color:Blue;"&gt;this&lt;/span&gt; Texture Input, DoubleBl Div, DoubleBl RandomSeed, PointBl Progress) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Input.Distort(uv =&amp;gt;  (uv + CloudPoint(uv, Div, RandomSeed) * Progress).Frac);
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Result of an intermediate crumple:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 15:16:46 GMT</pubDate><guid isPermaLink="false">Updated Wiki: transition 20090720031646P</guid></item><item><title>Updated Wiki: Pixel effect</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Pixel effect&amp;version=3</link><description>&lt;div class="wikidoc"&gt;A pixel effect is a texture to texture transformation that defines a pixel shader. Example of a pixel effect is a ripple:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; PixelEffect Ripple(&lt;span style="color:Blue;"&gt;this&lt;/span&gt; PointBl Center, DoubleBl Amplitude, 
                                            DoubleBl Frequency, DoubleBl Phase) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PixelEffect(Input =&amp;gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(UV =&amp;gt; {
  PointBl ToPoint = UV - Center;
  DoubleBl Distance = ToPoint.Length;
  PointBl Direction = ToPoint / Distance;
  PointBl Wave = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Angle2DBl(Frequency * Distance + Phase).ToPoint;
  DoubleBl Falloff = (1d - Distance).Saturate.Square;
  DoubleBl Lighting = (Wave.Y * Falloff).Saturate * 0.2 + 0.8;
  PointBl Distance2 = Distance + Amplitude * Wave.X * Falloff;
  ColorBl Color = Input[Center + Distance2 * Direction];
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; ColorBl.FromScRGB(Color.ScA, Color.ScRGB * Amplitude.Lerp(1d, Lighting));
 }));
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The effect is self contained, and leads to the following result:&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=75929" alt="ripple.PNG" title="ripple.PNG" /&gt;&lt;br /&gt;&lt;br /&gt;As with textures, pixel effects can be composed via basic arithmetic operators such as addition or multiplication, or through interpolation (lerp), clamping, and so on. Pixel effects can also be composed using a circle operator of sorts via array indexing notation where e&lt;sub&gt;0&lt;/sub&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=e%2c%2c1%2c%2c&amp;referringTitle=Home"&gt;e,,1,,&lt;/a&gt; is equivalent to input =&amp;gt; e&lt;sub&gt;0&lt;/sub&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=e%2c%2c1%2c%2c%5binput&amp;referringTitle=Home"&gt;e,,1,,&amp;#91;input&lt;/a&gt;].&lt;br /&gt;
&lt;h2&gt;Related&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=transition&amp;referringTitle=Home"&gt;Transitions&lt;/a&gt; yield pixel effects when their progress, random seed, and next texture arguments are provided. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=Lighting&amp;referringTitle=Home"&gt;Lighting&lt;/a&gt; results yield pixel effects when normal maps or height fields (normals are approximated) are provided. This forms the basis for bump mapping in pixel shaders.&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 15:07:43 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Pixel effect 20090720030743P</guid></item><item><title>Updated Wiki: Pixel effect</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Pixel effect&amp;version=2</link><description>&lt;div class="wikidoc"&gt;A pixel effect is a texture to texture transformation that defines a pixel shader. Example of a pixel effect is a ripple:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;static&lt;/span&gt; PixelEffect Ripple(&lt;span style="color:Blue;"&gt;this&lt;/span&gt; PointBl Center, DoubleBl Amplitude, 
                                            DoubleBl Frequency, DoubleBl Phase) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PixelEffect(Input =&amp;gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(UV =&amp;gt; {
  PointBl ToPoint = UV - Center;
  DoubleBl Distance = ToPoint.Length;
  PointBl Direction = ToPoint / Distance;
  PointBl Wave = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Angle2DBl(Frequency * Distance + Phase).ToPoint;
  DoubleBl Falloff = (1d - Distance).Saturate.Square;
  DoubleBl Lighting = (Wave.Y * Falloff).Saturate * 0.2 + 0.8;
  PointBl Distance2 = Distance + Amplitude * Wave.X * Falloff;
  ColorBl Color = Input[Center + Distance2 * Direction];
  &lt;span style="color:Blue;"&gt;var&lt;/span&gt; Color2 = ColorBl.FromScRGB(Color.ScA, Color.ScRGB * Amplitude.Lerp(1d, Lighting));
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; Color2;
 }));
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The above pixel effect is self contained and creates a ripple, as&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=bling&amp;DownloadId=75929" alt="ripple.PNG" title="ripple.PNG" /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 14:54:22 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Pixel effect 20090720025422P</guid></item><item><title>Updated Wiki: Pixel effect</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Pixel effect&amp;version=1</link><description>&lt;div class="wikidoc"&gt;page exists.&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 14:45:39 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Pixel effect 20090720024539P</guid></item><item><title>Updated Wiki: Home</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Home&amp;version=46</link><description>&lt;div class="wikidoc"&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=Tutorial"&gt;Tutorial Manual&lt;/a&gt; | &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=FAQ"&gt;FAQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Bling is a C#-based library for easily programming images, animations, interactions, and visualizations on Microsoft's WPF/.NET. Bling is oriented towards design technologists, i.e., designers who sometimes program, to aid in the rapid prototyping of rich UI design ideas.  Students, artists, researchers, and hobbyists will also find Bling useful as a tool for quickly expressing ideas or visualizations. Bling's APIs and constructs are optimized for the fast programming of throw away code as opposed to the careful programming of production code. &lt;br /&gt;&lt;br /&gt;Bling as the following features that aid in the rapid prototyping of rich UIs:
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=constraints"&gt;Declarative constraints&lt;/a&gt;&lt;/b&gt; that maintain dynamic relationships in the UI without the need for complex event handling.  For example, &lt;i&gt;button.Width = 100 - slider.Value&lt;/i&gt; causes button to shrink as the slider thumb is moved to the right, or grow as it is moved to the left. Constraints have many benefits: they allow rich custom layouts to be expressed with very little code, they are easy animate, and they support UIs with lots of dynamic behavior. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=constraints&amp;ANCHOR#animation"&gt;Simplified animation&lt;/a&gt;&lt;/b&gt; with one line of code. For example, &lt;i&gt;button.Left.Animate().Duration(500).To = label.Right&lt;/i&gt; will cause button to move to the right of label in 500 milliseconds. &lt;/li&gt;
&lt;li&gt;High-level &lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=fungraphics"&gt;functional programming constructs&lt;/a&gt;&lt;/b&gt; for graphics programming including abstractions for &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=texture"&gt;textures&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=pixel%20effect"&gt;pixel effects&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=transition"&gt;transitions&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=curve"&gt;curves&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=surface"&gt;surfaces&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=height%20field"&gt;height fields&lt;/a&gt;, &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=normal%20map"&gt;normal maps&lt;/a&gt;, and 3D/2.5D &lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=lighting"&gt;lighting&lt;/a&gt;&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;Experimental support for Direct3D 10 pixel/vertex shaders.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=shader"&gt;Pixel shader effects&lt;/a&gt;&lt;/b&gt; without the need to write HLSL code or boilerplate code! For example, &lt;i&gt;canvas.Effect.Custom = (input) =&amp;gt; (uv) =&amp;gt; new ColorBl(new Point3DBl(1,1,1) - input[uv].ScRGB, input[uv].ScA);&lt;/i&gt; defines and installs a pixel shader on a canvas that inverts the canvas's colors.  Pixel shading in Bling takes advantage of your graphics card to create rich, pixel-level effects. &lt;/li&gt;
&lt;li&gt;An experimental &lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=physics"&gt;UI physics engine&lt;/a&gt;&lt;/b&gt; for integrating physics into user interfaces! The physics supported by Bling is flexible, controllable, and easy to program.  &lt;/li&gt;
&lt;li&gt;A rich library of &lt;b&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=geometry"&gt;geometry routines&lt;/a&gt;&lt;/b&gt;; e.g., finding where two lines intersect, the base of a triangle, the area of triangle, or a point on Bezier curve. These routines are compatible with all of Bling's features; e.g., they can be used in express constraints, pixel shaders, or physical constraints. Bling also provides a rich API for manipulating angles in both degrees and radians.&lt;/li&gt;
&lt;li&gt;And many &lt;b&gt;smaller things&lt;/b&gt;; e.g., a frame-based background animation manager and slide presentation system.&lt;/li&gt;
&lt;li&gt;As a &lt;b&gt;lightweight wrapper&lt;/b&gt; around WPF, Bling code is completely compatible with conventional WPF code written in C#, XAML, or other .NET languages.&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;Bling is an open source project created by &lt;a href="mailto:sean.mcdirmid@gmail.com" class="externalLink"&gt;Sean McDirmid&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and friends to aid in design rapid prototyping. We used Bling to enhance our productivity and would like to share it with other WPF UI design prototypers.&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
Requirments: Visual Studio 2008 full or &lt;a href="http://www.microsoft.com/express/download/" class="externalLink"&gt;Express&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6" class="externalLink"&gt;.NET 3.5&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7" class="externalLink"&gt;.NET 3.5 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" class="externalLink"&gt;Visual Studio 2008 SP1&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (may not be necessary, comes with VS 2008 Express). To support WPF pixel shaders, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=c1367bc3-4676-481a-bfaa-5c15d1d7199d" class="externalLink"&gt;DirectX August 2008 runtime&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is sometimes required, although this is often already installed on your machine.&lt;br /&gt;&lt;br /&gt;As of Bling 3, DirectX 10 is also supported for Windows Vista and Windows 7 (sorry XP users!). If you want to use DirectX 10, you'll have to install the latest redistrutable; e.g., the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;amp;displaylang=en" class="externalLink"&gt;web installer&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Bling also depends on the WindowsAPICodePack and the DLR, but both DLLs are included in the distribution.&lt;br /&gt;&lt;br /&gt;Download the source release from the web page. An example comes with the release. To include in your own project for WPF development, simply add the Bling.Core and Bling.WPF projects to your solution, and then add a reference to the Bling project from your own project. For DirectX 10 development, add and refer to the Bling.Core, Bling.WPF, and Bling.D3D10 projects.&lt;br /&gt;
&lt;h3&gt;Example&lt;/h3&gt;
The code used in this getting started example is located in the GettingStarted.cs file of the GettingStarted project in the release. We start of this example by creating a &lt;b&gt;thumb&lt;/b&gt; and &lt;b&gt;label&lt;/b&gt; on a &lt;b&gt;canvas&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumb = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt;,
  CenterPosition = canvas.Size - &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(20,20),
  ZIndex = 1,
};
LabelBl label = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; LabelBl(canvas) {
  Content = &lt;span style="color:#A31515;"&gt;&amp;quot;Hello World: &amp;quot;&lt;/span&gt;.Bl() + thumb.CenterPosition.ToStringBl(),
  Font = { Weight = FontWeights.SemiBold, Size = 80, },
  CenterPosition = canvas.CenterSize,
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The first statement creates a red &lt;b&gt;thumb&lt;/b&gt; that can be dragged (&lt;i&gt;CanDrag = true&lt;/i&gt;).  The initial location of the &lt;b&gt;thumb&lt;/b&gt; is in the right hand bottom corner of the &lt;b&gt;canvas&lt;/b&gt;,&lt;br /&gt;while its Z index is set to one.  The second statement creates a &lt;b&gt;label&lt;/b&gt; whose content is bound to &amp;quot;Hello World&amp;quot; prepended to the current location of the &lt;b&gt;thumb&lt;/b&gt;.  By default,&lt;br /&gt;assignments to properties in Bling are &lt;i&gt;contraints&lt;/i&gt; where the bound to property will change as the bound-to expression changes.  In our example, the &lt;b&gt;label&lt;/b&gt;'s content will change&lt;br /&gt;to always reflect the location of the &lt;b&gt;thumb&lt;/b&gt;, which you can experience this by moving the &lt;b&gt;thumb&lt;/b&gt;. Likewise, the center position of the &lt;b&gt;label&lt;/b&gt; is bound to the center of its containing canvas. As the window that contains the canvas is resized, the label is repositioned so that it always remains in the center. &lt;br /&gt;&lt;br /&gt;Constraints are ubiquitous and incredibly expressive in Bling. Consider another constraint:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
label.RenderTransform.Rotate = (thumb.CenterPosition - label.CenterPosition).Angle.ToDegrees();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This code rotates the &lt;b&gt;label&lt;/b&gt; according to the position of the &lt;b&gt;thumb&lt;/b&gt; with respect to the center of the &lt;b&gt;label&lt;/b&gt;. A vector from the center of the &lt;b&gt;label&lt;/b&gt; is first computed using subtraction, where the vector is then converted into a radian angle (via &lt;i&gt;Angle&lt;/i&gt;), which itself is turned into a degree angle (&lt;i&gt;ToDegrees&lt;/i&gt;).  The result is that the &lt;b&gt;label&lt;/b&gt; rotates as the &lt;b&gt;thumb&lt;/b&gt; is moved in a circle around its center.  This example demonstrates the power of Bling constraints: properties can be bound to many kinds of expressions including those that operate over angles.&lt;br /&gt;&lt;br /&gt;The next piece of code demonstrates how a UI widget can easily undergo custom pixel shading: &lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
ThumbBl thumbB = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ThumbBl(canvas) {
  Background = Brushes.Blue, LeftTop = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PointBl(0,0), CanDrag = &lt;span style="color:Blue;"&gt;true&lt;/span&gt; 
};
label.Effect.Custom = (input) =&amp;gt; (uv) =&amp;gt; {
  &lt;span style="color:Green;"&gt;/*L1*/&lt;/span&gt; PointBl p = label.RenderTransform.Inverse.Transform(thumbB.CenterPosition - label.LeftTop);
  &lt;span style="color:Green;"&gt;/*L2*/&lt;/span&gt; PointBl q = uv * label.Size;
  &lt;span style="color:Green;"&gt;/*L3*/&lt;/span&gt; DoubleBl d = (p - q).Length;
  &lt;span style="color:Green;"&gt;/*L4*/&lt;/span&gt; d = 1 - (d / 500).Min(1);
  &lt;span style="color:Green;"&gt;/*L5*/&lt;/span&gt; ColorBl clr = (d).Lerp(Colors.Black, Colors.Blue);
  &lt;span style="color:Green;"&gt;/*L6*/&lt;/span&gt; &lt;span style="color:Blue;"&gt;return&lt;/span&gt; ColorBl.FromScRgb((input[uv].ScA).Min((1 - (d * d)).Max(.4)), clr.ScRGB);
};
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;We want to shade the &lt;b&gt;label&lt;/b&gt; with respect to the position of &lt;b&gt;thumbB&lt;/b&gt;. However, pixel shader effects are applied before render transforms, so we have to transform the position of &lt;b&gt;thumbB&lt;/b&gt; with respect to &lt;b&gt;label&lt;/b&gt;'s inverse transform, which happens on the first line of the shader (below &lt;i&gt;(input,uv) =&amp;gt; {&lt;/i&gt;). Since transforms are relative to the widgets they are applied, we also subtract &lt;b&gt;label&lt;/b&gt;'s left top position from &lt;b&gt;thumbB&lt;/b&gt;'s center position. &lt;b&gt;uv&lt;/b&gt; identifies the  position of the pixel being shaded in term of a percentage rather than in pixels.  So that we can compare &lt;b&gt;uv&lt;/b&gt; to the position of &lt;b&gt;thumbB&lt;/b&gt;, we multiple it by the size of the label (line two) and then we can find the distance between the two points (line three).  Line four specifies that the circle we care about is 500 pixels in radius, which we then invert so that closer distances are higher in value. Line five uses the result &lt;b&gt;d&lt;/b&gt; to interpolate between black and blue colors, which is then used on line six to create the color of the pixel with some modifications to its alpha. &lt;br /&gt;&lt;br /&gt;The resulting pixel shader executes on the GPU with performance similar to a DirectX pixel shader, and in fact, it is a DirectX pixel shader. Pixel shaders can refer to many UI objects and properties  directly, such as positions, although there are limitations. For example, a pixel shader can refer to a point property but not an enum property, and can refer to an image brush but not a solid color brush (due to limitations enforced by WPF). &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 14:45:10 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20090720024510P</guid></item><item><title>Updated Wiki: Texture</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Texture&amp;version=4</link><description>&lt;div class="wikidoc"&gt;A texture is a function from a 2D texture coordinate in (0,0) - (1,1) space to a color. Textures are often created from images; consider any image brush in WPF:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Texture Normals0 = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/3977-normal0.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(Shaders)));
Texture Heights0 = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/3977-height0.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(Shaders)));
Texture Autumn = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Autumn.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(TransitionsTest)));
Texture ImageBrushBl Dock = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Dock.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(TransitionsTest)));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Image textures in DirectX are created a bit differently via a rendering device:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Texture Autumn = Device.TextureFromUri(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Autumn.jpg&amp;quot;&lt;/span&gt;.MakePackUri(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(D3DTest)));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;A texture can also be formed directly from a in-code function, e.g., consider the following method that creates a meta-ball texture:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; Texture MetaBalls(IListBl&amp;lt;PointBl&amp;gt; Points, IListBl&amp;lt;ColorBl&amp;gt; BallColors) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(UV =&amp;gt; {
  ColorBl color = Colors.Black;
  DoubleBl metaball = 0;
  &lt;span style="color:Blue;"&gt;for&lt;/span&gt; (&lt;span style="color:Blue;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; Points.Count; i++) {
   PointBl p = Points[i];
   PointBl v = (UV - Points[i]);
   v = v * v;
   DoubleBl at = 3d / (v.X + v.Y);
   color += BallColors[i] * at;
   metaball += at;
  }
  ColorBl useColor = color / metaball;
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; (metaball &amp;gt; .0016).Condition(useColor, Colors.White);
 });
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The texture abstraction itself supports color-based operations and combinations. Consider lerping between two textures t&lt;sub&gt;0&lt;/sub&gt; and t&lt;sub&gt;1&lt;/sub&gt; as slider.Value.Lerp(t&lt;sub&gt;0&lt;/sub&gt; , t&lt;sub&gt;1&lt;/sub&gt;), which forms a texture that implements a basic fade transition from t&lt;sub&gt;0&lt;/sub&gt; to t&lt;sub&gt;1&lt;/sub&gt;. As with other Bling graphic functions, operations on textures are merely syntactic sugar for expanding out the functions and applying the operation directly to the resulting colors; e.g., the lerp above can be written out as:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(p =&amp;gt; slider.Value.Lerp(t0(p), t1(p)))
&lt;/pre&gt;&lt;/div&gt;Other useful texture operations include max, min, clamp, multiplication, and so on, and are often referred to as filtering. Textures also support distortions re-arrange its pixels by texture coordinate transformations. Example:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
input.Distort(UV =&amp;gt; UV + (UV - 0.5).Perpendicular.Normalize * 0.1)
&lt;/pre&gt;&lt;/div&gt;This distort will cause a 10% swirl about the center of the texture. &lt;br /&gt;
&lt;h2&gt;Related&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;Textures can be explicitly converted into &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=normal%20map&amp;referringTitle=Home"&gt;normal maps&lt;/a&gt; or &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=height%20field&amp;referringTitle=Home"&gt;height fields&lt;/a&gt; by explicit casts. These conversions are based on standard normal map and height field texture encodings produced by popular bump mapping tools, and are meant as a bump mapping convenience. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=pixel%20effect&amp;referringTitle=Home"&gt;Pixel effects&lt;/a&gt; map textures to new textures and are basically the core of a pixel shader. &lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 14:43:48 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Texture 20090720024348P</guid></item><item><title>Updated Wiki: Texture</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Texture&amp;version=3</link><description>&lt;div class="wikidoc"&gt;A texture is a function from a 2D texture coordinate in (0,0) - (1,1) space to a color. Textures are often created from images; consider any image brush in WPF:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Texture Normals0 = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/3977-normal0.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(Shaders)));
Texture Heights0 = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/3977-height0.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(Shaders)));
Texture Autumn = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Autumn.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(TransitionsTest)));
Texture ImageBrushBl Dock = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Dock.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(TransitionsTest)));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Image textures in DirectX are created a bit differently via a rendering device:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Texture Autumn = Device.TextureFromUri(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Autumn.jpg&amp;quot;&lt;/span&gt;.MakePackUri(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(D3DTest)));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;A texture can also be formed directly from a in-code function, e.g., consider the following method that creates a meta-ball texture:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; Texture MetaBalls(IListBl&amp;lt;PointBl&amp;gt; Points, IListBl&amp;lt;ColorBl&amp;gt; BallColors) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(UV =&amp;gt; {
  ColorBl color = Colors.Black;
  DoubleBl metaball = 0;
  &lt;span style="color:Blue;"&gt;for&lt;/span&gt; (&lt;span style="color:Blue;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; Points.Count; i++) {
   PointBl p = Points[i];
   PointBl v = (UV - Points[i]);
   v = v * v;
   DoubleBl at = 3d / (v.X + v.Y);
   color += BallColors[i] * at;
   metaball += at;
  }
  ColorBl useColor = color / metaball;
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; (metaball &amp;gt; .0016).Condition(useColor, Colors.White);
 });
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The texture abstraction itself supports color-based operations and combinations. Consider lerping between two textures t&lt;sub&gt;0&lt;/sub&gt; and t&lt;sub&gt;1&lt;/sub&gt; as slider.Value.Lerp(t&lt;sub&gt;0&lt;/sub&gt; , t&lt;sub&gt;1&lt;/sub&gt;), which forms a texture that implements a basic fade transition from t&lt;sub&gt;0&lt;/sub&gt; to t&lt;sub&gt;1&lt;/sub&gt;. As with other Bling graphic functions, operations on textures are merely syntactic sugar for expanding out the functions and applying the operation directly to the resulting colors; e.g., the lerp above can be written out as:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(p =&amp;gt; slider.Value.Lerp(t0(p), t1(p)))
&lt;/pre&gt;&lt;/div&gt;Other useful texture operations include max, min, clamp, multiplication, and so on, and are often referred to as filtering. Textures also support distortions re-arrange its pixels by texture coordinate transformations. Example:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
input.Distort(UV =&amp;gt; UV + (UV - 0.5).Perpendicular.Normalize * 0.1)
&lt;/pre&gt;&lt;/div&gt;This distort will cause a 10% swirl about the center of the texture. &lt;br /&gt;
&lt;h2&gt;Related&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;Textures can be explicitly converted into &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=normal%20maps&amp;referringTitle=Home"&gt;normal maps&lt;/a&gt; or &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=height%20fields&amp;referringTitle=Home"&gt;height fields&lt;/a&gt; by explicit casts. These conversions are based on standard normal map and height field texture encodings produced by popular bump mapping tools, and are meant as a bump mapping convenience. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=pixel%20effect&amp;referringTitle=Home"&gt;Pixel effects&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 14:42:03 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Texture 20090720024203P</guid></item><item><title>Updated Wiki: Texture</title><link>http://bling.codeplex.com/Wiki/View.aspx?title=Texture&amp;version=2</link><description>&lt;div class="wikidoc"&gt;A texture is a function from a 2D point in &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=0%2c0&amp;referringTitle=Home"&gt;0,0&lt;/a&gt; - &lt;a href="http://bling.codeplex.com/Wiki/View.aspx?title=1%2c1&amp;referringTitle=Home"&gt;1,1&lt;/a&gt; space to a color. Textures are often created from images; consider any image brush in WPF:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Texture Normals0 = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/3977-normal0.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(Shaders)));
Texture Heights0 = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/3977-height0.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(Shaders)));
Texture Autumn = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Autumn.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(TransitionsTest)));
Texture ImageBrushBl Dock = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; ImageBrushBl(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Dock.jpg&amp;quot;&lt;/span&gt;.ImageFor(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(TransitionsTest)));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Image textures in DirectX are created a bit differently via a rendering device:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Texture Autumn = Device.TextureFromUri(&lt;span style="color:#A31515;"&gt;&amp;quot;Resources/Autumn.jpg&amp;quot;&lt;/span&gt;.MakePackUri(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(D3DTest)));
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;A texture can also be formed directly from a in-code function, e.g., consider the following method that creates a meta-ball texture:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; Texture MetaBalls(IListBl&amp;lt;PointBl&amp;gt; Points, IListBl&amp;lt;ColorBl&amp;gt; BallColors) {
 &lt;span style="color:Blue;"&gt;return&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(UV =&amp;gt; {
  ColorBl color = Colors.Black;
  DoubleBl metaball = 0;
  &lt;span style="color:Blue;"&gt;for&lt;/span&gt; (&lt;span style="color:Blue;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; Points.Count; i++) {
   PointBl p = Points[i];
   PointBl v = (UV - Points[i]);
   v = v * v;
   DoubleBl at = 3d / (v.X + v.Y);
   color += BallColors[i] * at;
   metaball += at;
  }
  ColorBl useColor = color / metaball;
  &lt;span style="color:Blue;"&gt;return&lt;/span&gt; (metaball &amp;gt; .0016).Condition(useColor, Colors.White);
 });
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The texture abstraction itself supports color-based operations and combinations. Consider lerping between two textures t&lt;sub&gt;0&lt;/sub&gt; and t&lt;sub&gt;1&lt;/sub&gt; as slider.Value.Lerp(t&lt;sub&gt;0&lt;/sub&gt; , t&lt;sub&gt;1&lt;/sub&gt;), which forms a texture that implements a basic fade transition from t&lt;sub&gt;0&lt;/sub&gt; to t&lt;sub&gt;1&lt;/sub&gt;. As with other Bling graphic functions, operations on textures are merely syntactic sugar for expanding out the functions and applying the operation directly to the resulting colors; e.g., the lerp above can be written out as:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Texture(p =&amp;gt; slider.Value.Lerp(t,,0,,(p), t,,1,,(p)))
&lt;/pre&gt;&lt;/div&gt;Other useful texture operations include max, min, clamp, multiplication, and so on. &lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>mcdirmid</author><pubDate>Mon, 20 Jul 2009 14:28:37 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Texture 20090720022837P</guid></item></channel></rss>