Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Swift Shadows [RELEASED]

Discussion in 'Assets and Asset Store' started by ZimM, Feb 3, 2014.

  1. EugenBB

    EugenBB

    Joined:
    Jun 9, 2015
    Posts:
    2
    Hi there!
    I have very strange behavior of SwiftShadows (check the screenshot)
    SS_MultipleShadows.png
    It's demo scene from SwiftShadows package (SS_MultipleShadows)
    As you can see shadows are inverted.
    The same happens, when I try to add shadows to objects in my scene.
    I use Unity ver. 5.0.2f1
    How can I implement normal shadows?
     
  2. EugenBB

    EugenBB

    Joined:
    Jun 9, 2015
    Posts:
    2
    Solved!!!

    It was necessary to change wrong texture.
     
  3. yudixiaok

    yudixiaok

    Joined:
    Aug 29, 2014
    Posts:
    17
    HI,ZimM.
    Thanks for your amazing plugin! But I am having a problem with the plugin,
    upload_2015-8-13_16-8-20.png
    In the Scene View Mode, the shadow is visible
    upload_2015-8-13_16-8-49.png
    But In the Game View Mode, the shadow is invisible.
     
  4. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    That's strange. What version of Unity do you use? Could you please restart Unity and check if that fixes the problem?
    Do the shadows work in the build?
     
  5. yudixiaok

    yudixiaok

    Joined:
    Aug 29, 2014
    Posts:
    17
    my unity version is 5.0.1p2.
    the model is rotating in scene infinitely and the shadow only disappears at a particular direction !
    the shadow does not work in the build as well !
     
  6. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Could you please export your scene and PM it to me so I can examine it? It's hard to say why exactly this happens, but it sounds like the issue is scene-related somehow.
     
  7. Tonghae

    Tonghae

    Joined:
    Nov 1, 2013
    Posts:
    16
    Having similar issue: everything ok in editor, but nothing seen in game camera. Used this workaround in my level loading logic:

    GameObject shadowManager = GameObject.Find("_SwiftShadowManager");
    shadowManager.SetActive(false);
    yield return new WaitForEndOfFrame();
    shadowManager.SetActive(true);

    This helped me.
     
  8. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Does it works in the actual game builds without this workaround? I've suspected a few problems related to the special way everything is handled in the Editor mode, but there shouldn't be any issues in builds. If that's the case, then the problem is probably more involved...
     
  9. Dan2013

    Dan2013

    Joined:
    May 24, 2013
    Posts:
    200
    @ZimM
    I found Swift Shadow will find all Camera objects and attach a "Swift Shadow Event" component to them automatically.
    The problem is that component is always there, even after I delete all Swift Shadow projectors.

    If there is no Swift Shadow projector in the scene, Unity Editor shows this error information below when I build the project:
    "Component MonoBehaviour could not be loaded when loading game object. Cleaning up! UnityEditor.HostView:OnGUI()" that is pointing to the Camera object with a "Swift Shadow Event" component attached.

    I found I cannot disable the "Swift Shadow Event" component during scene editing mode.
    Thus, I can only fix this error message by completely removing Swift Shadow Asset from my project.
    Is there any better way to fix this error message?
     
  10. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @Dan2013
    Yes, that is an annoying error with how Unity handles scene changes and Play/Stop change. Sometimes it occurs, sometimes it doesn't, and it differs between Unity versions, but important thing is - this error is harmless. At the time it occurs, SwiftShadowEvent has no purpose anymore, so it can't affect anything and is safely disposed.
    Still, I agree, this is annoying. I'm working on an update that should fix some issues, including this one, so stay tuned!
    Meanwhile, there is a NoShadowsCamera component. Add it to the camera that is not supposed to render any shadows, and SwiftShadowEvent component won't be attached to it anymore.
     
  11. Dan2013

    Dan2013

    Joined:
    May 24, 2013
    Posts:
    200
    Thanks for your explanations. I am waiting for your update. :)
     
  12. Gelo_Man

    Gelo_Man

    Joined:
    Jun 6, 2015
    Posts:
    9
    Hey ZimM,

    I'm trying to use Swift Shadows to project a shadow onto a sprite using the default sprite shader. I'd think this should work since the shadows are just quads being placed on top of the scene, but they're just not showing up. They work fine if I change the shader on the sprite from sprite-default or sprite-diffuse into the standard shader. Is there something I extra I need to do?

    I have found a workaround by using a Toon shader (which is basically the same as the default sprite shader but more expensive), but I'm wondering if there is a way to get the shadow to project on the standard sprite shaders.

    Thanks!
     
    Last edited: Sep 13, 2015
  13. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I'm not sure what exactly you are trying to do and what is not working. Are the shadows not showing up, or the sprites? How do you want to project a shadow on a sprite? Swift Shadows only work with objects that have Collider (not Collider2D) attached, and it is uncommon to use 3D physics with sprites. How is your scene set up?
    It sounds somewhat like a render queue issue, but it's hard to say anything specific without more info.
     
  14. Gelo_Man

    Gelo_Man

    Joined:
    Jun 6, 2015
    Posts:
    9
    Hey ZimM,

    I'm putting together several prototypes for a top-down game, with one using Swift Shadows to fake shadows of 2d objects. The setup is just a terrain object and then on top of that a large sprite laid flat. I then have an object with the Swift Shadows projector moving around on top of that.

    When the sprite is using either the default sprite shader or the diffuse sprite shader then the swift shadow does not appear on top of the sprite. When I switch the shader on the sprite to the standard shader or a toon shader then the swift shadow appears.

    It's an interesting point about the shadow not working on an object without a collider, so possibly the shadow is actually projecting on the terrain object below the sprite. My question is why does the type of shader on the sprite have an effect on whether or not I can see the swift shadow and if there's anything I can do to get around this (outside of using a different shader).
     
  15. sxmad

    sxmad

    Joined:
    Nov 4, 2014
    Posts:
    6
    hi,
    now I want to use for my character in game. and the character animation have some action(attack,idle,walk,run...). what should I do?

    ummm...the different action have different shadow. so, I need to generate shadow png for each action with "Shadow texture generator". and pack this with "Sprite packer" then ,when I change action from idle to walk, I must be reset the shadow material and shadow sprite?
     
    Last edited: Oct 29, 2015
  16. Dan2013

    Dan2013

    Joined:
    May 24, 2013
    Posts:
    200
    @ZimM
    Here is a feature request. :)
    It will be huge helpful if there is a batch mode for the "Shadow texture generator".
    This batch mode can generate and configure shadow textures for all Swift-Shadow-Enabled objects in the scene without working with these shadow receiver objects one-by-one.

    For example, if I only have one static faked light source (e.g. only one directional light used as the faked light source that does not rotate a lot), I just want all Swift-Shadow-Enabled objects in my scene to have a top-down shadow with the same rotation. I can use this batch mode to generate and configure all shadow textures by one click.
     
  17. Gelo_Man

    Gelo_Man

    Joined:
    Jun 6, 2015
    Posts:
    9
    Hey ZimM,

    I posted a while back about using Swift Shadows for a top down game and some issues I was having with draw order. Just wanted to let you know I figured out what the issue was (it's a Unity wide issue with sprites drawing over quads unless you modify the standard shader).

    With that figured out, and some tweaks to the SwiftShadow class, it's been working great so thank you for this asset! Here are some *VERY* early WIP shots showing the shadows in action:





    Just about everything in the scene is a flat 2D sprite, and it still needs a lot of work (like anchoring the lower vertices of the shadow mesh to the lower bounds of the sprite) but SwiftShadows really helps sell the fake-perspective effect.

    As we keep fleshing out the prototype, I was wondering if there is an easy way to do the following:

    1) Is there a way to add a collider component to the shadows (either a box collider, or more likely a mesh collider)? I'm trying to see if the player is in the same space as a shadow, which requires a raytrace (and thus a collider).
    2) Is there a way to add a tag or layer to the shadows? This will just help with code management.

    Thanks again!
     
    Alverik likes this.
  18. Gelo_Man

    Gelo_Man

    Joined:
    Jun 6, 2015
    Posts:
    9
    Hey ZimM,

    Seems like you don't check this thread much anymore, but just wanted to say I solved the problem by using coordinate math. Anyways, thanks again for all your work in putting together Swiftshadows - it's a really neat asset.
     
  19. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    Hi I get an error in Unity 5.3.2 when I try to use the shadow texture generator.

    NullReferenceException: Object reference not set to an instance of an object
    LostPolygon.SwiftShadows.Internal.Editor.EditorInternal+EditorUtility.SetTemporarilyAllowIndieRenderTexture (Boolean allow) (at Assets/SwiftShadows/Internal/ShadowGenerator/Editor/EditorInternal.cs:23)
     
  20. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hey everyone!

    Swift Shadows was recently updated to 1.2.1, which fixes the Shadow Texture Generator tool for Unity 5.3, and gets rid of some compilation warnings caused by new Unity 5.3 APIs.

    @mattSydney Please check out the latest version.

    That sounds like a good idea, but after giving it some thought, I believe this won't work in the real-world scenario. The reason is, you usually need to tweak some options like model rotation and blur level for each model, and there is no way to figure out that information automatically, so if a batch-mode like you've proposed would be implemented, it'd generate wrong textures for half of the objects.

    @Gelo_Man Sorry for the slow reply. It's great to know that you've solved your problem. Still, I'll answer your questions in case someone else will have them.
    1) Shadow is not a GameObject, it's just a part of a big mesh, so you really can't attach anything to it. Basically, shadows do not exists as entities in the game world. And even if that' would be possible, it'd be horrendously slow for non-static shadows. What you can do is iterate over all shadows using ShadowManager.Instance.ShadowManagers and approximate that check using the coordinates of shadow vertices.
    2) You can manually set the layer in which in the shadow will be rendered, the option is in the very bottom of SwiftShadow component. You can't, however, add a tag, as that requires a GameObject.
     
    Gelo_Man and mattSydney like this.
  21. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    I recently purchased this asset about a week ago and have found a serious bug. Here are the steps to reproduce the issue in 4.6 and you should have multiple of the same prefab scattered in the level, in my case fruit.

    - Apply the swift shadow component to an object.
    - Set the shadow size of the blob to match the object.
    - Set the shadow color's opacity somewhere around 60.
    - Your shadow should now be set, finish by hitting the apply prefab button.

    Your prefab shadows should now apply to all other fruit prefabs except your original prefabs shadows just got darker somehow and the opacity did not apply to the other existing fruit....

    It turns out every time you hit apply prefab the swift shadow component is duplicated on the object you hit apply on. This is shown because the shadow gets darker and deactivating the only swift shadows component hides that instance but the shadows are still there. . It's a huge memory leak. I can pass a video or gif if you are having trouble understanding.

    I have a zero tolerance when using tools that have bugs and cannot afford to go back and forth fixing an issue so I am going to have to ask for a refund if that's alright with you.
     
    Last edited: Apr 10, 2016
  22. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Thank you a lot for posting this. I've actually heard about people having similar issues a few times, but no one ever described a way to reproduce the issue, and it seemed to fix itself for them mysteriously. I've tried to reproduce it the way you've described, and I can finally see the issue on my own. The issue is only reproducible when using prefabs, so perhaps no one was using prefabs that much?..

    All tools have bugs. If I knew how to reproduce the bug before, I'd have fixed it long ago. I've actually just fixed this one too.
    Just open SwiftShadow.cs and change line 1066 from
    Code (CSharp):
    1. if (!_isInitialized || _isDestroyed || !gameObject.activeSelf)
    to
    Code (CSharp):
    1. if (!_isInitialized || _isDestroyed)
    That's it, everything works fine for me after this change. I'll also update the version on Asset Store immediately.

    I will not conduct a refund because of such a simple issue.
     
  23. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    This has indeed fixed the issue. I will keep you posted on this and other improvements to come. I have a few things I would also like to ask:

    1.I am not 100% sure how to use the light to affect and rotate the shadow and the docs don't mention it?

    2.I would like to request that when the texture generator creates the shadow image that it also creates a material of it ready to go as it's more intuitive since the texture can't be used without making a material and dragging that into the script anyway.

    3. I would also like to know how to animate the transforms of shadows since my fruits transforms float up and down and I would like the shadows to go up and down with it.

    Thanks.
     
    Last edited: Apr 10, 2016
  24. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    +1
     
  25. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    From the manual:
    I don't know what to add here, really. You just switch the "Light Direction" property to "Light source object" and drag a GameObject to "Light source" field, and that GameObject will define the light position for that shadow. You can see this in action in SS_MultipleShadows demo scene.
    That's a good idea, will do.
    Not sure I understand you on this. Shadows don't have any transforms - they are projected on the ground, and that's where they are drawn. Do you want shadows to float above the ground?.. Shadows already do fade in/out and change their size depending on the distance from the object to the ground.
     
    Alverik likes this.
  26. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    1.I also suggest making the shadow camera events a required component rather than a greyed out temporary one. It was causing a lot of bugs due to reference errors which were fixed by just pressing the button to add a permanent shadow event component.

    2.My mistake, I meant I would like to animate the shadow size value. The fruit animates up and down and if it had a real shadow the shadow would be on the ground and it's shadow radius changes size depending on how close or far the fruit is to the ground.

    Since the fruit moves up and down I want the shadow size to animate it's values as well.
    I need the shadow to be under the fruit at all times no matter where the light is coming from so I am using a Static Vector. Can I request this as a feature to animate shadow size and smoothly transition the size value from one value to another or is this not a good idea?
     
  27. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I've never seen any errors related to this, or had reports about such problems before, so I guess it works fine for most people, so there's no point in making it a requirement. For cases when it doesn't works for some reason - the button to add it permanently is there.
    This is already implemented. See the "Fading" section of SwiftShadow component. Here's how it looks in action:
     
    Last edited: Apr 11, 2016
  28. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    So because most people are lazy on bug reporting you will ignore it?
    Here is your next bug:

    Cleaning up leaked objects in scene since no game object, component or manager is referencing them
    Mesh _ShadowMesh_Dynamic_Shadow Multiply has been leaked 1 times.
    Mesh _ShadowMesh_Dynamic_Shadow_Life has been leaked 1 times.

    It goes away on a restart of Unity. These are minor so I am just making you aware of it.
     
    Last edited: Apr 12, 2016
  29. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I'm not ignoring bugs, of course. But if I don't even know that a bug exists, how can I fix it?.. Even if I do know there is some kind of bug, I need some way to reproduce it. I try my best to figure it out by myself, but without a proper description from a user it's always a guessing game, so obviously, sometimes my investigation leads to nothing. I'm taking stability seriously, but hunting ghosts isn't something what I'd like to do, especially when the issue only occurs for some people and rarely, or/and there is an easy workaround.
    And of course, if there is a proper description of how I can reproduce the bug - it's usually very easy to fix.

    I'll take a look at this, but in any case, this is purely cosmetic and could only happen in the Editor. You can build the game just fine, there won't be any leaks.
     
    Last edited: Apr 12, 2016
  30. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Ok. For the next thing I seem to be experiencing strange issues with the shadow. Distortions and incorrect projections as the image may help.

    The shadow is not casting from it's source but instead nudged with a strange offset. I did apply a offset as the image shows to make it appear like the light is shining from a specific direction but the direction is not like it would be in reality. Is this a limitation or because I am not using a lightsource but instead a static vector or?

    Thanks.
     

    Attached Files:

    Last edited: Apr 12, 2016
  31. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    It's hard to say without seeing the scene and knowing what are trying to achieve. You can't really talk about "light source" if you are using a static vector. When static vector is used, it means that light comes from a directional source that is infinitely away from the object (like a sun). This will look wrong if your light source is actually a object in the scene (like a torch). What is your case?

    I'm not exactly sure I understand your "correct casting" image. The way you've drawn it looks like the cube is practically touching the ground, but it clearly isn't.

    What you might try is to increase the shadow size to around 1.2 or so. The shadow texture has blurred edges, which visually decreases the shadow size. Increasing the actual size compensates that:


    For comparison, here's how Unity renders directional shadow ("actual" real-time Unity shadows)
    https://dl.dropboxusercontent.com/u/12721305/Screenshots/Unity_2016-04-12_14-00-15.jpg
    And here's the same with SwiftShadows:
    https://dl.dropboxusercontent.com/u/12721305/Screenshots/Unity_2016-04-12_14-00-40.jpg
    You can see that the projection is nearly identical, so I guess the issue is not with the projection itself, and perhaps you want something different.
    If you actually have a light source in the scene, like a torch, I'd recommend setting that torch as a Light Source Object of the shadow, and enabling Perspective Projection checkbox to make it more realistic.

    Hope this helps.
     
  32. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    The cube IS touching the ground but the shadow makes it look like it's not - That's the problem.
    It casts perfectly fine when the x and z parameters are at 0. So to reproduce the issue try to put the cube on the ground and put the x y and z direction vectors like this:
    X: 0.50
    Y: -0.66
    Z: 0.55

    It looks like they are locked to each other, meaning editing one will force the others to change.
    After setting it like this you should have the same result of the illusion that the cube is floating when it's actually on the ground and a wrong shadow projection.

    I remember someone saying this plugin works best with objects that hover, maybe this is what they meant. If you still aren't getting the same results I can upload a video or gif.
     
    Last edited: Apr 12, 2016
  33. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    ZimM,

    Is there any way to fade a SwiftShadow in and out during runtime through code? I'm using SwiftShadow to project sprites onto my terrain that surround my character and form a combat zone. When he walks, the swiftshadows follow the contour of the terrain nicely. So basically, I'm using the projection features to place contour adjusting textures on the terrain. I would like to be able to fade in and out as needed.

    I can set initial color doing the following and set the color alpha to 0 but I was just wondering if there is a way to fade in and out.
    Code (CSharp):
    1. attackZone1SwiftShadowArray[i].InitialColor = new Color(.28f, 0f, 0f, 0f);
    I've also tried grabbing a reference to the SwiftShadow material and changing the color there but have had no luck.

    Thanks
    Allan
     
  34. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I guess the name of the InitialColor property is a bit misleading. You can change it during runtime, and it will behave as expected. To fade in or out, just decrement/increment a variable in your code over time, and use that as an alpha value to modify the InitialColor property value.
     
    Alverik likes this.
  35. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    If you have Dotween pro you can easily make it animate quite effectively.

    Update: Nope Doesn't work that way.
     
    Last edited: Jul 26, 2016
    Alverik likes this.
  36. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    What command are you using with DoTween Pro? I haven't been able to find anything in Dotween that lets me alter the alpha value of a color struct and at the same time assign it to New Color and assign it to InitialColor. My preference is always to use DoTween if I can figure out a way to do it but since accessing the material does not work, I can't figure out how to alter the alpha float within Initialcolor that uses the color struct.

    Right now I just have my own Coroutine altering a float then assigning that to a new Color value and then assigning that to InitialColor. It's messy but it works.

    thanks
     
    Last edited: Jul 25, 2016
  37. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Not entirely sure what you want to do but does this help;

    The default "Fade" on Dotween already edits the Alpha channel using either From or To (0, 255 etc) which already access the RGBA data of the Gameobject this component is attached to just by being attached to it.

    You can then use the OnComplete or other functions on Dotween Pro to trigger the next step.
    In your case you then assign or drag in the object you want changed - here you can use the Color option instead of fade in Dotween to change the color of this gameobject From current color to another color and OnComplete again to do another thing. You also have access to the Dotween ID since you will probably be using multiple of them on the same gameobject - the ID will help you sort it out via script so you can call them from script via if statements or whatever rather than use a co-routine.

    Remember that using the Oncomplete and other functions will allow you to drag in gameobjects like you would for Unity GUI and then a selection of commands will appear, ultimately if you cannot see access to the Alpha there you can access your own script on that object and activate a function which will get and then set based on the Alpha that dotween changes and update in realtime the changes to the Alpha in the struct.
     
  38. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Thanks for the following up on this. I really appreciate it. :) But I don't understand what you mean by default "Fade" on Dotween. All I'm trying to do is fade the shadow in and out. I can do it by incrementing a float in a coroutine and applying that float to the alpha value of a New Color and then assigning the new color to SwiftShadow.InitialColor. If I can figure out a way to use DoTween, it would be much cleaner.

    Taking a look at the DoTween documentation, I don't see anything that fits the description of a default "Fade". And I'm not aware of any way to fade or alter the alpha channel on a Gameobject. Do you mean a material with a shader that has a color property on a given gameobject?

    I'm only aware of 2 ways to use DoTween. Using the generic method, I can change basically any variable, vector3, float etc.. Using the shortcuts method, I need a reference to a component that has a color option. For example, Material.DOFade, CanvaseGroup.DOFade, Image.DOFade etc.

    I use OnComplete frequently using both the generic method and the shortcuts method but usually I'm simply using it to call a method once my Tween has completed.

    If you or anyone else has a code snippet that allows you to fade the swiftshadow shadow using DOTween, that would be appreciated.

    Allan
     
  39. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    I see what you mean now, yes dotween can only act on the direct color or materials and so on....

    However there is one trick you can do instead, it's also hacky but it still works.

    0. Make sure you have a gameobject with the swift shadow component assigned, this will be the one you want to fade in and out the shadow of.
    1. Create a new standard plane, place it out of the game view.
    2. Select the gameobject with the Swift Shadow component on it and locate the material it is using. That material should show up in your project somewhere. It is not the gameobjects mesh renderer material, it is the Swift Shadow material that we want which was generated and contains the fake shadow.

    3. Now drag this material onto the new Plane objects Mesh Renderer, Dotween can now access it using the built in Fade and Color abilities.

    4. You can now use Dotween's Fade to animate the material on the plane, because the plane contains the source material that the Swift Shadow component is also using, whatever changes made to the planes material will also be made to the object with the Swift Shadow component - in this case it's the Alpha we want to fade in and out.

    This is possible because of how Unity handles Source Materials and instances for optimization.
    If the gameobject whose shadow we wanted to animate was a Coin, using this method all the other coins would also have their shadows animated all at the same time because they all share the same root material. This may or may not be what you want.

    UPDATE: This method would work if the Material Shader generated contained access to the Alpha but it doesn't....Swift shadows seems to generate and override it with it's own values.

    It looks like Zim was right "To fade in or out, just decrement/increment a variable in your code over time, and use that as an alpha value to modify the InitialColor property value."....


    Sorry bout that but it seems a little strange that the Swift Shadow material Shader doesn't expose an RGBA property in it while the Script is able to access it. Maybe it can be done by adding an Alpha channel in the shader and modifying that instead.
     
    Last edited: Jul 26, 2016
    Alverik likes this.
  40. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    I love your hack. :) Amazingly creative. Too bad it doesn't work in this situation but I appreciate your effort.

    I even tried using the Particles/Alphablend shader, grabbing a reference to the material being used by SwiftShadow and using Dotween (Material.DOFade()) to change it's alpha but I keep getting errors saying my Material does not have a color property. Except that the Particles/Alphablend shader does indeed had a color property. So that confirms what you are saying about the material somehow being overridden.

    There is actually a fairly healthy discussion on the topic of adjusting Color using DoTween in the DOTween forums and the DoTween author created a static Tween specific for the alpha in the Color struct called DoTween.alpha. It's in the docs in section C. Additional generic ways. But of course to use it, you still need direct access to Color.

    So I have to agree with you, at this point, I'll just keep using my overly messy coroutine that assigns an incrementing/decrementing float to a new color that is assigned to InitialColor.

    Thanks again for the help.

    Allan
     
  41. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @chaneya
    @SilverStorm
    Just tried DOTween. Guys, you are way overthinking it :) DOTween has a generic DOTween.To method that can tween anything. Here's my simple test script, works fine for me:
    Code (CSharp):
    1. using DG.Tweening;
    2. using LostPolygon.SwiftShadows;
    3. using UnityEngine;
    4.  
    5. public class ShadowFadeTest : MonoBehaviour {
    6.     public SwiftShadow Shadow;
    7.  
    8.     private void OnGUI() {
    9.         GUILayout.Space(500f);
    10.         if (GUILayout.Button("Fade In")) {
    11.             Fade(255);
    12.         }
    13.         if (GUILayout.Button("Fade Out")) {
    14.             Fade(0);
    15.         }
    16.     }
    17.  
    18.     private void Fade(int targetAlpha) {
    19.         DOTween.To(
    20.             () => Shadow.InitialColor.a,
    21.             alpha => {
    22.                 Color32 color32 = Shadow.InitialColor;
    23.                 color32.a = (byte) alpha;
    24.                 Shadow.InitialColor = color32;
    25.             },
    26.             targetAlpha,
    27.             3f
    28.             );
    29.     }
    30. }
    31.  
    And here's an even simpler variant that uses DOTween.ToAlpha:
    Code (CSharp):
    1. using DG.Tweening;
    2. using LostPolygon.SwiftShadows;
    3. using UnityEngine;
    4.  
    5. public class ShadowFadeTest : MonoBehaviour {
    6.     public SwiftShadow Shadow;
    7.  
    8.     private void OnGUI() {
    9.         GUILayout.Space(500f);
    10.         if (GUILayout.Button("Fade In")) {
    11.             Fade(1f);
    12.         }
    13.         if (GUILayout.Button("Fade Out")) {
    14.             Fade(0f);
    15.         }
    16.     }
    17.  
    18.     private void Fade(float targetAlpha) {
    19.         DOTween.ToAlpha(() => Shadow.InitialColor, color => Shadow.InitialColor = color, targetAlpha, 3f);
    20.     }
    21. }
    22.  
    Am I missing something? :)

    Swift Shadow material does not exposes a Color property for one simple reason - color is stored per-shadow in the mesh itself. This allows shadows to have different colors while still taking a single draw call. Sure, I could have added a Color property to the shader itself, but it will tint all shadows, which is not something you'd usually want.
     
    Last edited: Jul 26, 2016
    Alverik likes this.
  42. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Damn! You discovered my superpower......making the simple, overly complex. :)

    Seriously though. Thanks for posting that code. I was getting all tripped up on the nomenclature of using color in a DoTween and properly accessing the InitialColor property in SwiftShadow.cs. Both solutions you posted work great! I'll save the DoTween.To option for future reference when I need to remember how to pack a custom property into a generic DoTween.

    Thanks Again! :)

    Allan
     
  43. warmanw

    warmanw

    Joined:
    Feb 2, 2015
    Posts:
    32
    Hi Guys,

    Just updated the Unity to 5.3.5 from 5.3.4 and all shadows went purple.

    For information we load models dynamically with swiftshadow component added on them initially using assetbundles.

    However even with 5.3.5 unity shadows works when I build on android platform.

    Please help
     
  44. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Pink shadows mean that shadow material is broken in some way. Perhaps the shadow shader is not loading, or the material?.. I've just tested with 5.3.5 and found no issues. On what platform are you experiencing the issue? This feels more a Unity bug, actually, since there is nothing in Swift Shadows that makes shadows pink...
     
  45. warmanw

    warmanw

    Joined:
    Feb 2, 2015
    Posts:
    32
    Hi,

    I pack projected shadow textures in one atlas.

    The shadows which use atlas material are purple, while default one which is a circle sprite is ok. (unity editor windows 10)

    Note I load the objects with shadow from the server as assetbundle.

    However with same configuration all works on when I run on android
     
    Last edited: Aug 15, 2016
  46. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    ZimM,

    Just a heads up, but I decided to try out the new Unity 5.5 beta with sweet new Particles system features and Trail Renderer and Swift Shadows is throwing a nasty little Editor bug every time play is initiated.

    ArgumentException: Value does not fall within the expected range.
    LostPolygon.SwiftShadows.Internal.Editor.ShadowManagerEditorHelper.CreateHelper () (at Assets/SwiftShadows/Internal/Editor/ShadowManagerEditorHelper.cs:62)
    UnityEditor.EditorApplication.Internal_CallDelayFunctions () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorApplicationBindings.gen.cs:207)

    At least the bug is consistent since it occurs every time you click Play.

    Allan
     
  47. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    No idea, I have never used Asset Bundles. Swift Shadows uses the material in a standard way. It sounds like your atlas materials are not being included to your asset bundles for some reason, you might try to check that.
    And the fact that it works on Android, and that it worked on the previous version of Unity, heavy suggests that this is an issue on Unity side.
    Unity 5.5 is in very early state now, it makes no sense to investigate this issue just yet, since it might actually be a Unity bug. I guess you can just ignore it. But thanks for the heads up, I appreciate it!
     
  48. Barliesque

    Barliesque

    Joined:
    Jan 12, 2014
    Posts:
    128
    Hi,
    I've been looking around at shadow libraries, and came across Swift Shadows, which looks great. However, when running the demo (WebGL and WebPlayer) I notice that shadows snap from one surface to another. Something tells me that's not the intended behavior, so I wanted to let you know.
    All the best,
    David
     
  49. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    This is the intended behaviour. Swift Shadows works by doing a raycast from the light to the object, and when the angle changes abruptly (as in, shadow goes from the ground onto the wall), the shadow immediately follows that change as well. That said, there is in fact an option in Swift Shadows that allows to smooth out that transition, but whether or not it will look good very much depends on the scene. For example, smoothing is enabled in the "Terrain Interaction" demo scene, and you can't really see any snapping there.
     
  50. bromske

    bromske

    Joined:
    Sep 11, 2012
    Posts:
    28
    Hi,
    I'm using Swift Shadows, it works fine, but i have a problem with objects coming from a objectpool. I reuse my objects so i only enable and disable this objects. Everytime i enable a object swift shadow add a new shadow to the shadowmanager and the shadow is getting darker. Can i remove the shadow from the shadowmanager or how can i remove the doubled shadows?


    First use of the bomb (left bottom corner)


    after 5 times reuse (5 shadows added)