C# 为什么延迟照明会破坏FPS?(2D)
为什么延迟照明会破坏FPS? 我试着在我的地图的可视空间上放置大约20-26个延迟照明,它将fps从61降低到28-31 它还使我的VGA温度从68°C上升到72-73°C。 我觉得这有点奇怪,因为它只是2D。 我不认为要把我的FPS减半需要这么多的计算 所以基本上我不明白为什么这个方法花费这么多。 或者我的代码和我如何解决它有问题吗 还有没有其他比这便宜得多的好照明方法? 点光源 我的代码是:C# 为什么延迟照明会破坏FPS?(2D),c#,xna,2d,hlsl,deferred,C#,Xna,2d,Hlsl,Deferred,为什么延迟照明会破坏FPS? 我试着在我的地图的可视空间上放置大约20-26个延迟照明,它将fps从61降低到28-31 它还使我的VGA温度从68°C上升到72-73°C。 我觉得这有点奇怪,因为它只是2D。 我不认为要把我的FPS减半需要这么多的计算 所以基本上我不明白为什么这个方法花费这么多。 或者我的代码和我如何解决它有问题吗 还有没有其他比这便宜得多的好照明方法? 点光源 我的代码是: Texture_Lights = RenderTargetBase.GetTexture();
Texture_Lights = RenderTargetBase.GetTexture();
for (int i = 0; i < LightRef.Count; i++)
{
//Draw lights
for (int techniqueindex = 0; techniqueindex < LightRef[i].Parent.effect.Techniques.Count; techniqueindex++)
{
LightRef[i].Parent.effect.CurrentTechnique = LightRef[i].Parent.effect.Techniques[techniqueindex];
LightRef[i].Parent.effect.Parameters["time"].SetValue(((float)timer.Elapsed.TotalSeconds) * 0.0000158f);
LightRef[i].Parent.effect.Parameters["GameTime"].SetValue(timer.Elapsed.Seconds);
LightRef[i].Parent.effect.Parameters["lightPosition"].SetValue(
new Vector3(
(LightRef[i].Position.X-CameraX)/(1.0f/ZoomFloat),
(LightRef[i].Position.Y-CameraY)/(1.0f/ZoomFloat),
0
));
LightRef[i].Parent.effect.Parameters["screenWidth"].SetValue(this.Width);
LightRef[i].Parent.effect.Parameters["screenHeight"].SetValue(this.Height);
for (int cx = 0; cx < LightRef[i].Parent.SelfTextures.Count; cx++)
{
LightRef[i].Parent.effect.Parameters[LightRef[i].Parent.SelfTextures[cx]].SetValue(RenderTargetBase.GetTexture());
}
foreach (EffectPass pass in LightRef[i].Parent.effect.CurrentTechnique.Passes)
{
GraphicsDevice.SetRenderTarget(0, RenderTargetLights);
GraphicsDevice.Clear(ClearColor);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
LightRef[i].Parent.effect.Begin();
LightRef[i].Parent.effect.GraphicsDevice.RenderState.AlphaBlendEnable = true;
pass.Begin();
spriteBatch.Draw(
Texture_Lights,
new Vector2(0,0),
new Rectangle(0, 0, Texture_Lights.Width, Texture_Lights.Height),
Color.White,
0,
new Vector2(0, 0),
1.0f,
SpriteEffects.None,
0);
spriteBatch.End();
pass.End();
LightRef[i].Parent.effect.End();
GraphicsDevice.SetRenderTarget(0, null);
GraphicsDevice.Clear(ClearColor);
Texture_Lights = RenderTargetLights.GetTexture();
}
}
}
GraphicsDevice.SetRenderTarget(0, null);
GraphicsDevice.Clear(ClearColor);
//Draw the Lightings #2
if (Texture_Lights != null)
{
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
spriteBatch.Draw(
Texture_Lights,
new Vector2(0, 0),
new Rectangle(0, 0, Texture_Lights.Width, Texture_Lights.Height),
Color.White,
0,
new Vector2(0, 0),
this.ZoomFloat,
SpriteEffects.None,
0);
spriteBatch.End();
}
Texture\u Lights=RenderTargetBase.GetTexture();
对于(int i=0;i
和着色器:
float GameTime;
float time;
texture2D colortexture;
texture2D normaltexture;
float ambient = 1.00;
float4 ambientColor = (1, 1, 1, 1);
float3 lightPosition = (230,230,0);
float4 lightColor = (120,120,120,120);
float lightPower = 0.27;
float screenWidth = 1000;
float screenHeight = 600;
sampler ColorMap = sampler_state
{
Texture = <colortexture>;
};
sampler NormalMap = sampler_state
{
Texture = <normaltexture>;
};
float4 DeferredNormalPS(float2 texCoords : TEXCOORD0) : COLOR
{
float4 base = tex2D(ColorMap, texCoords);
float3 normal = tex2D(NormalMap, texCoords);
float3 pixelPosition = float3(screenWidth * texCoords.x, screenHeight * texCoords.y,0);
float3 direction = lightPosition - pixelPosition;
float distance = 1 / length(lightPosition - pixelPosition) * lightPower;
float amount = max(dot(base + normal, normalize(distance)), 0);
lightColor *= lightPower;
float4 finalColor = (base * ambientColor * ambient) +
(base * distance * amount * lightColor * ambient);
finalColor.a = base.a;
return finalColor;
}
technique Deferred
{
pass Pass1
{
PixelShader = compile ps_3_0 DeferredNormalPS();
}
}
float游戏时间;
浮动时间;
纹理2d彩色纹理;
纹理2D正常纹理;
浮动环境=1.00;
float4-ambientColor=(1,1,1,1);
浮动3光位置=(230230,0);
float4 lightColor=(120120);
浮子光功率=0.27;
浮动屏幕宽度=1000;
浮网高度=600;
采样器颜色映射=采样器状态
{
纹理=;
};
采样器法线贴图=采样器状态
{
纹理=;
};
float4延迟的normalps(float2 texCoords:TEXCOORD0):颜色
{
float4 base=tex2D(彩色贴图,texCoords);
float3 normal=tex2D(NormalMap,texCoords);
float3 pixelPosition=float3(屏幕宽度*texCoords.x,屏幕高度*texCoords.y,0);
float3方向=光照位置-像素位置;
浮动距离=1/长度(光位置-像素位置)*光功率;
浮动量=最大值(点(基准+法线,归一化(距离)),0);
lightColor*=光功率;
float4最终颜色=(基本*环境颜色*环境颜色)+
(基准*距离*数量*浅色*环境光);
finalColor.a=基本颜色.a;
返回最终颜色;
}
技术延迟
{
通行证1
{
PixelShader=编译ps_3_0递延法线ps();
}
}
你应该试着问一下。他们对图形渲染有更多的了解。我会试试。谢谢你的回答。