FX Application Notes

Overlay/Logo FX Example
Grayscale Subroutines
Controlling Progress
Gettimg Real Time
Gamma Effect Example
PNG Transparency
Button Icon DLLs
Night Vision Example
Emboss Example
Placeholder













Other

Return To Home Page
HL & XML App Notes
Favorite MM Links








    

FX Application Notes for DPL Stuff

This section is Vista Movie Maker 6.0 specific and addresses the High Level Shader Language (HLSL - fx) that can be used with Rehan's ShaderTFX plugin. Rehan's ShaderTFX website

ShaderTFX must be installed and operating to use the fx constructs described here. Some may work with a expired ShaderTFX, but most will require an unexpired or licensed version (any using a referenced external image will fail - such as overlays). $15 well spent in my opinion.

The HLSL concept allows direct programming of the graphics hardware of your computer in a syntax that is very similar to the "C" language. You may write HLSL code that operates independently of ShaderTFX as described on the Microsoft site, but Rehan's addition of External Image use allows many neat things, such as gradient transitions, overlays, logos, masking etc.

Included will be simple examples of full fx programs, and some shorter tips and tricks and code constructs.

Also, I will place here some general high level information that is (hopefully) useful in the composing of HLSL programs.

This area is definitely a work in progress.

ShaderTFX & DPL TFX
 
 
    

Working Logo/Overlay Effect FX Code

This effect FX code will provide a basis for XML code below to place a screen size copy of Overlay1.png over the image or video on Moviemaker's timeline. Transparent areas in Overlay1.png will show the background image and opaque areas will thow the Overlay1 image.

Copy this code into notepad, then save as an Overlay1.fx into the .../Movie Maker/Shared/ folder. Because of Vista security, you may have to have administrator privileges and save to someplace like Desktop and then copy/move to the .../Movie Maker/Shared/ folder.

//////////////////////////////////////////////////////////
//  FX Sample (Overlay.fx) - Image Overlay Effect ShaderTFX
//  Freely adapted from Rehan's Overlay code
//////////////////////////////////////////////////////////
#include "ShaderCommon.fxh"

// XML File semantics
float  alphaO : OverlayAlpha =  1;
float4 rectO  : RectOverlay  = {0,0,1,1};

const float gb = 0.0025;  // Guard Band for Color 
                          // Fringing at Image Edges                
////////////////////////////////////////////////////////////
// In Rectangle Subroutine - Determine if t.x t.y point is in rect
bool isInRect(float2 t, float4 rect) {
  return (t.x>(rect.x+gb)        && 
          t.x<(rect.x+rect.z-gb) && 
          t.y>(rect.y+gb)        &&
          t.y<(rect.y+rect.w-gb)    );
}

////////////////////////////////////////////////////////////
// Pixel Shader Overlay Effect Main FX code
////////////////////////////////////////////////////////////
float4 PS_OverlayEffect(float2 t : TEXCOORD0) : COLOR {
float2 tO;          // XY position on overlay (t is XY on the screen)
float4 col, colO    // establish color variables rgba
  float4 col = tex2D(Sampler0, t);     // Get Video Color - Image0
  if (isInRect(t, rectO)) {            // Check for inside overlay rect
    tO.x = (t.x - rectO.x)/rectO.z;      // Scale OverlayRect X position
    tO.y = (t.y - rectO.y)/rectO.w;      // Scale OverlayRect Y position
    float4 colO = tex2D(Sampler2, tO);   // Get Overlay Color - Image2
    col = (colO.a<0.3) ? col : lerp(col,colO,alphaO); //lerp if overlay not transparent
  }
  return col;
}

///////////////////////////// //////////////////////////////
// Overlay Effect Technique 
technique OverlayEffect {
  pass P0     {        
    VertexShader = compile vs_2_0 VS_Basic();
    PixelShader  = compile ps_2_0 PS_OverlayEffect(); 
  }
}

The XML code in the HL & XML App Notes page will utilize this FX code. See the XML

In ShaderTFX the images frames are:

  • Sampler0 - The image the effect is applied to or the 1st image in a transition pair
  • Sampler1 - The 2nd image in a transition pair
  • Sampler2 - The still image specified in the ShaderTFX XML code

