1
$\begingroup$

I need some help understanding whats happening to my view space.

I have the following colour buffers coming out of my deffered renderer... Depth buffer Normal buffer ViewSpace positions My concern is with the view space buffer (third image), while this seems correct for the xy view space coordinate, should I not be seeing some purple/pink/white for the z component of the view space coordinate?

This scene is fairly large in an attempt to try to get varying depth values to see in the view space position buffer.

For a small model (near and far clipping planes are sized according to scene bounding box), I get... enter image description here Which, while it has gradient changes between the xy (not like the large scene which has sharp gradient changes, due to its size perhaps?) which makes sense to me. However I am still missing z/depth values it appears (pinks, purples and whites).

I pressume the view space in the range -1 < x < 1, -1 < y < 1, -1 < z < 1. Is this correct? Is there a problem with my view space coordinates? Could anyone spot anything I am doing wrong here?

Here are my shaders:

Vertex shader of gBuffer...

#version 430 core

layout (std140) uniform MatrixPV
{
    mat4 P;
    mat4 V;
};

layout(location = 0) in vec3 InPoint;
layout(location = 1) in vec3 InNormal;
layout(location = 2) in vec2 InUV;

uniform mat4 M;

out vec4 MVPosition;
out vec3 Normal;
out vec2 UV;

void main()
{
    mat4 VM = V * M;
    gl_Position = P * VM * vec4(InPoint, 1.0);
    MVPosition = VM * vec4(InPoint, 1.0);
    Normal = mat3(M) * InNormal;
    UV = InUV;
}

Fragment shader of gBuffer...

#version 430 core

layout(location = 0) out vec4 gBufferPicker;
layout(location = 1) out vec4 gBufferPosition;
layout(location = 2) out vec4 gBufferNormal;
layout(location = 3) out vec4 gBufferDiffuse;

in vec3 Normal;
in vec4 MVPosition;

vec4 Diffuse();
uniform vec4 PickerColour;

void main()
{
    gBufferPosition = MVPosition;
    gBufferNormal = vec4(Normal.xyz, 1.0);
    gBufferPicker = PickerColour;
    gBufferDiffuse = Diffuse();
}

And here is the 'lighting pass' shader to visualise the view space coordinate...

#version 430 core

uniform sampler2D debugBufferPosition;

in vec2 UV;
out vec4 frag;

void main()
{
    vec3 val = texture(debugBufferPosition, UV).xyz;
    frag = vec4(val.xyz, 1.0);
}

Any help is appreciated. Many thanks in advance.

$\endgroup$
1
  • $\begingroup$ What is the format of your position buffer texture? Also, do you have any reason not to use the depth buffer to reconstruct the position? You would need RGBA32F for your position buffer to not cause artifacts while calculating the lighting. That uses up a lot of bandwidth. $\endgroup$ Nov 24, 2020 at 6:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.