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:
- Preview the transition or effect in MM, pause it midway and save a snapshot
- Use IrfanView to resize it to 96*72 (optionally put a 3D button look like the original icons)
- Repeat 1-2 for other effects/transitions saving each icon
- Use Irfanview to make a horizontal panorama of all the icons - save as *.bmp
- Use ResourceHacker to put the new bitmap inside an existing MM button DLL
- 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
|