More comments to come here!

Return to top
 
 
    

Grayscale Conversion Subroutines

These subroutines accept a float4 color variable and return a float or float4 grayscale rendition of the color.

////////////////////////////////////////////////////////////////////////////////
// Get float Gray Subroutine
float getGray1(float4 col) {
  return (0.299*col.r + 0.587*col.g + 0.114*col.b);
}

////////////////////////////////////////////////////////////////////////////////
// Get float4 Gray Subroutine
float4 getGray4(float4 col) {
float gray = 0.299*col.r + 0.587*col.g + 0.114*col.b;
  return float4 (gray, gray, gray, 1);
}
Return to top

Installing a Progress Parameter

Sometimes it is usefull to control the progress of a TFX directly from the XML. Here is one way to do it.

// XML File semantics
float  prog : Progress = -1;

//(then in the main routine)
float lTime = (prog==-1) ? fTime : prog;

Use the lTime variable to measure progress. Then if no progress parameter is specified in the XML, the progress is just the normal linear progression of the TFX with fTime. Or you can distort or stop the progress with an XLM construct like this:

   <Progress type="float" value= "0.75" />
Return to top

Getting Realtime

Since the fTime (or lTime above) variable gives the time from 0.0 to 1.0 for any length TFX it is sometimes useful to know real time in seconds to do things like flashing or timed alpha ramps. Here is how to get real time:

// Real Time Variable
  float rTime = (fDuration/10000000)*lTime; // fDuration is in 100ns units, rTime in seconds
Return to top

Gamma Effect Example

7/15/2008 This seems to match about what IrfanView does with Gamma Correction and also Rehan's reference (I think).

It is also an example of using an FX file in Vista Movie Maker without using ShaderTFX.

The FX file:

// Save as DPL_Gamma_Effect.fx to Shared Folder 
#include "common.fxh" 

//Global semantics for Gamma Effect 
shared float gamma : Gamma = 1.0; 

//////////////////////////////////////////////////////////////////////////////// 
// Pixel Shader For Gamma Effect 
float4 PS_Gamma(float2 t : TEXCOORD0) : COLOR { 
float4 lgamma = 1.0/gamma; // Inverse ala' graphic editors 
  lgamma.a = 1.0; 
  return saturate(pow(tex2D(PointSampler, t),lgamma)); // Not sure if saturate needed? 
} 

//////////////////////////////////////////////////////////////////////////////// 
// Gamma Effect Technique 
technique GammaEffect { 
  pass P0 { 
    VertexShader = compile vs_2_0 VS_Basic(); 
    PixelShader = compile ps_2_0 PS_Gamma(); 
  } 
} 
and an XML file:
<-- ************* Save as DPL_Gamma_Effect.xml to AddOnTFX folder************* --> 
<TransitionsAndEffects Version="2.8" > 
 <Effects> 
  <EffectDLL guid="TFX"> 

   <Effect name="DPL Gamma 1.5" iconid="3" guid="DPL Gamma 1.5" ShaderModel="2"> 
    <Animation value="FX" /> 
    <FXFile value="DPL_Gamma_Effect.fx" /> 
    <Technique value="GammaEffect"/> 
    <Semantics> 
     <Gamma type="float" value="1.5" /> 
    </Semantics> 
   </Effect> 

   <Effect name="DPL Gamma 0.667" iconid="2" guid="DPL Gamma 0.667" ShaderModel="2"> 
    <Animation value="FX" /> 
    <FXFile value="DPL_Gamma_Effect.fx" /> 
    <Technique value="GammaEffect"/> 
    <Semantics> 
     <Gamma type="float" value="0.667" /> 
    </Semantics> 
   </Effect> 

  </EffectDLL> 
 </Effects> 
</TransitionsAndEffects> 

You can change the Gamma in:

<Gamma type="float" value="0.667" />
Make Gamma >0.0. Gamma=1.0 is no change, <1.0 is darken and >1.0 is lighten.

The Icons used are the Movie Maker ones provided for Brightness, Decrease and Brightness, Increase even though the HLSL for them is more like Josh's in the MovieMaker Forum Gamma Entry.

See Video Sample.

Have Fun, PatrickL

Return to top

