|
(The description and demo below applies to the latest downloadable version. Please upgrade to the latest version before developing plug-ins.)
GPU-based modifiers use a snippet of HLSL (High Level Shading Language) code to define a pixel-shader that executes on the GPU and modifies pixels in the image. This language is not unique to EIE, it's a language that works for all DirectX applications, but it is used in a specific way in EIE.
Like all other types of plug-ins in EIE, HLSL-based modifiers are built by creating classes in a C# class library that inherit from base classes define in the EIE.Base namespace. In the case of HLSL modifiers, the class should inherit from Base.HLSLModifier1 and implement the abstract methods.
The best way to illustrate this is by example. The following C# class declaration defines a modifier that converts pixels in the image to grayscale:
using System;
using System.Collections.Generic;
using System.Text;
namespace EIE
{
class DesaturateHLSL : Base.HLSLModifier1
{
public override EIEReturnCode Execute(EIEDocument doc,
int imageIndex,
EIEModifierPlugin.ExecuteFlags flags)
{
return EIEReturnCode.Success;
}
public override string HLSLMainCodeSlice
{
get
{
return "float avg = (clr.r + clr.g + clr.b) / 3.0f; " +
"clr.rgb = avg;";
}
}
public override string Title
{
get
{
return "Desaturate (convert to grayscale) (hardware)";
}
}
}
}
|
The Title property is the text that will appear on the menu item under the "Modifiers" menu. The HLSLMainCodeSlice string is the snippet of pixel-shader code that modifies a single pixel. The pixel from the image is in the float4 variable "clr". In this case, the red, green and blue pixel components are set to the average of the three (different color models have different definitions of how to compute grayscale, this is one of many ways to make a pixel grayscale).
With GPU-based plugins all you need to provide is a snippet of shader code that modifies a single pixel. The host application dynamically assembles a pixel shader and adds additional code that takes the selection into consideration, thus eliminating this requirement from the plugin developer. An undo action is also automatically created.
This example shows a non-configurable modification. The Execute function can be used to create and show a configuration dialog if desired, but it must not do so if the NoPrompt flag is set in the flags parameter. An overview of how to write configurable modifiers that use an input dialog and adjust pixel-shader values dynamically will be posted at a later date.
|