Skip to content

How to render to a specific rectangle on the surface texture? #5403

Answered by kpreid
tversteeg asked this question in Q&A
Discussion options

You must be logged in to vote

In your fragment shader you used:

    let color = textureLoad(input_tex, vec2<i32>(in.clip_position.xy), 0).rgb;

You're taking pixel/texel coordinates of the render target (@builtin(position) under the name in.clip_position) and using them as texel coordinates of the input_tex. So, no scaling can ever happen — this is always a 1:1 mapping of texels. Notice that you haven't used in.uv at all!

You should replace your textureLoad call with textureSample(input_tex, sampler, in.uv), with sampler being a sampler you've created with appropriate filtering settings for your desired result (probably linear filtering). Technically, you could do the arithmetic yourself and keep using textureLoad, but…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tversteeg
Comment options

Answer selected by tversteeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants