Hello Guest

Author Topic: Assigning new material to a duplicated sprite  (Read 5093 times)

TekuStudios

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 177
    • View Profile
    • Teku Studios
Assigning new material to a duplicated sprite
« on: June 11, 2013, 05:46:21 pm »
Hi, here we come with yet another question.

We are coding some custom faked "per-object" motion blur. We don't want a blur effect that affects the whole camera, but one that only applies to specific gameobjects. Since our game is 100% sprite based, we've came up with a peculiar solution.

When a gameobject is moving with certain velocity, we instantiate 4 sprite objects that have the same sprite as the original, give them a tiny X-Axis offset from the original position and -20% alpha each, so this creates an illusion of a "trail" that progressively fades when a object is moving fast.

This works and creates a rather nice visual effect, however all the sprite clones are rendered OVER the original sprite due to perspective issues, and we want them to be rendered behind it. Since our camera is special, we can't just displace them in the Z-Axis to hide them. To control the drawing order of the camera, we assign each "layer" of a scene a unique "Transparent" shader (Transparent+1, Transparent+2...), so the grater ones are drawn later.

So, when instantiating the sprite copies, we assign them a material shader that's 1 layer behind the original sprite material's shader to keep it drawn behind, but it instantly changes into the original's material, so the copies are drawn over the original again due to those perspective issues. Is there a way to prevent this from happening? e.g. copy a sprite, keep the original sprite but change the copy's material shader.


Sorry about the lame explanation, I know it's hard to understand. If you need it I can post a screenshot later. Thanks.
We are an Indie videogame developer located in Teruel, Spain. A small 6-people team which is currently working on the upcoming 'Candle'.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Assigning new material to a duplicated sprite
« Reply #1 on: June 11, 2013, 05:56:53 pm »
Theres actually a much easier solution to this. Insanely easier :)
Thing is its still a prototype, but I'm sure you could use it somehow and be my guinea pig if you wanted to?

Email support if you'd like to try it out

TekuStudios

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 177
    • View Profile
    • Teku Studios
Re: Assigning new material to a duplicated sprite
« Reply #2 on: June 11, 2013, 06:01:16 pm »
Email sent :)
We are an Indie videogame developer located in Teruel, Spain. A small 6-people team which is currently working on the upcoming 'Candle'.

TekuStudios

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 177
    • View Profile
    • Teku Studios
Re: Assigning new material to a duplicated sprite
« Reply #3 on: June 17, 2013, 06:11:49 pm »
Ok, we've spent the whole day but we managed to successfully upgrade our current project to 2.0+hotfix 1. It works perfect and the layering system you sent us has been doing well with our faked motion blur script.
We are an Indie videogame developer located in Teruel, Spain. A small 6-people team which is currently working on the upcoming 'Candle'.