Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DavidRon · Jan 24, 2017 at 04:07 PM · 2dtexturerenderingdistortion

2D Pixelated water reflection with shaders

I've been trying to create a shader for a pixelated water reflection, but I'm new to Unity and especially new to shaders.

What I'm after is something like this: GIF

I've managed to use Grabpass and flip it to get the surface to distort, but i cant figure out how to do the distortion.

Been trying something like this where i changed _Offset in a script over time, but the best result i got with that was a single wave, which is not what i'm really after. I was considering checking the y-coordinate compared to _Offset and using modulus to change direction of every third/fourth pixel or something but there doesnt seem to be any modulus available for shaders. Completely lost at this point.

              fixed4 frag(v2f IN) : SV_Target
              {
                  fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
  
                  fixed4 up = tex2D(_MainTex, IN.texcoord + fixed2(0, _MainTex_TexelSize.y));
                  fixed4 down = tex2D(_MainTex, IN.texcoord - fixed2(0, _MainTex_TexelSize.y));
                  fixed4 left = tex2D(_MainTex, IN.texcoord - fixed2(_MainTex_TexelSize.x, 0));
                  fixed4 right = tex2D(_MainTex, IN.texcoord + fixed2(_MainTex_TexelSize.x, 0));
 
                 if(IN.texcoord.y > _Offset && IN.texcoord.y < _Offset + 0.01){
                     c.rgb = right;
                 }else{
                     c.rgb = left;
                 }
 
                  return c;
              }

I realize this code is nowhere close to what i want to do, but that's about as far as my experiments has taken me.

Would appreciate some help or some pointers

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by tanoshimi · Jan 24, 2017 at 04:12 PM

There's a nice writeup of how the water shaders in Kingdom were created here (which, IMO, is one of the best examples of 2D pixelated water around).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DavidRon · Jan 24, 2017 at 04:52 PM 0
Share

Thanks for you reply. Thing is it seems i cant do this distortion with a distortion map, atleast it doesnt seem like it(i may be wrong), it simply gets too smooth. It was suggested to me to ins$$anonymous$$d of using a distortion map to use a sin function fort distortions. The experiements with sine so far arent looking much better though.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Texture rendering 1 Answer

2D Sprites Rendering Inconsistently Between Computers 0 Answers

Issue with Rendering Large Texture 0 Answers

Anti aliasing with sprites 0 Answers

Unity 5.6 Creating a Distortion in Sprites? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges