Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shader CG water reflection using pure shader and water splitting on chunks edge problem

Discussion in 'Shaders' started by yashak8, Dec 27, 2016.

  1. yashak8

    yashak8

    Joined:
    Nov 7, 2016
    Posts:
    3
    Hello guys,

    Have hope that my English will be clear enough.

    First of all I'm quite fresh in shaders. I took some time and start to getting nice results like I wanted but now I can't go much farther.

    Finding solution or any help with function that I should test/provide is very hard for now.

    First problem is water waves splitting on chunk edges:

    I made water waves by moving vertex in one axis but at the edge of chunk waves are mismatched. Wave height at beginning of chunk are not equal to wave at the end of chunk so water is splitting between them. It’s look like I should somehow inverse every second chunk but then it will rotate whole blocks in it so if there will be something else than water result will be wrong.

    upload_2016-12-27_16-3-13.png




    Second problem is water reflection.

    I generating whole world with one material ( because I want to have maximum performance) so I can’t use Unity script for reflections ( as I think and tried).

    My water reflections ( using GrabPass of course with ComputeGrabScreenPos and tex2Dproj with UNITY_PROJ_COORD) after long fight are so much better. Now reflection not moving with every axis with my camera but still getting wrong when I going like 2-3m above the water surfaces. After crossing some point in Y-axis reflections changing its orientation so they are not upside-down. When I looking to much down with camera there also a little issue.

    Maybe someone know what else need to be use to make reflection more stable on water surface.




    Here, near water surface looks almost good.

    upload_2016-12-27_16-4-15.png




    Little higher its look little bugged.

    upload_2016-12-27_16-4-55.png




    And here a little more above water.
    It just changing very quickly to this ( In code I don't check any positions or coords of anything that make change in reflection orientation)

    upload_2016-12-27_16-5-48.png



    Thanks for any help and directions that I should try.

    Best Regards,
     
    Last edited: Dec 27, 2016
  2. yashak8

    yashak8

    Joined:
    Nov 7, 2016
    Posts:
    3
    I did something more with water reflections but there's still same issue as above. I understand more but that's it.
    Im wonder what proper function should be used.

    There in one more thing ( weaving leaves splitting at chunk border) . Same think I had with water when I tried to make water waves by moving vertexes.
    Have anyone got idea how to do this correct when 1st block of leaves is in one chunk and 2nd block of leaves is in second chunk?

    upload_2017-2-1_18-24-14.png
     
  3. yashak8

    yashak8

    Joined:
    Nov 7, 2016
    Posts:
    3
    Hello again,

    After more and more attempts I didn't fix reflections.

    I using grabPass after drawing world then in next pass where the water is:

    o.GrabUV = ComputeGrabScreenPos(o.pos);

    and then I only calculate Y of water position and a camera pos

    i.GrabUV.y += _WorldSpaceCameraPos.y - i.position.y;

    then simply:

    reflTex = tex2Dproj(_GrabTexture,UNITY_PROJ_COORD(i.GrabUV));


    I thinking about calculate angle ( camera -> water) or something but I really don't have idea for now.

    Here is the problem. The more I look down then reflection of terrain is more streched.
    If terrain is far enough then I can look down little more.

    upload_2017-6-21_14-18-16.png


    PS: You see two reflections on those screens beacuse I actually using more than one pass with water.