Issue with translucent Terrain (Probably Depth Buffer issues)










0















I have issues with rendering. The Blocks im rendering are somewhat translucent. Everything is fine as long as im using Nvidia Graphics Cards. On Intel (integrated) or AMD Graphics Cards it looks like this:



enter image description here



As you can see there are blocks being rendered, that should be behind others.



This are my prepare methods.



 public void prepare()

GL.Clear(ClearBufferMask.ColorBufferBit

public void enableGLCaps()

GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.DepthClamp);

GL.Enable(EnableCap.CullFace);
GL.CullFace(CullFaceMode.Back);

GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);



This is my vertex shader:



#version 440
in vec3 position;
in vec2 textureCoords;

out vec2 pass_textureCoords;
out float visibility;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform float density;
uniform float gradient;

void main()
vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
vec4 positionRelativeToCam = viewMatrix * worldPosition;
gl_Position = projectionMatrix * positionRelativeToCam;

pass_textureCoords = textureCoords;
float distance = length(positionRelativeToCam.xyz);
visibility = exp(-pow((distance*density), gradient));
visibility = clamp(visibility, 0.0, 1.0);




And here my fragment shader:



#version 440

uniform sampler2D textureSampler;
uniform vec3 skyColour;

in vec2 pass_textureCoords;
in float visibility;

out vec4 color;

void main()

vec4 textureColour = texture(textureSampler, pass_textureCoords);
if (textureColour.a < 0.5)
discard;

color = mix(vec4(skyColour, 1.0), textureColour, visibility);
color.a = 1;



Changing the near plane doesnt help.



EDIT 1:



I have rendered the z value and have noticed, that some faces definitely dont have the correct value.
I am rendering every texture in a region (16*16*16 chunks) as a single VAO (will use texture atlases later, but im running into flickering/overlapping with mipmapping using it). The Faces, that are rendered as one VAO are not overlapping each other so the z buffer seems to be ok there. It looks like its being retested after every render call.
Here is my render call:



GL.DrawElements(BeginMode.Quads, vertices, DrawElementsType.UnsignedInt, 0);


SOLUTION:



The depth function I was using was wrong. You should be using Lequal. I also had to set the depth range to (0, 1).










share|improve this question
























  • I'd check the value of pow(x,y). It may be undefined if x<0 or x==0 && y<=0 In other words, some imprecision for different drivers on distance*density calculation.

    – Ripi2
    Nov 12 '18 at 0:08











  • That isnt the issue unfortunately. Ive removed everything but the three matrix multiplications and the texture function in the fragment shader. Still the same result. Ive rendered the Z value and there are many Faces not rendering in the color they are supposed to (many are rendered white = near, even tho they are far away). So i think its definitely an issue with the depth buffer.

    – N. J. Funk
    Nov 12 '18 at 2:12












  • See the edit for more information.

    – N. J. Funk
    Nov 12 '18 at 2:36











  • it might be also driver problem ... I got similar problems on AMD and Intel while rendering into texture and use result on semitransparent object. Intel is not capable of rendering to texture (other than ugly slow CPU/GPU side transfers) and AMD has problems with rendering correctly. The only work around I found is to not use rendering to texture at all on both vendors. But it does not look like you are rendering to texture so it might be entirely different issue (however I suspect its related)

    – Spektre
    Nov 12 '18 at 7:44












  • what z value have you rendered? Depth or space camera? Also your atmospheric fog computation should only take into account positionRelativeToCam.z, which contains the depth or distance from the camera to the vertex

    – Nadir
    Nov 12 '18 at 14:04















0















I have issues with rendering. The Blocks im rendering are somewhat translucent. Everything is fine as long as im using Nvidia Graphics Cards. On Intel (integrated) or AMD Graphics Cards it looks like this:



enter image description here



As you can see there are blocks being rendered, that should be behind others.



This are my prepare methods.



 public void prepare()

GL.Clear(ClearBufferMask.ColorBufferBit

public void enableGLCaps()

GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.DepthClamp);

GL.Enable(EnableCap.CullFace);
GL.CullFace(CullFaceMode.Back);

GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);



This is my vertex shader:



#version 440
in vec3 position;
in vec2 textureCoords;

out vec2 pass_textureCoords;
out float visibility;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform float density;
uniform float gradient;

void main()
vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
vec4 positionRelativeToCam = viewMatrix * worldPosition;
gl_Position = projectionMatrix * positionRelativeToCam;

pass_textureCoords = textureCoords;
float distance = length(positionRelativeToCam.xyz);
visibility = exp(-pow((distance*density), gradient));
visibility = clamp(visibility, 0.0, 1.0);




And here my fragment shader:



#version 440

uniform sampler2D textureSampler;
uniform vec3 skyColour;

in vec2 pass_textureCoords;
in float visibility;

out vec4 color;

void main()

vec4 textureColour = texture(textureSampler, pass_textureCoords);
if (textureColour.a < 0.5)
discard;

color = mix(vec4(skyColour, 1.0), textureColour, visibility);
color.a = 1;



Changing the near plane doesnt help.



EDIT 1:



I have rendered the z value and have noticed, that some faces definitely dont have the correct value.
I am rendering every texture in a region (16*16*16 chunks) as a single VAO (will use texture atlases later, but im running into flickering/overlapping with mipmapping using it). The Faces, that are rendered as one VAO are not overlapping each other so the z buffer seems to be ok there. It looks like its being retested after every render call.
Here is my render call:



GL.DrawElements(BeginMode.Quads, vertices, DrawElementsType.UnsignedInt, 0);


SOLUTION:



The depth function I was using was wrong. You should be using Lequal. I also had to set the depth range to (0, 1).










share|improve this question
























  • I'd check the value of pow(x,y). It may be undefined if x<0 or x==0 && y<=0 In other words, some imprecision for different drivers on distance*density calculation.

    – Ripi2
    Nov 12 '18 at 0:08











  • That isnt the issue unfortunately. Ive removed everything but the three matrix multiplications and the texture function in the fragment shader. Still the same result. Ive rendered the Z value and there are many Faces not rendering in the color they are supposed to (many are rendered white = near, even tho they are far away). So i think its definitely an issue with the depth buffer.

    – N. J. Funk
    Nov 12 '18 at 2:12












  • See the edit for more information.

    – N. J. Funk
    Nov 12 '18 at 2:36











  • it might be also driver problem ... I got similar problems on AMD and Intel while rendering into texture and use result on semitransparent object. Intel is not capable of rendering to texture (other than ugly slow CPU/GPU side transfers) and AMD has problems with rendering correctly. The only work around I found is to not use rendering to texture at all on both vendors. But it does not look like you are rendering to texture so it might be entirely different issue (however I suspect its related)

    – Spektre
    Nov 12 '18 at 7:44












  • what z value have you rendered? Depth or space camera? Also your atmospheric fog computation should only take into account positionRelativeToCam.z, which contains the depth or distance from the camera to the vertex

    – Nadir
    Nov 12 '18 at 14:04













0












0








0


0






I have issues with rendering. The Blocks im rendering are somewhat translucent. Everything is fine as long as im using Nvidia Graphics Cards. On Intel (integrated) or AMD Graphics Cards it looks like this:



enter image description here



As you can see there are blocks being rendered, that should be behind others.



This are my prepare methods.



 public void prepare()

GL.Clear(ClearBufferMask.ColorBufferBit

public void enableGLCaps()

GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.DepthClamp);

GL.Enable(EnableCap.CullFace);
GL.CullFace(CullFaceMode.Back);

GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);



This is my vertex shader:



#version 440
in vec3 position;
in vec2 textureCoords;

out vec2 pass_textureCoords;
out float visibility;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform float density;
uniform float gradient;

void main()
vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
vec4 positionRelativeToCam = viewMatrix * worldPosition;
gl_Position = projectionMatrix * positionRelativeToCam;

pass_textureCoords = textureCoords;
float distance = length(positionRelativeToCam.xyz);
visibility = exp(-pow((distance*density), gradient));
visibility = clamp(visibility, 0.0, 1.0);




And here my fragment shader:



#version 440

uniform sampler2D textureSampler;
uniform vec3 skyColour;

in vec2 pass_textureCoords;
in float visibility;

out vec4 color;

void main()

vec4 textureColour = texture(textureSampler, pass_textureCoords);
if (textureColour.a < 0.5)
discard;

color = mix(vec4(skyColour, 1.0), textureColour, visibility);
color.a = 1;



Changing the near plane doesnt help.



EDIT 1:



I have rendered the z value and have noticed, that some faces definitely dont have the correct value.
I am rendering every texture in a region (16*16*16 chunks) as a single VAO (will use texture atlases later, but im running into flickering/overlapping with mipmapping using it). The Faces, that are rendered as one VAO are not overlapping each other so the z buffer seems to be ok there. It looks like its being retested after every render call.
Here is my render call:



GL.DrawElements(BeginMode.Quads, vertices, DrawElementsType.UnsignedInt, 0);


SOLUTION:



The depth function I was using was wrong. You should be using Lequal. I also had to set the depth range to (0, 1).










share|improve this question
















I have issues with rendering. The Blocks im rendering are somewhat translucent. Everything is fine as long as im using Nvidia Graphics Cards. On Intel (integrated) or AMD Graphics Cards it looks like this:



enter image description here



As you can see there are blocks being rendered, that should be behind others.



This are my prepare methods.



 public void prepare()

GL.Clear(ClearBufferMask.ColorBufferBit

public void enableGLCaps()

GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.DepthClamp);

GL.Enable(EnableCap.CullFace);
GL.CullFace(CullFaceMode.Back);

GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);



This is my vertex shader:



#version 440
in vec3 position;
in vec2 textureCoords;

out vec2 pass_textureCoords;
out float visibility;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform float density;
uniform float gradient;

void main()
vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
vec4 positionRelativeToCam = viewMatrix * worldPosition;
gl_Position = projectionMatrix * positionRelativeToCam;

pass_textureCoords = textureCoords;
float distance = length(positionRelativeToCam.xyz);
visibility = exp(-pow((distance*density), gradient));
visibility = clamp(visibility, 0.0, 1.0);




And here my fragment shader:



#version 440

uniform sampler2D textureSampler;
uniform vec3 skyColour;

in vec2 pass_textureCoords;
in float visibility;

out vec4 color;

void main()

vec4 textureColour = texture(textureSampler, pass_textureCoords);
if (textureColour.a < 0.5)
discard;

color = mix(vec4(skyColour, 1.0), textureColour, visibility);
color.a = 1;



Changing the near plane doesnt help.



EDIT 1:



I have rendered the z value and have noticed, that some faces definitely dont have the correct value.
I am rendering every texture in a region (16*16*16 chunks) as a single VAO (will use texture atlases later, but im running into flickering/overlapping with mipmapping using it). The Faces, that are rendered as one VAO are not overlapping each other so the z buffer seems to be ok there. It looks like its being retested after every render call.
Here is my render call:



GL.DrawElements(BeginMode.Quads, vertices, DrawElementsType.UnsignedInt, 0);


SOLUTION:



The depth function I was using was wrong. You should be using Lequal. I also had to set the depth range to (0, 1).







c# opengl rendering opentk depth-buffer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 5 '18 at 12:55







N. J. Funk

















asked Nov 11 '18 at 22:56









N. J. FunkN. J. Funk

838




838












  • I'd check the value of pow(x,y). It may be undefined if x<0 or x==0 && y<=0 In other words, some imprecision for different drivers on distance*density calculation.

    – Ripi2
    Nov 12 '18 at 0:08











  • That isnt the issue unfortunately. Ive removed everything but the three matrix multiplications and the texture function in the fragment shader. Still the same result. Ive rendered the Z value and there are many Faces not rendering in the color they are supposed to (many are rendered white = near, even tho they are far away). So i think its definitely an issue with the depth buffer.

    – N. J. Funk
    Nov 12 '18 at 2:12












  • See the edit for more information.

    – N. J. Funk
    Nov 12 '18 at 2:36











  • it might be also driver problem ... I got similar problems on AMD and Intel while rendering into texture and use result on semitransparent object. Intel is not capable of rendering to texture (other than ugly slow CPU/GPU side transfers) and AMD has problems with rendering correctly. The only work around I found is to not use rendering to texture at all on both vendors. But it does not look like you are rendering to texture so it might be entirely different issue (however I suspect its related)

    – Spektre
    Nov 12 '18 at 7:44












  • what z value have you rendered? Depth or space camera? Also your atmospheric fog computation should only take into account positionRelativeToCam.z, which contains the depth or distance from the camera to the vertex

    – Nadir
    Nov 12 '18 at 14:04

















  • I'd check the value of pow(x,y). It may be undefined if x<0 or x==0 && y<=0 In other words, some imprecision for different drivers on distance*density calculation.

    – Ripi2
    Nov 12 '18 at 0:08











  • That isnt the issue unfortunately. Ive removed everything but the three matrix multiplications and the texture function in the fragment shader. Still the same result. Ive rendered the Z value and there are many Faces not rendering in the color they are supposed to (many are rendered white = near, even tho they are far away). So i think its definitely an issue with the depth buffer.

    – N. J. Funk
    Nov 12 '18 at 2:12












  • See the edit for more information.

    – N. J. Funk
    Nov 12 '18 at 2:36











  • it might be also driver problem ... I got similar problems on AMD and Intel while rendering into texture and use result on semitransparent object. Intel is not capable of rendering to texture (other than ugly slow CPU/GPU side transfers) and AMD has problems with rendering correctly. The only work around I found is to not use rendering to texture at all on both vendors. But it does not look like you are rendering to texture so it might be entirely different issue (however I suspect its related)

    – Spektre
    Nov 12 '18 at 7:44












  • what z value have you rendered? Depth or space camera? Also your atmospheric fog computation should only take into account positionRelativeToCam.z, which contains the depth or distance from the camera to the vertex

    – Nadir
    Nov 12 '18 at 14:04
















I'd check the value of pow(x,y). It may be undefined if x<0 or x==0 && y<=0 In other words, some imprecision for different drivers on distance*density calculation.

– Ripi2
Nov 12 '18 at 0:08





I'd check the value of pow(x,y). It may be undefined if x<0 or x==0 && y<=0 In other words, some imprecision for different drivers on distance*density calculation.

– Ripi2
Nov 12 '18 at 0:08













That isnt the issue unfortunately. Ive removed everything but the three matrix multiplications and the texture function in the fragment shader. Still the same result. Ive rendered the Z value and there are many Faces not rendering in the color they are supposed to (many are rendered white = near, even tho they are far away). So i think its definitely an issue with the depth buffer.

– N. J. Funk
Nov 12 '18 at 2:12






That isnt the issue unfortunately. Ive removed everything but the three matrix multiplications and the texture function in the fragment shader. Still the same result. Ive rendered the Z value and there are many Faces not rendering in the color they are supposed to (many are rendered white = near, even tho they are far away). So i think its definitely an issue with the depth buffer.

– N. J. Funk
Nov 12 '18 at 2:12














See the edit for more information.

– N. J. Funk
Nov 12 '18 at 2:36





See the edit for more information.

– N. J. Funk
Nov 12 '18 at 2:36













it might be also driver problem ... I got similar problems on AMD and Intel while rendering into texture and use result on semitransparent object. Intel is not capable of rendering to texture (other than ugly slow CPU/GPU side transfers) and AMD has problems with rendering correctly. The only work around I found is to not use rendering to texture at all on both vendors. But it does not look like you are rendering to texture so it might be entirely different issue (however I suspect its related)

– Spektre
Nov 12 '18 at 7:44






it might be also driver problem ... I got similar problems on AMD and Intel while rendering into texture and use result on semitransparent object. Intel is not capable of rendering to texture (other than ugly slow CPU/GPU side transfers) and AMD has problems with rendering correctly. The only work around I found is to not use rendering to texture at all on both vendors. But it does not look like you are rendering to texture so it might be entirely different issue (however I suspect its related)

– Spektre
Nov 12 '18 at 7:44














what z value have you rendered? Depth or space camera? Also your atmospheric fog computation should only take into account positionRelativeToCam.z, which contains the depth or distance from the camera to the vertex

– Nadir
Nov 12 '18 at 14:04





what z value have you rendered? Depth or space camera? Also your atmospheric fog computation should only take into account positionRelativeToCam.z, which contains the depth or distance from the camera to the vertex

– Nadir
Nov 12 '18 at 14:04












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254073%2fissue-with-translucent-terrain-probably-depth-buffer-issues%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254073%2fissue-with-translucent-terrain-probably-depth-buffer-issues%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