• 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
Question by Baldinoboy · Mar 24, 2015 at 08:49 PM · terrainwatereffectsunderwater

How to get caustics only show underwater?

I am trying to get a nice caustic effect. Right now I am using an extra directional light with a animated cookie script. Also using a underwater script which enables the caustic light along with a few other effects when I go below a certain value. This works and looks nice but still there are no caustics above the water but magically appears as soon as I am underwater.

My question is if there is anyway to get the caustics to always be enabled but only show under the water. I know it is possible but I am not sure how. I am using the terrain system so having two separate meshes above and below the water will not work.

Any help will be greatly appreciated. Thanks

Comment

People who like this

0 Show 2
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 siaran · Mar 24, 2015 at 11:43 PM 0
Share

I'm a bit confused by the question. You have something that only shows caustics underwater, but now you want to change it so that...it only shows caustics underwater? Why?

And what's wrong with enabling/disabling scripts or gameobjects?

avatar image Baldinoboy · Mar 24, 2015 at 11:48 PM 0
Share

I want the caustics to show on the ground below the water when I am standing on a dock and looking down at the water. Not only when I am underwater. It looks like crap when the caustics all of the sudden appear when the camera goes below the water. I want to have the caustics constantly showing but only on the ground below the water.

1 Reply

  • Sort: 
avatar image
Best Answer

Answer by Pangamini · Mar 25, 2015 at 08:53 AM

Try using an orthogonal projector instead of directional light. With some additive shader it will create light like effect, however it with lack of shadows. Or at least i don't know about projector having the shadowmap feature supported by the unity, however it could be scripted. So just create an ortho projector facing down and spreading over the water surface. The default unity additive projector shader doesn't clip correctly what's behind, so here's what I am using:

 Shader "Projector/Additive"
 {
     Properties
     {
         _Decal ("Decal", 2D) = "white" { TexGen ObjectLinear   }
         _Color ("Color", Color) = (0.5, 0.5, 0.5, 1)
     }
     
     Subshader
     {
         Pass
         {
             ZWrite On
             Fog { Color (1, 1, 1) }
             Offset -1, -1
             Blend One One
             Cull Back
              
             Tags { "RenderType"="Geometry-10" }
             
             CGPROGRAM
             #include "UnityCG.cginc"
             #pragma vertex vert
             #pragma fragment frag
     
             sampler2D _Decal;
             float4x4 _Projector;
             float4x4 _ProjectorClip;
             float4 _Color;
     
             struct vin
             {
                 float4  pos     :     POSITION;
                 float4  uv        :     TEXCOORD0;
             };
             
             struct v2f
             {
                 float4 vertex    : SV_POSITION;
                 float4 uv        : TEXCOORD0;
                 float4 pclip    : TEXCOORD1;
             };
     
             
             v2f vert (vin i)
             {
                 v2f o;
                 o.vertex     = mul(UNITY_MATRIX_MVP, i.pos);
                 o.uv         = mul(_Projector, i.pos);
                 o.pclip     = mul(_ProjectorClip, i.pos);
                 return o;
             }
     
             float4 frag(v2f i) : COLOR
             {
                 clip(1-i.pclip.z);
                 clip(i.pclip.z);
                 clip(i.uv.x);
                 clip(1-i.uv.x);
                 clip(i.uv.y);
                 clip(1-i.uv.y);
                 float4 col = tex2Dproj(_Decal, i.uv) * _Color;
                 return col;
             }
 
             ENDCG
         }
 
     }
 }

Comment
Baldinoboy

People who like this

1 Show 8 · 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 Pangamini · Mar 25, 2015 at 08:55 AM 0
Share

You may want to modify the shader a bit to support tiling

avatar image Baldinoboy · Mar 25, 2015 at 02:38 PM 0
Share

Thanks. Will give it a try.

avatar image Pangamini · Mar 26, 2015 at 09:08 AM 0
Share

Tell me how did it go, i might need to do something similar myself in the near future :)

avatar image Baldinoboy · Mar 26, 2015 at 01:09 PM 0
Share

I have not animated or set up tiling yet but I put the projector at the waters surface and applied a material with your shader. It does not clip parts of the terrain like before. It works. Thanks

The only problem I am having now is any animate projector script I had or can find does not work in Unity 5. I would fix the error it had and it would not animate at all. The animate cookie scripts work fine still just not projectors.

avatar image Baldinoboy · Mar 26, 2015 at 01:30 PM 1
Share

At least it is working underwater. That is what I needed the most. Thanks for the help

Show more comments

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Raycasting Through Terrain 1 Answer

Terain-Water creation problems 0 Answers

Water is reflecting my terrain texture 0 Answers

Underwater effects for rivers 0 Answers

How to combine the particle system with the plane? 0 Answers


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