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 GoldCoinGames · Dec 18, 2017 at 04:12 PM · shadersmaterialsshader programmingwater

How do I make a water shader that has depth.

In shader code and materials for water in unity I have seen some assets on the asset store that show brilliant photos of the water becoming more opaque or darker in colour the deeper the object underneath it is. It sort of makes a volumetric appearance. Here are some examples of what I am talking about: alt text

alt text

Notice how the deeper the water is the darker or less translucent it is, I was wondering how I could code this in a shader and make a material with these properties. Thanks for the help

ezuoicx.jpg (81.6 kB)
marc-sureda-screen-3840x2160-2017-03-29-21-56-25.jpg (179.0 kB)
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
2

Answer by JonPQ · Dec 18, 2017 at 08:17 PM

on PC you can read the Z buffer as input to a shader, so you draw the ground first, then the water on top (this is usual anyway, and transparencies are normally rendered after opaque geometry) then use the Z depth in the pixel shader to control blending to some other thing, other than the usual pixel you are about to render... Such as blend to a white color, or to a foam texture, or both a foam and a white color at the edge. subtract screen Z from the Z you are rendering... multiply by a scalar, and clamp to 0-1 range. Then you have something you can use to lerp with. https://forum.unity.com/threads/reading-depth-buffer-in-vertex-shader.431670/

On mobile you pretty much don't have access to the screen z depth in shader.... but you can do this another way, by rendering a top-town view of your map into a texture, to get the shoreline contour, and then paint in extra information in photoshop.... so you can paint your own depth into say the red channel... then paint other info into g,b,a channels also... whatever you want. Then add this as an extra texture input channel to your shader, using same UV input as the main texture (assuming mapped with parallel projection from above.

Comment
Add comment · 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

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

84 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding object to scene causes problem with other objects material/shader 0 Answers

Writing a shader that creates an infinite number of water ripples 1 Answer

See backside of a transparent emissive shader? 0 Answers

Grabpass 2D water reflection, UV issue 0 Answers

Turning standard materials from opaque to transparent and back in runtime 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