Setting PNG Transparency

I use IrfanView to do set a tranparent color like this:

  • Edit the Image File to put a single unique color everywhere you want to be transparent and save it.
  • Open the Image File in Irfanview
  • Click File->SaveAs...
  • in Save As Type select "PNG - Portable Network Graphics"
  • Check the "Show Options Dialog" checkbox
  • Check "Save Transparent Color" in the Options Dialog
  • Name the file and select the folder to save it in
  • Click Save
  • A dialog will pop up allowing you to select the transparent color - click on the color

Viola' you are done.

Other image prograns can set transparency also, read their help files.

Images that start out as JPG have compression artifacts and you may have to paint a solid color to touch up some edges before saving as a PNG. The transparent color in PNG is an exact color, not a shade of a color.

Also images with higher resolution will keep jaggies and pixelation at bay.

Return to top

Making a DLL for TFX Buttons

re: glow post on MM forum.

I use ResourceHacker.

ResourceHacker can take an existing DLL with a bitmap replace its bitmap. Just take an existing MM Button DLL and replace its pictures.

To make the replacement picture:
Like This:

  1. Preview the transition or effect in MM, pause it midway and save a snapshot
  2. Use IrfanView to resize it to 96*72 (optionally put a 3D button look like the original icons)
  3. Repeat 1-2 for other effects/transitions saving each icon
  4. Use Irfanview to make a horizontal panorama of all the icons - save as *.bmp
  5. Use ResourceHacker to put the new bitmap inside an existing MM button DLL
  6. Save the new DLL with the same name as the TFX XML file

Then in the XML, the line:

<TransitionsAndEffects Version="2.8" specialiconfileid="5642" specialiconresourceid="101">

should contain a unique (to your installation) specialiconfileid number, and the specialiconresourceid is always 101.
and a line like:

<Effect name="DPL PIP Effect2" iconid="2" guid="DPL PIP Effect2" ShaderModel="2">

is used to set the icon for the TFX. iconid is set to the image number where the left most icon is 0 and increasing numerically to the right.

If you just want to use an existing button icon, just do this in the XML (remove the specialiconfileid and specialiconresourceid):

<TransitionsAndEffects Version="2.8">

and set the iconids from this built-in set of effect buttons or this set of transition buttons.

Return to top


Night Vision Effect Example

11/17/2008 This effect gives a green cast (like night vision equipment) to the image.

It is also an example of using an FX file in Vista Movie Maker without using ShaderTFX.

The FX file:

//  PatrickL Night Vision  - save as DPL NightVision.fx in Shared folder
#include "common.fxh"

int invert   : Invert = 0;
float4 shade : Shade = {0, 1, 0, 0};  // green
float intens : Intensity = 1.0;

/////////////////// Pixel Shader /////////////////////////
float4 PS_NightVision( float2 t : TEXCOORD0 ) : COLOR0 {
float4 c0 = tex2D(PointSampler, t);
float cg = 0.299*c0.r + 0.587*c0.g + 0.114*c0.b; // get grayscale
  if (invert==1) cg = 1.0-cg;
  return shade*cg*intens;
}

/////////////////// Technique /////////////////////////
technique NightVision {
  pass P0 {
    VertexShader = compile vs_2_0 VS_Basic();
    PixelShader  = compile ps_2_0 PS_NightVision();
  }
}
and an XML file:
<!--  PatrickL Night Vision  - save as DPL NightVision.xml in AddOnTFX folder -->
<TransitionsAndEffects Version="2.8"> 
 <Effects>
  <EffectDLL guid="TFX">

   <Effect name="DPL NightVision" iconid="7" guid="DPL NightVision" shadermodel="2"> 
    <Animation value="FX" /> 
    <FXFile value="DPL NightVision.fx" />
    <Technique value="NightVision" />
   </Effect>

   <Effect name="DPL NightVisionInv" iconid="7" guid="DPL NightVisionInv" shadermodel="2"> 
    <Animation value="FX" /> 
    <FXFile value="DPL NightVision.fx" />
    <Technique value="NightVision" />
    <Semantics>
     <Invert type="int" value="1" />
     <Shade type="float4" value="0, 1, 0, 1" />  
     <Intensity type="float" value="1.0" />
    </Semantics>
   </Effect>

  </EffectDLL>
 </Effects>
