You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

  1. using UnityEngine;
  2. public enum WaterQuality {
  3. High = 2,
  4. Medium = 1,
  5. Low = 0,
  6. }
  7. [ExecuteInEditMode]
  8. public class WaterBase : MonoBehaviour
  9. {
  10. public Material sharedMaterial;
  11. public WaterQuality waterQuality = WaterQuality.High;
  12. public bool edgeBlend = true;
  13. public void UpdateShader()
  14. {
  15. if(waterQuality > WaterQuality.Medium)
  16. sharedMaterial.shader.maximumLOD = 501;
  17. else if(waterQuality> WaterQuality.Low)
  18. sharedMaterial.shader.maximumLOD = 301;
  19. else
  20. sharedMaterial.shader.maximumLOD = 201;
  21. // If the system does not support depth textures (ie. NaCl), turn off edge bleeding,
  22. // as the shader will render everything as transparent if the depth texture is not valid.
  23. if (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth))
  24. edgeBlend = false;
  25. if(edgeBlend)
  26. {
  27. Shader.EnableKeyword("WATER_EDGEBLEND_ON");
  28. Shader.DisableKeyword("WATER_EDGEBLEND_OFF");
  29. // just to make sure (some peeps might forget to add a water tile to the patches)
  30. if (Camera.main)
  31. Camera.main.depthTextureMode |= DepthTextureMode.Depth;
  32. }
  33. else
  34. {
  35. Shader.EnableKeyword("WATER_EDGEBLEND_OFF");
  36. Shader.DisableKeyword("WATER_EDGEBLEND_ON");
  37. }
  38. }
  39. public void WaterTileBeingRendered (Transform tr, Camera currentCam)
  40. {
  41. if (currentCam && edgeBlend)
  42. currentCam.depthTextureMode |= DepthTextureMode.Depth;
  43. }
  44. public void Update ()
  45. {
  46. if(sharedMaterial)
  47. UpdateShader();
  48. }
  49. }