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 2 of 2

Thread: Problem passing variable to fragment shader.

  1. #1
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    2

    Problem passing variable to fragment shader.

    Hello I have been learning the basics of GLSL and have come across a problem.

    I have tried a few different variations of code and the only time I have got it to work is if I disable the tessellation.


    When I run this code nothing renders....

    Code :
    	//SOURCE CODE FOR VERTEX SHADER
     
    	static const GLchar* vertShaderSource[] =
    	{
    		"#version 430 core \n"
    		"layout (location = 0) in vec4 offset; \n"
    		"layout (location = 1) in vec4 color; \n"
    		"out vec4 vs_color; \n"
    		"void main(void) \n"		
    		"{ \n"
    		"const vec4 vertices[3] = vec4[3](vec4(0.25,-0.25,0.5,1.0),vec4(-0.25,-0.25,0.5,1.0),vec4(0.25,0.25,0.5,1.0)); \n"
    		"gl_Position = vertices[gl_VertexID] + offset; \n"
    		"vs_color=color; \n"
    		"} \n"
    	};
     
    	//SOURCE FOR TESSALATION CONTROL SHADER
    	static const GLchar* TCSsource[] = 
    	{
    		"#version 430 core \n"
    		"layout (vertices = 3) out; \n"
    		"void main(void) \n"
    		"{ \n"
    		"if(gl_InvocationID == 0) \n"
    		"{ \n"
    		"gl_TessLevelInner[0] = 5.0; \n"
    		"gl_TessLevelOuter[0] = 5.0; \n"
    		"gl_TessLevelOuter[1] = 5.0; \n"
    		"gl_TessLevelOuter[2] = 5.0; \n"
    		"} \n"
    		"gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; \n"
    		"} \n"
    	};
     
     
    	//SOURCE FOR THE TEESALATION CONTROL SHADER
    	static const GLchar* TEShaderSource[] =
    	{
    		"#version 430 core \n"
    		"layout (triangles,equal_spacing,cw) in; \n"
    		"in vec4 vs_color; /n"
                    "out vec4 tes_color; \n"
    		"gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position + gl_TessCoord.y * gl_in[1].gl_Position + gl_TessCoord.z * gl_in[2].gl_Position); \n"
    		"tes_color = vs_color; \n"
    		"} \n"
    	};
     
     
    	//SOURCE CODE FOR FRAGMENT SHADER
    	static const GLchar* fragShaderSource[] =
    	{
    		"#version 430 core \n"
    		" \n"
    		"in vec4 tes_color;"
    		"out vec4 color; \n"
    		" \n"
    		"void main(void) \n"
    		"{ \n"
    		"color = tes_color; \n"
    		"} \n"
    	};

  2. #2
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    2
    Here is my updated code... but it still doesn't work.

    Code :
    static const GLchar* vertShaderSource[] =
    	{
    		"#version 430 core \n"
    		"layout (location = 0) in vec4 offset; \n"
    		"layout (location = 1) in vec4 color; \n"
    		"out vec4 vs_color; \n"
    		"void main(void) \n"		
    		"{ \n"
    		"const vec4 vertices[3] = vec4[3](vec4(0.25,-0.25,0.5,1.0),vec4(-0.25,-0.25,0.5,1.0),vec4(0.25,0.25,0.5,1.0)); \n"
    		"gl_Position = vertices[gl_VertexID] + offset; \n"
    		"vs_color[gl_VertexID]=color; \n"
    		"} \n"
    	};
     
    	//SOURCE FOR TESSALATION CONTROL SHADER
    	static const GLchar* TCSsource[] = 
    	{
    		"#version 430 core \n"
    		"layout (vertices = 3) out; \n"
    		"in vec4 vs_color[]; \n"
    		"out Tess{ \n"
    		"vec4 tcs_color; \n"
    		"} Out[]; \n"
    		"void main(void) \n"
    		"{ \n"
    		"if(gl_InvocationID == 0) \n"
    		"{ \n"
    		"gl_TessLevelInner[0] = 5.0; \n"
    		"gl_TessLevelOuter[0] = 5.0; \n"
    		"gl_TessLevelOuter[1] = 5.0; \n"
    		"gl_TessLevelOuter[2] = 5.0; \n"
    		"} \n"
    		"gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; \n"
    		"Out[gl_InvocationID].tcs_color = vs_color[gl_InvocationID]; \n"
    		"} \n"
    	};
     
     
    	//SOURCE FOR THE TEESALATION CONTROL SHADER
    	static const GLchar* TEShaderSource[] =
    	{
    		"#version 430 core \n"
    		"layout (triangles,equal_spacing,cw) in; \n"
    		"in Tess{ \n"
    		"vec4 tcs_color; \n"
    		"} In[];"
    		"out vec4 tes_color; \n"
    		"void main(void) \n"
    		"{ \n"
    		"gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position + gl_TessCoord.y * gl_in[1].gl_Position + gl_TessCoord.z * gl_in[2].gl_Position); \n"
    		"tes_color = In[0].tcs_color; \n"
    		"} \n"
    	};
     
     
    	//SOURCE CODE FOR FRAGMENT SHADER
    	static const GLchar* fragShaderSource[] =
    	{
    		"#version 430 core \n"
    		" \n"
    		"in vec4 tes_color; \n"
    		"out vec4 color; \n"
    		" \n"
    		"void main(void) \n"
    		"{ \n"
    		"color = tes_color; \n"
    		"} \n"
    	};

Posting Permissions

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