I am using the latest version of XNA. I am attempting to write a lighting pixel shader for my 2D game. (Thinks Starbound's lighting system)
To do this, I need to implement a recursive function to spread light onto the texture.
Unfortunately, when I try to compile the following HLSL code it throws an exception...
sampler s0;
texture lightMask;
sampler _lightMask = sampler_state{Texture = lightMask;};
texture blockMask;
sampler _blockMask = sampler_state{Texture = blockMask;};
int x1;
int y1;
//Info
float4 black = float4(0,0,0,1);
float4 white = float4(1,1,1,1);
float width, height;
float ux, uy;
//Recursive Lighting
float4 ApplyLight(float4 lastLight, float2 pos, bool first)
{
float4 newLight = lastLight;
if (!first)
{
newLight.rgb = lastLight.rgb - 0.1;
if ((newLight.r + newLight.g + newLight.b) / 3 <= 0)
return lastLight;
}
else
{
newLight = lastLight;
}
ApplyLight(newLight, pos + float2(0, uy), false);
ApplyLight(newLight, pos + float2(0, -uy), false);
ApplyLight(newLight, pos + float2(ux, 0), false);
ApplyLight(newLight, pos + float2(-ux, 0), false);
float4 color = tex2D(_lightMask, pos);
color = newLight;
return newLight;
}
//Shader Function
float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
{
float4 lightHere = tex2D(_lightMask, coords);
if (lightHere.r > 0
|| lightHere.g > 0
|| lightHere.b > 0)
{
ApplyLight(lightHere, coords, true);
}
return lightHere;
}
//Technique
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
Exception:
Error 1
Errors compiling C:\Users\Benjamin\Desktop\CURRENT PROJECTS\gmjosack-xna-2d-shader-examples-07cfe1a5aafb\ShaderTests\ShaderTestsContent\effects\Test.fx:
C:\Users\Benjamin\Desktop\CURRENT PROJECTS\gmjosack-xna-2d-shader-examples-07cfe1a5aafb\ShaderTests\ShaderTestsContent\effects\Test.fx(17,8): error X3500: 'ApplyLight': recursive functions not yet implemented
C:\Users\Benjamin\Desktop\CURRENT PROJECTS\gmjosack-xna-2d-shader-examples-07cfe1a5aafb\ShaderTests\ShaderTestsContent\effects\Test.fx(67,23): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
ID3DXEffectCompiler: Compilation failed
Do I need to be using a newer version of HLSL? If so, how? If not, how can I get around this?
PixelShader = compile ps_3_0 ...
. – Nico Schertler