OpenGL ES 3.0 subroutine问题

本文档只是测试OpenGL ES着色器语言是否支持subroutine功能。结论是,OpenGL着色器语言支持,OpenGL ES着色器语言不支持。

OpenGL ES 3.0 着色器语言并不支持subroutine,着色器编译期间提示错误ERROR: 0:8: 'subroutine' : syntax error: syntax error,示例代码如下。

#version 300 es

layout (location = 0) in vec4 VertexPosition;
layout (location = 1) in vec3 VertexTexCoord;

uniform mat4 ProjectionMatrix;

subroutine vec4 RenderPassType();
subroutine uniform RenderPassType RenderPass;

subroutine (RenderPassType)
vec4 pass1()
{
    return vec4(phongModel( Position, Normal ),1.0);
}

subroutine( RenderPassType )
vec4 pass2()
{
    vec4 noise = texture(NoiseTex, TexCoord);
    vec4 color = texture(RenderTex, TexCoord);
    float green = luminance( color.rgb );

    float dist1 = length(gl_FragCoord.xy - vec2(Width/4.0, Height/2.0));
    float dist2 = length(gl_FragCoord.xy - vec2(3.0 * Width/4.0, Height/2.0));
    if( dist1 > Radius && dist2 > Radius ) green = 0.0;

    return vec4(0.0, green * clamp( noise.a, 0.0, 1.0) , 0.0 ,1.0);
}

out vec3 TexCoord;

void main() {
    TexCoord = VertexTexCoord;
    gl_Position = ProjectionMatrix * VertexPosition;
}

你可能感兴趣的:(OpenGL ES 3.0 subroutine问题)