Skip to content

Unable to sample depth texture #4524

@dristic

Description

@dristic

Hello! I'm trying the challenge from https://sotrh.github.io/learn-wgpu/beginner/tutorial8-depth/#a-pixels-depth

Running WASM in Chrome

I saw there is an overload for textureSample that returns a f32 when passing in a depth texture:
https://www.w3.org/TR/WGSL/#texturesample, but this fragment shader fails to run:

@group(0) @binding(0)
var t_depth: texture_depth_2d;
@group(0)@binding(1)
var s_depth: sampler;

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
    let depth = textureSample(t_depth, s_depth, in.tex_coords);
    return vec4<f32>(vec3<f32>(depth), 1.0);
}

naga is telling me there is no valid overload for texture which I assume is the textureSample function parameters.

I got it to work using a textureSampleCompare along with a sampler_comparison but that function only seems to return 1.0 or 0.0 if the function passes or fails so I get a solid black/white texture instead of a gradient one based on the depth distance.

Is this currently supported?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: naga back-endOutputs of naga shader conversionhelp requiredWe need community help to make this happen.lang: GLSLOpenGL Shading LanguagenagaShader Translatortype: bugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions