Counter Texture Scaling

Hi,

I’m working on a Footprint project and having trouble when scaling my landscapes.

I’m transforming the position where the feet hit the ground into a screenposition that is used to draw a footprint material (a circle in this example) onto a rendertarget and using that as a displacement map for world displacement for the landscape material.

This is how it looks like when I do it in the centre of a landscape

When the character moves away from the centre the location of the “footprints” isn’t right anymore.
The further away from the centre the more the footprints are offset. Also the scale of the landscape increases the effect.

Here’s how it looks like near a corner

I’d like to counter the effect that scaling has on my rendertarget. How would I do that on my Vector2D ScreenPosition?

I’ve tried the following formula :

AdjustmentX = ( 1- ( ScreenPosition.X / 0.5 * RenderTargetSize.X ) ) ** ???

and subtracting that from my ScreenPosition. It serves the purpose that the adjustment is 0 in the centre and increases linear moving away from it. I’ve found numerical values for ??? when keeping the scale of the landscape constant but I couldn’t adjust it when increasing scale.

I’m not sure I’m following your method correctly, but I think you’re running into problems with foreshortening and perspective.

Rather than using the game view camera to get the screen coordinates, use an orthographic camera centered above the landscape pointed straight down, with bounds matched to the landscape’s width and length and get the screen coordinates from that. Those will align with UV coordinates from edge to edge.

But if you’re just using the screen projection to get UV coordinates to know where to adjust a displacement map, I’d go a different route. Get the X,Y coordinates of the feet (using bones, or sockets) and get their distance from the landscape corner that has UV 0,0; then scale the distances by the full length & width of the landscape. Those will be true UVs with no distortion and be cheaper than screen space conversions.

Thanks for your reply, I’ll try to explain my method.

As soon a foot hits the ground I perform a trace to get the hitlocation. With that and the origin of the landscape i calculate a relative position of the hit and transform it into a percentage, e.g. the hit is (20%,20%) away from the origin. Percentage*RenderTargetSize yields me an absolute Screenposition to where I draw the footprint shape . I’ll then have to move the footprint shape into the point it is drawn from to make the Screeposition the central point of the footprint shape rather than it’s origin from its coordinate system.
Screenposition.X = Screenposition.X - 0.5 * FootShapeScreenSize;

This method works always when the hit is in the centre of the landscape but it’ll be offset moving away from it.
I assumed when having a 1600x1600 landscape as well a rendertargetsize of 1600x1600 the displacement map would map 1:1 onto the landscape. But that assumption is wrong - the footsteps are offset when going away from the centre of the landscape . I can’t figure out why though.

If you’re doing a line trace, you can get the UV directly from that.
In your project settings: Physics->Optimizations, enable “Support UV From Hit Results”
Set bTraceComplex to true and you will be able to get the UV directly from the hit result via FindCollisionUV.

That at least may reveal what’s going on, if it doesn’t fix it completely.

My guess would be that the UV map doesn’t stretch the geometry all the way to the edges of the UV space, leaving a bordering buffer. That’s why you’ll see your offset increase as you get closer to the edges: the center remains the center and the edges are scaled down the greatest distance in UV space.

I’m glad you’ve got it working. Please mark the question as closed so others can find the answer if they need it.

Wow, that’s great!

I actually solved it by measuring the offset. I used a checkboard texture for my landscape and scaled it up with numerous values. The size of the squares changed, the squares far away from the centre were smaller. I measured their size and found a linear correlation with the scale and the distance from the offset. But why are the squares on the corners smaller than the ones in the centre in the first place?

Anyway, I calculate the offset as follows

Xoffset = XdistanceFromCentre ( in % ) x 0.5 x LandscapeScale.X

where XdistanceFromCentre = ( LandscapeSizeX - RelativeHitLocation.X) / LandscapeSizeX

The relativeHitLocation is then subtracted by the offset and then transformed into a percentage and then transformed into absolute ScreenPosition of the RenderTarget.

I tested this with a landscape with 64x64 quads and all scales.