1
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ Are you sure the first one compiles correctly? It looks like there are some implicit int to float conversions, 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\$ – user1118321 May 8 '17 at 5:15
  • \$\begingroup\$ Sure does i even checked with glslangValidator. \$\endgroup\$ – VersesDev May 8 '17 at 5:21
  • \$\begingroup\$ Is there a limit to code we stuff in fragment shader.striping down the code seems to run the code. \$\endgroup\$ – VersesDev May 8 '17 at 5:22
  • \$\begingroup\$ There can be, but I'd be very surprised on a modern video card if the short shaders you have above have hit any limits. I've seen shaders (computer generated) that had dozens to possibly over a hundred uniforms. Can you pinpoint if there's a particular function that is causing the problem? Like remove one function, recompile and see if the problem exists. If not, put that function back, remove a different one and try again. \$\endgroup\$ – user1118321 May 8 '17 at 5:26
  • \$\begingroup\$ The fresnel function 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\$ – Lasse May 8 '17 at 5:27
1
\$\begingroup\$

Thanks everyone i got the error.Silly actually i had the shader file reader's buffer size set to 500 bytes that was causing the smaller shader to run while not the large one. Not sure why it was linking still.

Still thanks for helping.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.