Jump to content

  • Log In with Google      Sign In   
  • Create Account

[GLSL] Fragment shader input from VS


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Juliean   GDNet+   -  Reputation: 2607

Like
0Likes
Like

Posted 16 December 2013 - 12:54 PM

Hello,

 

I've ran into yet another problem with GLSL. Consider this shader:

#version 440 core

in vec3 invPos;
in vec2 invTex0;
in vec4 invColor;

#define outvPos gl_Position
out vec2 outvTex0;
out vec4 outvColor;

void main()
{
	outvPos = vec4(invPos.yx,1.0-invPos.z, 1.0);
	outvTex0 = invTex0;
	outvColor = invColor;
}

// frag_begin
#version 440 core

in vec2 invTex0;
in vec4 invColor;
uniform sampler2D Image;

out vec4 outvColor;
void main()
{
	outvColor = texture(Image, invTex0) * invColor;
	outvColor = vec4(1.0f);
}

Its used for basic sprite rendering, and the sprite is already displaying on the screen. However, I seem to have problems passing anything other than the position from the vertex shader to the fragment shader. Nevermind the evil looking #define macro, but if I e.g. try to write

outvColor.rg = invTex0;

the screen stays black. It is not an issue with the input of the vertex attributes, as even if I make a new vertex output named "float test" and write "1.0" it will still output black from the fragment shader.

 

Now, I've searched around for a while but didn't really find anything helpful. Most shader tutorials I've read seam to magically get it to work. Is there anything else I have to consider, or something I've missed here?



Sponsor:

#2 Samith   Members   -  Reputation: 2256

Like
0Likes
Like

Posted 16 December 2013 - 01:47 PM

In your fragment program you're reading invTex0, but you never write to an output variable named invTex0 in your vertex program. The problem is that outvTex0 is not the same name as invTex0, so OpenGL doesn't know to link them together.

#3 Juliean   GDNet+   -  Reputation: 2607

Like
0Likes
Like

Posted 16 December 2013 - 02:25 PM


In your fragment program you're reading invTex0, but you never write to an output variable named invTex0 in your vertex program. The problem is that outvTex0 is not the same name as invTex0, so OpenGL doesn't know to link them together.

 

Do they really have to have the same name, or is there some other way to align those two values? My shaders are generated from an intermediat format, and having to rewrite all "in" prefixed values to "out" in the pixelshader could make things at least a tad bit more complicated.


Edited by Juliean, 16 December 2013 - 02:26 PM.


#4 Chris_F   Members   -  Reputation: 2369

Like
2Likes
Like

Posted 16 December 2013 - 02:47 PM

 


In your fragment program you're reading invTex0, but you never write to an output variable named invTex0 in your vertex program. The problem is that outvTex0 is not the same name as invTex0, so OpenGL doesn't know to link them together.

 

Do they really have to have the same name, or is there some other way to align those two values? My shaders are generated from an intermediat format, and having to rewrite all "in" prefixed values to "out" in the pixelshader could make things at least a tad bit more complicated.

 

 

Try this:

 

#version 440 core

in vec3 invPos;
in vec2 invTex0;
in vec4 invColor;

#define outvPos gl_Position
layout(location = 0) out vec2 outvTex0;
layout(location = 1) out vec4 outvColor;

void main()
{
    outvPos = vec4(invPos.yx,1.0-invPos.z, 1.0);
    outvTex0 = invTex0;
    outvColor = invColor;
}

// frag_begin
#version 440 core

layout(location = 0) in vec2 invTex0;
layout(location = 1) in vec4 invColor;
uniform sampler2D Image;

out vec4 outvColor;
void main()
{
    outvColor = texture(Image, invTex0) * invColor;
    outvColor = vec4(1.0f);
}

 

This should work with OpenGL 3.3+ or with ARB_explicit_attrib_location.



#5 Juliean   GDNet+   -  Reputation: 2607

Like
0Likes
Like

Posted 16 December 2013 - 04:47 PM


This should work with OpenGL 3.3+ or with ARB_explicit_attrib_location.

 

Yes thanks, that works and is a lot easier to generate.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS