Water plane and flip texture.

Discussion in 'Scripting' started by digiplayer, Apr 1, 2009.

  1. digiplayer

    digiplayer

    New Member

    Joined:
    Apr 1, 2009
    Messages:
    4
    I am having trouble trying to show water reflections while under the water. Does anyone know how to flip the texture so that while under water you can see the reflections? Any help appreciated.
     
  2. andreasng

    andreasng

    New Member

    Joined:
    Aug 15, 2011
    Messages:
    5
    Why no one have adressed this is beyond me. The problem is still there even with water4!

    anyone?
     
  3. KelsoMRK

    KelsoMRK

    Member

    Joined:
    Jul 18, 2010
    Messages:
    3,054
    Because it doesn't make any sense. What exactly are you reflecting when you're under water? Water surface reflection is caused by light rays bouncing off the water. When you're underwater the light is being reflected away from you so you wouldn't see a reflection anyway.
     
  4. andreasng

    andreasng

    New Member

    Joined:
    Aug 15, 2011
    Messages:
    5
    i see . the same way you can put gravity to -1 (which "makes no sense") the same way i want my water-surface to work underneath.

    wrong. if you have been under water at any time in your life you would have seen that reflections is the same if not more visible from below the water-surface than from above.

    this image speaks for itself.
    http://s2.desktopia.net/wp-content/uploads/walls/thumbs/Underwater-Pool-575x431.jpg

    even this one speaks for itself.
    http://www.safariegypt.com/egypt_hotels/cairo_hotels/Images/hyatt/p36388p010.jpg
     
    Last edited: Mar 2, 2012
  5. andreasng

    andreasng

    New Member

    Joined:
    Aug 15, 2011
    Messages:
    5
    aaaaanyway.....

    i made a really hacky fix to this problem, but i think this is on unity's hands not the users.

    I "declared" this (or whatever it's called i'm not a coder)

    Code (csharp):
    1. _Flip("Flip", Float) = 1.0
    then I fixed this spot

    Code (csharp):
    1. // shading for fresnel term
    2. worldNormal.xz *= _FresnelScale;
    3. half refl2Refr = Fresnel(viewVector, worldNormal, FRESNEL_BIAS, FRESNEL_POWER) * _Flip;
    it makes the water NOT akwardly bright when viewed from below but refractive/reflective.

    I think it has something to do with the way unity calculates the fresnel. When camera angle is below the water surface the fresnel just takes over instead of only taking over when the angles are close, and then go back to nothing when the angles are steep.

    Does anyone have a better solution?
     
    Last edited: Mar 2, 2012
  6. Adam Buckner

    Adam Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Messages:
    3,548
    Wow. Searching the basement to find a lost post in a locked filing cabinet in a disused lavatory with a sign on it saying "Beware of the Leopard".

    Andreasng: As this post was SOOOO old, it was probably OK for you to start a new post.

    I believe the question is:

    "When underwater, how can I make the surface look like real water from underneath?"

    Some images of the water surface can be found here: http://tinyurl.com/84djjbo ... some of which I have posted below:

    [​IMG]

    This is not an easy task, but one, if it's solved, may be useful to many people.

    A challenge to the entrepreneur to get a package together for the Asset Store?
     
  7. andreasng

    andreasng

    New Member

    Joined:
    Aug 15, 2011
    Messages:
    5
    yeah i guess i could just start a new thread - on the other hand it's newer appreciated to have 10 threads with people wanting the same thing. HAHAHA

    Anyway... It ISSSSS and easy task. Unity team, and anyone with experience in shading would be able to "flip" the numbers for the water4 shader in no time.

    All I want is the already working reflection and refraction to work both above and below.
     
  8. Adam Buckner

    Adam Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Messages:
    3,548
    If you simply want the reflection for the water plane but from below, you can use two water planes:



    This was created in a few minutes by:
    • Creating a new stock Unity Terrain and sculpting it into a ring.
    • Adding a water plane and positioning it (demo shows both basic and pro water)
    • Duplicating the water plane and setting the transform.scale.y on the second plane to -1.0

    The underwater fog is a simple script:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Underwater : MonoBehaviour {
    5.     public float waterLevel;
    6.     public Transform waterPlane;    //  Testing
    7.     private bool isUnderwater;
    8.     private Color normalColor;
    9.     private Color underwaterColor;
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.         normalColor = new Color (0.5f, 0.5f, 0.5f, 0.5f);
    14.         underwaterColor = new Color (0.22f, 0.65f, 0.77f, 0.5f);
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update () {
    19.         if ((transform.position.y < waterLevel) != isUnderwater) {
    20.             isUnderwater = transform.position.y < waterLevel;
    21.             if (isUnderwater) SetUnderwater ();
    22.             if (!isUnderwater) SetNormal ();
    23.         }
    24.     }
    25.  
    26.     void SetNormal () {
    27.         RenderSettings.fogColor = normalColor;
    28.         RenderSettings.fogDensity = 0.01f;
    29.  
    30.         //  Testing
    31.         waterPlane.localScale = new Vector3 (waterPlane.localScale.x, 1.0f, waterPlane.localScale.z);
    32.     }
    33.  
    34.     void SetUnderwater () {
    35.         RenderSettings.fogColor = underwaterColor;
    36.         RenderSettings.fogDensity = 0.1f;
    37.  
    38.         //  Testing
    39.         waterPlane.localScale = new Vector3 (waterPlane.localScale.x, -1.0f, waterPlane.localScale.z);
    40.     }
    41. }
    42.  
    Out of curiosity I tested flipping a single water plane when under the water level, which worked as well, but I'm completely unclear if doing this has any value at all... I was just curious. You can delete the lines marked "Testing"
     
  9. Adam Buckner

    Adam Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Messages:
    3,548
    I saw a comment on YouTube re: this thread...

    First off, reply to the thread, not the YouTube clip please. YouTube is hosting the clip, but YouTube is not part of the Unity Forum.

    Please check your code, and don't forget to fill in all of the public data in the inspector. If the water plane is not triggering your fog, then most likely you have forgotten to set your water level value in the inspector.