Wednesday, 25 February 2015

Mapping a texture to world coordinates. Part 4.

Example 3: Starry night

Now, this is a little experiment I run over a year ago as I got started with UE4 vector fields. I wanted to create an animated version of Van Gogh's famous painting ‘Starry Night’ with GPU particles.
I hand painted the vector field in maya, created a flat initial location box (same ratio as the painting's), and thousands of small rectangular particles followed the vector field. As they moved, they would pick the colour of the painting used as a texture mapped in world space.

I was really quite happy with this idea but it turned out that someone had already created this as an app and they'd done a good job of it. Once I found out it seemed pointless to complete the project. Great minds think alike, they say. Fair enough but really, you wanna be the first of those minds.
Oh well, nevermind. I still had some good fun doing the tests plus it gives me an example for you people to enjoy.

So. We have the dimensions we want the painting to be displayed at, and we want them to be translated to texture coordinates. I've decided I'd keep the centre of the painting in the middle; I could have decided for it to be in a corner, I would just have had to use different values for the min and max.

Here's what's happening in the material: I'm ‘projecting’ the texture in world space (as seen in the first part) and making its coordinates local (as seen previously), and then I use my favourite little snippet (described here) to remap the 0 to 1 texture coordinates to the size I want the texture to appear in world units.

Then in cascade I create a box with an initial location that matches my min and max and as the sprites move, they pick the colour of the painting underneath.
It's rather basic, close up you can see it is a cut out and it doesn't feel like moving paint strokes. I was thinking of trying to see if I could use the ParticleSpeed to offset the texture but as I said I gave up on the project quite early on.
Painting this vector field again in maya has actually been very interesting, it's going to be helpful for my personal project. I've found out a few things about how to get a vector field UE4 ready. I'll keep that for a later post, still lots I don't know about.

This is a capture of the animated particles in cascade preview: (for those who don't know, cascade is the name of unreal's particle editor)

If I place this emitter in the world, and I add more particles around my initial location area, you can see how the last pixels are stretched. It shows that the texture is mapped to a precise area in space (centered around the emitter position).

Same thing from the side, the pixels are stretched because we only projected along one axis.

Hope you enjoyed this, folks. The next and last example will actually be my favourite one, so stay tuned.

No comments:

Post a Comment