FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • Why does reading my depth texture in GLSL return less than one?Grimelios
    I've created a depth texture in OpenGL (using C#) as follows: // Create the framebuffer. var framebuffer = 0u; glGenFramebuffers(1, &framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); // Create the depth texture. var depthTexture = 0u; glGenTextures(1, &depthTexture); glBindTexture(GL_TEXTURE_2D, depthTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 800, 600, 0, GL_DEPTH_COMPONENT, GL_FLOAT, null); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     

Why does reading my depth texture in GLSL return less than one?

I've created a depth texture in OpenGL (using C#) as follows:

// Create the framebuffer.
var framebuffer = 0u;

glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

// Create the depth texture.
var depthTexture = 0u;

glGenTextures(1, &depthTexture);
glBindTexture(GL_TEXTURE_2D, depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 800, 600, 0, GL_DEPTH_COMPONENT, GL_FLOAT, null);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);

Later, I sample from the depth texture as follows:

float depth = texture(depthTexture, texCoords).r;

But even when no geometry has been rendered to that pixel, the depth value coming back is less than 1 (seems to be very slightly above 0.5). This is confusing to me since, per the documentation on glClearDepth, the default value is 1. Note that this is not a problem of linearizing depth since I'm attemping to compare depth directly (using the same near and far planes), not convert that depth back to world space.

Why is my depth texture sample returning <1 when no geometry has been rendered?

  • ✇Recent Questions - Game Development Stack Exchange
  • How to prevent Sprite3D from clipping into nearby objects?Noideas
    Gotot 4.2 Sprite3D is very useful for representing 2D objects within the gameworld. However, when billboarded (Y-billboard), 3D Sprites are prone to clipping into the floor/walls/other 3D models they are close to. There is an easy way to "force" the sprite3D to be drawn in front of the cube by checking "No depth test" in the sprite 3D's flags, but that makes the sprite visible through all walls/floor. The other method I tried is to manipulation of the sprite3D's and Cube's material transparency
     

How to prevent Sprite3D from clipping into nearby objects?

Gotot 4.2

Sprite3D is very useful for representing 2D objects within the gameworld. However, when billboarded (Y-billboard), 3D Sprites are prone to clipping into the floor/walls/other 3D models they are close to.

enter image description here

There is an easy way to "force" the sprite3D to be drawn in front of the cube by checking "No depth test" in the sprite 3D's flags, but that makes the sprite visible through all walls/floor.

The other method I tried is to manipulation of the sprite3D's and Cube's material transparency settings:

3D Cube's and Floor's material:

        Transparency: Alpha
        Blend Mode: Mix
        Cull Mode: Disabled
        Depth Draw: Always
        No Depth Test: unticked

This solves the "see-through walls" problem and prevents clipping through the cube, but the sprite3D is still visible through the floor.

Is there some other way to prevent this clipping? Maybe to have the sprite's depth (or "render order") depend on its origin?

❌
❌