- Home /
Grass shader sprite 2D
Hello community, I've been searching for quite some time and I can't seem to find an answer.
What I want: Shader for grass wind/sway for a sprite in 2D game. Shaders are not easy to start with so I'm looking for a written script. All I've found renders my sprite completely black.
Any idea how to fix it?
Example: https://gist.github.com/jaycelq/a137666f95e2abe3e713730ec21953f3 I understand that this is a surface shader and it works with lighting which sprites don't have.
Any ideas how to achieves this windy effect? Thanks!
EDIT: I solved the problem by going to Window > Rendering > Lighting Settings and setting Ambient Color to white.
Answer by rufopufo · Jul 26, 2019 at 08:46 AM
Hi there,
Have you consider making an animation for the windy effect on the grass? This is not as complex as the shader, and personally I think it gives a pretty decent effect.
If you want to change the speed of the wind, you can just change the speed of the animation, and it could be dynamic with random wind zones.
I think that for 2D is the best way to go. Simple animations. You can do two or three, for right wind, left wind or even wind going straight down. And as I said, playing around with the animation's speed, will get really nice effects, as if wind was real.
Hope it helps.
Hi, thanks for suggestions. I did. The thing is that I will have a bunch of different sprites that should have this animation throughout the game. This shader would be an universal solution as I would just put it on the sprite. This method you're suggesting can it be one "universal" animation that could be assigned to all sprites or it would need to be created manually for each sprite? The last thing is performace - but here I have no idea, aren't animations more heavy?
Answer by Fred-Koa · Jul 29, 2019 at 01:46 AM
https://unity3d.com/get-unity/download/archive In the drop-down buttons you can download the built-in shaders. The grass shaders are in DefaultResourcesExtra/TerrainShaders/Details/. Just modify one of them and put it anywhere in your project without changing its name. You can also find these shaders on github: https://github.com/TwoTailsGames/Unity-Built-in-Shaders
Hi, thanks for the links. Interesting that there's a grass shader created directly by Unity but I didn't find it when I was searching for these shaders. What do you mean by "modify" ? This shader doesn't render my sprite at all. With a current understanding of how shaders works I'm not able to make big changes at this moment.
Answer by DawidNorasDev · Jul 26, 2019 at 11:24 AM
What I've done in my game: (see the short video) https://www.hedgehogsoft.com/spring-is-in-the-air/ It's a simple sprite shader with vertex offsets which are greater, further you are from pivot point.
You can achieve this effect by following Brackeys tutorial: https://www.youtube.com/watch?v=L_Bzcw9tqTc It's in SRP, but the concept stays the same.
Good luck!
Your answer
Follow this Question
Related Questions
Skew a sprite at runtime while preserving the pixel shape? 1 Answer
Are shaders more efficient than manual pixel replacement? 0 Answers
Shader on 3D model not seen over 2D sprites 0 Answers
Allow 2D sprite to receive light from any direction and show on both sides 0 Answers
Shaders - offset texture coordinates by a single pixel 2 Answers