Samplers cannot be structure or block members

Modern OpenGL
  • megoboss
    Likes 0

    Problem Description

    #version 330 core
    struct Material 
    {
        sampler2D diffuse;
        sampler2D specular;
        float shininess;
    };

    struct Light
    {
        vec3 position;
        
        vec3 ambient;
        vec3 diffuse;
        vec3 specular;
    };

    in vec3 FragPos;
    in vec3 Normal;
    in vec2 TexCoords;

    out vec4 color;

    uniform vec3 viewPos;
    uniform Material material;
    uniform Light light;

    void main()
    {
        // Ambient
        vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords));
        
        // Diffuse
        vec3 norm = normalize(Normal);
        vec3 lightDir = normalize(light.position - FragPos);
        float diff = max(dot(norm, lightDir), 0.0);
        vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords));
        
        // Specular
        vec3 viewDir = normalize(viewPos - FragPos);
        vec3 reflectDir = reflect(-lightDir, norm);
        float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
        vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoords));
        
        color = vec4(ambient + diffuse + specular, 1.0f);
    }

    that is the code i’m using 

    and this is the output https://www.dropbox.com/s/176o13l43opo306/Screenshot%202017-05-22%2000.00.17.png?dl=0

     

  • Sonar Systems admin
    Likes 0

    Please check line 25 in the fragment shader to make sure it is correct.

  • megoboss
    Likes 0

    line 25 :: uniform Material material; 

    i don’t see something wrong in it

  • Sonar Systems admin
    Likes 0

    Where did you get this code from?

  • megoboss
    Likes 0

    from github

  • Sonar Systems admin
    Likes 0

    Which github page?

Login to reply