• Advertisement
Sign in to follow this  

[GLSL] Fragment shader input from VS

This topic is 1493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

 


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.

Share this post


Link to post
Share on other sites


This should work with OpenGL 3.3+ or with ARB_explicit_attrib_location.

 

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement