2011-02-01 158 views
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時,必須在當通過了紋理採樣從抽取數據採樣任何好的教程嗎?

+0

TBH管理DX不受支持。使用SlimDX你會更好。 – Goz 2011-02-02 19:33:14

回答

2

我覺得雪碧忽略效應狀態 - 紋理的它只是複製的部分指定給定的位置。它不運行當前着色器。看起來你只是想用當前的效果畫一個窗口大小的四邊形;而不是使用雪碧,你可能只是想直接使用Device.DrawPrimitives。