Jump to content
  • Advertisement
Sign in to follow this  
SetsudanHana

OpenGL Problem with Deffered Rendering

This topic is 1569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:

74207a86-0205-11e4-9816-0ba5972d33e3.png

Normal:

90bd05a6-0205-11e4-9b1e-5cc7a6bf671e.png

 

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

 

Share this post


Link to post
Share on other sites
Advertisement
I took the liberty to look the format up in his repo:
for (unsigned int i = 0 ; i < GBUFFER_NUM_TEXTURES ; i++) {
    glBindTexture(GL_TEXTURE_2D, m_textures[i]);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, windowWidth, windowHeight, 0, GL_RGB, GL_FLOAT, NULL);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_textures[i], 0);
}
 
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, windowWidth, windowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);
Now I'm pretty sure, there are no real GL_RGB formats, only GL_R, GL_RG and GL_RGBA. But OpenGL should extend that automatically. However note, that the textures are incomplete: no calls to glTexParameter{i,f}. I would expect s.th. like this:
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Regarding the CodeXL images, can you hover over the pixels with your mouse and look at the numeric content? Maybe the colors are just the result of some weird banding filter, that CodeXL automatically applies to all float buffers.


Also note, that your GBuffer is extremely big. You currently have 64 bytes per pixel, not counting the depth buffer. Once you have everyting running correctly, you might want to decrease that a bit.

Share this post


Link to post
Share on other sites

Sry i didnt answer, timezone...

 

But what about texture initializing, i did everything according to the tutorial and there was no line about setting any TexParameter. I checked out values in CodeX and you may be right about this filtering, i will try to save those textures as an image from my code and check results there.

 

And yeah i will have to think about optimalization, but now it is my least problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!