【发布时间】:2012-09-20 05:10:36
【问题描述】:
对于我的项目,我使用的是 directx 9 C++。 我正在使用像素着色器,以便在index image (color image) 的方法中使用耦合纹理显示大图片。
为了节省纹理空间,我想使用查找表条目来存储图像的像素,以便在像素着色器阶段使用查找表值作为图像像素值。
我使用了 2 个纹理,第一个纹理是图像纹理,大小为 2048^2。 pixesl 的品种是 128 pixesl,第二个纹理是 128*1 的 LUT(查找表)大小。
我将第二个纹理用作index image(查找表),
不知何故,我发现很难从第一个纹理(图像纹理)中采样值 --> A[i,j] 并在同一点采样第二个纹理 --> Pixel value = LUT[A[i,j]]
然后,将像素值输出到屏幕。
这是我的像素着色器代码:
sampler2D layoutSample : register (s0)
sampler2D LUTSampler : register (s1)
struct PS_INPUT
{
float2 texture : TEXCOORD0;
float2 LUT_Texture: TEXCOORD1;
}
struct PS_OUTPUT
{
float4 color : COLOR0;
}
PS_OUTPUT ps_main ( in PS_INPUT input )
{
PS_OUTPUT out;
/// Sample the first texture - the image texture
float4 color = tex2D(layoutSampler, input.Texture);
float2 locationInLUT = float2(color.a , 0.0) ;
// I WOULD LIKE TO USE: But it's seems like a sampler is neccery for tex2D command
///float4 realColor = tex2D(locationInLUT , input.LUT_Texture);
float4 realColor = tex2D(LUTSamplerm , input.LUT_Texture);
Out.color = float4(realColor.r, realColor.b, realColor.g, 1.0);
return Out;
}
【问题讨论】:
-
试试
float4 realColor = tex2D(LUTSampler, locationInLUT);。 -
你是对的——它成功了!谢谢