0
我正在使用托管的DirectX 2.0(我认为是一样的DirectX9)的应用程序,我是新来的HLSL,所以我很抱歉,如果我在做什么是愚蠢的。我正在写一个简单的像素着色器,简单地输出所储存的纹理(指定为全局变量)的屏幕,但我发现它,而不是渲染传递给它的纹理(我也是通过不同的渲染纹理,这个着色器是一个测试着色器)。的DirectX 9 HLSL纹理采样问题
我的HLSL代码如下:
texture inputTex;
sampler2D InputSampler = sampler_state
{
Texture = <inputTex>;
};
texture DepthTexture;
sampler2D DepthSampler = sampler_state
{
Texture = (DepthTexture);
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
float4 testPass(float2 TextureCoordinate : TEXCOORD0) : COLOR0
{
float4 new_color = saturate(tex2D(DepthSampler,TextureCoordinate));
new_color.a=1;
return new_color;
}
technique DoF
{
pass Pass0
{
PixelShader = compile ps_2_0 testPass();
}
}
,我的C#是:
postProc.SetValue("DepthTexture", DepthTexture);
postProc.Begin(FX.DoNotSaveState);
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0f, 0);
device.BeginScene();
{
postProc.SetValue("inputTex", RenderTexture);
postProc.CommitChanges();
postProc.BeginPass(0);
sprite.Draw(RenderTexture, new Rectangle(0, 0, WINDOWWIDTH, WINDOWHEIGHT), new Vector3(0, 0, 0), new Vector3(0, 0, 0), Color.Black);
postProc.EndPass();
postProc.End();
sprite.End();
}
device.EndScene();
device.Present();
输出无论是存储在渲染纹理,而不是什么是存储在DepthTexture,这是它应该做什么。我曾尝试与交换的DepthTexture在渲染纹理这一行:
sprite.Draw(RenderTexture, new Rectangle(0, 0, WINDOWWIDTH, WINDOWHEIGHT), new Vector3(0, 0, 0), new Vector3(0, 0, 0), Color.Black);
,输出为DepthTexture,所以它显然是从那里获取数据和纹理格式正确。
是否有人知道如何告诉HLSL时,必须在当通过了纹理采样从抽取数据采样任何好的教程吗?
TBH管理DX不受支持。使用SlimDX你会更好。 – Goz 2011-02-02 19:33:14