Converting shaders to opengles 3.0

182 views Asked by At

I switched my shaders to the opengles 3.0 glsl.

Shaders not compiled in 3.0...

No error info i just now that this not pass : if (gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {

 #version 300 es

  in vec3 aVertexPosition;
  in vec3 aVertexNormal;
  in vec2 aTextureCoord;

  uniform mat4 uMVMatrix;
  uniform mat4 uPMatrix;
  uniform mat3 uNMatrix;
  uniform vec3 uAmbientColor;
  uniform vec3 uLightingDirection;
  uniform vec3 uDirectionalColor;
  uniform bool uUseLighting;

  out vec2 vTextureCoord;
  out vec3 vLightWeighting;

  // Spot
  uniform vec3 u_lightWorldPosition;
  out vec3 v_normal;

  out vec3 v_surfaceToLight;
  out vec3 v_surfaceToView;

  // spot-Shadow
  uniform mat4 u_textureMatrix;
  out vec2 v_texcoord;
  out vec4 v_projectedTexcoord;

  void main(void) {
    // SPOT
    v_normal = mat3(uNMatrix) * aVertexNormal;
    vec3 surfaceWorldPosition = (uNMatrix * aVertexPosition).xyz;
    v_surfaceToLight = u_lightWorldPosition - surfaceWorldPosition;
    v_surfaceToView = (uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0)).xyz - surfaceWorldPosition;

    // spot shadow
    // Multiply the position by the matrix.
    // vec4 worldPosition = u_world * a_position;
    vec4 worldPosition = vec4(0,0,0,0) * vec4( aVertexPosition, 1.0);

    v_texcoord = aTextureCoord;
    v_projectedTexcoord = u_textureMatrix * worldPosition;


    gl_Position   = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
    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;
    }
  } 




FS 


#version 300 es
    precision mediump float;
    precision highp float;
    in vec2 vTextureCoord;
    in vec3 vLightWeighting;
    uniform float textureSamplerAmount[1];
    int MixOperandString = 0;

    uniform sampler2D uSampler;
    uniform sampler2D uSampler1;
    uniform sampler2D uSampler2;
    uniform sampler2D uSampler3;
    uniform sampler2D uSampler4;
    uniform sampler2D uSampler5;
    uniform sampler2D uSampler6;
    uniform sampler2D uSampler7;
    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;          // in dot space
  uniform float u_outerLimit;          // in dot space

  uniform mat4 u_projection;
  uniform mat4 u_view;
  uniform mat4 u_world;
  uniform mat4 u_textureMatrix;

  out vec4 outColor;

  void main(void) {

        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 textureColor3 = texture2D(uSampler3, vec2(vTextureCoord.s, vTextureCoord.t));
        vec4 textureColor4 = texture2D(uSampler4, vec2(vTextureCoord.s, vTextureCoord.t));

        if (1 == 1) {
          outColor = vec4(textureColor.rgb * vLightWeighting, textureColor.a);
        } 

   
  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);

  outColor.rgb *= light;
  // Just add in the specular
  // outColor.rgb += specular;
  
  

    }
`;

trying to catch error log :

    var shaderProgram = gl.createProgram();
    // console.log("Creating Shader fragment");
    gl.attachShader(shaderProgram, vertexShader);
    gl.attachShader(shaderProgram, fragmentShader);
    gl.linkProgram(shaderProgram);

    console.info('TEST ERROR => ' + gl.getShaderInfoLog(vertexShader));
    console.info('TEST ERROR => ' + gl.getShaderInfoLog(fragmentShader));

This not returning anything... it is empty ''.

I try this also

    var compiled = gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS);
    console.log('Shader compiled successfully: ' + compiled);
    var compiled = gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS);
    console.log('Shader fragmentShader compiled successfully: ' + compiled);

output is

Shader compiled successfully: true
app.js:810 Shader fragmentShader compiled successfully: true

Ok o got error log :

Shader Program compile failed:ERROR: 0:41: 'texture2D' : no matching overloaded function found
ERROR: 0:41: '=' : dimension mismatch
ERROR: 0:41: '=' : cannot convert from 'const mediump float' to 'highp 4-component vector of float'
0

There are 0 answers