Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] Sci-Fi Damage FX

Discussion in 'Assets and Asset Store' started by unityuser94, Sep 13, 2015.

  1. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    For the last few months I have been working on a damage affects asset. It supports volumetric damage over a surface and can be used to create a variety of affects.

    Original WIP thread: http://forum.unity3d.com/threads/released-sci-fi-damage-fx.345391/

    Demo videos:




    Webplayer Demo:
    http://vectorforgegames.com/Sci Fi Damage FX Demo/

    Features:
    *Heat damage affect as shown in the demo videos
    *Fade in damage gradient for damaged areas.
    *Fade in heat damage gradient for heat damaged areas.
    *Can adjust normal's based on damage, to add depth.
    *Can adjust vertices based on damage, to add real depth
    *Can customize gradients to make new affects.
    *Multithreading to speed up performance (this is currently experimental)
    *Includes transparent shaders; can be used to create a variety of affects including decent looking shields.

    Limitations:

    *Will not work well if at all on skinned mesh.
    *Requires shader model 4.0 for normal modification and shader model 3.0 without it.
    *Requires Texture3D support.

    It is currently available at: https://www.cleansourcecode.com/index.php/sf-realistic-damage-fx.html#

    And also: https://www.assetstore.unity3d.com/en/#!/content/45933
     
    Last edited: Oct 10, 2015
    Ony and theANMATOR2b like this.
  2. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    110
    Looks great! Glad you were able to get multithreading in.
     
  3. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,954
    Very cool. Will keep an eye on this for future use.
     
  4. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    497
    Interesting. Planning on a web demo?
     
  5. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    That's a good idea, when its up I'll post an update with the link.

    Also, if there are any particular things (test cases/objects?) you would like to see there that aren't in the demo video, let me know and I'll try to include them if I can.
     
  6. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    497
    Usage on complex meshes would be good (like how it works when the mesh itself has a lot of detail). The skinned mesh note could be a bit more specific. Does it flat not work or could you describe the kinds of errors it produces?
     
  7. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    It does not really matter how much detail the mesh has, unless you are using the vertex displace. (With vertex displace, generally the more vertices, the better the displacement affect will look).

    The affect is local, but doesn't take into account mesh deformation.
    Say for example you trigger the affect on a deformable mesh, and it is set to glow at the impact point. If a bone moves some of the previously glowing geometry away from the impact point, it will fade out as if the impact point was stationary relative to the bone controlled geometry.

    One way to get around this would be to do all the calculations in vertex space, instead of local space. The issue with this is that you would need to use high poly models, with even vertex distribution. The other downside is that it will not be possible to distort the normals.
     
    Last edited: Sep 18, 2015
  8. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    Last edited: Oct 31, 2015
  9. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    Got multi-threading working properly, works well enough to remove the experimental label. In my tests it improved performance by a factor of around 10 on my quad core 3rd gen i5. With 8k voxels being updated 3 times per frame (at 60 fps), there was a ~0.7 ms overhead, without multi-threading, there was a ~7.2 ms overhead on the main thread.

    I had to resubmit to the unity asset store, as I found a few minor bugs and wanted to include the improved multithreading in the initial release.
     
    overthere likes this.
  10. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
  11. CornDog

    CornDog

    Joined:
    Nov 17, 2012
    Posts:
    13
    Are you generating the heatmap in the shader or on the CPU? I'm assuming it's the latter since you spoke of adding threading. And I'm curious what the performance difference would be between the two approaches.
     
  12. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    The heatmap is currently generated on the cpu, this is because, at the time, I knew no other method that would support virtually infinite number of contact points. The cpu "bakes" each contact point into the heat map, where as if I sent a list of points to the shader, the fragment shader would have to take into account every single point, leading to a very, very expensive surface shader, that gets more expensive the more points sent to it. With the cpu method, it bakes each point once, and then forgets about it.

    Its a bit of a trade-off, with the cpu method, you can draw beams of heat across surfaces, with the gpu method, only a few points would be supported before the pixel shader got too expensive to use.
     
  13. CornDog

    CornDog

    Joined:
    Nov 17, 2012
    Posts:
    13
    Ahh, a very good point. i was only thinking in terms of your demos. but you were clearly thinking of the larger scale.

    Last question: why does it require Texture3D support? Isn't it just making a heatmap, and performing a deformation of the mesh along the negative normal direction, using the UV coordinates and heatmap to determine deformation and color? I'm not sure I understand why a Texture3D is needed.
     
  14. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    The reason 3DTextures are used, is for blending. This way you can get away with fewer pixels and still produce good results. For example, the 3dTexture is mapped to the bounds of the mesh. In the pixel shader, each fragments 3d position corresponds to a "voxel" on the 3dTexture. You can blend the results of the 3d texture, so that the heat amounts are interpolated across the boundaries between voxels.

    In a seperate project, I use a 2x2x2 3dTexture (could probably use 4x4x4) and it still produces good enough results.

    If I were to use a 2d heatmap, there would be no way to preserve spatial interpolation, because UV mapping is arbitrary, so there would be inconsistencies across seams.

    As another bonus, using a 3DTexture also allows for really cool affects like this:

    These affects use raymarching, they are in my dev version of the asset, but not yet released due to some bugs I haven't yet been able to solve. I am considering adding them as "experimental" shaders though.
     
  15. CornDog

    CornDog

    Joined:
    Nov 17, 2012
    Posts:
    13
    Very cool. Thanks for answering my questions. I'll be buying when my project is ready for it.
     
  16. local306

    local306

    Joined:
    Feb 28, 2016
    Posts:
    147
    @unityuser94 Would you be able to update the shaders to include sliders (or at least expose the fields) to control gains for normal, AO, emission, etc., like they have for the default Unity PBR shaders? My shader knowledge is pretty limited...

    For my current project, enemies are robots and heat is a method of damaging them. Using HDR enabled rendering and a bloom effect, I've created a pretty neat glowing effect to represent temperature.



    The damage effect in your package is nice because it can localize damage based on rays. I would love to be able to extend this and ramp the emission value of that material as the temperature rises.
     
  17. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    @local306 Are you saying you wold like to control the global emission/ao etc independently of the scripts control? Currently you can set these through a preset texture, and then they are further modified in the shader based on the damage. The emission is already set based on the temperature.
     
  18. local306

    local306

    Joined:
    Feb 28, 2016
    Posts:
    147
    If it's not too difficult to do, having control like the default shader Emission field would be nice in order to hook into the system I have developed.

     
  19. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    @local306 That shouldn't be hard to do; it brings up a few questions though. Should that emission value control the global emission? What color should it emit? Should it emit the color of the emission texture, or should it act as a heat value direct scalar? (ie a sort of, global heat scalar?). There are several ways to combine the emission values. The way the standard shader does it (assumes a white emissions texture, multiplies by that, and sets the pixel color to the result+whatever the color was before) may not be what you want.
     
  20. local306

    local306

    Joined:
    Feb 28, 2016
    Posts:
    147
    @unityuser94 for my situation, I've created my own emission textures that I ramp up.

    I'm kind of split now because I really do like how your asset is a lot more localized, whereas my approach is to ramp the emission up for the entire texture.

    I guess the thing I am looking for most is knowing the exact value of the emission value. Through my experience, I have found values that work best with the bloom effect I am using. When I use your asset, I'm not sure what the values are which makes it hard to control the amount of bloom.
     
  21. unityuser94

    unityuser94

    Joined:
    Mar 29, 2013
    Posts:
    39
    @local306 Hmm your right, it is hard to tell the exact emission values; when I had created it originally I had assumed it would be simple enough to tweek the values and judge by eye, but if you already figured out the values you like, it would be better if you could just put them as numbers somewhere.

    That's definitely something I could add. Not sure when I will have time, as I will need to walk through all the code and figure it out; not something simple. But yes I will definitely look into this.
     
    local306 likes this.
  22. local306

    local306

    Joined:
    Feb 28, 2016
    Posts:
    147
    Thanks for the reply @unityuser94. I'm in no rush at the moment so take your time :)

    I haven't had a chance to peek at the code, but if you could somehow expose a scalar value for the emission value, I think that would be good enough. I'm assuming the max value at the moment it probably 1. However, for my application I am using HDR and in order for the bloom to start to show up as intended, my values range from 8 to 16 depending on how large the object is.
     
unityunity