hashbrown

09-23-2016, 11:02 PM

I'm learning how to use the geometry shader and managed to display vertex normals. But when I use this shader type, the only colors I see are (default) black lines representing the normals. My texture and lighting disappears.

Is there a way I can render primitives with the geometry shader without the texture and lighting disappearing? My guess is creating another VBO just for geometry shader work, but I'm sure I'm wrong.

I'll share what I got for the vertex and geometry shaders so far, thanks in advanced!

// Vertex

#version 330 core

uniform mat4 model;

uniform mat4 view;

uniform mat4 projection;

layout (location = 0) in vec3 position;

layout (location = 1) in vec2 texCoord;

layout (location = 2) in vec3 normals;

uniform mat4 mvp;

uniform mat3 nrmMatrix;

out vec3 position0;

out vec2 texCoord0;

out vec3 normals0;

out mat3 nrmMatrix0;

out mat4 model0;

out vec3 dirLightPos0;

out VS_OUT {

vec3 normal;

} vs_out;

void main() {

position0 = position;

texCoord0 = texCoord;

normals0 = normals;

nrmMatrix0 = nrmMatrix;

model0 = model;

vs_out.normal = vec3(projection * vec4(nrmMatrix * normals, 1.0));

gl_Position = mvp * vec4(position, 1.0);

}

// Geometry

#version 330 core

layout (triangles) in;

layout (line_strip, max_vertices = 6) out;

in VS_OUT {

vec3 normal;

} gs_in[];

const float MAG = 0.2f;

out vec3 color0;

void GenerateLine(int index) {

gl_Position = gl_in[index].gl_Position;

EmitVertex();

gl_Position = gl_in[index].gl_Position + vec4(gs_in[index].normal, 0.0f) * MAG;

EmitVertex();

EndPrimitive();

}

void main() {

GenerateLine(0);

GenerateLine(1);

GenerateLine(2);

color0 = vec3(1, 0, 0);

}

Is there a way I can render primitives with the geometry shader without the texture and lighting disappearing? My guess is creating another VBO just for geometry shader work, but I'm sure I'm wrong.

I'll share what I got for the vertex and geometry shaders so far, thanks in advanced!

// Vertex

#version 330 core

uniform mat4 model;

uniform mat4 view;

uniform mat4 projection;

layout (location = 0) in vec3 position;

layout (location = 1) in vec2 texCoord;

layout (location = 2) in vec3 normals;

uniform mat4 mvp;

uniform mat3 nrmMatrix;

out vec3 position0;

out vec2 texCoord0;

out vec3 normals0;

out mat3 nrmMatrix0;

out mat4 model0;

out vec3 dirLightPos0;

out VS_OUT {

vec3 normal;

} vs_out;

void main() {

position0 = position;

texCoord0 = texCoord;

normals0 = normals;

nrmMatrix0 = nrmMatrix;

model0 = model;

vs_out.normal = vec3(projection * vec4(nrmMatrix * normals, 1.0));

gl_Position = mvp * vec4(position, 1.0);

}

// Geometry

#version 330 core

layout (triangles) in;

layout (line_strip, max_vertices = 6) out;

in VS_OUT {

vec3 normal;

} gs_in[];

const float MAG = 0.2f;

out vec3 color0;

void GenerateLine(int index) {

gl_Position = gl_in[index].gl_Position;

EmitVertex();

gl_Position = gl_in[index].gl_Position + vec4(gs_in[index].normal, 0.0f) * MAG;

EmitVertex();

EndPrimitive();

}

void main() {

GenerateLine(0);

GenerateLine(1);

GenerateLine(2);

color0 = vec3(1, 0, 0);

}