Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

How do I sample a depth texture? [Linux Mint] #162

Closed
sotrh opened this issue Jan 14, 2020 · 12 comments
Closed

How do I sample a depth texture? [Linux Mint] #162

sotrh opened this issue Jan 14, 2020 · 12 comments
Labels
question Further information is requested

Comments

@sotrh
Copy link

sotrh commented Jan 14, 2020

I'm working on my tutorial series, and I'm working on building an example of using the depth buffer. The depth test itself is working fine, but I want to render the texture itself, but the texture is coming up black.

Screenshot from 2020-01-14 12-21-59

I know this is wrong because I've saved the texture to a file and its mostly white.

image

You can see the code on my github. https://github.com/sotrh/learn-wgpu/blob/master/code/beginner/tutorial8-depth/src/challenge.rs

Here's the shader code in my local branch.

#version 450

layout(location=0) in vec2 v_tex_coords;
layout(location=1) in vec3 v_color;

layout(location=0) out vec4 f_color;

// layout(set = 0, binding = 0) uniform texture2DArray t_diffuse;
// layout(set = 0, binding = 1) uniform samplerShadow s_diffuse;
layout(set = 0, binding = 0) uniform texture2D t_diffuse;
layout(set = 0, binding = 1) uniform sampler s_diffuse;

void main() {
    // f_color = texture(sampler2DArrayShadow(t_diffuse, s_diffuse), vec4(v_tex_coords, 0, 1));
    f_color = texture(sampler2D(t_diffuse, s_diffuse), v_tex_coords);
}

You can see the master branch version here. https://github.com/sotrh/learn-wgpu/blob/master/code/beginner/tutorial8-depth/src/challenge.frag

@sotrh sotrh changed the title How do I sample a depth texture? How do I sample a depth texture? [Linux Mint] Jan 15, 2020
@kvark
Copy link
Member

kvark commented Jan 15, 2020

Before I look at your full source, please check out our shadow example, which samples from the depth.

@kvark kvark added the question Further information is requested label Jan 15, 2020
@kvark
Copy link
Member

kvark commented Jan 15, 2020

Nothing strikes me particularly worrying about the code. I would take a RenderDoc capture and look at the contents of the targets as well as the state. If you have a full repro case (if I understand correctly, you still got some local changes?), I can look at it on my machine as well.

@sotrh
Copy link
Author

sotrh commented Jan 15, 2020

The local changes are just the shader code I posted in the issue. The version on master should reproduce the issue. I don't have RenderDoc installed currently. I'll see if I can get that working on my machine.

@sotrh
Copy link
Author

sotrh commented Jan 15, 2020

It's going to take awhile to download. I'll update this tomorrow with my findings

@kvark
Copy link
Member

kvark commented Jan 15, 2020

One problem I found so far - gfx-rs/wgpu#458
Still looking

@kvark
Copy link
Member

kvark commented Jan 15, 2020

Another one is gfx-rs/wgpu#459
That one would explain why you are getting a black texture on screen: without proper barriers, the image there may fail to sample, which is subject to HW/driver and timing.

@sotrh
Copy link
Author

sotrh commented Jan 15, 2020

So does that mean I should just wait for the patch, or is there something I can do in the meantime?

@kvark
Copy link
Member

kvark commented Jan 15, 2020

There are some choices:

  1. wait till we get to fix these 2 issues
  2. try fixing them yourself, at least the first one is easy. The other one less so, but I'll be happy to mentor (we can talk on #wgpu:matrix.org)
  3. switch to master in the tutorial, even Update wgpu dependency #155 since it has important API changes. We'll release 0.5 some time later in February.

@sotrh
Copy link
Author

sotrh commented Jan 16, 2020

Ok I'm going to close this issue, as it looks like later releases will fix it. I'll check out #wgpu:matrix.org as well.

@sotrh sotrh closed this as completed Jan 16, 2020
@kvark
Copy link
Member

kvark commented Jan 20, 2020

I made a few fixes in gfx-rs/wgpu#465, and I'm able to run it without any validation layer errors (by tweaking the shader a bit), and even capture with RenderDoc (by running it from command line for some reason).
Interestingly, the depth output still doesn't work, and RenderDoc shows the sampler to be broken. It sees it as "Unrecognized Object XXX", which is strange. Also #459 is still not there, so that would explain why it doesn't work (outside of the sampler issue).

@kvark
Copy link
Member

kvark commented Jan 20, 2020

@sotrh found another problem, now on your side. The depth_pass.bind_group survives window resize, even though you recreate the depth texture and the view. That means, after resize you are rendering to a different "depth" texture than the one you are sampling from. And resize may very well happen right on load, considering winit behavior on platforms. The fix needed is - recreating the bind groups for any resources that you are recreating.

@sotrh
Copy link
Author

sotrh commented Jan 20, 2020

Good catch. Recreating the bind group fixes the issue.
Screenshot from 2020-01-20 16-56-33

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants