[英]OpenGL Fragment Shader VS DirectX Fragment Shader
在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片段着色器,而且我似乎找不到任何可以告诉我可以返回更多信息的信息。
在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);
}
然后,在您的应用程序中,需要确保已绑定一个帧缓冲区对象,该对象具有要写入的正确数量和类型的附件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.