Xna HLSL变量将零返回到单对策
为了提高性能,我将一些CPU任务卸载到GPU上,效果良好。这就是我的HLSL代码的样子:Xna HLSL变量将零返回到单对策,xna,monogame,hlsl,Xna,Monogame,Hlsl,为了提高性能,我将一些CPU任务卸载到GPU上,效果良好。这就是我的HLSL代码的样子: float angle; extern float2 direction; float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR { angle = atan2(direction.x, -direction.y); re
float angle;
extern float2 direction;
float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR
{
angle = atan2(direction.x, -direction.y);
return float4(1, 1, 1, 1);
}
technique DefaultTechnique
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
在Emitter类中,我设置方向,应用技术,然后检索“angle”变量:
gpu.SetValue("direction", particles[i].Velocity);
for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
effect.CurrentTechnique.Passes[i].Apply();
particles[i].Angle = gpu.RetrieveFloat("angle");
gpu.SetValue(“方向”,粒子[i]。速度);
for(int i=0;i
这运行良好,没有碰撞。但是,“角度”值始终为0。我的HLSL技能不是很好,但是代码看起来应该像预期的那样工作
非常感谢您的建议。出于好奇,您能否尝试将
角度值更改为特定值?如果您成功地从着色器中获取该值,那么您很可能在尝试进行的计算中遇到问题。。。与如何使用API提取值的问题相反:)只是出于好奇,您能否尝试将角度值更改为特定值?如果您成功地从着色器中获取该值,那么您很可能在尝试进行的计算中遇到问题。。。与如何使用API获取值的问题相反:)