HLSL 2D像素着色器递归帮助?(XNA)
本文关键字:帮助 XNA 递归 2D 像素 HLSL | 更新日期: 2023-09-27 18:05:59
我使用的是最新版本的XNA。我正在尝试为我的2D游戏编写一个照明像素着色器。(认为Starbound的照明系统)
为了做到这一点,我需要实现一个递归函数来将光线扩散到纹理上。
不幸的是,当我尝试编译以下HLSL代码时,它抛出了一个异常…
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();
}
}
异常:错误1编译C:'Users'Benjamin'Desktop'CURRENT PROJECTS'gmjosac -xna-2d-shader-examples-07cfe1a5aafb'ShaderTests'ShaderTestsContent'effects'Test.fx:C:'Users'Benjamin'Desktop'CURRENT PROJECTS' gmjoack -xna-2d-shader-examples-07cfe1a5aafb'ShaderTests'ShaderTestsContent'effects'Test.fx(17,8):错误X3500: 'ApplyLight':递归函数尚未实现C:'Users'Benjamin'Desktop'CURRENT PROJECTS' gmjobag - xner -2d-shader-examples-07cfe1a5aafb'ShaderTests'ShaderTestsContent'effects'Test.fx(67,23): ID3DXEffectCompiler::CompileEffect:编译表达式出错ID3DXEffectCompiler:编译失败
我需要使用更新版本的hsl吗?如果有,怎么做?如果不是,我该如何解决这个问题?
目前,没有可用的像素着色器或顶点着色器配置文件(直到着色器模型5)支持递归函数调用。你必须重新设计算法