From 28a48fa2373a74fd85f594cfd10bf550827d0119 Mon Sep 17 00:00:00 2001 From: Abhilash Majumder <30946547+abhilash1910@users.noreply.github.com> Date: Sun, 13 Oct 2019 19:15:01 +0530 Subject: [PATCH 1/3] Geometry-normal-vertex.shader Vertex shader which is used to verify the proper allocation of normals in the uv wrapped texture of a 3d model. --- Geometry-normal-vertex.shader | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Geometry-normal-vertex.shader diff --git a/Geometry-normal-vertex.shader b/Geometry-normal-vertex.shader new file mode 100644 index 000000000..8a1d143ed --- /dev/null +++ b/Geometry-normal-vertex.shader @@ -0,0 +1,31 @@ +//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); +} From 5c964ef81b7a59df13c5d643f6dd2a50ea9065a8 Mon Sep 17 00:00:00 2001 From: Abhilash Majumder <30946547+abhilash1910@users.noreply.github.com> Date: Sun, 13 Oct 2019 19:38:35 +0530 Subject: [PATCH 2/3] Geometry-Normal-Shader Contains geometry shaders along with normals to check for the correct disposition of the normals in a texture wrapped object. Contains 3 shaders: 1.vertex shader -initialized the variables ,interface block and passes the necessary arguments after NDC normalization 2.geometry shader- spawns adjacent normal lines in line_strip form alon each of the 3 vertices of a raster triangle.Passes the attributes to pixel shader for coloring.If an object does not have the normals then it throws error and rendering stops 3. fragment shader-Colorizes the pixels of the normals The shader code is written in GLSL and uses #version 330 core. --- tutorial19_Geometry_Normal_Shader/Readme.txt | 5 +++ .../model-geometry-fragment-normal.frag | 16 +++++++ .../model-geometry-shader-normal.gs | 43 +++++++++++++++++++ .../model-geometry-vertex-normal.vs | 38 ++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 tutorial19_Geometry_Normal_Shader/Readme.txt create mode 100644 tutorial19_Geometry_Normal_Shader/model-geometry-fragment-normal.frag create mode 100644 tutorial19_Geometry_Normal_Shader/model-geometry-shader-normal.gs create mode 100644 tutorial19_Geometry_Normal_Shader/model-geometry-vertex-normal.vs diff --git a/tutorial19_Geometry_Normal_Shader/Readme.txt b/tutorial19_Geometry_Normal_Shader/Readme.txt new file mode 100644 index 000000000..2aca29908 --- /dev/null +++ b/tutorial19_Geometry_Normal_Shader/Readme.txt @@ -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 \ No newline at end of file diff --git a/tutorial19_Geometry_Normal_Shader/model-geometry-fragment-normal.frag b/tutorial19_Geometry_Normal_Shader/model-geometry-fragment-normal.frag new file mode 100644 index 000000000..acd9b06c3 --- /dev/null +++ b/tutorial19_Geometry_Normal_Shader/model-geometry-fragment-normal.frag @@ -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); +} \ No newline at end of file diff --git a/tutorial19_Geometry_Normal_Shader/model-geometry-shader-normal.gs b/tutorial19_Geometry_Normal_Shader/model-geometry-shader-normal.gs new file mode 100644 index 000000000..aad6ae922 --- /dev/null +++ b/tutorial19_Geometry_Normal_Shader/model-geometry-shader-normal.gs @@ -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); +} diff --git a/tutorial19_Geometry_Normal_Shader/model-geometry-vertex-normal.vs b/tutorial19_Geometry_Normal_Shader/model-geometry-vertex-normal.vs new file mode 100644 index 000000000..08577ce22 --- /dev/null +++ b/tutorial19_Geometry_Normal_Shader/model-geometry-vertex-normal.vs @@ -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); +} \ No newline at end of file From df37f7f906c6ebb3cce943a144e969eb87184648 Mon Sep 17 00:00:00 2001 From: Abhilash Majumder <30946547+abhilash1910@users.noreply.github.com> Date: Sun, 13 Oct 2019 19:39:14 +0530 Subject: [PATCH 3/3] Delete Geometry-normal-vertex.shader --- Geometry-normal-vertex.shader | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 Geometry-normal-vertex.shader diff --git a/Geometry-normal-vertex.shader b/Geometry-normal-vertex.shader deleted file mode 100644 index 8a1d143ed..000000000 --- a/Geometry-normal-vertex.shader +++ /dev/null @@ -1,31 +0,0 @@ -//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); -}