2013-01-16 207 views
0

在DirectX中,我知道我可以做这样的事情。OpenGL片段着色器VS DirectX片段着色器

struct GBufferVertexOut 
{ 
    float4 position  : POSITION0; 
    float4 normal  : TEXCOORD0; 
    float2 texCoord  : TEXCOORD1; 
}; 

GBufferFragOut GBuffersFS(GBufferVertexOut inVert) 
{ 
    GBufferFragOut buffOut; 
    buffOut.normal = normalize(inVert.normal); 
    buffOut.normal = (buffOut.normal + 1) * .5; 
    buffOut.diffuse = tex2D(diffuseSampler, inVert.texCoord); 
    buffOut.diffuse.a = tex2D(ambientSampler, inVert.texCoord).r; 
    buffOut.specular = float4(1, 1, 1, 1); 

    return buffOut; 
} 

所以我的片段结果的信息 我想转换一个OpenGL着色器做类似的

东西的集合,但你能甚至做到这一点?我从来没有返回任何其他的东西,虽然除了vec4的“片段颜色”openGL片段着色器,我似乎无法找到任何信息,告诉我我可以返回更多。

回答

2

在opengl中,您可以在主函数之外定义输出变量,然后在该函数中设置它们的值。所以,你必须将HLSL代码相当于会有这样的事情(片段着色器)

layout (location = 0) out vec4 diffuse;  //these are the outputs 
layout (location = 1) out vec4 normal; 
layout (location = 2) out vec4 specular; 

in vec4 in_position; //these are the inputs from the vertex shader 
in vec4 in_normal; 
in vec2 in_tex_coord; 

void main() 
{ 
    normal = normalize(in_normal); 
    normal = (normal + vec4(1.0, 1.0, 1.0, 1.0)) * 0.5; 
    diffuse = texture(diffuseSampler, in_tex_coord); 
    ambient = texture(ambientSampler, in_tex_coord); 
    specular = vec4(1.0, 1.0, 1.0, 1.0); 
} 

然后在你的应用程序,你需要确保你已经绑定其带有附件的正确数量和类型f​​ramebufferobject写信给。

+0

对不起。是的,我的顶点着色器中有这些变量。你是在说我应该操纵那里的信息吗?因为我试图获得每个像素“正常”的数据或跟踪像素位置。 –

+0

,因为我正在跟踪图像。我确实绑定了我的帧缓冲区。我写信给它。但在directX中,你的片段着色器会输出你告诉它丢弃的所有信息。 –

+0

对不起,编辑答案,没有正确地读取问题 – Slicedpan