the fragment shader is working so strange, can someone explain me whats going on.
this one compiles fine but crashes when i use it-
#version 330 core
const float PI = 3.14159265359;
out vec4 coloroutfinal;
in vec3 fragpos;
uniform vec3 lightpos;
uniform vec3 camerapos;
vec3 wi;
vec3 normal;
float cosT;
uniform vec3 lightcolor;
vec3 incidentlight;
uniform float metallic;
uniform float roughness;
uniform vec3 albedo;
uniform float ao;
vec3 fresnel(float cosT,vec3 Fo);
float ND(vec3 H,vec3 N,float roughness);
float G(vec3 L,vec3 N,vec3 V,float roughness);
void main()
{
coloroutfinal=vec4(1.0);
}
vec3 fresnel(float cosT,vec3 Fo)
{
return Fo+(1.0-Fo)*pow((1-cosT),5);
}
float ND(vec3 H,vec3 N,float roughness)
{
float roughness4=pow(roughness,4);
float cosT=max(dot(N,H),0.0);
float cosT2=cosT*cosT;
float num=roughness4;
float denom=cosT2*(1.0-roughness4)+1.0;
return num/denom;
}
float GP(float cosT,float roughness)
{
roughness-=1.0;
float r2=roughness*roughness;
float k=r2/8;
float num=cosT;
float denom=cosT*(1.0-k)+k;
return num/denom;
}
float G(vec3 L,vec3 N,vec3 V,float roughness)
{
float cosTL=max(dot(N,L),0.0);
float cosTV=max(dot(N,V),0.0);
float GL=GP(cosTL,roughness);
float GV=GP(cosTV,roughness);
return GL*GV;
}
but this one is just the same as above but no function definitions but works fine(renders my object in white)-
#version 330 core
const float PI = 3.14159265359;
out vec4 coloroutfinal;
in vec3 fragpos;
uniform vec3 lightpos;
uniform vec3 camerapos;
vec3 wi;
vec3 normal;
float cosT;
uniform vec3 lightcolor;
vec3 incidentlight;
uniform float metallic;
uniform float roughness;
uniform vec3 albedo;
uniform float ao;
vec3 fresnel(float cosT,vec3 Fo);
float ND(vec3 H,vec3 N,float roughness);
float G(vec3 L,vec3 N,vec3 V,float roughness);
void main()
{
coloroutfinal=vec4(1.0);
}
I never call the function so how are they interfearing. also both the shaders compile and link fine.
can someone point me to the mistake?
inttofloatconversions, which I thought were not handled by the glsl compiler. Even if they're unused, the compiler may have to (at least partially) compile them to figure that out. \$\endgroup\$fresnelfunction is not used and shouldn't be added to the resulting binary, which is what code stripping does. This smells like a driver bug. Do you have the latest drivers? Your shader is not nearly large enough to be hitting any limits. \$\endgroup\$