Results 1 to 11 of 11
  1. #1
    MSgt. Shooter Person
    Join Date
    Apr 2009
    Location
    Austin, TX
    Posts
    46
    Gamer IDs

    Gamertag: TheRogue00

    Default 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:


  2. #2
    Palace Guard

    Join Date
    Jun 2007
    Location
    Christchurch
    Posts
    3,514

    Default

    Really nice work.

  3. #3
    MSgt. Shooter Person
    Join Date
    Sep 2011
    Location
    Manchester, UK
    Posts
    215

    Default

    Oh wow Ozz! I could definitely use this feature Thank you very much for the tutorial and thanks for breaking down exactly how you found a problem and then a solution. Very cool process. Thanks again!

  4. #4
    MSgt. Shooter Person
    Join Date
    Feb 2009
    Posts
    162

    Default

    Really cool man thanks for sharing!

  5. #5
    Skaarj
    Join Date
    Mar 2012
    Location
    Germany
    Posts
    18

    Default

    wow!
    really cool

    thanks

  6. #6
    MSgt. Shooter Person
    Join Date
    Jul 2010
    Posts
    31

    Default

    neat ! nicely done , imagining lots of possibilities for this to have the environment respond to the players or other entities presence. such as alien flora lighting up and start undulating, or revealing hidden runes. other then the player it could follow a lava monster who chars and burns the surrounding env and plants .

    thanks for sharing this !

  7. #7

    Default

    Hey,

    I wrote a simple pawn class that uses this material so you can free up your Kismet a bit. The trick was to create a MaterialInstance in the UDK editor first, then reference it in UnrealScript.

    I used this 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.


    Here's what it looks like on a pawn:



    And here's the code:

    Code:
    class WorldPawn extends UTPawn;
    
    
    var MaterialInstanceConstant WorldPos;
    
    
    function Tick( float DeltaTime )
    {
    	local float X;
    	local float Y;
    	local float Z;
    	
    	X = Location.X;
    	Y = Location.Y;
    	Z = Location.Z;
    	
    	super.Tick(DeltaTime);
    	
    	WorldPos.SetScalarParameterValue('Radius', 50);
    	WorldPos.SetScalarParameterValue('XPos', X);
    	WorldPos.SetScalarParameterValue('YPos', Y);
    	WorldPos.SetScalarParameterValue('ZPos', Z);
    }
    
    defaultproperties
    {
    	WorldPos=MaterialInstanceConstant'MyPackage.material.mat_test_worldpos_INST'
    	Name="Default__WorldPawn"
    }

    Thanks, Ozz.

  8. #8
    MSgt. Shooter Person
    Join Date
    Sep 2011
    Location
    Manchester, UK
    Posts
    215

    Default

    Hey Slaine,

    I saw this post a couple of days ago and can't believe no one has said thanks! This is a pretty cool feature, and although not useful for my purposes, I think it will help a lot of people out Good job doing it!

  9. #9

    Default

    Hey, no problem

    Like CorvaenOboros was saying, you could definitely make all kinds of cool environment effects with this.

    I did find one problem with my script, though - it logs every time the material instance is updated, so it will spam your log file. I'm not really sure how to prevent that, but it does work.

  10. #10
    MSgt. Shooter Person
    Join Date
    Sep 2007
    Location
    Netherlands
    Posts
    413

    Default

    Hey, very cool that you made that!
    I also played around with that effect a while back. I wanted to make a environment out of it. so that team A had a jungel around the players and team B would have something else. (see pic of a jungel around the player)
    http://imageshack.us/photo/my-images...ntimesphe.jpg/
    The reason why I did not continue with this idea was that the light did not realy understand when i object was masked. in normal materials the moveble masks work fine with lights. but for some reasone when i attatched it to the player it went acting wrong. and my second thing was the collision of all the invisible objects how could i toggle them with out creating 10000 triggers in kismet.

    but for simple material effects you can creat realy need stuf with it!
    TriggerHappy!
    Maps that I made, Some require a MOD te be downloaded.
    Forum^: Download: PC/PS3 DM-Focus-SE
    Forum^: Download: PC/PS3 CTF4-AnubisResurrection
    Forum^: Download: PC/PS3 DM-Xiao
    Forum^: Download: PC/PS3 DOM-Contrast + MOD Domination
    Forum^: Download: PC/PS3 RenX-Islands + MOD RenegadeX
    Mess with the best! Die like the rest! Boom HèadShøt!

  11. #11

    Default

    Can anyone show how this may be extended in a material so that the player's vector acts over time as an eraser on a Lerp mask to expose A under B in a Lerp'd texture ?


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.