[UDK] Player Position-based Material

Recently, a coworker posed a question to me:
“How do you pass the player position to a material in UDK?”

“Well, couldn’t you just use the CameraWorldPosition node? The player and the camera are so close together the effect should be enough, right?” replied I.

“That could work, but I want to do a far-back third-person camera,” he countered.

“Oh…” I said.

After attempting a solution that was, admittedly, rather hacky involving trying to programmatically derive the location of the player based off a known distance between the camera and the player, I opted for something that could be considered hacky, but is as close to a programatic solution as an artist can get.

Looking into the situation, I thought perhaps I could use Kismet to pass the position of the player to a Material Instance using the Set VectorParam node… only to find out that node was taken offline back in 2010. Of course, with the clever use of “Append Vector” nodes, three scalar parameters can quickly turn into a float3, right?

Do excuse the garish colors. They were chosen to best showcase what’s happening. This could certainly be used to implement more subtle effects.

So that’s what I did. Here’s the base material (click to enlarge)

And the kismet setup. I put a delay after the operation is complete, otherwise Kismet throws a “too many operations” error. The delay is .033 seconds, or roughly 1 frame at 30 frames per second. The delay is barely perceptible, and it minimizes the number of calculations that have to happen. (click to enlarge)

Combining all that, you get this (video forthcoming):

From a CameraActor:

Also visible on my website: http://www.oztalay.com/matt/tutorials/player-position-based-material/

sweet! so you could fake a dynamic light on the player. Anyway to control the size of the area highlighted?

That’ll be on the radius parameter. It would be fairly trivial conceptually to include the math to do something like putting a cone in front of the player.

the catch is that every asset that you want to have affected would have to have these calculations in the pixel shader, which would get very expensive very fast (also, for faking a dynamic light, you’d also get a lot of weird results from backfaces and lack of shadows.

I’m going to do a test with making an InstanceB of InstanceA, where InstanceA’s modifiable parameters are the X,Y,Z values, and since InstanceB is an instance of InstanceA, InstanceA would pass its X,Y,Z values to InstanceB, eliminating the need for setting up Kismet for each MaterialInstance you’d want to create.

Nice material, you could also do it something like this (on udn):

Just replace the object position and radius node with your own :slight_smile:

Multiply your Falloff Distance by an interesting noise map and you should be able to get some really cool noisiness to the transition between materials!

This is pretty great stuff!

A buddy of mine modified the falloff portion to include an edge mask-type thing so the edges of the circle glow. Lots of potential here.

This is cool. You can construct and entire game idea off of this alone.

DM Spectrum a Unreal tournament 3 custom death-match map, I think worked off this.
[video=vimeo;7615467]http://vimeo.com/7615467[/video]

http://spectrum.matthewbradley.co.uk/media.html
He also remade the UT map DM Deck in this style.
[video=vimeo;14605213]http://vimeo.com/14605213[/video]