Mapping Texture to Pixel Position on Window

I am trying to replicate an effect where a texture follows the position on the window rather than an object, and have been trying to do so using the Texture Coordinate node’s Window socket. My problem with this is that it gives values between 0 and 1 rather than pixel coordinates, so the texture gets warped if the window is not at a 1:1 ratio. I am aware that I can just multiply the x and y by the render’s aspect ratio manually, but if I do so the texture only looks correct in the render, but not in the viewport.

I am trying to create an effect similar to what is shown in this old thread

However, the solution that they came up with no longer works on newer versions of Blender.

Are you sure about the warping… ?? Seems to eb the same for rendered image and viewport and no warping the 1:1 ratio generated image to the 16:9 (?) render size…

The warping is only an issue when plugging the Texture Coordinate node’s Window socket into the Mapping node’s Vector input. But when I use the Camera socket, it doesn’t completely give me the effect I want. You can see that on the top face of the cube your texture gets squished down a little bit, which I don’t want.

Oh yes i see… not camera:


but window:

but still:

viewport and rendered image show the same…

This is the output that I’m getting. I’m not sure why there’s a difference between your output and mine. Are you also on Blender 4.2?

As you yourself wrote:

…and so i did (on 3.6.12) while using a 2:1 ratio for the image and a the generated pattern using 1:1 (shown with the comparesion slider).

Yes, but then the only way to keep the texture at the correct size would be to keep manually changing the values when I change the viewport’s aspect ratio, or if not, always keep the viewport’s aspect ratio the same as the render’s. What I want ideally is to be able to get the aspect ratio of the viewport window as a shader node so that I can automatically change these values.

Viewport aspect ration ?? Or do you mean image AR ???

You may use this info:

to do it automatically

1 Like

Yes, I mean the viewport’s aspect ratio. You said that in your example, the viewport window had an aspect ratio of 2:1, so you multiplied the scale of the texture by 2 on the x axis. I want to be able to get this aspect ratio automatically in shader graph so that I don’t have to change the scale manaully.

You may have not seen / read this correctly but answereing you initial question i showed" the my mapped textures does have the same ratio for the viewport and the rendered image and there is no difference:


Of course the screen mapped texture only look correct wehn view in camera view

So the only solution is to use camera view and multiply the texture’s scale by the aspect ratio manually?

The mapping is associated to the camera so it only looks like in the render when using the camera view, yes. And the suggested GN methods works; here is a 1280x900 (ratio 1.422) texture used in a render dimension of 1920x1080 (ratio 1.7777).