</TransitionsAndEffects>

The XML variable parameters are: Invert (1,0), Shade (r,g,b,1) and Intensity (1.0 default).

Video Sample

Have Fun, PatrickL

Return to top

Emboss Effect Example

1/19/2009 This effect gives an embossed look to the image.

It is also an example of using an FX file in Vista Movie Maker without using ShaderTFX.

The FX file:

// DPL_Emboss_Effect.fx to Shared Folder 
//Copyright (c) 2008 PatrickL 

#include "common.fxh" 

//Global semantics for Emboss Effect 
shared float4 rectA : RectA = {0,0,1,1}; 
shared float dx : EmbossDX = 0.003; 
shared float dy : EmbossDY = 0.003; 
shared float bias : Bias = 0.5; 
shared float4 clr : Color = {1,1,1,1}; 
shared float gb : GuardBand= 0.000; 

//////////////////////////////////////////////////////////////////////////////// 
// In Rectangle Subroutine 
bool isInRect(float2 t, float4 rect) { 
 return (t.x<(rect.x+gb)?false:(t.x>(rect.x+rect.z-gb)?false:(t.y<(rect.y+gb)?false:
        (t.y>(rect.y+rect.w-gb)?false:true)))); 
} 

//////////////////////////////////////////////////////////////////////////////// 
// Emboss Subroutine 
float emboss(float2 tex) { 
float4 c[10]; 
 c[1] = tex2D(PointSampler, tex + float2(-dx,-dy)); 
 c[2] = tex2D(PointSampler, tex + float2(0,-dy)); 
/// c[3] = tex2D(PointSampler, tex + float2(dx,-dy)); 
 c[4] = tex2D(PointSampler, tex + float2(-dx,0)); 
 c[6] = tex2D(PointSampler, tex + float2(dx,0)); 
/// c[7] = tex2D(PointSampler, tex + float2(-dx,dy)); 
 c[8] = tex2D(PointSampler, tex + float2(0,dy)); 
 c[9] = tex2D(PointSampler, tex + float2(dx,dy)); 
 c[0] = (-c[1]-c[2]-c[4]+c[6]+c[8]+c[9]); 
 return (0.299*c[0].r+0.587*c[0].g+0.114*c[0].b) + bias; 
} 

//////////////////////////////////////////////////////////////////////////////// 
// Pixel Shader For Emboss Effect 
float4 PS_Emboss(float2 t : TEXCOORD0) : COLOR { 
float4 c0; 
 if (isInRect(t, rectA)) { 
  c0 = emboss(t); 
  c0.a = 1.0; 
  c0 *= clr; 
 } else 
  c0 = tex2D(PointSampler, t); 
 return c0; 
} 

//////////////////////////////////////////////////////////////////////////////// 
// Emboss Effect Technique 
technique EmbossEffect { 
 pass P0 { 
  VertexShader = compile vs_2_0 VS_Basic(); 
  PixelShader = compile ps_2_0 PS_Emboss(); 
 } 
} 

and an XML file:

<!-- ************* DPL_Emboss_Effect.xml to AddOnTFX folder************* --> 
<TransitionsAndEffects Version="2.8" > 
 <Effects> 
  <EffectDLL guid="TFX"> 
   <Effect name="DPL Emboss" iconid="15" guid="DPL Emboss" ShaderModel="2"> 
    <Animation value="FX" /> 
    <FXFile value="DPL_Emboss_Effect.fx" /> 
    <Technique value="EmbossEffect"/> 
    <Semantics> 
     <RectA type="float4" value="0,0,1,1" /> 
     <EmbossDX type="float" value="0.003" /> 
     <EmbossDY type="float" value="0.003" /> 
     <Color type="float4" value = "1,1,1,1" /> 
    </Semantics> 
   </Effect> 
  </EffectDLL> 
 </Effects> 
</TransitionsAndEffects> 

See some discussion of theis at Forum Link and see a Video Sample

Have Fun, PatrickL

Return to top

Dummy Section

Placeholder Dummy

Return to top

Steve's Website templates This site is © Copyright PatrickL 2008,2009 All Rights Reserved.