Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Strange problem in GLSL while assigning attribute to a varying in vertex shader

  1. #1
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3

    Strange problem in GLSL while assigning attribute to a varying in vertex shader

    Hi All,

    I am writing a GLSL program for texture mapping. I am having a weird problem. From my vertex shader I am trying to pass the texture coordinate vec2 as a varying to frag shader. In a diff shader in the same prog I did the same and it worked. But for this texture its not working. If I comment that line, then everything works. I have no clue why this is happening. Any help would be greately appreciated.

    Thanks
    mindbender12

    This is the vertex shader:
    Code :
     
    attribute vec4 position; 
    attribute vec4 color1; 
    attribute vec4 normal; 
    attribute vec2 texCoord;
     
    uniform mat4 model; //passed to shader 
    uniform mat4 projection; //passed to shader
    uniform mat4 view; // passed to shader
    uniform mat4 normalMatrix; //passed to shader
    uniform mat4 worldNormalMatrix;
    uniform vec3 eyePos;
     
    varying vec4 pcolor; 
    varying vec3 fNormal;
    varying vec3 v;
    varying mat4 modelMat;
    varying mat4 viewMat;
    varying mat4 projectionMat;
    varying vec2 texCoordinate;
    varying vec3 reflector;
     
    void main()
    {     
          //texCoordinate = texCoord;  // If I uncomment this, then I get wrong output. but the same thing works in a diff shader!! 
          mat4 projectionModelView;
          vec4 N;
          vec3 WorldCameraPosition = vec3(model*vec4(eyePos,1.0));
          vec3 worldPos = vec3(model*position);
    	  vec3 worldNorm = normalize(vec3(worldNormalMatrix*normal));
    	  vec3 worldView = normalize(vec3(WorldCameraPosition-worldPos));
    	  reflector = reflect(-worldView, worldNorm);      
          projectionMat = projection;
          modelMat=model;
    	  viewMat=view;
          N=normalMatrix*normal;	  
          fNormal = vec3(N); //need to multiply this with normal matrix
    	  projectionModelView=projection*view*model;
    	  v=vec3(view*model*position); // v is the position at eye space for each vertex passed to frag shader
          gl_Position =  projectionModelView * position; // calculate clip space position	  
    }

  2. #2
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    325
    Hello,

    maybe you try to use more varyings as your GPU supports. MAX_VARYING_FLOATS can be as low as 32 in GL 2.1 (I assume you have to support very old versions of GL as you are still using 2.1 syntax). Check for those limits and check for shader link errors.

  3. #3
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3

    Quote Originally Posted by menzel View Post
    Hello,

    maybe you try to use more varyings as your GPU supports. MAX_VARYING_FLOATS can be as low as 32 in GL 2.1 (I assume you have to support very old versions of GL as you are still using 2.1 syntax). Check for those limits and check for shader link errors.

    Hi Menzel,

    You are absolutely right.. I was passing too many varying and I did not need all those, so I removed some of the unnecessary ones and all started showing up.. turned out that my GLSL version only supports 16 varying vectors and I was passing 17 of them.. that's why when I was just commenting that line, it was working.. thanks for the reply!!
    This thread is solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •