This is a mirror of official site: http://jasper-net.blogspot.com/

Custom Bitmap Effects - HLSL

| Wednesday, June 16, 2010
In the article Custom Bitmap Effects - Getting started we discovered how to work with HLSL in WPF. Now we are in a position to write more sophisticated shaders and  this means learning some more HLSL.

In general shaders can work on vertices - i.e. the basic geometry of a 3D object - or the pixels that are about to be displayed. That is HLSL is a language that has commands that are about manipulating geometry and pixels.
In WPF and Silverlight you can only use HLSL to write pixel shaders and the rest of this article concentrates on writing a pixel shader. If you lookup HLSL in the help or a manual you will encounter lots of commands that you can't use to create an effect.
The same ideas, however, apply to vertex shaders and you can use this as an introduction to shaders in general - but you will have to use DirectX to make use of a compiled vertex shader.
Basic syntax

In the previous article on getting started with custom bitmap effects a very simple shader was used as an example and it is now time to examine it in closer detail.
The shader simply returned the color red every time it was called:

float4 main(float2 uv:TEXCOORD):COLOR
{
 vector<float,4>color={1,0,0,1};
 return color;
}

This may be a very simple shader but it illustrates several important ideas. The first is that HLSL is much like C or C# but it is much simpler. You can lookup the syntax in the DirectX help file (installed with the SDK).

Read more: I-Programmer

Posted via email from .NET Info

0 comments: