I can't detect real reason for gl.LINK_STATUS return failed state

40 Views Asked by At

SHADERS:

export function getInitFSCubeMap() {
  const f = `#version 300 es
  precision mediump float;

  in vec2 vTextureCoord;
  in vec3 vLightWeighting;

  // The CubeMap texture test.
  uniform samplerCube u_texture;
  // cube map
  in vec3 v_normal_cubemap;

  uniform float numberOfsamplers;

  // Spot
  // Passed in from the vertex shader.
  in vec3 v_normal;
  in vec3 v_surfaceToLight;
  in vec3 v_surfaceToView;

  uniform vec4 u_color;
  uniform float u_shininess;
  uniform vec3 u_lightDirection;
  uniform float u_innerLimit;
  uniform float u_outerLimit;

  out vec4 outColor;

  void main(void) {
    // because v_normal is a varying it's interpolated
    // so it will not be a unit vector. Normalizing it
    // will make it a unit vector again
    vec3 normal = normalize(v_normal);

    vec3 surfaceToLightDirection = normalize(v_surfaceToLight);
    vec3 surfaceToViewDirection = normalize(v_surfaceToView);
    vec3 halfVector = normalize(surfaceToLightDirection + surfaceToViewDirection);

    float dotFromDirection = dot(surfaceToLightDirection,
                                 -u_lightDirection);
    float limitRange = u_innerLimit - u_outerLimit;
    float inLight = clamp((dotFromDirection - u_outerLimit) / limitRange, 0.0, 1.0);
    float light = inLight * dot(normal, surfaceToLightDirection);
    float specular = inLight * pow(dot(normal, halfVector), u_shininess);

    // Directioin vs uAmbientColor
    // vec4 textureColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
    // vec4 textureColor1 = texture2D(uSampler1, vec2(vTextureCoord.s, vTextureCoord.t));
    // vec4 textureColor2 = texture2D(uSampler2, vec2(vTextureCoord.s, vTextureCoord.t));
    // vec4 testUnused = texture2D(u_texture, vec2(vTextureCoord.s, vTextureCoord.t));

    outColor = texture(u_texture, normal);
    // Lets multiply just the color portion (not the alpha)
    // by the light
    outColor.rgb *= light;
    // Just add in the specular
    outColor.rgb += specular;
  }
  `;
  scriptManager.LOAD(f, "cubeMap-shader-fs", "x-shader/x-fragment", "shaders")
}

export function getInitVSCubeMap() {
 const f = `#version 300 es
  in vec3 aVertexPosition;
  in vec3 aVertexNormal;

  uniform mat4 uMVMatrix;
  uniform mat4 uPMatrix;
  uniform mat3 uNMatrix;

  out vec3 v_normal;
  out vec3 v_normal_cubemap;

  // lights
  uniform vec3 uAmbientColor;
  uniform vec3 uLightingDirection;
  uniform vec3 uDirectionalColor;
  uniform bool uUseLighting;
  // varying vec2 vTextureCoord;
  out vec3 vLightWeighting;

  void main(void) {

    v_normal = mat3(uNMatrix) * aVertexNormal;
    v_normal_cubemap = normalize(aVertexPosition.xyz);
    gl_Position   = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);

    // lights
    // vTextureCoord = aTextureCoord;

    if (!uUseLighting) {
      vLightWeighting = vec3(1.0, 1.0, 1.0);
    }
    else {
      vec3 transformedNormal          = uNMatrix * aVertexNormal;
      float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0);
      vLightWeighting                 = uAmbientColor + uDirectionalColor * directionalLightWeighting;
    }

  } `;
   scriptManager.LOAD(f, "cubeMap-shader-vs", "x-shader/x-vertex", "shaders")
}

LOAD SHADER


function initShaders(gl, fragment, vertex) {
  // console.log("Initialize Shader");
  var fragmentShader = this.getShader(gl, fragment);
  var vertexShader = this.getShader(gl, vertex);

  if (0 == fragmentShader || 0 == vertexShader) {
    console.warn('Failed to Load shader');
    return 0;
  } else {
    var shaderProgram = gl.createProgram(); // console.log("Creating Shader fragment");

    gl.attachShader(shaderProgram, vertexShader);
    gl.attachShader(shaderProgram, fragmentShader);
    gl.linkProgram(shaderProgram);

    if (gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
          ......
    } else {

       console.warn('WHO TO CATCH REAL ERROR IN MY SHADER')
    }

ANY SUGGESTION ?

0

There are 0 best solutions below