C# XNA中的进度条着色器存在问题
我正在创建一个简单的着色器,用于在XNA中绘制进度条 想法很简单:有两个纹理和值,若X纹理坐标小于该值,则使用前景纹理中的像素,否则使用背景纹理C# XNA中的进度条着色器存在问题,c#,xna,progress-bar,hlsl,effect,C#,Xna,Progress Bar,Hlsl,Effect,我正在创建一个简单的着色器,用于在XNA中绘制进度条 想法很简单:有两个纹理和值,若X纹理坐标小于该值,则使用前景纹理中的像素,否则使用背景纹理 /* Variables */ texture BackgroundTexture; sampler2D BackgroundSampler = sampler_state { Texture = (BackgroundTexture); MagFilter = Point; MinFilter = Point; Ad
/* Variables */
texture BackgroundTexture;
sampler2D BackgroundSampler = sampler_state
{
Texture = (BackgroundTexture);
MagFilter = Point;
MinFilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
texture ForegroundTexture;
sampler2D ForegroundSampler = sampler_state
{
Texture = (ForegroundTexture);
MagFilter = Point;
MinFilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
float Value;
/* Pixel shaders */
float4 PixelShader1(float4 pTexCoord : texcoord0) : color0
{
float4 texColor =
pTexCoord.x <= Value ?
tex2D(ForegroundSampler, pTexCoord) :
tex2D(BackgroundSampler, pTexCoord);
return texColor;
}
/* Techniques */
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShader1();
}
}
/*变量*/
纹理背景纹理;
采样器2D背景采样器=采样器\状态
{
纹理=(背景纹理);
磁过滤器=点;
MinFilter=点;
地址U=夹具;
地址V=钳位;
};
纹理前地纹理;
sampler2D ForegroundSampler=采样器\u状态
{
纹理=(前地面纹理);
磁过滤器=点;
MinFilter=点;
地址U=夹具;
地址V=钳位;
};
浮动值;
/*像素着色器*/
float4像素着色器1(float4 pTexCoord:texcoord0):颜色0
{
浮动4 texColor=
pTexCoord.x我找到了!
有所有正确的着色器
错误是赫恩:
this.progressBarEffect.Parameters["Value"].SetValue(progressBarValue);
this.progressBarEffect.Parameters["ForegroundTexture"].SetValue(this.progressBarForegroundTexture);
this.progressBarEffect.Parameters["BackgroundTexture"].SetValue(this.progressBarBackgroundTexture);
this.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointWrap, null, null, this.progressBarEffect);
this.spriteBatch.Draw(this.pixelTexture, new Rectangle(5, 200, 180, 30), Color.White);
this.spriteBatch.End();
正确的变体是:
this.progressBarEffect.Parameters["Value"].SetValue(progressBarValue);
//this.progressBarEffect.Parameters["ForegroundTexture"].SetValue(this.progressBarForegroundTexture);
this.progressBarEffect.Parameters["BackgroundTexture"].SetValue(this.progressBarBackgroundTexture);
this.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointWrap, null, null, this.progressBarEffect);
this.spriteBatch.Draw(this.progressBarForegroundTexture, new Rectangle(5, 200, 180, 30), Color.White);
this.spriteBatch.End();
我忘记了第一个声明的纹理使用的索引和传递给Draw方法的纹理相同
也许它对某些人有用。该帖子的答案不应包含在帖子中。请在下面将您的解决方案作为答案发布。:)对不起,我是新手。