Mobile Material Instance Constants

One of the things I’ve hated about mobile development with UDK is mobile materials. Because of the way the hardware is set up on iOS, everything has to be compiled into a set of “flat” shaders, meaning no more material graph network. You want something to show up on mobile, you have to go through the little “Mobile” preferences tab to do it. It’s downright humiliating.

This flatness also means no material parameters. For those of you who have never worked with parameters or Material Instance Constants, they’re basically one of the most powerful tools available in the material network. They allow you to dynamically change the color, size, shape, or practically anything else about a material from within code or through Matinee. Last week I needed to use a MIC in my mobile game, specifically to cycle through a set of colors on-screen, and I was surprised that I couldn’t do it (and while we’re on the subject, you also can’t do Scripted Textures, at least not through a material…it has to be routed through a Canvas first).

But don’t panic, there’s a workaround. First, open up the material you want to animate and make the graph look like this:

Apparently “Vertex Color” is one of the few nodes that still propagates to mobile. Don’t ask me why.

Then comes the hack: make a new Particle System. In the “Required” tab, select the material you just made. Set the duration to X seconds (whatever you want X to be). In the “Spawn” tab, set both the Rate and Rate Scale to 0. Under “Burst” make sure the method is EPBM_Instant and add an element to the Burst List: count 1, time 0. Then under “Lifetime”, set both Min and Max to X seconds. Delete the “Initial Velocity” tab…we don’t want the particle to move! And finally under “Initial Size” set both the min and max to be the same, making for an unchanging particle.

Alright, so we’ve now got a particle that looks basically like the material you put in — it doesn’t move, change, or do anything particularly interesting. To fix that hop over to the “Color Over Life” tab and mess around with it. You’ll quickly see what happens to the material :-). This is all thanks to the Vertex Color node in the graph network, which provides a hook for the Particle System to animate the material’s color. And if you hop on over to iOS you’ll see that it works there as well.

Of course, this little trick isn’t anything like the magic of full-fledged MICs. But for me it was certainly enough, and it’s a good substitute for one of the most common things people use MICs for in the first place.

Advertisements

5 thoughts on “Mobile Material Instance Constants

  1. Nice tips. Just to know, i suppose from your article that is possible to draw something on a canvas and then put it in a material as a texture. How we can do that?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s