Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: christougher on March 28, 2017, 11:26:43 AM

Title: Material Property Block
Post by: christougher on March 28, 2017, 11:26:43 AM
Hi, couldn't find it myself so not sure if there is a way to do this already but I was just wondering if there are actions to affect the Material Property Block to take advantage of the relatively new gpu instancing and change colors of individual objects that share the same material.  Thx!

EDIT: here's a nice post on the subject.
http://thomasmountainborn.com/2016/05/25/materialpropertyblocks/
Title: Re: Material Property Block
Post by: tcmeric on March 28, 2017, 11:41:48 AM
So it looks like it needs a custom shader to work. Do you have one in specific you want it to work with? Recently I wrote a bunch of custom actions for shaders. (Although I have no skills to write shaders). They do give an example however.

It looks like it wouldnt be too hard to write a custom action to take care of this. I am willing to give it a try. Who knows, maybe I can pull it off.

Ill post my results here.
Title: Re: Material Property Block
Post by: tcmeric on March 28, 2017, 12:32:49 PM
Ok, i even surprised myself that I could get that to work.

Here is the example script from the linked tutorial, that lerps between two colors. Make sure to set it to everyframe to animate the lerp. Otherwise it just sits in the middle between the two colors.

Also, you have to add this custom shader to your material. (Or make your own).

https://github.com/dumbgamedev/general-playmaker/tree/master/Shaders
Title: Re: Material Property Block
Post by: tcmeric on March 28, 2017, 12:38:28 PM
Ok, I added a non-lerping version as well. Basically the same principle. It just sets a single color.

Its all in the github link.
Title: Re: Material Property Block
Post by: tcmeric on March 28, 2017, 12:47:45 PM
Guess it could still use some work. Maybe a finished event after completing one lerp cycle, rather than now. (Right now, every frame will keep going back and forth, like a police light).

Also, if you set the offset to -1, it will start on the first color. If you set the offset to 1, it will start on the second color. If set to 0, it will start in the middle of the two colors.
Title: Re: Material Property Block
Post by: christougher on March 29, 2017, 07:20:33 AM
This is great!  I agree, a finished event would a good addition.  But nicely done!
Title: Re: Material Property Block
Post by: tcmeric on March 29, 2017, 07:43:35 AM
If I set an end event, then it seems to "end", which wouldnt be good if you want it to keep looping.

Seems easier to use the second action (setMaterialProperyBlocksColor), which just sets a single color (and set to every frame). Just before that action, use "Ease Color" and store the result in a variable. That way it can do a single color lerp.
Title: Re: Material Property Block
Post by: christougher on April 01, 2017, 08:42:46 AM
If it's not too much trouble I suppose we should also have actions for setting position and rotation.

Side note, just learned that in Unity 5.6 you will no longer need a separate script to set the color/position/rotation with the new Procedural Instancing, although I'm not sure yet how to go about changing them at run time...
Title: Re: Material Property Block
Post by: tcmeric on April 01, 2017, 11:31:42 AM
Set rotation and position for objects? The actions are "set rotation" and "set position".

For material, I am not familiar with position and rotation. I know of tiling and offset however. Is there another one I am missing?

These are the properties I see: https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html
Title: Re: Material Property Block
Post by: christougher on April 01, 2017, 04:04:35 PM
Doh!  And I had gone so long without a bone headed post lol.   :o
Title: Re: Material Property Block
Post by: tcmeric on April 01, 2017, 11:42:32 PM
Busted  ;D  ;D  ;D