2016-09-27 226 views
0

我目前面臨着OpenGL採樣器的一個問題。我有一個正在運行的片段着色器,它使用isampler2DArray變量來採樣一堆二維圖像以及一個用於從堆棧中檢索所需片的整數索引。OpenGL:isampler2DArray與sampler2DArray與sampler3DArray

片段着色器看起來是這樣的:

#version 430 

/* Per Fragment Input Attributes */ 
in vec2 texCoord; 

/* Per Fragment Uniform Attributes */ 
layout (binding = 0) uniform isampler2DArray textureSampler; 

/* Per Fragment Output Values */ 
layout (location = 0) out vec3 out_color; 

uniform float windowCenter; 
uniform float windowWidth; 

uniform int texIndex; 

void main() 
{ 
    float value = float(texture(textureSampler, vec3(texCoord, texIndex)).r); 

    float min = windowCenter - windowWidth/2; 

    value = (value - min)/windowWidth; 

    out_color = vec3(value); 
} 

當我試圖改變採樣器sampler2DArray和統一變量來檢索數據float,我只得到一個黑色的屏幕,而不是抽樣的質感。類似於sampler3D

紋理設置代碼如下:

m_texture= std::make_unique<Texture>(GL_TEXTURE_2D_ARRAY, nullptr, sequence->width(), sequence->height(), sequence->images().size(), GL_R16I, GL_RED_INTEGER, 1, 0, GL_SHORT); 

glPixelStorei(GL_UNPACK_ROW_LENGTH, sequence->width()); 

for (int i = 0; i < sequence->images().size(); i++) 
{ 
    m_texture->UpdateTexture(sequence->images()[i]->data(), 0, sequence->images()[i]->width(), 0, sequence->images()[i]->height(), i, 1); 
} 

glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 

sampler2DArraysampler3D,我上傳了我的float一致通過以下方式,根據該計算器問題(OpenGL 3D Texture Coordinates):

prg_texture3D->SetUniform("currentSliceTexCoord", (1.0f + 2.0f * currentSlice)/(2.0f * sequence->images().size())); 

我我不明白爲什麼程序運行在isampler2DArray而不是其他兩個。你能否告訴我他們之間的區別,尤其是isampler2DArraysampler2DArray之間的區別?

+0

紋理類從哪裏來?您是否正確設置了浮點紋理的最小/最大值濾鏡? – BDL

+0

這是我自己創建的一個自定義的。這兩個值都設置爲「GL_LINEAR」。 – Schnigges

回答

1
GL_R16I, GL_RED_INTEGER 

如果使用非整數採樣器,那麼你的紋理的image format必須match that。它必須是浮點或標準化的整數格式。而GL_R16I是一種整數格式,而不是浮點/標準化格式。

+0

好吧,我的數據是12位DICOM數據,有沒有辦法在着色器中將其轉換爲「float」? – Schnigges

+0

@Schnigges:你當前的方法將其轉換爲「float」會出現什麼問題? –