Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geometry shader used to verify normals of 3d object #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tutorial19_Geometry_Normal_Shader/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The tutorial contains geometry shaders aimed to generate and verify the correct disposition of the normals of a uv wrapped texture on a 3d object.
It contains 3 shaders
vertex shader
geometry shader
fragement shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

// Fragment shader for simple coloured rendering of the normals

#version 330 core
//declaring the vec4 color variable

out vec4 FragColor;



void main()
{
//assigning the fragment shader with the vec4 color.

FragColor = vec4(1.0,1.0,0.5,1.0);
}
43 changes: 43 additions & 0 deletions tutorial19_Geometry_Normal_Shader/model-geometry-shader-normal.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//geometry shader to draw the normals

#version 330 core

//Since the normals are to be drawn at the 3 vertices of the raster triangle,the vertices have an upper bound of 3
//line_strip specifies the normals to be drawn adjacent to each other on each of the 3 vertices of a triangle


layout(triangles) in;
layout(line_strip,max_vertices=3) out;

//interface block inherited from the vertex shader

in VS_OUT{

vec3 normal;

}gs_in[];

//magnitude of the length of the normals
float magnitude=0.4;

//generator function which will assign the normals based on the 3 indices (0,1,2) of each triangle
void generateLine(int index)
{
//gets the position and draws the normal from the vertices
gl_Position=gl_in[index].gl_Position;


EmitVertex();
gl_Position=gl_in[index].gl_Position + vec4(gs_in[index].normal,0.0)*magnitude;
EmitVertex();
EndPrimitive();

}

void main()
{
//line is generated from the vertices
generateLine(0);
generateLine(1);
generateLine(2);
}
38 changes: 38 additions & 0 deletions tutorial19_Geometry_Normal_Shader/model-geometry-vertex-normal.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//geometry shader used for debugging the general position of the normals of the texture wrapping.
//Used to decide whether the normals have been loaded properly.

#version 330 core

//vertex attributes position and normals

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;

//interface block to be passed to the geometry shader
//passing only the normal attribute to the geometry shader


out VS_OUT{

vec3 normal;
}vs_out;

//MVP matrix loading


uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
//generate normal matrix to convert to NDC (Normalized Device Coordinates)

mat3 normalMatrix= mat3(transpose(inverse(view*model)));

//normalizing the normals of the vertices

vs_out.normal=normalize(vec3(projection * vec4(normalMatrix * aNormal,0.0)));

gl_Position = projection * view * model * vec4(aPos, 1.0);
}