Offsetting UV based on camera position in relation to the object?

I’m trying to make a simple/stylized reflection on windows that’s basically a diagonal line texture that I want to offset on the UV X axis if the camera moves horizontally with the object and on the Y axis if the camera moves vertically. This to creates the illusion that the reflection “changes” based on the viewing angle. It also shouldn’t, preferably, change based on distance to the object as long as the angle is the same (I think that’s how reflections work?).
This will only be used on flat planes so it doesn’t have to apply to other cases, but the planes will be rotated differently in the world.
I’ve tried adding the camera position to the UV coordinates, but that becomes inconsistent if the objects have different rotations.
I’ve also tried using the camera vector, but I only get gradient values which makes the UVs warp into circles (which I solved in some weird ways I no longer understand why I did)
I’ve tried a bunch of things and worked on this material on several occasions during the past year (it’s part of a bigger project) without ever solving it so I think this is just beyond my knowledge.
I would appreciate any help or insight!

Here’s some pics of stuff I’ve tried that hasn’t worked:

1 Like

What about this?

I just copied your picture, so it doesn’t tile


I think that keeping the scale the same with camera distance would look weird.

Attempt #2


When trying it out it seems to give very similar results as my top image, but with fewer nodes, which is nice. But the problem still remains that the lines behave differently based on the rotation of the object as the camera move on different axes.

Here’s a video of what I mean. The first example is how I want all windows to behave in relationship to the camera, regardless of their rotation or the camera’s movement direction in the world:
If the camera moves back and forth the lines shouldn’t move.
Moving sideways the lines should move sideways.
Moving up and down the lines should move up and down.

But as seen in my video, this doesn’t work if the surface has been rotated as the relation between the world axes and the object’s rotation changes.
So I would like to have something that works universally, regardless of the object’s rotation?

2023-07-24 10-52-24.mkv (19.6 MB)

1 Like

Ah, got it - thinking…

This is closer ( in fact, correct, I just checked )

The lines don’t move when the camera move in and out, with respect to the glass pane.

They will move on a panel at right angles, though, because for that panel, the camera is moving left and right.

1 Like

Yes, this seems to work! Thank you so much for the help! :smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.