Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Official Wind shader add-on

Discussion in 'Open Projects' started by treivize, Nov 6, 2020.

  1. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    Here is a proposition for the wind effect as an add-on of the Toon Shader:

    - Wind Sub Graph:
    upload_2020-11-6_16-54-21.png

    - Toon Shader update:
    upload_2020-11-6_16-56-31.png

    - Vertex Color layer on Palm tree to apply wind only on leaves:
    upload_2020-11-6_16-57-48.png

    Result:
    wind_shader_2.gif

    I have opened a PR after having added the capability to input a wind direction from the material properties. PR link: https://github.com/UnityTechnologies/open-project-1/pull/150
     
    Last edited: Nov 6, 2020
    Amel-Unity likes this.
  2. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hey @treivize, I moved this post in its own thread so we can discuss the wind shader add-on in here, probably some time in the future.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    @treivize i am sorry but IMHO your wind function is way too simple to be any kind of "official" solution and at the same time way too expensive: using "gradient noise"?!
     
  4. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    Hello @larsbertram1,

    Definitely, I have not your experience in this domain, but IMHO having a simple unrealistic model for the the wind function for the type of game we are building might not be a problem. At the end, it is just a way to make the environment lively where the wind effect will remain an artistical touch not part of the game mechanics or wow effects.

    Next, regarding the cost of shader graph "gradient noise" it is really good to know that it is an expensive function. Do you have suggestions to replace it with something more efficient?
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,911
    you can use a tiny perlin noise texture. or have a look into the old tee creator/crytek shaders and speedtree.
     
  6. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Apologies if this isnt the right place to comment on this, but i was looking at the Sail shader ticket.

    I'm not quite sure why the existing wind solution wont work on the sail, how is the sail any different? The wind shader might be a little costly, but overall its excellently made!
    Is it that the object itself moves, and the strength of the wind in that case should be increased? If thats the case, even a C# script that modulates the wind-strength property on the material (or more performant via materialpropertyblock!) would do.

    I'm more worried about the mesh topology not working well for vertex-color modulation

    upload_2021-2-18_14-6-36.png

    This is what the mesh looks like, on the red dots are the vertices. Because of the low poly count its very hard to get an acceptable mask.

    upload_2021-2-18_14-11-43.png

    There simply are too few polygons to animate properly, would it be possible for someone to export a higher poly model? This is the result at the moment, there are especially polygons missing in the middle of the sail to bulk out.
     
  7. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    I see it the same way. I guess that's taking economizing on triangles too far - especially when the hulk has 2178 triangles. So I couldn't resist the challenge to create a credible sail with as little triangles as possible (which were 158):
    SailMesh.PNG

    I can add it to the PR I am about to raise anyway for the desserter if @cirocontinisio approves.
     
    TJHeuvel-net likes this.
  8. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    That would be great!

    All i did there was paint some colors with PolyBrush, and slap on the existing Wind shader. If noone else picks it up i can make a script that sets the strength based on the current velocity of an object, that should be sufficient for the sail. And any other object that should flutter with the wind!
     
  9. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hey @TJHeuvel-net, nice to see you here!

    You're right, the sail is very lowpoly, that's why I mentioned in the card that the mesh probably needs to be changed. As for the shader, yeah... it might be the same as wind. But I figured, maybe for the sail it could be ok if it's in Object space, rather than world?
    Of course it's just slightly unrealistic if the sail bloats in exactly the same way while it rotates, but it should be ok for our game.

    But to be fair, both the sail and the plants blow to the same wind, right? So the direction should be the same.

    If you have time and will, you can also tweak the existing Wind shader in a way that makes sense for the sail too. Optimising it too, if you want.

    Thanks @Smurjo, it's always better if PRs are separate (and you don't need to write too many details for them, of course)
     
    TJHeuvel-net likes this.
  10. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    I have both ready. I have observed that any additional commits will be automatically added to an open PR if you have one. How can I avoid this and have 2 separate PR instead?
     
  11. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    You probably need to have them on different branches. You can always branch from an already made commit, and submit that?
     
  12. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    @TJHeuvel-net
    Answering your questions:
    • There seem to be some problems with importing, that you noticed too. In the prefab you've changed the scale of the wind sail, and rotated it around. This causes issues with the wind-shader, would it be possible to fix these in the modeling program?
      • It would be no problem, it is just that the sail is in the position and scale where I found it




    • The boat is made of 3 different objects, the original fbx too. Why is this? Its inefficient to render this as three different draw calls. It could be one for the entire thing, or perhaps two so we have a separate material for the sail. I dont see why the mast has to be another object.
      • Same here - it was 3 different objects. It would not be a problem to join them into 1, albeit we would then have the windshader on the hulk and would have to vertex-paint it black. Maybe it is better to have 2 separate objects. The only reason I can imagine why it was 3 objects is that you can actually steer the boat then - albeit you would then need to control the sail rotation and the rudder rotation separately - resulting in four objects. @cirocontinisio What do we want? Can we imagine we animate steering the boat in a cutscene?
    • I think its best to overwrite the current boat fbx, instead of making a new one with your name appended. With GIT we always have history of the project, so we can go back to the old version, or even see that you've made it. Like this we'd have a ton of models real fast, and we wouldnt know which one to use!
    • The model comes without vertex colors for the weight of the sail, do you think it makes sense to do so in the modeling program instead of in Unity?
      • I can certainly paint the vertex colors - it is just because you had painted them before I didn't touch them. Do you have any specific wishes? In your videos I considered the movement of the outer edge somewhat too strong or I would have to make more edges there. P.S.: Living far from the coast, I personally have no experience with sail boats.
     
    Last edited: Feb 20, 2021
    TJHeuvel-net likes this.
  13. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Ah thats a great reason i hadnt considered yet. Although at that point we could also consider using a skinned mesh.

    I'm just a simple programmer, and added some colors for testing. I'll try to commit the shader so you can play around with it and i'm sure you can get much better results than me.

    Even when living below sea level this can be a struggle. I'm assuming something like Zelda Wind Waker is the goal, as seen here for example. What i'm currently aiming for:

    1. The ripples we can see in the sail is the existing wind solution.
    2. The bulging of the sail itself is an effect specifically for the sail shader. I was thinking of moving the sail out along the normal, based on the rotation of the boat, modulated by the vertex color red channel.

    E.g. if we are looking world-space-forward we push it 100% along the normal, and the red vertex color makes sure it bulges out more in the middle, and hardly at all around the edges. And when you turn the boat backwards it would be point in the opposite direction of the normal.
     
    Smurjo likes this.
  14. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    This is pretty decent if you ask me! Lets iterate over this together, i'm certain you can get much better results than me.

    I've also made a pull request, the shader works fine here on your model too, but you just have to increase the 'SailBulgeStrength' to 100, to counteract the scale. Because the sail object is scaled at 0.01 the bulge is also very small.

    Please let me know if you have some suggestions in order to improve the effect.

    I am now pushing the sail object to the right, not along the normal, because this caused the sail to rip apart. Makes a lot of sense that this happens, on the one side the normals point the other way.
    upload_2021-2-20_19-41-11.png

    I'd like to see if i can make the direction less linear, right now if you are sailing east the sail hardly bulges. Hopefully not making it linear but something extreme like quadratic it will bulge much faster, and those directions that have no bulge are rarer. It all kind of depends on the intended use case though.
     
  15. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    It's pretty decent except the sail goes through this upper horizontal piece on the mast. Could we have blue vertex color to limit the bulging in the other direction? I would then adapt the mesh yet again, and we can make it look as if was blown against this piece of wood.

    It is quite possibly the reality that you can't sail in any direction as you desire. I think if you want to go against the wind you need to do it in zigzag.
     
  16. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Sounds like an excellent solution, i will look into that. Maybe even tweaking the vertex colors i filled in will do the trick, not allowing any bulge in that area.

    upload_2021-2-20_21-55-11.png
    Looking at the reference i arbitrarily choose, the sail is very simple, and attached only in a few specific points. This makes it possible to flutter much more, thats probably a very deliberate decision.
     
    Last edited: Feb 20, 2021
  17. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    I have added the vertex colors including a blue channel and put it into the pull request. I think we need different channels as we want the sail to bulge when it doesn't hit the wood.

    I have also sorted out the pivots, scales and positions. The boat can be steered now.
     
  18. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Thank you! I will take a look today, so the top of the sail only bulges in one direction.

    I'm not artist, but what do you think about removing that side-beam, and attaching it in fewer places, so the sail can move more dynamically? I think in the end it would look better, more interesting.
     
  19. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    Will it look more interesting without the side-beam? Definitely not if we can pull it off to make the sail look as if it was blown against the wood but doesn't go through it. If we don't manage we can always fall back to removing the beam.

    Would your shader possibly need a Vector3 then to tell it the "red" - direction of the bulging? I am thinking we could then use the same shader e.g. for the cover of a market stall bulging downward due to gravity.
     
  20. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Alright cool, lets try that!

    I thought so too, thats why i wanted to use the normal at first. But that didnt work, so i just tried pushing it to object-space-right, and that looked ok.

    We could encode the direction in something else as well, such as uv2 or in a separate texture. Or just use vertexcolor for this, where black means no movement, red fully to the right, blue fully up etc. That could even be relative to the normal. Not quite sure how to then also encode the limit, e.g. some part is allowed to move all the way in the direction and the opposite, and some parts are not.

    Ill first make the version that limits motion to the left according to the blue channel.
     
    Last edited: Feb 22, 2021
  21. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Good news @Smurjo , I think i got it!

    upload_2021-2-22_20-17-37.png
    Using this for testing, the edges are black to indicate no bulge, and no wind. The bottom is full green and red (shown as yellow), showing full wind and full bulge. The top part has blue mixed in, which limits the bulge to the right side.


    The sail bulges out left when we look south (world space backwards).

    upload_2021-2-22_20-41-6.png

    But the upper part doesnt bulge when we face the other way.
    upload_2021-2-22_20-41-30.png

    There is still some clipping because of the wind, you probably also want to tone down the green channel higher up.

    I've just comitted, you can also find it in my pull request. I'd be happy to close it, so your pull request can both be the sail and the shader. Please let me know if it works for you too!
     
  22. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    I pulled your pull request and refined the vertex painting and also mirrowed the mast to match with the bulging of the sail (so make sure you pull the new model before playing with). Good news first: In some angles it really looks like as if the sail was blown against the mast:
    SailBulge1.PNG SailBulge2.PNG
    Bad news: Shouldn't it bulge in the other direction when the boat is turned (albeit it perfectly ignores the mast now as we intended)?
     
  23. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838

    Attached Files:

  24. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    I suspect it was partly caused by the backside of the sail going through the frontside with the wind. I made the sail thicker in the middle and modified the weight painting, which improved things a lot. Noneless there is still some weird effect on the shadow which possibly has another cause (I can't imagine the backside can still get through the frontside now).
    SailBulge1.PNG SailBulge2.PNG
     
  25. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Checking out this PR. I closed @TJHeuvel-net 's one, as requested, and was about to pull in @Smurjo's. But I guess it's not finished?

    One small suggestion: if harnessing the Wind add-on made by treivize seems like too much, just simplify it! Remove that and make a very simple displacement along a local axis, which we can control with a variable. Optionally with some noise.
     
  26. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Its basically 2 effects at the moment, the wind as made by Treivize, plus a bulge effect. In this example you only see the bulging, as you see when the ships rotate the sail goes the opposite way. Thats the added sail-effect as i understood it.

    I'm pretty much done i think, ill check the normals which i think cause the odd shadows Smurjo described.

    Is this the effect that was intended?
     
  27. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    That's a nice plus, I wasn't thinking of an auto rotation, also because the geometry of the mast doesn't support bulging on both sides (if you do, the sail goes through the support in the centre).

    But the effect is not looking the best yet :/
    In my mind it would be much closer to what you see in the Wind Waker: a sail that is full of wind, and the vibrato effect described in the card would only be a small perturbation on the surface (if we want it at all).

    Right now, the effect looks like the sail is very loose, swinging in the wind almost like a flag.

    Also one question: this latest video you posted is before Smurjo's additional polygons, right? It looks very blocky.
     
  28. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Smurjo suggested earlier in the thread to limit bulging in that area, which we added.

    Apologies, that gif was mostly to show off my addition of the bulging, not to represent the final effect. Here is the full effect, with Smurjo's model and settings slightly amped: https://dl.dropboxusercontent.com/s/0btjz38l3gte5wm/UGDlgaCiFP.mp4
    A top view shows the rotation better: https://dl.dropboxusercontent.com/s/8aljkgj3jmab0et/r69MuNVA6W.mp4

    I'm not sure what vibrato means, but the sail fluttering is just using the existing wind solution which seems to work well, but please let me know if its not as you expect. I've just added the bulge, based on what i saw from the wind waker.

    Compared to the wind waker example ive posted before i think we're very close. With some more tweaking we can hide the low poly look a bit better.
     
    Smurjo likes this.
  29. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hmm, I still think we should go with the bulging only on one side, since having the effect limited to accommodate that pole in the middle means that we cannot bulge the sail fully when it's rotated the other way.
    Since we won't have many sailing scenes, we can totally have the sail always facing the right direction (i.e. the beach) and bulge it that way, with minimum rotation of the mast (10 degrees at best) to make it more realistic. Then we could use the full surface of the sail for the bulge, which would come out more round because we'd have more polygons to play with.

    Here's a drawing of what I mean, compared to what it is now:

    Sail.jpeg

    Red would be the bulged sail, which we'd use most of the time while the pig is approaching the beach.
    In green I represented the vibrato that I mean, but it's maybe even too strong (sorry, I was drawing with a mouse) and as I said, we can also leave it out or maybe use it only when the sail is not full of wind.

    The effect that I see now (in the image) for me is more when the ship is at rest.
    I know the effect can be tuned via the parameter, but I'd like to see how it looks when in full.

    Maybe it could be interesting to have the vibrato only when the wind is low (i.e. the ship is stopped).

    So yeah, all in all not a super realistic boat or sailing model, but nicer to look at! These are my thoughts, but let me know your opinion too!
     
  30. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    We have thought of that and do it separately:
    SailBulge3.PNG SailBulge4.PNG
     
  31. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    I have wipped up a quick script which should help in eventually changing the strength of the effect, for when the boat starts moving. Here is an example with some settings, you can give a range to the shader values and then the Strength interpolates between them. Apologies for the low fps, my laptop can hardly handle recording.

    I've comitted it here, as well as the prefab with the settings i just showed. Please feel free to tweak them, they are probably too extreme at the moment.

    @Smurjo Is there anything else in the shader you'd want in order to get the right effect?

    upload_2021-2-28_20-32-15.png
    There is also a context-menu item to apply the current settings to the material, as a default fallback for when the script is not present.
     
  32. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Interesting choice with the Component! I need to test it out a bit...
    Can you make a PR? At this point I'll take a look at it after Tuesday when we have the livestream, so I have a bit more time. I think we also need to repaint the vertex colour, I can see the top vertices seem to move when the effect is stronger, detaching them a lot from the top part of the mast.
     
  33. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    I'm using a bit of an older version of Smurjo's models, it might already have been fixed in the last commit.

    This pull request is the one we're using now, since we're collaborating a lot before its actually ready to be accepted. I dont think i can commit to that directly, before Smurjo just downloaded my shader changes and comitted it there.
     
  34. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    A Vector3 for the direction of the red bulging? (blue would then be the opposite of it)
     
  35. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    No, you can't, but you can open a PR to the branch she's using for the PR on our repo. If she merges it, I think your commits will join her original PR.
    I think :D

    Not really, the main concern is getting the sail to look soft and smooth, but again, this will be for only one scene so it doesn't need to be a "ready for anything" kind of effect, we can build it for the scene if needed. (that's why I was saying that the mast won't really rotate 180°)
     
  36. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    I was hoping to use it for the stage cover and sunshades - this would save me from modeling the hanging of the fabric. I would have Vertex paint anyway to prevent the the fabric from going through the frame with the wind shader.
     
  37. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hmm, I'm not sure if it would work the best because (and I'm thinking of the stages you made) the cloth surfaces face very different directions. So if for instance the wind is blowing North, the top part of the tent will be blown towards the north which is a bit strange... but as you say, you could use vertex colour to prevent it from moving.

    Up to you, in the end it depends a lot on the model and the vertex colour!
     
  38. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Ah that makes a lot of sense, will do that instead.

    Is that just one direction per material, or would you like some per-vertex option? Kind of ran out of space to do it per-vertex, we'd have to get quite creative. It is possible, but a bit tricky to author too.
     
  39. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    Just one per material - for gravity instead of wind.
     
  40. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Smurjo likes this.
  41. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    I have merged it.
     
    TJHeuvel-net likes this.