Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASE] Calm Water

Discussion in 'Assets and Asset Store' started by Phantom_X, Jan 22, 2016.

  1. garyhaus

    garyhaus

    Joined:
    Dec 16, 2006
    Posts:
    601
    Can this be used with single pass VR? I haven't found or have ONE water asset that does....
     
  2. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Not yet, but I will have a look at it. I think realtime reflection will be a problem, but the rest should be doable.

    Regards
     
  3. BurtsJ811

    BurtsJ811

    Joined:
    Mar 7, 2017
    Posts:
    2
    Hello, thank you for this amazing shader, although I am currently having some issues with it. namely, anytime I put one of the shaders on a material, the object turns pink and I am thrown this error:

    Shader error in 'CalmWater/Calm Water [DX11]': invalid subscript '_ShadowCoord' at Assets/Calm Water/Shaders/CalmWater.cginc(270) (on d3d11)

    Compiling Vertex program with DIRECTIONAL SHADOWS_SHADOWMASK _DEPTHFOG_ON _DISTORTIONQUALITY_HIGH _FOAM_ON _REFLECTIONTYPE_MIXED
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP

    It occurs for all versions of the shader, The project started in Unity 5.6.0f3 but then got reverted back to 5.6.0f1, however even re importing a clean version of the package still results in this error.
     
  4. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Hi,
    I will need more information since I cannot reproduce the problem on 5.6.0f3 on a PC targeting PC.

    What platform are you targeting and are you developing on? Does the problem occurs in an empty project?

    When you say you do a reimport, do you delete all the folder and import the package again or right click on the folder and hit reimport?
     
  5. philc_uk

    philc_uk

    Joined:
    Jun 17, 2015
    Posts:
    85
  6. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
  7. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    812
    Hello Yan,

    Man, how should I go about expanding the specular light of the water shader? so instead of being narrow, it shows in a more wide area of the water when the camera is facing the sun.

    Regards,
    Carlos
     
  8. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Hey,
    This should be the smoothness parameter you have in the specular section.
     
  9. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    812
    Hello Yan,

    No, what I am talking is having the specular smoothness tight to look very shiny but have the light more spread. See the pictures in the first the specular is really tight and narrow, in the second picture the specular is tight but spread, that is what I want.

    Regards,
    Carlos ocean_TightSpecular.jpg ocean_WiderSpecular.png
     
  10. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    I see, the current lighting model is BlinnPhong and does not allow this kind of behavior. However I will investigate to see if I can find something better.
    regards
     
  11. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    812
    That would be awesome because that wide specular is what your wonderful water asset is missing to make it look really awesome. I have tested many water assets but I keep using yours because it is the best despite being the most simple asset to use and with great compatibility and results.

    Regards,
    Carlos
     
    Last edited: Jun 3, 2017
  12. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,830
    This looks promising. I have several other water systems, but none of them work with GlobalFog. Does this asset work properly with GlobalFog? I don't mean does this use GlobalFog for underwater effects. I have scenes that use GlobalFog to have a foggy atmosphere in the scene and the water needs to be affected by this so it looks properly fogged. Can Calm Water do that?
     
  13. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Hi, I understand what you mean, but unfortunately it doesn't and the reason is that global fog needs the objects to render to the depth buffer and if the water renders to the depth buffer what's beneath it will get culled and won't get rendered so you won't be able to see objects through the water and have distortion and all this good stuff.
     
  14. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    812
    Hey Yan,

    I have a question for you. I have been using the regular Unity linear fog with your water and it works as expected. Now yesterday I tried to use the Unity Exponential or Exponential Squared fog, and the water doesn't seem to affected by these fogs... Is there a place where I can change this? I remember a while back you told me about setting something in order to change this but I can't find the email.

    Regards,
    Carlos
     
  15. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    I use the macro from unity to make the fog work, every fog type is working for me. If one is working for you and others are not, maybe there is something wrong with you fog settings or there is a bug in unity.
     
  16. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    812
    What macro are you referring to?
     
  17. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
  18. jwilliamsen

    jwilliamsen

    Joined:
    Aug 8, 2010
    Posts:
    56
    Hi Yan,

    Is there any way I could use this for a flowing stream? Scrolling along the UV's as well as having the built-in x and y parameters? I tried using a scrolling UV script, but wasn't getting any expected results....

    Thanks :)
     
  19. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Hey!
    you will have to make your UV straight and then you can set the scrolling parameters to go only in one direction (X or Y). This way the ripples will follow the stream while still scroll.

    Right now I have the same normal map scroll in two opposite directions and you cannot control their direction independently. I would have to expose those values in the editor, not a big change, but I wanted to avoid having too much stuff in the editor to keep is as simple as possible.

    Now that I think about that it's true that you need those value to make a proper stream, otherwise you the stream will go both ways. So I will probably expose it in the next release.

    Cheers!
     
  20. jwilliamsen

    jwilliamsen

    Joined:
    Aug 8, 2010
    Posts:
    56
    Hey Yan,

    I managed to get it working with a script (woot!) - but it would be a nice feature to have as part of the shader. So, I hope you include it in a future version :)

    Thanks!
     
  21. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Good that you found a workaround for now, but it will definitely be in the next release.
     
  22. CubicleNinjas

    CubicleNinjas

    Joined:
    Apr 5, 2014
    Posts:
    15
    Everytime I turn off shadows on my directional light the edges and water loses its transaparency. I have the Camera Depth Mode script on the camera so not sure what I need to do to fix the problem. Here's a couple pics with shadows on and off and what happens. Is there a fix for this?
     

    Attached Files:

  23. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Humm are you on Unity 5.6 or up with Calm Water 1.6.4 ? I made a lot of changes to support the new lightmaping modes in this version and it is possible that there is a bug.
     
  24. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    524
    This is unity 5.5.0p3. Does it not work with this version? Because of unitys lightmapping were using this version for this project. We are currently using the latest calm water on the asset store.
     
  25. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    I'm using it with version Unity 5.5.1 right now and I can't reproduce it. Would you be able to send me a sample project reproducing the issue? Or try various lightmaping modes / rendering path to see if it's happening only in certain conditions.
     
  26. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    524
    So I did a lighting baking first and directional light is set to Mixed mode. Light baking mode is directional specular. Im using the Forward renderer in Linear mode. Also my camera has a post processing behaviour script on it. I did notice when I uncheck the post processing then when I hit play the transparency comes back. Is it maybe just the post processing overiding the camera depth script maybe?

    I'm also using this in VR with the oculus setup and it runs and looks great. Haven't tested single pass stereo only using multi pass.
     

    Attached Files:

  27. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    humm looks that way the post processing is disabling the depth texture needed for calm Water. Normaly you would get a small box on the camera saying "Info: renders Depth texture" now you don't that means the post processing is turning it off.

    try putting the Camera Depth Mode script after the post process to see if it helps
     
  28. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    524
    Ok so I added the camera depth mode after the post processing still doesn't work. Here's something even stranger with post processing and camera depth mode on the camera and with shadows set to soft or hard shadows the transparency comes back. Being its for VR I bake in all the shadows then turn shadows off when its all done so it doesn't take up anymore resources.

    I recreated my problem in the Island demo scene that calm water comes with. Turned on camera depth mode on the camera. Turned shadows off on the directional light. Then add in the post processing behaviour script and the post processing profile hit play and the transparency goes away.
     

    Attached Files:

  29. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Yes, post processing stack is completely disabling the depth texture unless you use something that needs it in the stack like depth of field or motion blur. Going through all the processing stack to find out what is doing this is kind of a too big task so instead you can to this workaround:

    Have one additional directional light that is affecting only the water in the culling mask. This light will have shadow on, but disable the shadow casting/receiving on the water plane. To get the proper result the water needs one realtime light anyway.
     
  30. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    524
    All I have is bloom and AA on nothing else is on. Even when I uncheck those 2 and hit play it still does the same thing so kinda weird if nothing is happing on the post processing side it still does that. I'll look into that using 1 light only for the water with shadows on if nothing else will work.
     
  31. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Last edited: Jul 28, 2017
  32. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    524
    Thanks for finding that out.
     
  33. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Hi, how is this shader performing on PC? Will this work on Xbox One?
     
  34. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Performance depends on the options that you choose and the nature of your game, but it's running on mobile so a PC should have no problem running it. Realtime reflection is the most expensive since it has to rerender you scene so if you already have a lot of draw calls in your game you would probably be better using cubemap reflection. As for Xbox one support I know that some users are using it on this platform. I'm not equipped to test is my self so I cannot guarantee that it's going to work, but if it's not I'm willing to collaborate with you to make it work free of charges.
     
  35. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    524
    What I did for reflections on VR is positioned the reflection probe best in the scene where I wanted the capture. Captured the 2k resolution in the probe. Then extracted those 6 images in Photoshop and then used those for a cubemap and then used that cubemap with calm water for a reflection in my scene that matches the surroundings. Realtime reflections with any water in VR I've seen just never come out right. Thanks for making the cubemap approach works best and runs really good also.
     
  36. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Yes you are right, realtime reflection doesn't work for VR, CubeMap with reflection probes like you did is the way to go.
     
  37. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    812
    This asset works on Xbox One and it is beautiful!
     
  38. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
  39. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    I modified the script to be able to change the reflection texture size (256, 128) for lodding. Are you planning to update it with such feature?
     
  40. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    If many people ask for it I will put it in, otherwise no.
     
  41. jasonoda

    jasonoda

    Joined:
    Sep 7, 2012
    Posts:
    67
    Hey Yan,

    I've been experiencing a 20 fps loss when activating the mirror reflection (60fps to 40fps). Is this to be expected? or is there perhaps something in my configurations I've implemented improperly? I'm using 5.6

    Thanks, great product!
    Jason
     
  42. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    I modified it a bit

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [ExecuteInEditMode]
    6. [RequireComponent(typeof(MeshRenderer))]
    7. public class MirrorReflection : MonoBehaviour
    8. {
    9.     public enum TextureSize
    10.     {
    11.         Low = 128,
    12.         High = 256,
    13.         Full = 0
    14.     }
    15.  
    16.     //private RenderTexture rt;
    17.     public LayerMask reflectionMask = -1;
    18.     [Tooltip("Color used instead of skybox if you choose to not render it.")]
    19.     public Color clearColor = Color.grey;
    20.     public bool reflectSkybox = true;
    21.     public bool m_DisablePixelLights = false;
    22.     [Tooltip("You won't be able to select objects in the scene when thi is active.")]
    23.     public bool UpdateSceneView = true;
    24.     public float clipPlaneOffset = 0.07F;
    25.  
    26.     public TextureSize ReflectionTextureSize;
    27.  
    28.     private String reflectionSampler = "_ReflectionTex";
    29.  
    30.  
    31.     Vector3 m_Oldpos;
    32.     Camera m_ReflectionCamera;
    33.     Material m_SharedMaterial;
    34.     Dictionary<Camera, bool> m_HelperCameras;
    35.  
    36.  
    37.     void OnEnable()
    38.     {
    39.         gameObject.layer = LayerMask.NameToLayer("Water");
    40.         setMaterial();
    41.     }
    42.  
    43.     void OnDisable()
    44.     {
    45.         if (m_ReflectionCamera != null)
    46.         {
    47. #if (UNITY_EDITOR)
    48.             DestroyImmediate(m_ReflectionCamera);
    49. #else
    50.             Destroy(m_ReflectionCamera);
    51. #endif
    52.         }
    53.     }
    54.  
    55.     void Start()
    56.     {
    57.         gameObject.layer = LayerMask.NameToLayer("Water");
    58.         setMaterial();
    59.     }
    60.  
    61.     public void setMaterial()
    62.     {
    63.         m_SharedMaterial = GetComponent<Renderer>().sharedMaterial;
    64.     }
    65.  
    66.     Camera CreateReflectionCameraFor(Camera cam)
    67.     {
    68.         String reflName = gameObject.name + "Reflection" + cam.name;
    69.         GameObject go = GameObject.Find(reflName);
    70.  
    71.         if (!go)
    72.         {
    73.             go = new GameObject(reflName, typeof(Camera));
    74.             go.hideFlags = HideFlags.HideAndDontSave;
    75.         }
    76.         if (!go.GetComponent(typeof(Camera)))
    77.         {
    78.             go.AddComponent(typeof(Camera));
    79.         }
    80.  
    81.         Camera reflectCamera = go.GetComponent<Camera>();
    82.  
    83.         reflectCamera.backgroundColor = clearColor;
    84.         reflectCamera.clearFlags = reflectSkybox ? CameraClearFlags.Skybox : CameraClearFlags.SolidColor;
    85.  
    86.         SetStandardCameraParameter(reflectCamera, reflectionMask);
    87.  
    88.         if (!reflectCamera.targetTexture)
    89.         {
    90.             reflectCamera.targetTexture = CreateTextureFor(cam);
    91.         }
    92.  
    93.         return reflectCamera;
    94.     }
    95.  
    96.     void SetStandardCameraParameter(Camera cam, LayerMask mask)
    97.     {
    98.         cam.cullingMask = mask & ~(1 << gameObject.layer);
    99.         cam.backgroundColor = Color.black;
    100.         cam.enabled = false;
    101.     }
    102.  
    103.  
    104.     RenderTexture CreateTextureFor(Camera cam)
    105.     {
    106.         //RenderTexture rt = new RenderTexture(Mathf.FloorToInt(cam.pixelWidth * 0.5F), Mathf.FloorToInt(cam.pixelHeight * 0.5F), 24);
    107.  
    108.  
    109.         RenderTexture rt = new RenderTexture((int)ReflectionTextureSize > 0 ? (int)ReflectionTextureSize : Mathf.FloorToInt(cam.pixelWidth * 0.5F),
    110.             (int)ReflectionTextureSize > 0 ? (int)ReflectionTextureSize : Mathf.FloorToInt(cam.pixelWidth * 0.5F), 16);
    111.         rt.hideFlags = HideFlags.DontSave;
    112.         return rt;
    113.     }
    114.  
    115.  
    116.     public void RenderHelpCameras(Camera currentCam)
    117.     {
    118.         if (null == m_HelperCameras)
    119.         {
    120.             m_HelperCameras = new Dictionary<Camera, bool>();
    121.         }
    122.  
    123.         if (!m_HelperCameras.ContainsKey(currentCam))
    124.         {
    125.             m_HelperCameras.Add(currentCam, false);
    126.         }
    127.  
    128.         if (m_HelperCameras[currentCam] && !UpdateSceneView)
    129.         {
    130.             return;
    131.         }
    132.  
    133.         if (!m_ReflectionCamera)
    134.         {
    135.             m_ReflectionCamera = CreateReflectionCameraFor(currentCam);
    136.         }
    137.  
    138.         RenderReflectionFor(currentCam, m_ReflectionCamera);
    139.  
    140.         m_HelperCameras[currentCam] = true;
    141.     }
    142.  
    143.  
    144.     public void LateUpdate()
    145.     {
    146.         /*
    147.         if (null != m_HelperCameras)
    148.         {
    149.             m_HelperCameras.Clear();
    150.         }
    151.         */
    152.     }
    153.  
    154.  
    155.     public void WaterTileBeingRendered(Transform tr, Camera currentCam)
    156.     {
    157.         RenderHelpCameras(currentCam);
    158.  
    159.         if (m_ReflectionCamera && m_SharedMaterial)
    160.         {
    161.             m_SharedMaterial.SetTexture(reflectionSampler, m_ReflectionCamera.targetTexture);
    162.         }
    163.     }
    164.  
    165.  
    166.     public void OnWillRenderObject()
    167.     {
    168.         WaterTileBeingRendered(transform, Camera.current);
    169.     }
    170.  
    171.  
    172.     void RenderReflectionFor(Camera cam, Camera reflectCamera)
    173.     {
    174.         if (!reflectCamera)
    175.         {
    176.             return;
    177.         }
    178.  
    179.         if (m_SharedMaterial && !m_SharedMaterial.HasProperty(reflectionSampler))
    180.         {
    181.             return;
    182.         }
    183.  
    184.         // Optionally disable pixel lights for reflection
    185.         int oldPixelLightCount = QualitySettings.pixelLightCount;
    186.         if (m_DisablePixelLights)
    187.         {
    188.             QualitySettings.pixelLightCount = 0;
    189.         }
    190.  
    191.         reflectCamera.cullingMask = reflectionMask & ~(1 << gameObject.layer);
    192.         //reflectCamera.cullingMask = ~(1<<4) & reflectionMask.value; // never render water layer
    193.  
    194.         SaneCameraSettings(reflectCamera);
    195.  
    196.         reflectCamera.backgroundColor = clearColor;
    197.         reflectCamera.clearFlags = reflectSkybox ? CameraClearFlags.Skybox : CameraClearFlags.SolidColor;
    198.         if (reflectSkybox)
    199.         {
    200.             if (cam.gameObject.GetComponent(typeof(Skybox)))
    201.             {
    202.                 Skybox sb = (Skybox)reflectCamera.gameObject.GetComponent(typeof(Skybox));
    203.                 if (!sb)
    204.                 {
    205.                     sb = (Skybox)reflectCamera.gameObject.AddComponent(typeof(Skybox));
    206.                 }
    207.                 sb.material = ((Skybox)cam.GetComponent(typeof(Skybox))).material;
    208.             }
    209.         }
    210.  
    211.         GL.invertCulling = true;
    212.  
    213.         Transform reflectiveSurface = transform; //waterHeight;
    214.  
    215.         Vector3 eulerA = cam.transform.eulerAngles;
    216.  
    217.         reflectCamera.transform.eulerAngles = new Vector3(-eulerA.x, eulerA.y, eulerA.z);
    218.         reflectCamera.transform.position = cam.transform.position;
    219.  
    220.         Vector3 pos = reflectiveSurface.transform.position;
    221.         pos.y = reflectiveSurface.position.y;
    222.         Vector3 normal = reflectiveSurface.transform.up;
    223.         float d = -Vector3.Dot(normal, pos) - clipPlaneOffset;
    224.         Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);
    225.  
    226.         Matrix4x4 reflection = Matrix4x4.zero;
    227.         reflection = CalculateReflectionMatrix(reflection, reflectionPlane);
    228.         m_Oldpos = cam.transform.position;
    229.         Vector3 newpos = reflection.MultiplyPoint(m_Oldpos);
    230.  
    231.         reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;
    232.  
    233.         Vector4 clipPlane = CameraSpacePlane(reflectCamera, pos, normal, 1.0f);
    234.  
    235.         Matrix4x4 projection = cam.projectionMatrix;
    236.         projection = CalculateObliqueMatrix(projection, clipPlane);
    237.         reflectCamera.projectionMatrix = projection;
    238.  
    239.         reflectCamera.transform.position = newpos;
    240.         Vector3 euler = cam.transform.eulerAngles;
    241.         reflectCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
    242.  
    243.         reflectCamera.Render();
    244.  
    245.         GL.invertCulling = false;
    246.  
    247.         // Restore pixel light count
    248.         if (m_DisablePixelLights)
    249.         {
    250.             QualitySettings.pixelLightCount = oldPixelLightCount;
    251.         }
    252.     }
    253.  
    254.  
    255.     void SaneCameraSettings(Camera helperCam)
    256.     {
    257.         helperCam.depthTextureMode = DepthTextureMode.None;
    258.         helperCam.backgroundColor = Color.black;
    259.         helperCam.clearFlags = CameraClearFlags.SolidColor;
    260.         helperCam.renderingPath = RenderingPath.Forward;
    261.     }
    262.  
    263.  
    264.     static Matrix4x4 CalculateObliqueMatrix(Matrix4x4 projection, Vector4 clipPlane)
    265.     {
    266.         Vector4 q = projection.inverse * new Vector4(
    267.             Sgn(clipPlane.x),
    268.             Sgn(clipPlane.y),
    269.             1.0F,
    270.             1.0F
    271.         );
    272.         Vector4 c = clipPlane * (2.0F / (Vector4.Dot(clipPlane, q)));
    273.         // third row = clip plane - fourth row
    274.         projection[2] = c.x - projection[3];
    275.         projection[6] = c.y - projection[7];
    276.         projection[10] = c.z - projection[11];
    277.         projection[14] = c.w - projection[15];
    278.  
    279.         return projection;
    280.     }
    281.  
    282.  
    283.     static Matrix4x4 CalculateReflectionMatrix(Matrix4x4 reflectionMat, Vector4 plane)
    284.     {
    285.         reflectionMat.m00 = (1.0F - 2.0F * plane[0] * plane[0]);
    286.         reflectionMat.m01 = (-2.0F * plane[0] * plane[1]);
    287.         reflectionMat.m02 = (-2.0F * plane[0] * plane[2]);
    288.         reflectionMat.m03 = (-2.0F * plane[3] * plane[0]);
    289.  
    290.         reflectionMat.m10 = (-2.0F * plane[1] * plane[0]);
    291.         reflectionMat.m11 = (1.0F - 2.0F * plane[1] * plane[1]);
    292.         reflectionMat.m12 = (-2.0F * plane[1] * plane[2]);
    293.         reflectionMat.m13 = (-2.0F * plane[3] * plane[1]);
    294.  
    295.         reflectionMat.m20 = (-2.0F * plane[2] * plane[0]);
    296.         reflectionMat.m21 = (-2.0F * plane[2] * plane[1]);
    297.         reflectionMat.m22 = (1.0F - 2.0F * plane[2] * plane[2]);
    298.         reflectionMat.m23 = (-2.0F * plane[3] * plane[2]);
    299.  
    300.         reflectionMat.m30 = 0.0F;
    301.         reflectionMat.m31 = 0.0F;
    302.         reflectionMat.m32 = 0.0F;
    303.         reflectionMat.m33 = 1.0F;
    304.  
    305.         return reflectionMat;
    306.     }
    307.  
    308.  
    309.     static float Sgn(float a)
    310.     {
    311.         if (a > 0.0F)
    312.         {
    313.             return 1.0F;
    314.         }
    315.         if (a < 0.0F)
    316.         {
    317.             return -1.0F;
    318.         }
    319.         return 0.0F;
    320.     }
    321.  
    322.  
    323.     Vector4 CameraSpacePlane(Camera cam, Vector3 pos, Vector3 normal, float sideSign)
    324.     {
    325.         Vector3 offsetPos = pos + normal * clipPlaneOffset;
    326.         Matrix4x4 m = cam.worldToCameraMatrix;
    327.         Vector3 cpos = m.MultiplyPoint(offsetPos);
    328.         Vector3 cnormal = m.MultiplyVector(normal).normalized * sideSign;
    329.  
    330.         return new Vector4(cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos, cnormal));
    331.     }
    332. }
    333.  
     
  43. jasonoda

    jasonoda

    Joined:
    Sep 7, 2012
    Posts:
    67
    Hey Yan,

    Still getting the 20fps drop off even at the low setting. I reimported just to make sure I'm updated, but still pretty slow. Is this just to be expected? or could there be another problem? Turing off the updateSceneView makes the 20 come back, if that info helps at all.
     
  44. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Hi,
    Yes it is expected to be heavy. The effect has to rerender the scene from a different projection. What you can do to make it faster is to make use of the reflectionMask option and mixed reflection mode. Instead of rerendering everything you can only render big objetcs or moving objects in the realtime reflection and use the cubemap for the rest.

    the updateSceneView was really meant for an older version of unity where due to a unity bug you would not be able to select objects while the effect was running. So I added this option do disable the affect in edit mode. If not checked the reflection is not updating in realtime that's why you get your frame rate back.
     
  45. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    What if I want to use reflection probes to generate the cubemap, is it possbile?
     
  46. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Yes, reflection probes generate a cube map that you can use with the shader.

    If you talk about realtime reflection probles, you can try using this trick: http://twiik.net/articles/realtime-reflections-in-unity-5
    But realtime reflection probes still re renders the scene from different angles every frame, so I'm guessing it won't really increase the performance.
     
  47. TacoPlayStudio

    TacoPlayStudio

    Joined:
    Jan 12, 2013
    Posts:
    187
    Hello my friend. Have you done any tests with ENVIRO? I wonder if they work well together.:) greetings
     
  48. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    272
    Hi,
    I did not test it, but at first sight, I'm guessing that the only thing in ENVIRO that might not fully work with calm water is their fog.
    thanks!
     
  49. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    Indeed no, I was playing around with reflection probes and shaders. Basically with cubemap is ok as long as you don't walk, am I right?
     
  50. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,002
    Does this water provide a method to add buoyancy to objects, so they float on top of the water?
     
unityunity