Results 1 to 2 of 2

Thread: Fragment shader compilation problem

  1. #1
    Newbie Newbie
    Join Date
    Aug 2014
    Posts
    17

    Fragment shader compilation problem

    For several days I am trying to reach the problem with my shader. I have several varying floats and problem comes in question when I call my function join. Adding this line causes error which states: "Could not pack varying _v_linejoin". I am using Qt platform and OpenGL 3.2.

    This is my code for fragment shader:

    Code :
    precision highp float;
     
    const float PI = 3.14159265358979323846264;
    const float THETA = 15.0 * 3.14159265358979323846264/180.0;
     
    float cap( int type, float dx, float dy, float t ){
    		float d = 0.0;
    		dx = abs(dx);
    		dy = abs(dy);
     
    		// None
    		if      (type == 0)  discard;
    		// Round
    		else if (type == 1)  d = sqrt(dx*dx+dy*dy);
    		// Triangle in
    		else if (type == 3)  d = (dx+abs(dy));
    		// Triangle out
    		else if (type == 2)  d = max(abs(dy),(t+dx-abs(dy)));
    		// Square
    		else if (type == 4)  d = max(dx,dy);
    		// Butt
    		else if (type == 5)  d = max(dx+t,dy);
     
    		return d;
    }
     
     
    float join( in float type, in float d, in vec2 segment, in vec2 texcoord, in vec2 miter, in float miter_limit, in float linewidth )
    {
    		float dx = texcoord.x;
     
    		// Round join
    		// --------------------------------
    		if( type == 1.0 )
    		{
    			if (dx < segment.x) {
    				d = max(d,length( texcoord - vec2(segment.x,0.0)));
    				//d = length( texcoord - vec2(segment.x,0.0));
    			} else if (dx > segment.y) {
    				d = max(d,length( texcoord - vec2(segment.y,0.0)));
    				//d = length( texcoord - vec2(segment.y,0.0));
    			}
    		}
     
    		else if ( type == 2.0 )
    		{
    			if( (dx < segment.x) ||  (dx > segment.y) )
    				d = max(d, min(abs(miter.x),abs(miter.y)));
    		}
     
    		// Miter limit
    		// --------------------------------
    		if( (dx < segment.x) ||  (dx > segment.y) )
    		{
    			d = max(d, min(abs(miter.x),abs(miter.y)) - miter_limit*linewidth/2.0 );
    		}
     
    		return d;
    }
     
     
    uniform sampler2D u_dash_atlas;
     
     
    varying vec4  v_color;
    varying vec2  v_segment;
    varying vec2  v_angles;
    varying vec2  v_linecaps;
    varying vec2  v_texcoord;
    varying vec2  v_miter;
    varying float v_miter_limit;
    varying float v_length;
    varying float v_linejoin;
    varying float v_linewidth;
    varying float v_antialias;
    varying float v_dash_phase;
    varying float v_dash_period;
    varying float v_dash_index;
    varying vec2  v_dash_caps;
    varying float v_closed;
     
     
     
    	void main() 
    	{
    		//gl_FragColor = vec4(0.,0.,0.,1.);
     
    		// If color is fully transparent we just discard the fragment
    		if( v_color.a <= 0.0 )
    		{
    			discard;
     
    		}
     
    		// Test if dash pattern is the solid one (0)
    		bool solid =  (v_dash_index == 0.0);
     
    		// Test if path is closed
    		bool closed = (v_closed > 0.0);
     
    		vec4 color = v_color;
    		float dx = v_texcoord.x;
    		float dy = v_texcoord.y;
    		float t = v_linewidth/2.0-v_antialias;
    		float width = v_linewidth;
    		float d = 0.0;
     
    		vec2 linecaps = v_linecaps;
    		vec2 dash_caps = v_dash_caps;
    		float line_start = 0.0;
    		float line_stop  = v_length;
     
    		if( solid ) 
    		{
    			d = abs(dy);
    			if( (!closed) && (dx < line_start) )
    			{
    				d = cap( int(v_linecaps.x), abs(dx), abs(dy), t );
    			}
    			else if( (!closed) &&  (dx > line_stop) )
    			{
    				d = cap( int(v_linecaps.y), abs(dx)-line_stop, abs(dy), t );
    			}
    			else
    			{
                                    d = join( v_linejoin, abs(dy), v_segment, v_texcoord,
                                                      v_miter, v_miter_limit, v_linewidth );
    			}
     
    		}
     
    			gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
     
     
    	}

    I have no idea why it fails to compile.

  2. #2
    Member Newbie
    Join Date
    Apr 2014
    Posts
    47
    I think you may be exceeding the maximum number of varying components. You can check with glGet to see how many you can use.

    Code :
    GL_MAX_VARYING_COMPONENTS
    data returns one value, the number components for varying variables, which must be at least 60.
     
    GL_MAX_VARYING_VECTORS
    data returns one value, the number 4-vectors for varying variables, which is equal to the value of GL_MAX_VARYING_COMPONENTS and must be at least 15.
     
    GL_MAX_VARYING_FLOATS
    data returns one value, the maximum number of interpolators available for processing varying variables used by vertex and fragment shaders. This value represents the number of individual floating-point values that can be interpolated; varying variables declared as vectors, matrices, and arrays will all consume multiple interpolators. The value must be at least 32.

    Other people have had the same problem too:
    http://www.khronos.org/message_board...k-varying-quot

    http://www.opengl.org/discussion_boa...98#post1162398

Similar Threads

  1. Fragment shader compilation error: syntax error : unexpected $end
    By tusharpandey13 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-04-2018, 02:54 AM
  2. Fragment Shader problem
    By draco_22 in forum OpenGL: GLSL
    Replies: 1
    Last Post: 04-01-2017, 07:27 AM
  3. Replies: 7
    Last Post: 09-15-2015, 04:00 AM
  4. Shader compilation on Raspberry Pi - very strange problem ;?
    By SHristov in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-01-2015, 07:18 AM
  5. Compilation error during program fragment shader
    By SagoO in forum OpenGL: GLSL
    Replies: 2
    Last Post: 04-03-2011, 05:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean