【发布时间】:2011-11-15 10:37:16
【问题描述】:
我有一个非常简单的像素着色器:
float4 PixelShaderFunction(float2 uv : TEXCOORD0) : COLOR0
{
return float4(0, 1, 0, 1);
}
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}
我有一个纹理:
Vector4[] textureData = new Vector4[width * height];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
textureData[y * width + x] = new Vector4(1, 0, 0, 1);
}
}
myTexture = new Texture2D(GraphicsDevice, width, height, false, SurfaceFormat.Vector4);
myTexture.SetData(textureData);
我用这段代码绘制它:
spriteBatch.Begin(SpriteSortMode.Texture,
BlendState.Additive,
SamplerState.PointWrap,
DepthStencilState.DepthRead,
RasterizerState.CullNone);
myEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(myTexture, new Rectangle(0, 0, width, height), Color.White);
spriteBatch.End();
我会想到,通过在像素着色器上调用 .Apply(),随后的 spriteBatch.Draw() 调用会通过我的像素着色器发送 myTexure。由于像素着色器函数总是返回 float4(0, 1, 0, 1) 我希望结果是一个绿色方块,但它却渲染了一个红色方块,就好像像素着色器没有接触它一样。
我错过了什么?
【问题讨论】: