[英]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.