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:
Replies
It's good... but fairly heavy to do it through kismet unforunately Good for proof of concept though
This x1000. All you have to do is use a vector parameter and set the value of it from UnrealScript. It's much more efficient than deriving it like this, and it's very easy!
I'm pretty new to UnrealScript, but I gave this one a shot. The trick was to create a MaterialInstance in the UDK editor first, then reference it in UnrealScript.
I also tried putting it in a Pawn class other than the player, and that works, too. The only catch is that you can only use the location of one pawn as things are.
I used your exact Material setup, but I changed the X/Y/Z ScalarParameter names to XPos, YPos, and ZPos.
Here's the code for the Pawn, but you could just as easily put this in the PlayerController class with a couple simple edits. You can see the material is located at "MyPackage.material.mat_test_worldpos_INST" - MyPackage is the package, Material is the group, and Mat_Test_WorldPos_INST is the MaterialInstanceName.
Hope this helps someone!
http://forums.epicgames.com/threads/899690-Player-Position-based-Material
You'd need a unique mask for each player in the shader - then you'd need appropriate math to sort them out properly. It's not fun, and rapidly gets expensive
Also look at ObjectRadius etc.
Done!
I had a look at this node, and I couldn't figure out how you could use it to recreate this effect. As far as I know, it gives the world position of the actor that it's applied to, whereas this effect feeds the player's position to the material instance.
Yeah, I wouldn't want to deal with all that. I think this would be a great visual effect for a boss type character - so it's better to keep it unique.
ya i remember doing a forcefield shader, where i was using the hitlocation for a effect on it, and i pretty much gave up trying to multiple hits working in one material and ended up just spawning a new mesh, doing the effect on that mesh than killing hte mesh to get multiple hits.
That's not that useful really, since you want to affect actors in the world other than the one you're using (also, IIRC those nodes are vertex shader only?).
Correct! Which is why this thread exists in the first place. It's great for creating interesting effects as an object moves through the world. I've got another tutorial coming down the pipe for something to help break up modular kits.