Why i can not load a simple pixel shader effect (. fx) file in xna?
Posted
by
Mehdi Bugnard
on Game Development
See other posts from Game Development
or by Mehdi Bugnard
Published on 2013-10-17T06:50:24Z
Indexed on
2013/10/17
16:26 UTC
Read the original article
Hit count: 481
I just want to load a simple *.fx file into my project to make a (pixel shader) effect.
But whenever I try to compile my project, I get the following error in visual studio Error List:
Errors compiling ..
ID3DXEffectCompiler: There were no techniques
ID3DXEffectCompiler: Compilation failed
I already searched on google and found many people with the same problem. And I realized that it was a problem of encoding. With the return lines unrecognized '\ n' .
I tried to copy and paste to notepad and save as with ASCII or UTF8 encoding. But the result is always the same.
Do you have an idea please ? Thanks a looot :-)
Here is my [.fx] file :
sampler BaseTexture : register(s0);
sampler MaskTexture : register(s1)
{
addressU = Clamp;
addressV = Clamp;
};
//All of these variables are pixel values
//Feel free to replace with float2 variables
float MaskLocationX;
float MaskLocationY;
float MaskWidth;
float MaskHeight;
float BaseTextureLocationX; //This is where your texture is to be drawn
float BaseTextureLocationY; //texCoord is different, it is the current pixel
float BaseTextureWidth;
float BaseTextureHeight;
float4 main(float2 texCoord : TEXCOORD0) : COLOR0
{
//We need to calculate where in terms of percentage to sample from the MaskTexture
float maskPixelX = texCoord.x * BaseTextureWidth + BaseTextureLocationX;
float maskPixelY = texCoord.y * BaseTextureHeight + BaseTextureLocationY;
float2 maskCoord = float2((maskPixelX - MaskLocationX) / MaskWidth, (maskPixelY - MaskLocationY) / MaskHeight);
float4 bitMask = tex2D(MaskTexture, maskCoord);
float4 tex = tex2D(BaseTexture, texCoord);
//It is a good idea to avoid conditional statements in a pixel shader if you can use math instead.
return tex * (bitMask.a);
//Alternate calculation to invert the mask, you could make this a parameter too if you wanted
//return tex * (1.0 - bitMask.a);
}
© Game Development or respective owner