Error X3650 when compiling shader in XNA
- by Saikai
I'm attempting to convert the XBDEV.NET Mosaic Shader for use in my XNA project and having trouble. The compiler errors out because of the half globals.
At first I tried replacing the globals and just writing the variables explicitly in the code, but that garbles the Output. Next I tried replacing all the half with float vars, but that still garbles the resulting Image.
I call the effect file from SpriteBatch.Begin().
Is there a way to convert this shader to the new pixel shader conventions? Are there any good tutorials for this topic?
Here is the shader file for reference:
/*****************************************************************************/
/*
File: tiles.fx
Details: Modified version of the NVIDIA Composer FX Demo Program 2004
Produces a tiled mosaic effect on the output.
Requires: Vertex Shader 1.1
Pixel Shader 2.0
Modified by: [email protected] (www.xbdev.net)
*/
/*****************************************************************************/
float4 ClearColor : DIFFUSE = { 0.0f, 0.0f, 0.0f, 1.0f};
float ClearDepth = 1.0f;
/******************************** TWEAKABLES *********************************/
half NumTiles = 40.0;
half Threshhold = 0.15;
half3 EdgeColor = {0.7f, 0.7f, 0.7f};
/*****************************************************************************/
texture SceneMap : RENDERCOLORTARGET <
float2 ViewportRatio = { 1.0f, 1.0f };
int MIPLEVELS = 1;
string format = "X8R8G8B8";
string UIWidget = "None";
>;
sampler SceneSampler = sampler_state {
texture = <SceneMap>;
AddressU = CLAMP;
AddressV = CLAMP;
MIPFILTER = NONE;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
/***************************** DATA STRUCTS **********************************/
struct vertexInput {
half3 Position : POSITION;
half3 TexCoord : TEXCOORD0;
};
/* data passed from vertex shader to pixel shader */
struct vertexOutput {
half4 HPosition : POSITION;
half2 UV : TEXCOORD0;
};
/******************************* Vertex shader *******************************/
vertexOutput VS_Quad( vertexInput IN)
{
vertexOutput OUT = (vertexOutput)0;
OUT.HPosition = half4(IN.Position, 1);
OUT.UV = IN.TexCoord.xy;
return OUT;
}
/********************************** pixel shader *****************************/
half4 tilesPS(vertexOutput IN) : COLOR {
half size = 1.0/NumTiles;
half2 Pbase = IN.UV - fmod(IN.UV,size.xx);
half2 PCenter = Pbase + (size/2.0).xx;
half2 st = (IN.UV - Pbase)/size;
half4 c1 = (half4)0;
half4 c2 = (half4)0;
half4 invOff = half4((1-EdgeColor),1);
if (st.x > st.y) { c1 = invOff; }
half threshholdB = 1.0 - Threshhold;
if (st.x > threshholdB) { c2 = c1; }
if (st.y > threshholdB) { c2 = c1; }
half4 cBottom = c2;
c1 = (half4)0;
c2 = (half4)0;
if (st.x > st.y) { c1 = invOff; }
if (st.x < Threshhold) { c2 = c1; }
if (st.y < Threshhold) { c2 = c1; }
half4 cTop = c2;
half4 tileColor = tex2D(SceneSampler,PCenter);
half4 result = tileColor + cTop - cBottom;
return result;
}
/*****************************************************************************/
technique tiles
{
pass p0
{
VertexShader = compile vs_1_1 VS_Quad();
ZEnable = false;
ZWriteEnable = false;
CullMode = None;
PixelShader = compile ps_2_0 tilesPS();
}
}