playMaker

Author Topic: get pixel color, set pixel color, apply texture changes  (Read 8079 times)

kiriri

  • Hero Member
  • *****
  • Posts: 506
get pixel color, set pixel color, apply texture changes
« on: December 18, 2012, 04:07:54 PM »
Some of the actions needed to generate a terrain from a heightmap (regarding http://hutonggames.com/playmakerforum/index.php?topic=2761.msg12580;topicseen#msg12580)
More to come.
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: get pixel color, set pixel color, apply texture changes
« Reply #1 on: December 21, 2012, 03:57:32 AM »
Hi,

 That is cool!

bye,

 Jean

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: get pixel color, set pixel color, apply texture changes
« Reply #2 on: March 28, 2013, 11:17:21 PM »
Do you think this could be used to make fog of war? I messed around with this for a bit to try and get something going, but I just couldn't quite get my head around it.

If we took a unit position and somehow translated that into the texture/pixel(?) space, then used set pixel to transparent, then I imagine we could use these actions to make fog of war. Does that sound doable? Any thoughts?

Cheers!
Jay

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: get pixel color, set pixel color, apply texture changes
« Reply #3 on: April 02, 2013, 06:44:15 AM »
I've done some tests and you would have to wait until a version of PlayMaker that has a better performance at loops is released. Otherwise it would be very slow. Then you could do it rather easily for the minimap, but the actual viewport would be a slightly more complex setup. You could add a plane on top of your level (but visible to the camera) that stretches across all your terrain. Then you could turn that transparrent by using a transparrent shader. Then you'd need to floodfill the texture of that material with a color that would stand for the fog of war (You can't use a grey texture from the start because Unity won't reset the texture). You can floodfill it by using an FSM like this :

STATE1
Set Pixel color (indexX, indexY)
int add (indexX + 1)
int compare (indexY>textureSizeX) if false go to STATE1, if true, continue the state
int add (indexY + 1)
set int (indexX = 0)
int compare (indexY>textureSizeY) if false go to STATE1, if true then you've succesfully set all the pixels in the texture :)


If you set indexX/indexY to 0 and the texture sizes to something fitting then this should floodfill it.

Now, as for setting parts of the texture to "clear":
Start of by getting the position of the unity in textureSpace in our new texture (http://hutonggames.com/playmakerforum/index.php?topic=2806.msg12694#msg12694)
Then we need to write an fsm which sets the color of the pixels around it to transparrent. This is slightly trickier. First we need a radius for our actor/unit. I'll call it... radius ^^

STATE1
Int Operator (maxX = RaycastX + radius)  // first we define the outer points of a rectangle
Int Operator (maxY = RayCast Y + radius)
Int Operator (minX = RayCast X - radius)
Int Operator (minY = RayCast Y - radius)
set int (indexX = minX)
set int (indexY = minY)

STATE2
int add (indexX + 1)
int compare (indexX>maxX) if false, go to STATE3, if true, continue in this state
int add (indexY + 1)
set int (indexX = minX)
int compare (indexY>maxY) if false go to STATE3, if true then you've succesfully set all the pixels in the texture :)

STATE3
int compare ((indexX-RayCastX)^2 + (indexY-RayCastY)^2 < radius^2 ) if true then the pixel is within your radius, so continue in this state. If false, go to STATE2
Set Pixel color (indexX, indexY)
go to STATE2


So yeah, what we did there was we created a square with the center at our RayCast result and the length of 2 radius. Then we checked each pixel within that rectangle and had a look whether it  was within the radius. If it was, we set the pixel.
If you want a fog of war that returns after some time, then I'll have to think some more :D
Best,
Sven

logiquefloue

  • Playmaker Newbie
  • *
  • Posts: 35
Re: get pixel color, set pixel color, apply texture changes
« Reply #4 on: June 26, 2013, 04:23:59 AM »
Hello,

I'm new in the world of playmaker.

I want to draw a rectangle on the texture at the cursor point when the play clicks.

It is this position that does exactly what I want  :) But unfortunately I can not put it into practice playmaker  :(

I do not understand how we can draw the rectangle with the script while RaycastX RaycastY and can take only 0 or 1 as the value around?

in advance, thank you for your help  :)