How to pan texture relative to camera rotation for post process?

Hi all,

I’m working on an effect where I would like to create a tiling texture mapped to the camera, but I would like to offset its panning so that when you rotate the camera view, it feels like the texture is locked to world space.

The texture in this case would be a flow map that distorts the uvs of the sceneTexture:sceneColor in a post process material

so if the camera rotates around to the left, the texture is panned to the right to cancel out the feeling that the texture is locked to the camera. I hope that description makes sense :slight_smile:

I’m guessing I need to do some sort of screenspace to world space conversion, but I’m not entirely sure where to start, any suggestions would be great

Cheers

I think I know what you are describing. Sounds similar to how I did snow for Mt. Kadar in Gears2. In that case I basically mapped panning snow textures onto a sphere mesh that followed the camera, and set the sphere to render on top of everything and then did custom depth testing to fake the appearance of layers/depth. So most of the snow was all a fake single sphere.

Back then we didn’t have fancy post process materials with the same power as we do now.

Doing this now, you should simply be able to map your flowmap to the CameraVector. You could convert CameraVector.xy to a radial angle using the “Vector to radial angle” to generate a continuous 0-1 UV going around the camera. Then your Y component could be just the Z component or perhaps use screenposition but shift it using the Z component. Or just use the sphere on top of everything using refraction. Using the sphere (or perhaps an inside out cylinder) gives you UVs to map to without doing any math. You can have it follow your camera by simply adding CameraPosition to the vertex shader, just make sure your object bounds get scaled up to the size of your whole playable area, otherwise the sphere will dissapear once the camera moves outside of its origin.

4 Likes

Awesome thanks for the reply Ryan. Funny, I just thought about the idea of using the sphere following the camera on my lunch break :slight_smile:

It led me to wonder if the sphere could go into its own stencil buffer, but not be directly visible in the main render scene. Can that be done?

So say I want to use whatever texture is mapped to the sphere as a mask for some other effect in the main post process, can I pull that info from a stencil buffer and use it elsewhere?