danielscherzer / GLSL

VSIX Project that provides GLSL language integration.
257 stars 28 forks source link

ERROR: OpenGL shader compiler has crashed #33

Closed EngHell closed 5 years ago

EngHell commented 5 years ago

Installed product versions

Description

When writing any shader at the top line of the file it shows an intellisense error i belive that reads the title.

OpenGL version 3.1

Steps to recreate

  1. write literally any shader and this occurs

Expected behavior

I dont know as the only thing i get is code coloring and some basic intellisense.

I'm using a laptop with an Intel HD 3000 in case that happens to be part of the problem.

danielscherzer commented 5 years ago

Thanks for your feedback! If I understand correctly you get an error if you write something like

void main() 
{
    gl_FragColor = vec4(1);
}

This is not the case for me. Could you try out to use glslangvalidator as shader compiler (options) to rule out your graphics card driver. Cheers, Daniel

EngHell commented 5 years ago

Hello thanks for your reply, after trying https://github.com/KhronosGroup/glslang as external compiler i no longer get the error, but without it any shader creates that output.

As well is it normal for the intellisense to show even members of other structs and variables in scope as sugestions for member of another struct?

danielscherzer commented 5 years ago

Regarding the first issue: try to force update your intel driver. often the automatically installed intel drivers are really old; for instance on my notebook the driver windows was installing was almost 3 years old; when I searched on the intel webpage I found a newer version. Still the driver was complaining that my hardware was not compatible; after force installing it, I never had any problems. Regarding the second issue: could you post some code... + maybe a screenshot? I'm not sure I understand the problem.

EngHell commented 5 years ago

Will give it the driver update a chance as for the second issue here is a frag shader im writting from learnopengl.com with some modifications to suit my taste:

#version 140 core

#define M_PI 3.1415926535897932384626433832795
#define M_POINT 0
#define M_DIRECTIONAL 1
#define M_SPOT 2
#define M_MAX_LIGHTS 10

struct Material {
    float shininess;
};

struct Light {
    vec3 position;
    vec3 direction;

    vec3 ambient;
    vec3 diffuse;
    vec3 specular;

    // those for attenuation
    float constant;
    float linear;
    float quadratic;

    // those for spot
    float cutOff;
    float outerCutOff;
    int type;
};

vec3 pointLight(vec3 texDiffuse, vec3 texSpecular, Light light, vec3 norm, float attenuation);
vec3 spotLight(vec3 texDiffuse, vec3 texSpecular, Light light, vec3 norm, float attenuation);
vec3 directionalLight(vec3 texDiffuse, vec3 texSpecular, Light light, vec3 norm);

out vec4 FragColor;

in vec3 Normal;
in vec3 FragPos;
//in vec3 LightPos;
in vec2 TexCoords;

//uniform Light light;
uniform Material material;
uniform int lightCount = 0;
// 1
uniform sampler2D specular;
// 0
uniform sampler2D diffuse;

//2 
//uniform sampler2D emission;
uniform vec3 objectColor;
uniform bool hasEmissionMap = false;
uniform Light lights[M_MAX_LIGHTS];

void main()
{
    vec3 result = vec3(0.0f);
    vec3 texDiffuse = texture(diffuse, TexCoords).rgb;
    vec3 texSpecular = texture(specular, TexCoords).rgb;

    for (int i = 0; i < lightCount; i++){

        Light light = lights[i];
        float dist = length(light.position - FragPos);
        float attenuation = 1.0 / (light.constant + (light.linear * dist)  + (light.quadratic * dist));

        vec3 norm = normalize(Normal);
        // this one is for point light

        switch(light.type) {
            case M_POINT:
                result += pointLight(texDiffuse, texSpecular, light, norm, attenuation);
            break;
            case M_DIRECTIONAL:
                result += directionalLight(texDiffuse, texSpecular, light, norm);
            break;
            case M_SPOT:
                result += spotLight(texDiffuse, texSpecular, light, norm, attenuation);
            break;
        }
    }

    if(hasEmissionMap){
        //result += vec3(texture(emission, TexCoords));
    }

    FragColor = vec4( result, 1.f);

// remember to decoment this thing if you switch from spotlight

}

vec3 spotLight(vec3 texDiffuse, vec3 texSpecular, Light light, vec3 norm, float attenuation){
    vec3 result = vec3(0.0);

    float cutOffCos = cos(light.cutOff);
    float outerCutOffCos = cos(light.outerCutOff);
    vec3 lightDir = normalize(light.position - FragPos);

    float theta = dot(lightDir, normalize(-light.direction));
    float epsilon = cutOffCos - outerCutOffCos;
    float intensity = clamp((theta - outerCutOffCos) / epsilon, 0.0, 1.0);

    float diff = max(dot(norm, lightDir), 0.0);
    vec3 diffuse = light.diffuse * (diff * texDiffuse);
    diffuse *= attenuation;
    diffuse *= intensity;

    vec3 viewDir = normalize(-FragPos); // since view always 0,0,0
    vec3 reflectDir = reflect(-lightDir, norm);
    float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
    vec3 specular = light.specular * spec * texSpecular;
    specular *= attenuation;
    specular *= intensity;

    // we add up everything
    result = ( diffuse + specular);

    return result;
}

vec3 directionalLight(vec3 texDiffuse, vec3 texSpecular, Light light, vec3 norm) {
    vec3 result = vec3(0.0f);

    vec3 ambient = light.ambient * texDiffuse;
    vec3 lightDir = normalize(-light.direction);
    float diff = max(dot(norm, lightDir), 0.0);
    vec3 diffuse = light.diffuse * (diff * texDiffuse);

    vec3 viewDir = normalize(-FragPos); // since view always 0,0,0
    vec3 reflectDir = reflect(-lightDir, norm);
    float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
    vec3 specular = light.specular * spec * texSpecular;

    // we add up everything
    result = (ambient + diffuse + specular);

    return result;
}

vec3 pointLight(vec3 texDiffuse, vec3 texSpecular, Light light, vec3 norm, float attenuation){
    vec3 result = vec3(0.0f);

    vec3 lightDir = normalize(light.position - FragPos);
    float diff = max(dot(norm, lightDir), 0.0);
    vec3 diffuse = light.diffuse * (diff * texDiffuse);
    diffuse *= attenuation;

    vec3 viewDir = normalize(-FragPos); // since view always 0,0,0
    vec3 reflectDir = reflect(-lightDir, norm);
    float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
    vec3 specular = light.specular * spec * texSpecular;
    specular *= attenuation;

    // we add up everything
    result = ( diffuse + specular);

    return result;

}

as you can see in the image https://snag.gy/viad9N.jpg i get code completion for all the variables instead of only the struct's member since light is of type Light it should only show sugestions from it's members.

danielscherzer commented 5 years ago

I can confirm this behaviour. My extension does not build a syntax tree, but does only word completion with any string match.

EngHell commented 5 years ago

So thanks for your time, after updating my drivers it still crashed the compiler but using glslangvalidator it does not so i will use that as work arround, as for the later I'm not good writing parsers or i would gladly send you a PR with a syntax tree and VS extensions are not my thing.

Thank you.