Search Unity

The Community Ocean Shader (Open Source) Unity 5

Discussion in 'Shaders' started by laurent-clave, Nov 30, 2015.

  1. messij7

    messij7

    Joined:
    Jan 31, 2018
    Posts:
    4
    Hello everybody, I love the work you've done with this asset and I would like to use the shader in my project.
    I already have my buoyancy physic and my ocean wave script working pretty well.
    So, I was looking for a shader for him (I don't know anything about shaders).

    The problem is that my ocean mesh is moving and rotating with my camera ( to optimise triangles ) and because of that the texture also moves and rotate with the camera what is very weird.

    Is there an easy way to avoid this ?
    I try to change some parameters in the shader but with no results.

    Thanks.
     
  2. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hello.

    I think you should apply worldUV map on the shader to avoid this.

    Search for //World UV's in the shader and replace the appropriate variables.
     
  3. messij7

    messij7

    Joined:
    Jan 31, 2018
    Posts:
    4
    Thanks elias_t for your help.
    I found 2 commented sections with //Word UV's title in the shader under LOD5 and 8.

    In LOD8 these lines are commented:
    Code (CSharp):
    1. //World UV's
    2. o.worldPos = mul(_Object2World, v.vertex).xyz;
    3. o.bumpuv.xyzw = o.worldPos.xzxz  * _WaveTiling*0.005  + frac(_Time.xxxx * _WaveDirection);
    4. float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
    5. o.buv = float4(worldPos.x + _CosTime.x * 0.2, worldPos.z + _SinTime.x *0.3 ,worldPos.x + _CosTime.y * 0.04, worldPos.z + o.bumpTexCoord.w )*0.05;
    But it Only Work when I uncomment the 2 last ones:
    Code (CSharp):
    1. float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
    2. o.buv = float4(worldPos.x + _CosTime.x * 0.2, worldPos.z + _SinTime.x *0.3 ,worldPos.x + _CosTime.y * 0.04, worldPos.z + o.bumpTexCoord.w )*0.05;
    With this the water texture stay fix but the foam and speculation light continue to move. I had to do the same trick with them but I don't know how.

    And in LOD5, uncomment the lines :
    Code (CSharp):
    1. //World UV's
    2.                 o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;  
    3.                 o.bumpuv.xyzw = o.worldPos.xzxz  * _WaveTiling*0.005  + frac(_Time.xxxx * _WaveDirection);
    Did do nothing.

    Unfortunately my shader knowledge is very low ( something I have to learn ... ) and can't find any solutions to go further.
     
  4. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Let me make some modifications and I will sent you a shader in a pm.
     
  5. messij7

    messij7

    Joined:
    Jan 31, 2018
    Posts:
    4
    Thanks for you help.
    I starting to learn about shader in unity and I have found kind of a solution.
    I've make a simple texture shader to train my self.
    I fisrt calculate the world position like this in vert function:
    Code (CSharp):
    1. o.worldPos = mul(unity_ObjectToWorld, v.vertex)
    Then use it with xz coordinates (take me a lot of time to understand I have to use xz coordinates ...) like this with the main texture in the frag function:
    Code (CSharp):
    1. col = tex2D(_MainTex, i.worldPos.xz)
    I have to learn more about shaders to apply this to the community Ocean shader.
     
    elias_t likes this.
  6. messij7

    messij7

    Joined:
    Jan 31, 2018
    Posts:
    4
    Ok I find a solution with the Ocean Community Shader but not completly ...
    I stoped the textures to rotate and move with my mesh by calculating a world position:
    Code (CSharp):
    1. float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
    And apply it to the o.buv:
    Code (CSharp):
    1. o.buv = float4(worldPos.x + _CosTime.x * 0.2, worldPos.z + _SinTime.x * 0.3 ,worldPos.x + _CosTime.y * 0.04, worldPos.z + o.bumpTexCoord.w ) * 0.05;
    Unfortunately the bumps and foam are no longer sliding a the surface ( even with the cos and sin calculation )
    And the last thing I have to fix is the Specularity that is always rotating with my mesh so fix at screen.
    I try to change the line:
    Code (CSharp):
    1. o.lightDir = mul(rotation, half3(_SunDir.xyz));
    by:
    Code (CSharp):
    1. o.lightDir = half3(_SunDir.xyz);
    But with that, the specular effect just disepear and I don't know how to manage this.
    I'm close to my goal, If anyone have any idea thanks.
     
  7. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    anyone was able to fix the shoreline? I haven't had one for over a year, since I don't even remember which unity version.
     
  8. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
  9. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    yeah i have, but we are working on mobile and with the community ocean shader. That paper requires a full new system that I would be happy to pay for. Can you develop it? Otherwise, it's out of scope on this thread. The current system is perfect but it broke with unity updates. It had shore lines already implemented. Just nobody seems to know how to fix them on the newer version of unity.
     
    Last edited: Feb 17, 2021
  10. NorthDevNet

    NorthDevNet

    Joined:
    Mar 1, 2021
    Posts:
    1
    Hey guys! Awesome implementation. I had two short questions:

    1. It's open source and the license states you can do whatever but I wanted to be 100% sure this can be freely used in a commercial project.
    2. What is the part of the shader code responsible for trail foam? The foam left behind as you move around.
    Thanks!
     
  11. bangoo

    bangoo

    Joined:
    Apr 25, 2015
    Posts:
    12
    Is it possible to add endless underwater to the library somehow?
     
  12. Roman_Keivan

    Roman_Keivan

    Joined:
    May 31, 2019
    Posts:
    22
    Hi community, I understand the old branch. Can anyone know if it will work on openGL 3.0 and Vulkan? I'm doing a project on google cardboard.
     
    p33t likes this.
  13. Litwin

    Litwin

    Joined:
    Aug 15, 2013
    Posts:
    70
    Is there a version adapted for URP?
     
    p33t likes this.