So i'm trying to implement deffered rendering in my first "graphic engine" using this tutorial: http://ogldev.atspace.co.uk/www/tutorial35/tutorial35.html . And got some issues with drawing my position and normal to the texture. I think i'm sending everything alright, cause before it worked normally with forward rendering. This is how it looks.
Position:
Normal:
Texture coords, diffuse and depth buffer are looking fine.
Here are my shaders for model geometry (for terrain it is similar, just with additional calculation)
VS:
#version 400
layout(location = 1) in vec3 vertex_position;
layout(location = 2) in vec2 vertex_texture;
layout(location = 3) in vec3 vertex_normals;
uniform mat4 pvw_matrix;
uniform mat4 world;
layout(location = 0) out vec2 texture_coords;
layout(location = 1) out vec3 normals;
layout(location = 2) out vec3 world_pos;
void main()
{
vec4 tmp = (world * vec4(vertex_normals, 0.0));
normals = tmp.xyz;
tmp = (world * vec4(vertex_position, 1.0));
world_pos = tmp.xyz;
texture_coords = vertex_texture;
gl_Position = pvw_matrix * vec4( vertex_position, 1.0 );
}
FS:
#version 400
layout(location = 0) in vec2 TexCoord;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec3 WorldPos;
layout (location = 0) out vec3 WorldPosOut;
layout (location = 1) out vec3 DiffuseOut;
layout (location = 2) out vec3 NormalOut;
layout (location = 3) out vec3 TexCoordOut;
uniform sampler2D sampler;
void main()
{
vec4 texel = texture(sampler, TexCoord);
WorldPosOut = WorldPos;
DiffuseOut = texel.xyz;
NormalOut = normalize(Normal);
TexCoordOut = vec3(TexCoord, 0.0);
}
Thanks for any clues, that will help me solve this riddle. I will paste more code if necessary. Link to my repo is here: https://github.com/SetsudanHana/Tsukuyomi---OpenGL-engine