Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


values not transfering from vertex shader


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
3 replies to this topic

#1 Shadoh   Members   -  Reputation: 108

Like
0Likes
Like

Posted 13 November 2012 - 11:01 PM

Hi guys, I'm in dire need for help; For some reason my ins/outs don't seem to be matching up, and I can't figure out why, I've spent a few days on it now.
My code was based off a billboarding tutorial, I seem to have lost the link to it. But here's the source for my shaders below. Can you tell me what's going on?
My Color is black in the fragment shader, even though it's sent in to the shader as white. And even if I manually set the color to white in the vertex shader it still appears black in the fragment shader.

Geometry shader
#version 330
#extension GL_ARB_separate_shader_objects : enable
layout (points) in;
layout (triangle_strip) out;
layout (max_vertices = 4) out;
uniform mat4 gVP;
uniform vec3 gCameraPos;
layout (location = 1) in float inScale[1];
layout (location = 2) in vec4 inTexCoord[1];
layout (location = 3) in vec4 inColor[1];
layout (location = 1) out vec2 TexCoord;
layout (location = 2) out vec4 Color;

void main()
{
    vec3 Pos = gl_in[0].gl_Position.xyz;

vec3 toCamera = normalize(gCameraPos - Pos);
    vec3 up = vec3(0.0, 1.0, 0.0);
    vec3 right = cross(toCamera, up);
 
vec4 tc = inTexCoord[0];
float Sc = inScale[0];
vec4 col = inColor[0];
Pos -= (right * (Sc * 0.5));
Pos.y -= Sc * 0.5;
    gl_Position = gVP * vec4(Pos, 1.0);
    TexCoord = vec2(tc.x, tc.y);
Color = col;
    EmitVertex();
    Pos.y += Sc;
    gl_Position = gVP * vec4(Pos, 1.0);
    TexCoord = vec2(tc.x, tc.w);
Color = col;
    EmitVertex();
    Pos.y -= Sc;
    Pos += right * Sc;
    gl_Position = gVP * vec4(Pos, 1.0);
    TexCoord = vec2(tc.z, tc.y);
Color = col;
    EmitVertex();
    Pos.y += Sc;
    gl_Position = gVP * vec4(Pos, 1.0);
    TexCoord = vec2(tc.z, tc.w);
Color = col;
    EmitVertex();
    EndPrimitive();
}

Vertex shader
#version 330
#extension GL_ARB_separate_shader_objects : enable

layout (location = 0) in vec3 Position;
layout (location = 1) in vec2 TexCoord;
layout (location = 2) in vec4 Color;



// vertex shader

layout (location = 1) out vec2 TexCoordOut;
layout (location = 2) out vec4 ColorOut;



void main()
{
	gl_Position = vec4(Position, 1.0);
	TexCoordOut = TexCoord;
	ColorOut = Color;
}

Fragment shader
#version 330
#extension GL_ARB_separate_shader_objects : enable


uniform sampler2D TextureMap;
uniform float Alpha;

// fragment shader
in vec2 TexCoordOut;
in vec4 ColorOut;


out vec4 outputF;



void main(void)
{
	//vec4 tex = texture(TextureMap, TexCoordOut.xy);
	//tex.a *= Alpha;
	//tex *= ColorOut;
	//if (tex.a <= 0.0)
	//{
	//	discard;
	//}
	//else
	//{
		outputF = ColorOut;
	//}
}

Edited by Shadoh, 14 November 2012 - 04:58 PM.


Sponsor:

#2 Nyssa   Members   -  Reputation: 426

Like
0Likes
Like

Posted 13 November 2012 - 11:23 PM

Id start commenting out code till I narrowed down the issue.
First change your fragment shader to the following...

[source lang="java"]void main(void){ outputF = ColorOut;}[/source]

Is the colour shown? If so then it's either your texture or the "Alpha" parameter not being initialise correctly.

Edited by Jaroy, 13 November 2012 - 11:26 PM.


#3 Shadoh   Members   -  Reputation: 108

Like
0Likes
Like

Posted 14 November 2012 - 12:54 AM

Id start commenting out code till I narrowed down the issue.
First change your fragment shader to the following...

[source lang="java"]void main(void){ outputF = ColorOut;}[/source]

Is the colour shown? If so then it's either your texture or the "Alpha" parameter not being initialise correctly.


Still comes out blank, infact the current setup doesn't work properly unless I manually set the locations. The weird thing is, it maps the texture properly. So the texture comes out fine, but it's black (obviously because of the coloring). I'll update the original post with the semi-working version. So it show's the texture, but not the color.

This screenshot below shows what it looks like when only using the ColorOut value with OutputF. Note: the black squares should at-least be white.

Posted Image

Edited by Shadoh, 14 November 2012 - 01:04 AM.


#4 Shadoh   Members   -  Reputation: 108

Like
0Likes
Like

Posted 16 November 2012 - 04:35 PM

Found the solution! I was unaware that the Geometry shader actually takes input from the Vertex shader (I thought it was the other way around). This got answered on the OpenGL forums over here.

Thanks to all who answered.




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