vendredi 15 mars 2019

glslangvalidator simple usage

I'm trying to use glslangvalidator to generate reflection information from my shaders. However, I can't seem to get past this error for a simple shader, test.vert

#version 450
layout(std140, binding = 0) uniform matrix_state {
    mat4 vmat;
    mat4 projmat;
    mat4 mvmat;
    mat4 mvpmat;
    vec3 light_pos;
} matrix

layout(location = 0) in vec4 attr_vertex;
layout(location = 1) in vec3 attr_normal;
layout(location = 2) in vec2 attr_texcoord;
layout(location = 3) out vec3 vpos;
layout(location = 4) out vec3 norm;
layout(location = 5) out vec3 ldir;
layout(location = 6) out vec2 texcoord;
void main()
{
    gl_Position = matrix.mvpmat * attr_vertex;
    vpos = (matrix.mvmat * attr_vertex).xyz;
    norm = mat3(matrix.mvmat) * attr_normal;
    texcoord = attr_texcoord * vec2(2.0, 1.0);
    ldir = matrix.light_pos - vpos;
}

I then run: ./glslangvalidator test.vert

The output is:

ERROR: 0:10: '' : syntax error, unexpected LAYOUT, expecting LEFT_BRACKET or SEMICOLON ERROR: 1 compilation errors. No code generated.

However, using this simple fragment shader test.frag

#version 450
layout(binding = 0) uniform sampler2D tex;
layout(location = 3) in vec3 vpos;
layout(location = 4) in vec3 norm;
layout(location = 5) in vec3 ldir;
layout(location = 6) in vec2 texcoord;
layout(location = 0) out vec4 color;
void main()
{
    vec4 texel = texture(tex, texcoord);
    vec3 vdir = -normalize(vpos);
    vec3 n = normalize(norm);
    vec3 l = normalize(ldir);
    vec3 h = normalize(vdir + ldir);
    float ndotl = max(dot(n, l), 0.0);
    float ndoth = max(dot(n, h), 0.0);
    vec3 diffuse = texel.rgb * ndotl;
    vec3 specular = vec3(1.0, 1.0, 1.0) * pow(ndoth, 50.0);
    color.rgb = diffuse + specular;
    color.a = texel.a;
}

does not produce any errors when I run it like so: ./glslangValidator test.frag

My question is: How do I get both these shaders to generate reflection information for me? Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire