├── Assets ├── BoyantObject.prefab ├── BoyantObject.prefab.meta ├── Grass&Rock.psd ├── Grass&Rock.psd.meta ├── MouseLook.cs ├── MouseLook.cs.meta ├── New Terrain.asset ├── New Terrain.asset.meta ├── Ocean Sources.meta ├── Ocean Sources │ ├── Boyancy.js │ ├── Boyancy.js.meta │ ├── Ocean Cubemap.cubemap │ ├── Ocean Cubemap.cubemap.meta │ ├── Ocean Material.mat │ ├── Ocean Material.mat.meta │ ├── Ocean foam.tif │ ├── Ocean foam.tif.meta │ ├── Ocean.js │ ├── Ocean.js.meta │ ├── Ocean.shader │ └── Ocean.shader.meta ├── Ocean.prefab ├── Ocean.prefab.meta ├── Plugins.meta ├── Plugins │ ├── CameraHelper.cs │ ├── CameraHelper.cs.meta │ ├── Exocortex_FFT.meta │ ├── Exocortex_FFT │ │ ├── Complex.cs │ │ ├── Complex.cs.meta │ │ ├── ComplexArray.cs │ │ ├── ComplexArray.cs.meta │ │ ├── ComplexF.cs │ │ ├── ComplexF.cs.meta │ │ ├── ComplexMath.cs │ │ ├── ComplexMath.cs.meta │ │ ├── ComplexStats.cs │ │ ├── ComplexStats.cs.meta │ │ ├── Fourier.cs │ │ ├── Fourier.cs.meta │ │ ├── FourierDirection.cs │ │ └── FourierDirection.cs.meta │ ├── WaterPostEffect.cs │ └── WaterPostEffect.cs.meta ├── Pro Standard Assets.meta ├── Pro Standard Assets │ ├── Glass Refraction.meta │ ├── Glass Refraction │ │ ├── FX-Refractive.mat │ │ ├── FX-Refractive.mat.meta │ │ ├── Glass-Stained-BumpDistort.shader │ │ ├── Glass-Stained-BumpDistort.shader.meta │ │ ├── Glass-Stained-BumpSpecDistort.shader │ │ ├── Glass-Stained-BumpSpecDistort.shader.meta │ │ ├── glass.tif │ │ ├── glass.tif.meta │ │ ├── glassbump.tif │ │ └── glassbump.tif.meta │ ├── Image Based.meta │ ├── Image Based │ │ ├── BlurEffect.cs │ │ ├── BlurEffect.cs.meta │ │ ├── ColorCorrectionEffect.cs │ │ ├── ColorCorrectionEffect.cs.meta │ │ ├── ColorCorrectionEffect.shader │ │ ├── ColorCorrectionEffect.shader.meta │ │ ├── Contrast Stretch.meta │ │ ├── Contrast Stretch │ │ │ ├── Adaptation.shader │ │ │ ├── Adaptation.shader.meta │ │ │ ├── Apply.shader │ │ │ ├── Apply.shader.meta │ │ │ ├── ContrastStretchEffect.cs │ │ │ ├── ContrastStretchEffect.cs.meta │ │ │ ├── Luminance.shader │ │ │ ├── Luminance.shader.meta │ │ │ ├── MinMaxReduction.shader │ │ │ └── MinMaxReduction.shader.meta │ │ ├── EdgeDetectEffect.cs │ │ ├── EdgeDetectEffect.cs.meta │ │ ├── EdgeDetectX.shader │ │ ├── EdgeDetectX.shader.meta │ │ ├── GlowEffect.cs │ │ ├── GlowEffect.cs.meta │ │ ├── GlowEffectDownsample.shader │ │ ├── GlowEffectDownsample.shader.meta │ │ ├── GrayscaleEffect.cs │ │ ├── GrayscaleEffect.cs.meta │ │ ├── GrayscaleEffect.shader │ │ ├── GrayscaleEffect.shader.meta │ │ ├── ImageEffectBase.cs │ │ ├── ImageEffectBase.cs.meta │ │ ├── ImageEffects.cs │ │ ├── ImageEffects.cs.meta │ │ ├── MotionBlur.cs │ │ ├── MotionBlur.cs.meta │ │ ├── MotionBlur.shader │ │ ├── MotionBlur.shader.meta │ │ ├── NoiseEffect.cs │ │ ├── NoiseEffect.cs.meta │ │ ├── NoiseEffectGrain.png │ │ ├── NoiseEffectGrain.png.meta │ │ ├── NoiseEffectScratch.png │ │ ├── NoiseEffectScratch.png.meta │ │ ├── NoiseEffectShaderRGB.shader │ │ ├── NoiseEffectShaderRGB.shader.meta │ │ ├── NoiseEffectShaderYUV.shader │ │ ├── NoiseEffectShaderYUV.shader.meta │ │ ├── SepiaToneEffect.cs │ │ ├── SepiaToneEffect.cs.meta │ │ ├── SepiaToneEffect.shader │ │ ├── SepiaToneEffect.shader.meta │ │ ├── TwirlEffect.cs │ │ ├── TwirlEffect.cs.meta │ │ ├── TwirlEffect.shader │ │ ├── TwirlEffect.shader.meta │ │ ├── VortexEffect.cs │ │ ├── VortexEffect.cs.meta │ │ ├── VortexEffect.shader │ │ ├── VortexEffect.shader.meta │ │ ├── color correction ramp.png │ │ ├── color correction ramp.png.meta │ │ ├── grayscale ramp.png │ │ └── grayscale ramp.png.meta │ ├── Samples.unity │ ├── Samples.unity.meta │ ├── Water.meta │ └── Water │ │ ├── Daylight Water.prefab │ │ ├── Daylight Water.prefab.meta │ │ ├── Nighttime Water.prefab │ │ ├── Nighttime Water.prefab.meta │ │ ├── Sources.meta │ │ └── Sources │ │ ├── Daylight Water.mat │ │ ├── Daylight Water.mat.meta │ │ ├── FX-Water.shader │ │ ├── FX-Water.shader.meta │ │ ├── Nighttime Water.mat │ │ ├── Nighttime Water.mat.meta │ │ ├── Water Fresnel.psd │ │ ├── Water Fresnel.psd.meta │ │ ├── Water.cs │ │ └── Water.cs.meta ├── Resources.meta ├── Resources │ ├── Ocean.meta │ └── Ocean │ │ ├── Bump.png │ │ ├── Bump.png.meta │ │ ├── DeepWaterBelow.shader │ │ ├── DeepWaterBelow.shader.meta │ │ ├── Foam.tif │ │ ├── Foam.tif.meta │ │ ├── Fresnel.psd │ │ ├── Fresnel.psd.meta │ │ ├── OceanReflectionRefraction.shader │ │ ├── OceanReflectionRefraction.shader.meta │ │ ├── WaterComposition.shader │ │ ├── WaterComposition.shader.meta │ │ ├── WaterHeight.shader │ │ └── WaterHeight.shader.meta ├── Skyboxes.meta ├── Skyboxes │ ├── Source Images.meta │ ├── Source Images │ │ ├── Sunset Back.jpg │ │ ├── Sunset Back.jpg.meta │ │ ├── Sunset Down.jpg │ │ ├── Sunset Down.jpg.meta │ │ ├── Sunset Front.jpg │ │ ├── Sunset Front.jpg.meta │ │ ├── Sunset Left.jpg │ │ ├── Sunset Left.jpg.meta │ │ ├── Sunset Right.jpg │ │ ├── Sunset Right.jpg.meta │ │ ├── Sunset Up.jpg │ │ └── Sunset Up.jpg.meta │ ├── Sunset.mat │ └── Sunset.mat.meta ├── Trees Ambient-Occlusion.meta ├── Trees Ambient-Occlusion │ ├── Palm.meta │ └── Palm │ │ ├── Materials.meta │ │ ├── Materials │ │ ├── palmbark.mat │ │ ├── palmbark.mat.meta │ │ ├── palmbranch.mat │ │ └── palmbranch.mat.meta │ │ ├── Palm.fbx │ │ ├── Palm.fbx.meta │ │ ├── PalmBark.psd │ │ ├── PalmBark.psd.meta │ │ ├── PalmBranch.psd │ │ └── PalmBranch.psd.meta ├── scene.unity └── scene.unity.meta ├── Library ├── AudioManager.asset ├── BuildSettings.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── EditorUserBuildSettings.asset ├── InputManager.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset └── README.txt /Assets/BoyantObject.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/BoyantObject.prefab -------------------------------------------------------------------------------- /Assets/BoyantObject.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 7169d1a2293584210833f4a8217e26d6 3 | -------------------------------------------------------------------------------- /Assets/Grass&Rock.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Grass&Rock.psd -------------------------------------------------------------------------------- /Assets/Grass&Rock.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 976ed14a3e5344f88862db416660cbf5 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 0 28 | -------------------------------------------------------------------------------- /Assets/MouseLook.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | /// MouseLook rotates the transform based on the mouse delta. 5 | /// Minimum and Maximum values can be used to constrain the possible rotation 6 | 7 | /// To make an FPS style character: 8 | /// - Create a capsule. 9 | /// - Add a rigid body to the capsule 10 | /// - Add the MouseLook script to the capsule. 11 | /// -> Set the mouse look to use LookX. (You want to only turn character but not tilt it) 12 | /// - Add FPSWalker script to the capsule 13 | 14 | /// - Create a camera. Make the camera a child of the capsule. Reset it's transform. 15 | /// - Add a MouseLook script to the camera. 16 | /// -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.) 17 | [AddComponentMenu("Camera-Control/Mouse Look")] 18 | public class MouseLook : MonoBehaviour { 19 | 20 | public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 } 21 | public RotationAxes axes = RotationAxes.MouseXAndY; 22 | public float sensitivityX = 15F; 23 | public float sensitivityY = 15F; 24 | 25 | public float minimumX = -360F; 26 | public float maximumX = 360F; 27 | 28 | public float minimumY = -60F; 29 | public float maximumY = 60F; 30 | 31 | float rotationX = 0F; 32 | float rotationY = 0F; 33 | 34 | Quaternion originalRotation; 35 | 36 | void OnGUI() 37 | { 38 | GUI.Label(new Rect(20, Screen.height-30, 500, 20), "Hold RMB or LMB to activate camera control. WASD for movement, LShift for speedboost"); 39 | } 40 | 41 | void Update () 42 | { 43 | if (!Input.GetMouseButton(1) && !Input.GetMouseButton(0)) 44 | return; 45 | 46 | if (axes == RotationAxes.MouseXAndY) 47 | { 48 | // Read the mouse input axis 49 | rotationX += Input.GetAxis("Mouse X") * sensitivityX; 50 | rotationY += Input.GetAxis("Mouse Y") * sensitivityY; 51 | 52 | rotationX = ClampAngle (rotationX, minimumX, maximumX); 53 | rotationY = ClampAngle (rotationY, minimumY, maximumY); 54 | 55 | Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up); 56 | Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left); 57 | 58 | transform.localRotation = originalRotation * xQuaternion * yQuaternion; 59 | } 60 | else if (axes == RotationAxes.MouseX) 61 | { 62 | rotationX += Input.GetAxis("Mouse X") * sensitivityX; 63 | rotationX = ClampAngle (rotationX, minimumX, maximumX); 64 | 65 | Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up); 66 | transform.localRotation = originalRotation * xQuaternion; 67 | } 68 | else 69 | { 70 | rotationY += Input.GetAxis("Mouse Y") * sensitivityY; 71 | rotationY = ClampAngle (rotationY, minimumY, maximumY); 72 | 73 | Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left); 74 | transform.localRotation = originalRotation * yQuaternion; 75 | } 76 | 77 | float multiplier = 1.0f; 78 | 79 | if (Input.GetKey(KeyCode.LeftShift)) 80 | multiplier = 5.0f; 81 | 82 | Vector3 pos = transform.position; 83 | 84 | pos += (transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")) * Time.deltaTime * 50.0f * multiplier; 85 | 86 | transform.position = pos; 87 | } 88 | 89 | void Start () 90 | { 91 | // Make the rigid body not change rotation 92 | if (rigidbody) 93 | rigidbody.freezeRotation = true; 94 | originalRotation = transform.localRotation; 95 | } 96 | 97 | public static float ClampAngle (float angle, float min, float max) 98 | { 99 | if (angle < -360F) 100 | angle += 360F; 101 | if (angle > 360F) 102 | angle -= 360F; 103 | return Mathf.Clamp (angle, min, max); 104 | } 105 | } -------------------------------------------------------------------------------- /Assets/MouseLook.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: fc7da416789e14863a22739f9426cb2a 3 | -------------------------------------------------------------------------------- /Assets/New Terrain.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/New Terrain.asset -------------------------------------------------------------------------------- /Assets/New Terrain.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 0e5ee247734904b11b6afb62223a715b 3 | -------------------------------------------------------------------------------- /Assets/Ocean Sources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 3014b3968663a48d9be6744ee541cc54 3 | -------------------------------------------------------------------------------- /Assets/Ocean Sources/Boyancy.js: -------------------------------------------------------------------------------- 1 | 2 | var ocean : Ocean; 3 | // Water plane at y = 0 4 | private var mag = 1.0; 5 | 6 | private var ypos = 0.0; 7 | private var blobs : Array; 8 | private var ax = 2.0; 9 | private var ay = 2.0; 10 | 11 | private var dampCoeff = .2; 12 | 13 | private var engine = false; 14 | 15 | function Start () { 16 | 17 | // mag = rigidbody.mass / (ax * ay) * 10; 18 | rigidbody.centerOfMass = Vector3 (0.0, -0.5, 0.0); 19 | 20 | var bounds = GetComponent("MeshCollider").mesh.bounds.size; 21 | var length = bounds.z; 22 | var width = bounds.x; 23 | 24 | blobs = new Array(); 25 | blobs.length = ax * ay; 26 | var i = 0; 27 | xstep = 1.0 / (ax-1); 28 | ystep = 1.0 / (ay-1); 29 | 30 | var point; 31 | var velocity; 32 | for (x=0;x 0.0f) return 1.0f; 9 | if (a < 0.0f) return -1.0f; 10 | return 0.0f; 11 | } 12 | 13 | public static void CalculateObliqueMatrix (ref Matrix4x4 projection, Vector4 clipPlane) 14 | { 15 | Vector4 q = projection.inverse * new Vector4( 16 | sgn(clipPlane.x), 17 | sgn(clipPlane.y), 18 | 1.0f, 19 | 1.0f 20 | ); 21 | Vector4 c = clipPlane * (2.0F / (Vector4.Dot (clipPlane, q))); 22 | // third row = clip plane - fourth row 23 | projection[2] = c.x - projection[3]; 24 | projection[6] = c.y - projection[7]; 25 | projection[10] = c.z - projection[11]; 26 | projection[14] = c.w - projection[15]; 27 | } 28 | 29 | public static Vector4 CameraSpacePlane (Camera cam, Vector3 pos, Vector3 normal, float sideSign) 30 | { 31 | Vector3 offsetPos = pos + normal * 0.02f;//m_ClipPlaneOffset 32 | Matrix4x4 m = cam.worldToCameraMatrix; 33 | Vector3 cpos = m.MultiplyPoint(offsetPos); 34 | Vector3 cnormal = m.MultiplyVector( normal ).normalized * sideSign; 35 | return new Vector4( cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos,cnormal) ); 36 | } 37 | 38 | public static void CalculateReflectionMatrix (ref Matrix4x4 reflectionMat, Vector4 plane) 39 | { 40 | reflectionMat.m00 = (1F - 2F*plane[0]*plane[0]); 41 | reflectionMat.m01 = ( - 2F*plane[0]*plane[1]); 42 | reflectionMat.m02 = ( - 2F*plane[0]*plane[2]); 43 | reflectionMat.m03 = ( - 2F*plane[3]*plane[0]); 44 | 45 | reflectionMat.m10 = ( - 2F*plane[1]*plane[0]); 46 | reflectionMat.m11 = (1F - 2F*plane[1]*plane[1]); 47 | reflectionMat.m12 = ( - 2F*plane[1]*plane[2]); 48 | reflectionMat.m13 = ( - 2F*plane[3]*plane[1]); 49 | 50 | reflectionMat.m20 = ( - 2F*plane[2]*plane[0]); 51 | reflectionMat.m21 = ( - 2F*plane[2]*plane[1]); 52 | reflectionMat.m22 = (1F - 2F*plane[2]*plane[2]); 53 | reflectionMat.m23 = ( - 2F*plane[3]*plane[2]); 54 | 55 | reflectionMat.m30 = 0F; 56 | reflectionMat.m31 = 0F; 57 | reflectionMat.m32 = 0F; 58 | reflectionMat.m33 = 1F; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Assets/Plugins/CameraHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 186df9be9990d4569a40f2f9c3e18812 3 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 89959934cf4d542909c09c52a77d6839 3 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/Complex.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Plugins/Exocortex_FFT/Complex.cs -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/Complex.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 2c37f37a733bc455e984c80ac600c0b3 3 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/ComplexArray.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: b77730082c33c4d63a56b84c92ece031 3 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/ComplexF.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Plugins/Exocortex_FFT/ComplexF.cs -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/ComplexF.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: cdee6b31ddea345f5a80d175f05231a4 3 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/ComplexMath.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD Licence: 3 | * Copyright (c) 2001, 2002 Ben Houston [ ben@exocortex.org ] 4 | * Exocortex Technologies [ www.exocortex.org ] 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 29 | * DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Diagnostics; 34 | 35 | 36 | // Comments? Questions? Bugs? Tell Ben Houston at ben@exocortex.org 37 | // Version: May 4, 2002 38 | 39 | /// 40 | ///

Various mathematical functions for complex numbers.

41 | ///
42 | public class ComplexMath { 43 | 44 | //--------------------------------------------------------------------------------------------------- 45 | 46 | private ComplexMath() { 47 | } 48 | 49 | //--------------------------------------------------------------------------------------------------- 50 | 51 | /// 52 | /// Swap two complex numbers 53 | /// 54 | /// 55 | /// 56 | static public void Swap( ref Complex a, ref Complex b ) { 57 | Complex temp = a; 58 | a = b; 59 | b = temp; 60 | } 61 | 62 | /// 63 | /// Swap two complex numbers 64 | /// 65 | /// 66 | /// 67 | static public void Swap( ref ComplexF a, ref ComplexF b ) { 68 | ComplexF temp = a; 69 | a = b; 70 | b = temp; 71 | } 72 | 73 | //--------------------------------------------------------------------------------------------------- 74 | 75 | static private double _halfOfRoot2 = 0.5 * Math.Sqrt( 2 ); 76 | 77 | /// 78 | /// Calculate the square root of a complex number 79 | /// 80 | /// 81 | /// 82 | static public ComplexF Sqrt( ComplexF c ) { 83 | double x = c.Re; 84 | double y = c.Im; 85 | 86 | double modulus = Math.Sqrt( x*x + y*y ); 87 | int sign = ( y < 0 ) ? -1 : 1; 88 | 89 | c.Re = (float)( _halfOfRoot2 * Math.Sqrt( modulus + x ) ); 90 | c.Im = (float)( _halfOfRoot2 * sign * Math.Sqrt( modulus - x ) ); 91 | 92 | return c; 93 | } 94 | 95 | /// 96 | /// Calculate the square root of a complex number 97 | /// 98 | /// 99 | /// 100 | static public Complex Sqrt( Complex c ) { 101 | double x = c.Re; 102 | double y = c.Im; 103 | 104 | double modulus = Math.Sqrt( x*x + y*y ); 105 | int sign = ( y < 0 ) ? -1 : 1; 106 | 107 | c.Re = (double)( _halfOfRoot2 * Math.Sqrt( modulus + x ) ); 108 | c.Im = (double)( _halfOfRoot2 * sign * Math.Sqrt( modulus - x ) ); 109 | 110 | return c; 111 | } 112 | 113 | //--------------------------------------------------------------------------------------------------- 114 | 115 | /// 116 | /// Calculate the power of a complex number 117 | /// 118 | /// 119 | /// 120 | /// 121 | static public ComplexF Pow( ComplexF c, double exponent ) { 122 | double x = c.Re; 123 | double y = c.Im; 124 | 125 | double modulus = Math.Pow( x*x + y*y, exponent * 0.5 ); 126 | double argument = Math.Atan2( y, x ) * exponent; 127 | 128 | c.Re = (float)( modulus * System.Math.Cos( argument ) ); 129 | c.Im = (float)( modulus * System.Math.Sin( argument ) ); 130 | 131 | return c; 132 | } 133 | 134 | /// 135 | /// Calculate the power of a complex number 136 | /// 137 | /// 138 | /// 139 | /// 140 | static public Complex Pow( Complex c, double exponent ) { 141 | double x = c.Re; 142 | double y = c.Im; 143 | 144 | double modulus = Math.Pow( x*x + y*y, exponent * 0.5 ); 145 | double argument = Math.Atan2( y, x ) * exponent; 146 | 147 | c.Re = (double)( modulus * System.Math.Cos( argument ) ); 148 | c.Im = (double)( modulus * System.Math.Sin( argument ) ); 149 | 150 | return c; 151 | } 152 | 153 | //--------------------------------------------------------------------------------------------------- 154 | 155 | } 156 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/ComplexMath.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 86a8d4481513a4f51b8238e840d1d008 3 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/ComplexStats.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD Licence: 3 | * Copyright (c) 2001, 2002 Ben Houston [ ben@exocortex.org ] 4 | * Exocortex Technologies [ www.exocortex.org ] 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 29 | * DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Diagnostics; 34 | 35 | // Comments? Questions? Bugs? Tell Ben Houston at ben@exocortex.org 36 | // Version: May 4, 2002 37 | 38 | /// 39 | ///

A set of statistical utilities for complex number arrays

40 | ///
41 | public class ComplexStats 42 | { 43 | //--------------------------------------------------------------------------------------------- 44 | 45 | private ComplexStats() { 46 | } 47 | 48 | //--------------------------------------------------------------------------------------------- 49 | //-------------------------------------------------------------------------------------------- 50 | 51 | /// 52 | /// Calculate the sum 53 | /// 54 | /// 55 | /// 56 | static public ComplexF Sum( ComplexF[] data ) { 57 | Debug.Assert( data != null ); 58 | return SumRecursion( data, 0, data.Length ); 59 | } 60 | static private ComplexF SumRecursion( ComplexF[] data, int start, int end ) { 61 | Debug.Assert( 0 <= start, "start = " + start ); 62 | Debug.Assert( start < end, "start = " + start + " and end = " + end ); 63 | Debug.Assert( end <= data.Length, "end = " + end + " and data.Length = " + data.Length ); 64 | if( ( end - start ) <= 1000 ) { 65 | ComplexF sum = ComplexF.Zero; 66 | for( int i = start; i < end; i ++ ) { 67 | sum += data[ i ]; 68 | 69 | } 70 | return sum; 71 | } 72 | else { 73 | int middle = ( start + end ) >> 1; 74 | return SumRecursion( data, start, middle ) + SumRecursion( data, middle, end ); 75 | } 76 | } 77 | 78 | /// 79 | /// Calculate the sum 80 | /// 81 | /// 82 | /// 83 | static public Complex Sum( Complex[] data ) { 84 | Debug.Assert( data != null ); 85 | return SumRecursion( data, 0, data.Length ); 86 | } 87 | static private Complex SumRecursion( Complex[] data, int start, int end ) { 88 | Debug.Assert( 0 <= start, "start = " + start ); 89 | Debug.Assert( start < end, "start = " + start + " and end = " + end ); 90 | Debug.Assert( end <= data.Length, "end = " + end + " and data.Length = " + data.Length ); 91 | if( ( end - start ) <= 1000 ) { 92 | Complex sum = Complex.Zero; 93 | for( int i = start; i < end; i ++ ) { 94 | sum += data[ i ]; 95 | 96 | } 97 | return sum; 98 | } 99 | else { 100 | int middle = ( start + end ) >> 1; 101 | return SumRecursion( data, start, middle ) + SumRecursion( data, middle, end ); 102 | } 103 | } 104 | 105 | //-------------------------------------------------------------------------------------------- 106 | //-------------------------------------------------------------------------------------------- 107 | 108 | /// 109 | /// Calculate the sum of squares 110 | /// 111 | /// 112 | /// 113 | static public ComplexF SumOfSquares( ComplexF[] data ) { 114 | Debug.Assert( data != null ); 115 | return SumOfSquaresRecursion( data, 0, data.Length ); 116 | } 117 | static private ComplexF SumOfSquaresRecursion( ComplexF[] data, int start, int end ) { 118 | Debug.Assert( 0 <= start, "start = " + start ); 119 | Debug.Assert( start < end, "start = " + start + " and end = " + end ); 120 | Debug.Assert( end <= data.Length, "end = " + end + " and data.Length = " + data.Length ); 121 | if( ( end - start ) <= 1000 ) { 122 | ComplexF sumOfSquares = ComplexF.Zero; 123 | for( int i = start; i < end; i ++ ) { 124 | sumOfSquares += data[ i ] * data[ i ]; 125 | 126 | } 127 | return sumOfSquares; 128 | } 129 | else { 130 | int middle = ( start + end ) >> 1; 131 | return SumOfSquaresRecursion( data, start, middle ) + SumOfSquaresRecursion( data, middle, end ); 132 | } 133 | } 134 | 135 | /// 136 | /// Calculate the sum of squares 137 | /// 138 | /// 139 | /// 140 | static public Complex SumOfSquares( Complex[] data ) { 141 | Debug.Assert( data != null ); 142 | return SumOfSquaresRecursion( data, 0, data.Length ); 143 | } 144 | static private Complex SumOfSquaresRecursion( Complex[] data, int start, int end ) { 145 | Debug.Assert( 0 <= start, "start = " + start ); 146 | Debug.Assert( start < end, "start = " + start + " and end = " + end ); 147 | Debug.Assert( end <= data.Length, "end = " + end + " and data.Length = " + data.Length ); 148 | if( ( end - start ) <= 1000 ) { 149 | Complex sumOfSquares = Complex.Zero; 150 | for( int i = start; i < end; i ++ ) { 151 | sumOfSquares += data[ i ] * data[ i ]; 152 | 153 | } 154 | return sumOfSquares; 155 | } 156 | else { 157 | int middle = ( start + end ) >> 1; 158 | return SumOfSquaresRecursion( data, start, middle ) + SumOfSquaresRecursion( data, middle, end ); 159 | } 160 | } 161 | 162 | //-------------------------------------------------------------------------------------------- 163 | //-------------------------------------------------------------------------------------------- 164 | 165 | /// 166 | /// Calculate the mean (average) 167 | /// 168 | /// 169 | /// 170 | static public ComplexF Mean( ComplexF[] data ) { 171 | return ComplexStats.Sum( data ) / data.Length; 172 | } 173 | 174 | /// 175 | /// Calculate the mean (average) 176 | /// 177 | /// 178 | /// 179 | static public Complex Mean( Complex[] data ) { 180 | return ComplexStats.Sum( data ) / data.Length; 181 | } 182 | 183 | /// 184 | /// Calculate the variance 185 | /// 186 | /// 187 | /// 188 | static public ComplexF Variance( ComplexF[] data ) { 189 | Debug.Assert( data != null ); 190 | if( data.Length == 0 ) { 191 | throw new DivideByZeroException( "length of data is zero" ); 192 | } 193 | return ComplexStats.SumOfSquares( data ) / data.Length - ComplexStats.Sum( data ); 194 | } 195 | /// 196 | /// Calculate the variance 197 | /// 198 | /// 199 | /// 200 | static public Complex Variance( Complex[] data ) { 201 | Debug.Assert( data != null ); 202 | if( data.Length == 0 ) { 203 | throw new DivideByZeroException( "length of data is zero" ); 204 | } 205 | return ComplexStats.SumOfSquares( data ) / data.Length - ComplexStats.Sum( data ); 206 | } 207 | 208 | /// 209 | /// Calculate the standard deviation 210 | /// 211 | /// 212 | /// 213 | static public ComplexF StdDev( ComplexF[] data ) { 214 | Debug.Assert( data != null ); 215 | if( data.Length == 0 ) { 216 | throw new DivideByZeroException( "length of data is zero" ); 217 | } 218 | return ComplexMath.Sqrt( ComplexStats.Variance( data ) ); 219 | } 220 | /// 221 | /// Calculate the standard deviation 222 | /// 223 | /// 224 | /// 225 | static public Complex StdDev( Complex[] data ) { 226 | Debug.Assert( data != null ); 227 | if( data.Length == 0 ) { 228 | throw new DivideByZeroException( "length of data is zero" ); 229 | } 230 | return ComplexMath.Sqrt( ComplexStats.Variance( data ) ); 231 | } 232 | 233 | //-------------------------------------------------------------------------------------------- 234 | //-------------------------------------------------------------------------------------------- 235 | 236 | /// 237 | /// Calculate the root mean squared (RMS) error between two sets of data. 238 | /// 239 | /// 240 | /// 241 | /// 242 | static public float RMSError( ComplexF[] alpha, ComplexF[] beta ) { 243 | Debug.Assert( alpha != null ); 244 | Debug.Assert( beta != null ); 245 | Debug.Assert( beta.Length == alpha.Length ); 246 | 247 | return (float) Math.Sqrt( SumOfSquaredErrorRecursion( alpha, beta, 0, alpha.Length ) ); 248 | } 249 | static private float SumOfSquaredErrorRecursion( ComplexF[] alpha, ComplexF[] beta, int start, int end ) { 250 | Debug.Assert( 0 <= start, "start = " + start ); 251 | Debug.Assert( start < end, "start = " + start + " and end = " + end ); 252 | Debug.Assert( end <= alpha.Length, "end = " + end + " and alpha.Length = " + alpha.Length ); 253 | Debug.Assert( beta.Length == alpha.Length ); 254 | if( ( end - start ) <= 1000 ) { 255 | float sumOfSquaredError = 0; 256 | for( int i = start; i < end; i ++ ) { 257 | ComplexF delta = beta[ i ] - alpha[ i ]; 258 | sumOfSquaredError += ( delta.Re * delta.Re ) + ( delta.Im * delta.Im ); 259 | 260 | } 261 | return sumOfSquaredError; 262 | } 263 | else { 264 | int middle = ( start + end ) >> 1; 265 | return SumOfSquaredErrorRecursion( alpha, beta, start, middle ) + SumOfSquaredErrorRecursion( alpha, beta, middle, end ); 266 | } 267 | } 268 | 269 | /// 270 | /// Calculate the root mean squared (RMS) error between two sets of data. 271 | /// 272 | /// 273 | /// 274 | /// 275 | static public double RMSError( Complex[] alpha, Complex[] beta ) { 276 | Debug.Assert( alpha != null ); 277 | Debug.Assert( beta != null ); 278 | Debug.Assert( beta.Length == alpha.Length ); 279 | 280 | return Math.Sqrt( SumOfSquaredErrorRecursion( alpha, beta, 0, alpha.Length ) ); 281 | } 282 | static private double SumOfSquaredErrorRecursion( Complex[] alpha, Complex[] beta, int start, int end ) { 283 | Debug.Assert( 0 <= start, "start = " + start ); 284 | Debug.Assert( start < end, "start = " + start + " and end = " + end ); 285 | Debug.Assert( end <= alpha.Length, "end = " + end + " and alpha.Length = " + alpha.Length ); 286 | Debug.Assert( beta.Length == alpha.Length ); 287 | if( ( end - start ) <= 1000 ) { 288 | double sumOfSquaredError = 0; 289 | for( int i = start; i < end; i ++ ) { 290 | Complex delta = beta[ i ] - alpha[ i ]; 291 | sumOfSquaredError += ( delta.Re * delta.Re ) + ( delta.Im * delta.Im ); 292 | 293 | } 294 | return sumOfSquaredError; 295 | } 296 | else { 297 | int middle = ( start + end ) >> 1; 298 | return SumOfSquaredErrorRecursion( alpha, beta, start, middle ) + SumOfSquaredErrorRecursion( alpha, beta, middle, end ); 299 | } 300 | } 301 | 302 | 303 | } -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/ComplexStats.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: f973bed45675c4aeb90159679cc784e9 3 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/Fourier.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 809b33c95a0474fe3a8fffffdb905742 3 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/FourierDirection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD Licence: 3 | * Copyright (c) 2001, 2002 Ben Houston [ ben@exocortex.org ] 4 | * Exocortex Technologies [ www.exocortex.org ] 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 29 | * DAMAGE. 30 | */ 31 | 32 | 33 | using System; 34 | 35 | // Comments? Questions? Bugs? Tell Ben Houston at ben@exocortex.org 36 | // Version: May 4, 2002 37 | 38 | /// 39 | ///

The direction of the fourier transform.

40 | ///
41 | public enum FourierDirection : int { 42 | /// 43 | /// Forward direction. Usually in reference to moving from temporal 44 | /// representation to frequency representation 45 | /// 46 | Forward = 1, 47 | /// 48 | /// Backward direction. Usually in reference to moving from frequency 49 | /// representation to temporal representation 50 | /// 51 | Backward = -1, 52 | } 53 | -------------------------------------------------------------------------------- /Assets/Plugins/Exocortex_FFT/FourierDirection.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 8ce6830818c0246eab48d73d335a9523 3 | -------------------------------------------------------------------------------- /Assets/Plugins/WaterPostEffect.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class WaterPostEffect : MonoBehaviour 5 | { 6 | public Material waterCompositionMaterial = null; 7 | 8 | void Start() 9 | { 10 | StartCoroutine(Hack()); 11 | } 12 | 13 | //HACK FIXME BUGREPORT? 14 | IEnumerator Hack() 15 | { 16 | enabled = false; 17 | 18 | yield return 0; 19 | 20 | enabled = true; 21 | } 22 | 23 | void OnRenderImage (RenderTexture source, RenderTexture destination) 24 | { 25 | 26 | float nearClip = camera.nearClipPlane; 27 | float angle = Mathf.Deg2Rad*(camera.fieldOfView/2.0f); 28 | 29 | float h = nearClip/Mathf.Cos(angle); 30 | float k = Mathf.Sin(angle) * h; 31 | 32 | 33 | Vector3 center = transform.position + transform.forward * nearClip * 1.01f; 34 | Vector3 right = transform.right * camera.aspect * k * 1.01f; 35 | Vector3 up = transform.up * k * 1.01f; 36 | 37 | if (waterCompositionMaterial != null) 38 | { 39 | 40 | //TODO: Fix this using Graphics.Blit instead. 41 | //Graphics.Blit(source, destination, waterCompositionMaterial); 42 | 43 | 44 | RenderTexture.active = destination; 45 | waterCompositionMaterial.SetTexture("_MainTex", source); 46 | 47 | 48 | GL.PushMatrix (); 49 | //GL.LoadOrtho ();//Bah. This is screwing up my mind when it comes to unprojecting 50 | GL.Clear(true, false, Color.black); 51 | 52 | for (int i = 0; i < waterCompositionMaterial.passCount; i++) 53 | { 54 | waterCompositionMaterial.SetPass (i); 55 | 56 | GL.Begin (GL.QUADS); 57 | GL.TexCoord2( 0.0f, 0.0f ); GL.Vertex(center - up - right); 58 | GL.TexCoord2( 1.0f, 0.0f ); GL.Vertex(center - up + right); 59 | GL.TexCoord2( 1.0f, 1.0f ); GL.Vertex(center + up + right); 60 | GL.TexCoord2( 0.0f, 1.0f ); GL.Vertex(center + up - right); 61 | GL.End(); 62 | 63 | } 64 | GL.PopMatrix (); 65 | } 66 | else 67 | { 68 | Graphics.Blit(source, destination); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Assets/Plugins/WaterPostEffect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 4ec7a7a3f57f14aa09e87ec5fa1435fc 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 95bd9aac2d69043398f78c1a570ab7f1 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 3c788335fe2df44ca9bbf95bc580ce4d 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/FX-Refractive.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Pro Standard Assets/Glass Refraction/FX-Refractive.mat -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/FX-Refractive.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 848918a99d11f25f110026ca44295342 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/Glass-Stained-BumpDistort.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D' 2 | // Upgrade NOTE: replaced 'texRECTproj' with 'tex2Dproj' 3 | 4 | // Per pixel bumped refraction. 5 | // Uses a normal map to distort the image behind, and 6 | // an additional texture to tint the color. 7 | 8 | Shader "FX/Glass/Stained BumpDistort" { 9 | Properties { 10 | _BumpAmt ("Distortion", range (0,128)) = 10 11 | _MainTex ("Tint Color (RGB)", 2D) = "white" {} 12 | _BumpMap ("Bumpmap (RGB)", 2D) = "bump" {} 13 | } 14 | 15 | Category { 16 | 17 | // We must be transparent, so other objects are drawn before this one. 18 | Tags { "Queue"="Transparent" "RenderType"="Opaque" } 19 | 20 | // ------------------------------------------------------------------ 21 | // ARB fragment program 22 | 23 | SubShader { 24 | 25 | // This pass grabs the screen behind the object into a texture. 26 | // We can access the result in the next pass as _GrabTexture 27 | GrabPass { 28 | Name "BASE" 29 | Tags { "LightMode" = "Always" } 30 | } 31 | 32 | // Main pass: Take the texture grabbed above and use the bumpmap to perturb it 33 | // on to the screen 34 | Pass { 35 | Name "BASE" 36 | Tags { "LightMode" = "Always" } 37 | 38 | CGPROGRAM 39 | // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs. 40 | #pragma exclude_renderers gles 41 | #pragma fragment frag 42 | #pragma fragmentoption ARB_precision_hint_fastest 43 | #pragma fragmentoption ARB_fog_exp2 44 | 45 | sampler2D _GrabTexture : register(s0); 46 | float4 _GrabTexture_TexelSize; 47 | sampler2D _BumpMap : register(s1); 48 | sampler2D _MainTex : register(s2); 49 | 50 | struct v2f { 51 | float4 uvgrab : TEXCOORD0; 52 | float2 uvbump : TEXCOORD1; 53 | float2 uvmain : TEXCOORD2; 54 | }; 55 | 56 | uniform float _BumpAmt; 57 | 58 | half4 frag( v2f i ) : COLOR 59 | { 60 | // calculate perturbed coordinates 61 | half2 bump = tex2D( _BumpMap, i.uvbump ).rg * 2 - 1; 62 | float2 offset = bump * _BumpAmt; 63 | #ifdef SHADER_API_D3D9 64 | offset *= _GrabTexture_TexelSize.xy; 65 | #endif 66 | i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy; 67 | 68 | half4 col = tex2Dproj( _GrabTexture, i.uvgrab.xyw ); 69 | half4 tint = tex2D( _MainTex, i.uvmain ); 70 | 71 | return col * tint; 72 | } 73 | 74 | ENDCG 75 | // Set up the textures for this pass 76 | SetTexture [_GrabTexture] {} // Texture we grabbed in the pass above 77 | SetTexture [_BumpMap] {} // Perturbation bumpmap 78 | SetTexture [_MainTex] {} // Color tint 79 | } 80 | } 81 | 82 | // ------------------------------------------------------------------ 83 | // Radeon 9000 84 | 85 | #warning Upgrade NOTE: SubShader commented out because of manual shader assembly 86 | /*SubShader { 87 | 88 | GrabPass { 89 | Name "BASE" 90 | Tags { "LightMode" = "Always" } 91 | } 92 | 93 | Pass { 94 | Name "BASE" 95 | Tags { "LightMode" = "Always" } 96 | 97 | Program "" { 98 | SubProgram { 99 | Local 0, ([_BumpAmt],0,0,0.001) 100 | "!!ATIfs1.0 101 | StartConstants; 102 | CONSTANT c0 = program.local[0]; 103 | EndConstants; 104 | 105 | StartPrelimPass; 106 | PassTexCoord r0, t0.stq_dq; # refraction position 107 | SampleMap r1, t1.str; # bumpmap 108 | MAD r0, r1.2x.bias, c0.r, r0; 109 | EndPass; 110 | 111 | StartOutputPass; 112 | SampleMap r0, r0.str; # sample modified refraction texture 113 | SampleMap r2, t2.str; # Get main color texture 114 | 115 | MUL r0, r0, r2; 116 | EndPass; 117 | " 118 | } 119 | } 120 | SetTexture [_GrabTexture] {} 121 | SetTexture [_BumpMap] {} 122 | SetTexture [_MainTex] {} 123 | } 124 | }*/ 125 | 126 | // ------------------------------------------------------------------ 127 | // Fallback for older cards and Unity non-Pro 128 | 129 | SubShader { 130 | Blend DstColor Zero 131 | Pass { 132 | Name "BASE" 133 | SetTexture [_MainTex] { combine texture } 134 | } 135 | } 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/Glass-Stained-BumpDistort.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 963484209d11fd7f110076aa44295342 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/Glass-Stained-BumpSpecDistort.shader: -------------------------------------------------------------------------------- 1 | Shader "FX/Glass/Stained BumpDistorted Specular" { 2 | Properties { 3 | _Color ("Main Color", Color) = (1,1,1,0.5) 4 | _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) 5 | _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 6 | _BumpAmt ("Distortion", range (0,128)) = 10 7 | _MainTex ("Tint Color (RGB)", 2D) = "white" {} 8 | _BumpMap ("Bumpmap (RGB)", 2D) = "bump" { } 9 | } 10 | 11 | SubShader { 12 | Tags { "Queue"="Transparent" "RenderType"="Opaque" } 13 | UsePass "FX/Glass/Stained BumpDistort/BASE" 14 | UsePass " BumpedSpecular/PPL" 15 | } 16 | 17 | // Fallback shader for older cards & non-PRO Unities. 18 | SubShader { 19 | Tags { "Queue"="Transparent" "RenderType"="Opaque" } 20 | Blend DstColor Zero 21 | Pass { 22 | Name "BASE" 23 | SetTexture [_MainTex] { combine texture } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/Glass-Stained-BumpSpecDistort.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 41c783569d11bd7f11006b1944295342 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/glass.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Pro Standard Assets/Glass Refraction/glass.tif -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/glass.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 19555d7d9d114c7f1100f5ab44295342 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 512 6 | textureFormat: 12 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 0 28 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/glassbump.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Pro Standard Assets/Glass Refraction/glassbump.tif -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Glass Refraction/glassbump.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 4b8d081e9d114c7f1100f5ab44295342 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 512 6 | textureFormat: 10 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 1 21 | bumpyness: 0.1190323 22 | filter: 0 23 | textureSettings: 24 | filterMode: 2 25 | anisoLevel: 9 26 | mipmapBias: 0 27 | wrapMode: 0 28 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: c881fbc23e91145bcad0f3e492889a4b 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/BlurEffect.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [ExecuteInEditMode] 5 | [AddComponentMenu("Image Effects/Blur")] 6 | public class BlurEffect : MonoBehaviour 7 | { 8 | /// Blur iterations - larger number means more blur. 9 | public int iterations = 3; 10 | 11 | /// Blur spread for each iteration. Lower values 12 | /// give better looking blur, but require more iterations to 13 | /// get large blurs. Value is usually between 0.5 and 1.0. 14 | public float blurSpread = 0.6f; 15 | 16 | 17 | // -------------------------------------------------------- 18 | // The blur iteration shader. 19 | // Basically it just takes 4 texture samples and averages them. 20 | // By applying it repeatedly and spreading out sample locations 21 | // we get a Gaussian blur approximation. 22 | 23 | private static string blurMatString = 24 | @"Shader ""BlurConeTap"" { 25 | SubShader { 26 | Pass { 27 | ZTest Always Cull Off ZWrite Off Fog { Mode Off } 28 | SetTexture [__RenderTex] {constantColor (0,0,0,0.25) combine texture * constant alpha} 29 | SetTexture [__RenderTex] {constantColor (0,0,0,0.25) combine texture * constant + previous} 30 | SetTexture [__RenderTex] {constantColor (0,0,0,0.25) combine texture * constant + previous} 31 | SetTexture [__RenderTex] {constantColor (0,0,0,0.25) combine texture * constant + previous} 32 | } 33 | } 34 | Fallback off 35 | }"; 36 | 37 | static Material m_Material = null; 38 | protected static Material material { 39 | get { 40 | if (m_Material == null) { 41 | m_Material = new Material( blurMatString ); 42 | m_Material.hideFlags = HideFlags.HideAndDontSave; 43 | m_Material.shader.hideFlags = HideFlags.HideAndDontSave; 44 | } 45 | return m_Material; 46 | } 47 | } 48 | 49 | protected void OnDisable() { 50 | if( m_Material ) { 51 | DestroyImmediate( m_Material.shader ); 52 | DestroyImmediate( m_Material ); 53 | } 54 | } 55 | 56 | // -------------------------------------------------------- 57 | 58 | protected void Start() 59 | { 60 | // Disable if we don't support image effects 61 | if (!SystemInfo.supportsImageEffects) { 62 | enabled = false; 63 | return; 64 | } 65 | // Disable if the shader can't run on the users graphics card 66 | if (!material.shader.isSupported) { 67 | enabled = false; 68 | return; 69 | } 70 | } 71 | 72 | // Performs one blur iteration. 73 | public void FourTapCone (RenderTexture source, RenderTexture dest, int iteration) 74 | { 75 | RenderTexture.active = dest; 76 | source.SetGlobalShaderProperty ("__RenderTex"); 77 | 78 | float offsetX = (.5F+iteration*blurSpread) / (float)source.width; 79 | float offsetY = (.5F+iteration*blurSpread) / (float)source.height; 80 | GL.PushMatrix (); 81 | GL.LoadOrtho (); 82 | 83 | for (int i = 0; i < material.passCount; i++) { 84 | material.SetPass (i); 85 | Render4TapQuad( dest, offsetX, offsetY ); 86 | } 87 | GL.PopMatrix (); 88 | } 89 | 90 | // Downsamples the texture to a quarter resolution. 91 | private void DownSample4x (RenderTexture source, RenderTexture dest) 92 | { 93 | RenderTexture.active = dest; 94 | source.SetGlobalShaderProperty ("__RenderTex"); 95 | 96 | float offsetX = 1.0f / (float)source.width; 97 | float offsetY = 1.0f / (float)source.height; 98 | 99 | GL.PushMatrix (); 100 | GL.LoadOrtho (); 101 | for (int i = 0; i < material.passCount; i++) 102 | { 103 | material.SetPass (i); 104 | Render4TapQuad( dest, offsetX, offsetY ); 105 | } 106 | GL.PopMatrix (); 107 | } 108 | 109 | // Called by the camera to apply the image effect 110 | void OnRenderImage (RenderTexture source, RenderTexture destination) { 111 | RenderTexture buffer = RenderTexture.GetTemporary(source.width/4, source.height/4, 0); 112 | RenderTexture buffer2 = RenderTexture.GetTemporary(source.width/4, source.height/4, 0); 113 | 114 | // Copy source to the 4x4 smaller texture. 115 | DownSample4x (source, buffer); 116 | 117 | // Blur the small texture 118 | bool oddEven = true; 119 | for(int i = 0; i < iterations; i++) 120 | { 121 | if( oddEven ) 122 | FourTapCone (buffer, buffer2, i); 123 | else 124 | FourTapCone (buffer2, buffer, i); 125 | oddEven = !oddEven; 126 | } 127 | if( oddEven ) 128 | ImageEffects.Blit(buffer, destination); 129 | else 130 | ImageEffects.Blit(buffer2, destination); 131 | 132 | RenderTexture.ReleaseTemporary(buffer); 133 | RenderTexture.ReleaseTemporary(buffer2); 134 | } 135 | 136 | private static void Render4TapQuad( RenderTexture dest, float offsetX, float offsetY ) 137 | { 138 | GL.Begin( GL.QUADS ); 139 | 140 | // Direct3D needs interesting texel offsets! 141 | Vector2 off = Vector2.zero; 142 | if( dest != null ) 143 | off = dest.GetTexelOffset() * 0.75f; 144 | 145 | Set4TexCoords( off.x, off.y, offsetX, offsetY ); 146 | GL.Vertex3( 0,0, .1f ); 147 | 148 | Set4TexCoords( 1.0f + off.x, off.y, offsetX, offsetY ); 149 | GL.Vertex3( 1,0, .1f ); 150 | 151 | Set4TexCoords( 1.0f + off.x, 1.0f + off.y, offsetX, offsetY ); 152 | GL.Vertex3( 1,1,.1f ); 153 | 154 | Set4TexCoords( off.x, 1.0f + off.y, offsetX, offsetY ); 155 | GL.Vertex3( 0,1,.1f ); 156 | 157 | GL.End(); 158 | } 159 | 160 | private static void Set4TexCoords( float x, float y, float offsetX, float offsetY ) 161 | { 162 | GL.MultiTexCoord2( 0, x - offsetX, y - offsetY ); 163 | GL.MultiTexCoord2( 1, x + offsetX, y - offsetY ); 164 | GL.MultiTexCoord2( 2, x + offsetX, y + offsetY ); 165 | GL.MultiTexCoord2( 3, x - offsetX, y + offsetY ); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/BlurEffect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 34382083ad114a07d000fbfb8d76c639 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/ColorCorrectionEffect.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [ExecuteInEditMode] 5 | [AddComponentMenu("Image Effects/Color Correction")] 6 | public class ColorCorrectionEffect : ImageEffectBase { 7 | public Texture textureRamp; 8 | public float rampOffsetR; 9 | public float rampOffsetG; 10 | public float rampOffsetB; 11 | 12 | // Called by camera to apply image effect 13 | void OnRenderImage (RenderTexture source, RenderTexture destination) { 14 | material.SetTexture("_RampTex", textureRamp); 15 | material.SetVector("_RampOffset", new Vector4 (rampOffsetR, rampOffsetG, rampOffsetB, 0)); 16 | ImageEffects.BlitWithMaterial( material, source, destination ); 17 | } 18 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/ColorCorrectionEffect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: ea59781cad112c75d0008dfa8d76c639 3 | MonoImporter: 4 | importerVersion: 1 5 | defaultReferences: 6 | shader: {fileID: 4800000, guid: 67f8781cad112c75d0008dfa8d76c639, type: 1} 7 | textureRamp: {fileID: 2800000, guid: d440902fad11e807d00044888d76c639, type: 1} 8 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/ColorCorrectionEffect.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/Grayscale Effect" { 2 | Properties { 3 | _MainTex ("Base (RGB)", RECT) = "white" {} 4 | _RampTex ("Base (RGB)", 2D) = "grayscaleRamp" {} 5 | } 6 | 7 | #warning Upgrade NOTE: SubShader commented out because of manual shader assembly 8 | /*SubShader { 9 | Pass { 10 | ZTest Always Cull Off ZWrite Off 11 | Fog { Mode off } 12 | 13 | /* 14 | 15 | Cg 1.5 has a bug where this shader compiles incorrectly for D3D. 16 | So we don't actually compile the shader, instead below is the 17 | compiled&fixed assembly version. 18 | 19 | CGPROGRAM 20 | #pragma vertex vert_img 21 | #pragma fragment frag 22 | #pragma fragmentoption ARB_precision_hint_fastest 23 | #include "UnityCG.cginc" 24 | 25 | uniform samplerRECT _MainTex; 26 | uniform sampler2D _RampTex; 27 | uniform float4 _RampOffset; 28 | 29 | float4 frag (v2f_img i) : COLOR 30 | { 31 | float4 orig = texRECT(_MainTex, i.uv); 32 | float4 color; 33 | 34 | color.r = tex2D(_RampTex, float2(orig.r + _RampOffset.r, 0)).r; 35 | color.g = tex2D(_RampTex, float2(orig.g + _RampOffset.g, 0)).g; 36 | color.b = tex2D(_RampTex, float2(orig.b + _RampOffset.b, 0)).b; 37 | color.a = orig.a; 38 | 39 | return color; 40 | } 41 | ENDCG 42 | */ 43 | 44 | 45 | Program "" { 46 | SubProgram { 47 | Keywords { } 48 | Bind "vertex", Vertex 49 | Bind "texcoord", TexCoord0 50 | "!!ARBvp1.0 51 | # 8 instructions 52 | PARAM c[9] = { { 0 }, 53 | state.matrix.mvp, 54 | state.matrix.texture[0] }; 55 | TEMP R0; 56 | MOV R0.zw, c[0].x; 57 | MOV R0.xy, vertex.texcoord[0]; 58 | DP4 result.texcoord[0].y, R0, c[6]; 59 | DP4 result.texcoord[0].x, R0, c[5]; 60 | DP4 result.position.w, vertex.position, c[4]; 61 | DP4 result.position.z, vertex.position, c[3]; 62 | DP4 result.position.y, vertex.position, c[2]; 63 | DP4 result.position.x, vertex.position, c[1]; 64 | END 65 | " 66 | } 67 | 68 | SubProgram { 69 | Keywords { } 70 | Bind "vertex", Vertex 71 | Bind "texcoord", TexCoord0 72 | Matrix 0, [glstate_matrix_mvp] 73 | Matrix 4, [glstate_matrix_texture0] 74 | "vs_1_1 75 | dcl_position v0 76 | dcl_texcoord0 v1 77 | def c8, 0.000000, 0, 0, 0 78 | mov r0.zw, c8.x 79 | mov r0.xy, v1 80 | dp4 oT0.y, r0, c5 81 | dp4 oT0.x, r0, c4 82 | dp4 oPos.w, v0, c3 83 | dp4 oPos.z, v0, c2 84 | dp4 oPos.y, v0, c1 85 | dp4 oPos.x, v0, c0 86 | " 87 | } 88 | 89 | SubProgram { 90 | Keywords { } 91 | Local 0, [_RampOffset] 92 | SetTexture [_MainTex] {RECT} 93 | SetTexture [_RampTex] {2D} 94 | "!!ARBfp1.0 95 | OPTION ARB_precision_hint_fastest; 96 | PARAM c[2] = { program.local[0], 97 | { 0 } }; 98 | TEMP R0; 99 | TEX R0, fragment.texcoord[0], texture[0], RECT; 100 | MOV result.color.w, R0; 101 | MOV R0.w, c[1].x; 102 | ADD R0.z, R0, c[0]; 103 | TEX result.color.z, R0.zwzw, texture[1], 2D; 104 | ADD R0.z, R0.y, c[0].y; 105 | MOV R0.w, c[1].x; 106 | MOV R0.y, c[1].x; 107 | ADD R0.x, R0, c[0]; 108 | TEX result.color.y, R0.zwzw, texture[1], 2D; 109 | TEX result.color.x, R0, texture[1], 2D; 110 | END 111 | " 112 | } 113 | 114 | SubProgram { 115 | Keywords { } 116 | Local 0, [_RampOffset] 117 | SetTexture [_MainTex] {RECT} 118 | SetTexture [_RampTex] {2D} 119 | "ps_2_0 120 | dcl_2d s0 121 | dcl_2d s1 122 | def c1, 0.000000, 0, 0, 0 123 | dcl t0.xy 124 | texld r3, t0, s0 125 | add r0.x, r3.y, c0.y 126 | mov r0.y, c1.x 127 | add r2.x, r3.z, c0.z 128 | add r1.x, r3, c0 129 | mov r2.y, c1.x 130 | mov r1.y, c1.x 131 | texld r0, r0, s1 132 | texld r1, r1, s1 133 | texld r2, r2, s1 134 | mov r0.x, r1 135 | mov r0.y, r0 136 | mov r0.z, r2 137 | mov r0.w, r3 138 | mov oC0, r0 139 | " 140 | } 141 | 142 | } 143 | 144 | 145 | } 146 | }*/ 147 | 148 | Fallback off 149 | 150 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/ColorCorrectionEffect.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 67f8781cad112c75d0008dfa8d76c639 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: a40c1b84cf7fe418bae97a29041b85a4 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/Adaptation.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D' 2 | // Upgrade NOTE: replaced 'texRECT' with 'tex2D' 3 | 4 | // Calculates adaptation to minimum/maximum luminance values, 5 | // based on "currently adapted" and "new values to adapt to" 6 | // textures (both 1x1). 7 | 8 | Shader "Hidden/Contrast Stretch Adaptation" { 9 | Properties { 10 | _MainTex ("Base (RGB)", RECT) = "white" {} 11 | _CurTex ("Base (RGB)", RECT) = "white" {} 12 | } 13 | 14 | Category { 15 | SubShader { 16 | Pass { 17 | ZTest Always Cull Off ZWrite Off 18 | Fog { Mode off } 19 | 20 | CGPROGRAM 21 | #pragma vertex vert_img 22 | #pragma fragment frag 23 | #pragma fragmentoption ARB_precision_hint_fastest 24 | #include "UnityCG.cginc" 25 | 26 | uniform sampler2D _MainTex; // currently adapted to 27 | uniform sampler2D _CurTex; // new value to adapt to 28 | uniform float4 _AdaptParams; // x=adaptLerp, y=limitMinimum, z=limitMaximum 29 | 30 | float4 frag (v2f_img i) : COLOR { 31 | // value is: max, min 32 | float2 valAdapted = tex2D(_MainTex, i.uv).xy; 33 | float2 valCur = tex2D(_CurTex, i.uv).xy; 34 | 35 | // Calculate new adapted values: interpolate 36 | // from valAdapted to valCur by script-supplied amount. 37 | // 38 | // Because we store adaptation levels in a simple 8 bit/channel 39 | // texture, we might not have enough precision - the interpolation 40 | // amount might be too small to change anything, and we'll never 41 | // arrive at the needed values. 42 | // 43 | // So we make sure the change we do is at least 1/255th of the 44 | // color range - this way we'll always change the value. 45 | const float kMinChange = 1.0/255.0; 46 | float2 delta = (valCur-valAdapted) * _AdaptParams.x; 47 | delta.x = sign(delta.x) * max( kMinChange, abs(delta.x) ); 48 | delta.y = sign(delta.y) * max( kMinChange, abs(delta.y) ); 49 | 50 | float4 valNew; 51 | valNew.xy = valAdapted + delta; 52 | 53 | // Impose user limits on maximum/minimum values 54 | valNew.x = max( valNew.x, _AdaptParams.z ); 55 | valNew.y = min( valNew.y, _AdaptParams.y ); 56 | 57 | // Optimization so that our final apply pass is faster: 58 | // z = max-min (plus a small amount to prevent division by zero) 59 | valNew.z = valNew.x - valNew.y + 0.01; 60 | // w = min/(max-min) 61 | valNew.w = valNew.y / valNew.z; 62 | 63 | return valNew; 64 | } 65 | ENDCG 66 | 67 | } 68 | } 69 | } 70 | 71 | Fallback off 72 | 73 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/Adaptation.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 257bc83cbeb544540bd0e558aa9b1383 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/Apply.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP' 2 | // Upgrade NOTE: replaced 'glstate.matrix.texture[0]' with 'UNITY_MATRIX_TEXTURE0' 3 | // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D' 4 | // Upgrade NOTE: replaced 'texRECT' with 'tex2D' 5 | 6 | // Final pass in the contrast stretch effect: apply 7 | // color stretch to the original image, based on currently 8 | // adapted to minimum/maximum luminances. 9 | 10 | Shader "Hidden/Contrast Stretch Apply" { 11 | Properties { 12 | _MainTex ("Base (RGB)", RECT) = "white" {} 13 | _AdaptTex ("Base (RGB)", RECT) = "white" {} 14 | } 15 | 16 | Category { 17 | SubShader { 18 | Pass { 19 | ZTest Always Cull Off ZWrite Off 20 | Fog { Mode off } 21 | 22 | CGPROGRAM 23 | #pragma vertex vert 24 | #pragma fragment frag 25 | #pragma fragmentoption ARB_precision_hint_fastest 26 | #include "UnityCG.cginc" 27 | 28 | struct v2f { 29 | float4 pos : POSITION; 30 | float2 uv[2] : TEXCOORD0; 31 | }; 32 | 33 | uniform sampler2D _MainTex; 34 | uniform sampler2D _AdaptTex; 35 | 36 | v2f vert (appdata_img v) 37 | { 38 | v2f o; 39 | o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 40 | o.uv[0] = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord); 41 | o.uv[1] = float2(0.5,0.5); 42 | return o; 43 | } 44 | 45 | float4 frag (v2f i) : COLOR 46 | { 47 | float4 col = tex2D(_MainTex, i.uv[0]); 48 | float4 adapted = tex2D(_AdaptTex, i.uv[1]); 49 | float vmul = 1.0 / adapted.z; 50 | float vadd = -adapted.w; 51 | col.rgb = col.rgb * vmul + vadd; 52 | return col; 53 | } 54 | ENDCG 55 | 56 | } 57 | } 58 | } 59 | 60 | Fallback off 61 | 62 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/Apply.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: f4901f25d4e1542589348bbb89563d8e 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/ContrastStretchEffect.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | // TBD: if some shader is not supported, turn off! 5 | 6 | [AddComponentMenu("Image Effects/Contrast Stretch")] 7 | public class ContrastStretchEffect : MonoBehaviour 8 | { 9 | /// Adaptation speed - percents per frame, if playing at 30FPS. 10 | /// Default is 0.02 (2% each 1/30s). 11 | public float adaptationSpeed = 0.02f; 12 | 13 | /// If our scene is really dark (or really bright), we might not want to 14 | /// stretch its contrast to the full range. 15 | /// limitMinimum=0, limitMaximum=1 is the same as not applying the effect at all. 16 | /// limitMinimum=1, limitMaximum=0 is always stretching colors to full range. 17 | 18 | /// The limit on the minimum luminance (0...1) - we won't go above this. 19 | public float limitMinimum = 0.2f; 20 | 21 | /// The limit on the maximum luminance (0...1) - we won't go below this. 22 | public float limitMaximum = 0.6f; 23 | 24 | 25 | // To maintain adaptation levels over time, we need two 1x1 render textures 26 | // and ping-pong between them. 27 | private RenderTexture[] adaptRenderTex = new RenderTexture[2]; 28 | private int curAdaptIndex = 0; 29 | 30 | 31 | // Computes scene luminance (grayscale) image 32 | public Shader shaderLum; 33 | private Material m_materialLum; 34 | protected Material materialLum { 35 | get { 36 | if( m_materialLum == null ) { 37 | m_materialLum = new Material(shaderLum); 38 | m_materialLum.hideFlags = HideFlags.HideAndDontSave; 39 | } 40 | return m_materialLum; 41 | } 42 | } 43 | 44 | // Reduces size of the image by 2x2, while computing maximum/minimum values. 45 | // By repeatedly applying this shader, we reduce the initial luminance image 46 | // to 1x1 image with minimum/maximum luminances found. 47 | public Shader shaderReduce; 48 | private Material m_materialReduce; 49 | protected Material materialReduce { 50 | get { 51 | if( m_materialReduce == null ) { 52 | m_materialReduce = new Material(shaderReduce); 53 | m_materialReduce.hideFlags = HideFlags.HideAndDontSave; 54 | } 55 | return m_materialReduce; 56 | } 57 | } 58 | 59 | // Adaptation shader - gradually "adapts" minimum/maximum luminances, 60 | // based on currently adapted 1x1 image and the actual 1x1 image of the current scene. 61 | public Shader shaderAdapt; 62 | private Material m_materialAdapt; 63 | protected Material materialAdapt { 64 | get { 65 | if( m_materialAdapt == null ) { 66 | m_materialAdapt = new Material(shaderAdapt); 67 | m_materialAdapt.hideFlags = HideFlags.HideAndDontSave; 68 | } 69 | return m_materialAdapt; 70 | } 71 | } 72 | 73 | // Final pass - stretches the color values of the original scene, based on currently 74 | // adpated minimum/maximum values. 75 | public Shader shaderApply; 76 | private Material m_materialApply; 77 | protected Material materialApply { 78 | get { 79 | if( m_materialApply == null ) { 80 | m_materialApply = new Material(shaderApply); 81 | m_materialApply.hideFlags = HideFlags.HideAndDontSave; 82 | } 83 | return m_materialApply; 84 | } 85 | } 86 | 87 | void Start() 88 | { 89 | // Disable if we don't support image effects 90 | if (!SystemInfo.supportsImageEffects) { 91 | enabled = false; 92 | return; 93 | } 94 | } 95 | 96 | void OnEnable() 97 | { 98 | for( int i = 0; i < 2; ++i ) 99 | { 100 | if( !adaptRenderTex[i] ) { 101 | adaptRenderTex[i] = new RenderTexture( 1, 1, 32 ); 102 | adaptRenderTex[i].hideFlags = HideFlags.HideAndDontSave; 103 | } 104 | } 105 | } 106 | 107 | void OnDisable() 108 | { 109 | for( int i = 0; i < 2; ++i ) 110 | { 111 | DestroyImmediate( adaptRenderTex[i] ); 112 | adaptRenderTex[i] = null; 113 | } 114 | if( m_materialLum ) 115 | DestroyImmediate( m_materialLum ); 116 | if( m_materialReduce ) 117 | DestroyImmediate( m_materialReduce ); 118 | if( m_materialAdapt ) 119 | DestroyImmediate( m_materialAdapt ); 120 | if( m_materialApply ) 121 | DestroyImmediate( m_materialApply ); 122 | } 123 | 124 | 125 | /// Apply the filter 126 | void OnRenderImage (RenderTexture source, RenderTexture destination) 127 | { 128 | // Blit to smaller RT and convert to luminance on the way 129 | const int TEMP_RATIO = 1; // 4x4 smaller 130 | RenderTexture rtTempSrc = RenderTexture.GetTemporary(source.width/TEMP_RATIO, source.height/TEMP_RATIO); 131 | ImageEffects.BlitWithMaterial( materialLum, source, rtTempSrc ); 132 | 133 | // Repeatedly reduce this image in size, computing min/max luminance values 134 | // In the end we'll have 1x1 image with min/max luminances found. 135 | const int FINAL_SIZE = 1; 136 | //const int FINAL_SIZE = 1; 137 | while( rtTempSrc.width > FINAL_SIZE || rtTempSrc.height > FINAL_SIZE ) 138 | { 139 | const int REDUCE_RATIO = 2; // our shader does 2x2 reduction 140 | int destW = rtTempSrc.width / REDUCE_RATIO; 141 | if( destW < FINAL_SIZE ) destW = FINAL_SIZE; 142 | int destH = rtTempSrc.height / REDUCE_RATIO; 143 | if( destH < FINAL_SIZE ) destH = FINAL_SIZE; 144 | RenderTexture rtTempDst = RenderTexture.GetTemporary(destW,destH); 145 | ImageEffects.BlitWithMaterial( materialReduce, rtTempSrc, rtTempDst ); 146 | 147 | // Release old src temporary, and make new temporary the source 148 | RenderTexture.ReleaseTemporary( rtTempSrc ); 149 | rtTempSrc = rtTempDst; 150 | } 151 | 152 | // Update viewer's adaptation level 153 | CalculateAdaptation( rtTempSrc ); 154 | 155 | // Apply contrast strech to the original scene, using currently adapted parameters 156 | materialApply.SetTexture("_AdaptTex", adaptRenderTex[curAdaptIndex] ); 157 | ImageEffects.BlitWithMaterial( materialApply, source, destination ); 158 | 159 | RenderTexture.ReleaseTemporary( rtTempSrc ); 160 | } 161 | 162 | 163 | /// Helper function to do gradual adaptation to min/max luminances 164 | private void CalculateAdaptation( Texture curTexture ) 165 | { 166 | int prevAdaptIndex = curAdaptIndex; 167 | curAdaptIndex = (curAdaptIndex+1) % 2; 168 | 169 | // Adaptation speed is expressed in percents/frame, based on 30FPS. 170 | // Calculate the adaptation lerp, based on current FPS. 171 | float adaptLerp = 1.0f - Mathf.Pow( 1.0f - adaptationSpeed, 30.0f * Time.deltaTime ); 172 | const float kMinAdaptLerp = 0.01f; 173 | adaptLerp = Mathf.Clamp( adaptLerp, kMinAdaptLerp, 1 ); 174 | 175 | materialAdapt.SetTexture("_CurTex", curTexture ); 176 | materialAdapt.SetVector("_AdaptParams", new Vector4( 177 | adaptLerp, 178 | limitMinimum, 179 | limitMaximum, 180 | 0.0f 181 | )); 182 | ImageEffects.BlitWithMaterial( materialAdapt, 183 | adaptRenderTex[prevAdaptIndex], 184 | adaptRenderTex[curAdaptIndex] ); 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/ContrastStretchEffect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: ec92b071d2d424aecb3e46f28eb63174 3 | MonoImporter: 4 | importerVersion: 1 5 | defaultReferences: 6 | shaderLum: {fileID: 4800000, guid: befbb4b9c320b4b18a08ef7afb93b6c9, type: 1} 7 | shaderReduce: {fileID: 4800000, guid: 57b33a14b6d5347c5a85c36f6cb3b280, type: 1} 8 | shaderAdapt: {fileID: 4800000, guid: 257bc83cbeb544540bd0e558aa9b1383, type: 1} 9 | shaderApply: {fileID: 4800000, guid: f4901f25d4e1542589348bbb89563d8e, type: 1} 10 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/Luminance.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D' 2 | // Upgrade NOTE: replaced 'texRECT' with 'tex2D' 3 | 4 | // Outputs luminance (grayscale) of the input image _MainTex 5 | 6 | Shader "Hidden/Contrast Stretch Luminance" { 7 | 8 | Properties { 9 | _MainTex ("Base (RGB)", RECT) = "white" {} 10 | } 11 | 12 | Category { 13 | SubShader { 14 | Pass { 15 | ZTest Always Cull Off ZWrite Off 16 | Fog { Mode off } 17 | 18 | CGPROGRAM 19 | #pragma vertex vert_img 20 | #pragma fragment frag 21 | #pragma fragmentoption ARB_precision_hint_fastest 22 | #include "UnityCG.cginc" 23 | 24 | uniform sampler2D _MainTex; 25 | 26 | float4 frag (v2f_img i) : COLOR 27 | { 28 | float4 col = tex2D(_MainTex, i.uv); 29 | col.rgb = Luminance(col.rgb) * (1+col.a*2); 30 | return col; 31 | } 32 | ENDCG 33 | 34 | } 35 | } 36 | } 37 | 38 | Fallback off 39 | 40 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/Luminance.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: befbb4b9c320b4b18a08ef7afb93b6c9 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/MinMaxReduction.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP' 2 | // Upgrade NOTE: replaced 'glstate.matrix.texture[0]' with 'UNITY_MATRIX_TEXTURE0' 3 | // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D' 4 | // Upgrade NOTE: replaced 'texRECT' with 'tex2D' 5 | 6 | // Reduces input image (_MainTex) by 2x2. 7 | // Outputs maximum value in R, minimum in G. 8 | Shader "Hidden/Contrast Stretch Reduction" { 9 | 10 | Properties { 11 | _MainTex ("Base (RGB)", RECT) = "white" {} 12 | } 13 | 14 | Category { 15 | SubShader { 16 | Pass { 17 | ZTest Always Cull Off ZWrite Off 18 | Fog { Mode off } 19 | 20 | CGPROGRAM 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | #pragma fragmentoption ARB_precision_hint_fastest 24 | #include "UnityCG.cginc" 25 | 26 | struct v2f { 27 | float4 position : POSITION; 28 | float2 uv[4] : TEXCOORD0; 29 | }; 30 | 31 | uniform sampler2D _MainTex; 32 | 33 | v2f vert (appdata_img v) { 34 | v2f o; 35 | o.position = mul (UNITY_MATRIX_MVP, v.vertex); 36 | float2 uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord); 37 | 38 | // Compute UVs to sample 2x2 pixel block. 39 | o.uv[0] = uv + float2(0,0); 40 | o.uv[1] = uv + float2(0,1); 41 | o.uv[2] = uv + float2(1,0); 42 | o.uv[3] = uv + float2(1,1); 43 | return o; 44 | } 45 | 46 | float4 frag (v2f i) : COLOR 47 | { 48 | // Sample pixel block 49 | float4 v00 = tex2D(_MainTex, i.uv[0]); 50 | float2 v01 = tex2D(_MainTex, i.uv[1]).xy; 51 | float2 v10 = tex2D(_MainTex, i.uv[2]).xy; 52 | float2 v11 = tex2D(_MainTex, i.uv[3]).xy; 53 | 54 | float4 res; 55 | // output x: maximum of the four values 56 | res.x = max( max(v00.x,v01.x), max(v10.x,v11.x) ); 57 | // output y: minimum of the four values 58 | res.y = min( min(v00.y,v01.y), min(v10.y,v11.y) ); 59 | // output zw unchanged from the first pixel 60 | res.zw = v00.zw; 61 | 62 | //res.xy = (v00.xy + v01 + v10 + v11)/4; 63 | //res.zw = 0; 64 | 65 | return res; 66 | } 67 | ENDCG 68 | 69 | } 70 | } 71 | } 72 | 73 | Fallback off 74 | 75 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/Contrast Stretch/MinMaxReduction.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 57b33a14b6d5347c5a85c36f6cb3b280 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/EdgeDetectEffect.cs: -------------------------------------------------------------------------------- 1 | // Implements Edge Detection using a Roberts cross filter. 2 | 3 | using UnityEngine; 4 | 5 | [ExecuteInEditMode] 6 | [AddComponentMenu("Image Effects/Edge Detection")] 7 | public class EdgeDetectEffect : ImageEffectBase 8 | { 9 | public float threshold = 0.2F; 10 | 11 | // Called by camera to apply image effect 12 | void OnRenderImage (RenderTexture source, RenderTexture destination) 13 | { 14 | material.SetFloat("_Treshold", threshold * threshold); 15 | ImageEffects.BlitWithMaterial (material, source, destination); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/EdgeDetectEffect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: e2dabca7ad1189d6d00011d98d76c639 3 | MonoImporter: 4 | importerVersion: 1 5 | defaultReferences: 6 | shader: {fileID: 4800000, guid: 4116114fad112a07d000fbfb8d76c639, type: 1} 7 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/EdgeDetectX.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP' 2 | // Upgrade NOTE: replaced 'glstate.matrix.texture[0]' with 'UNITY_MATRIX_TEXTURE0' 3 | // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D' 4 | // Upgrade NOTE: replaced 'texRECT' with 'tex2D' 5 | 6 | Shader "Hidden/Edge Detect X" { 7 | Properties { 8 | _MainTex ("Base (RGB)", RECT) = "white" {} 9 | _Treshold ("Treshold", Float) = 0.2 10 | } 11 | 12 | SubShader { 13 | Pass { 14 | ZTest Always Cull Off ZWrite Off 15 | Fog { Mode off } 16 | 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | #pragma fragmentoption ARB_precision_hint_fastest 21 | #include "UnityCG.cginc" 22 | 23 | uniform sampler2D _MainTex; 24 | uniform float4 _MainTex_TexelSize; 25 | uniform float _Treshold; 26 | 27 | struct v2f { 28 | float4 pos : POSITION; 29 | float2 uv[3] : TEXCOORD0; 30 | }; 31 | 32 | v2f vert( appdata_img v ) 33 | { 34 | v2f o; 35 | o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 36 | float2 uv = MultiplyUV( UNITY_MATRIX_TEXTURE0, v.texcoord ); 37 | o.uv[0] = uv; 38 | o.uv[1] = uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y); 39 | o.uv[2] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y); 40 | return o; 41 | } 42 | 43 | 44 | half4 frag (v2f i) : COLOR 45 | { 46 | half4 original = tex2D(_MainTex, i.uv[0]); 47 | 48 | // a very simple cross gradient filter 49 | half3 p1 = original.rgb; 50 | half3 p2 = tex2D( _MainTex, i.uv[1] ).rgb; 51 | half3 p3 = tex2D( _MainTex, i.uv[2] ).rgb; 52 | 53 | half3 diff = p1 * 2 - p2 - p3; 54 | half len = dot(diff,diff); 55 | if( len >= _Treshold ) 56 | original.rgb = 0; 57 | 58 | return original; 59 | } 60 | ENDCG 61 | } 62 | } 63 | 64 | Fallback off 65 | 66 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/EdgeDetectX.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 4116114fad112a07d000fbfb8d76c639 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/GlowEffect.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | // Glow uses the alpha channel as a source of "extra brightness". 4 | // All builtin Unity shaders output baseTexture.alpha * color.alpha, plus 5 | // specularHighlight * specColor.alpha into that. 6 | // Usually you'd want either to make base textures to have zero alpha; or 7 | // set the color to have zero alpha (by default alpha is 0.5). 8 | 9 | [ExecuteInEditMode] 10 | [RequireComponent (typeof(Camera))] 11 | [AddComponentMenu("Image Effects/Glow")] 12 | public class GlowEffect : MonoBehaviour 13 | { 14 | /// The brightness of the glow. Values larger than one give extra "boost". 15 | public float glowIntensity = 1.5f; 16 | 17 | /// Blur iterations - larger number means more blur. 18 | public int blurIterations = 3; 19 | 20 | /// Blur spread for each iteration. Lower values 21 | /// give better looking blur, but require more iterations to 22 | /// get large blurs. Value is usually between 0.5 and 1.0. 23 | public float blurSpread = 0.7f; 24 | 25 | /// Tint glow with this color. Alpha adds additional glow everywhere. 26 | public Color glowTint = new Color(1,1,1,0); 27 | 28 | 29 | // -------------------------------------------------------- 30 | // The final composition shader: 31 | // adds (glow color * glow alpha * amount) to the original image. 32 | // In the combiner glow amount can be only in 0..1 range; we apply extra 33 | // amount during the blurring phase. 34 | 35 | private static string compositeMatString = 36 | @"Shader ""GlowCompose"" { 37 | Properties { 38 | _Color (""Glow Amount"", Color) = (1,1,1,1) 39 | _MainTex ("""", RECT) = ""white"" {} 40 | } 41 | SubShader { 42 | Pass { 43 | ZTest Always Cull Off ZWrite Off Fog { Mode Off } 44 | Blend One One 45 | SetTexture [_MainTex] {constantColor [_Color] combine constant * texture DOUBLE} 46 | } 47 | } 48 | Fallback off 49 | }"; 50 | 51 | static Material m_CompositeMaterial = null; 52 | protected static Material compositeMaterial { 53 | get { 54 | if (m_CompositeMaterial == null) { 55 | m_CompositeMaterial = new Material (compositeMatString); 56 | m_CompositeMaterial.hideFlags = HideFlags.HideAndDontSave; 57 | m_CompositeMaterial.shader.hideFlags = HideFlags.HideAndDontSave; 58 | } 59 | return m_CompositeMaterial; 60 | } 61 | } 62 | 63 | 64 | // -------------------------------------------------------- 65 | // The blur iteration shader. 66 | // Basically it just takes 4 texture samples and averages them. 67 | // By applying it repeatedly and spreading out sample locations 68 | // we get a Gaussian blur approximation. 69 | // The alpha value in _Color would normally be 0.25 (to average 4 samples), 70 | // however if we have glow amount larger than 1 then we increase this. 71 | 72 | private static string blurMatString = 73 | @"Shader ""GlowConeTap"" { 74 | Properties { 75 | _Color (""Blur Boost"", Color) = (0,0,0,0.25) 76 | _MainTex ("""", RECT) = ""white"" {} 77 | } 78 | SubShader { 79 | Pass { 80 | ZTest Always Cull Off ZWrite Off Fog { Mode Off } 81 | SetTexture [_MainTex] {constantColor [_Color] combine texture * constant alpha} 82 | SetTexture [_MainTex] {constantColor [_Color] combine texture * constant + previous} 83 | SetTexture [_MainTex] {constantColor [_Color] combine texture * constant + previous} 84 | SetTexture [_MainTex] {constantColor [_Color] combine texture * constant + previous} 85 | } 86 | } 87 | Fallback off 88 | }"; 89 | 90 | static Material m_BlurMaterial = null; 91 | protected static Material blurMaterial { 92 | get { 93 | if (m_BlurMaterial == null) { 94 | m_BlurMaterial = new Material( blurMatString ); 95 | m_BlurMaterial.hideFlags = HideFlags.HideAndDontSave; 96 | m_BlurMaterial.shader.hideFlags = HideFlags.HideAndDontSave; 97 | } 98 | return m_BlurMaterial; 99 | } 100 | } 101 | 102 | 103 | // -------------------------------------------------------- 104 | // The image downsample shaders for each brightness mode. 105 | // It is in external assets as it's quite complex and uses Cg. 106 | 107 | public Shader downsampleShader; 108 | Material m_DownsampleMaterial = null; 109 | protected Material downsampleMaterial { 110 | get { 111 | if (m_DownsampleMaterial == null) { 112 | m_DownsampleMaterial = new Material( downsampleShader ); 113 | m_DownsampleMaterial.hideFlags = HideFlags.HideAndDontSave; 114 | } 115 | return m_DownsampleMaterial; 116 | } 117 | } 118 | 119 | 120 | // -------------------------------------------------------- 121 | // finally, the actual code 122 | 123 | protected void OnDisable() 124 | { 125 | if( m_CompositeMaterial ) { 126 | DestroyImmediate( m_CompositeMaterial.shader ); 127 | DestroyImmediate( m_CompositeMaterial ); 128 | } 129 | if( m_BlurMaterial ) { 130 | DestroyImmediate( m_BlurMaterial.shader ); 131 | DestroyImmediate( m_BlurMaterial ); 132 | } 133 | if( m_DownsampleMaterial ) 134 | DestroyImmediate( m_DownsampleMaterial ); 135 | } 136 | 137 | protected void Start() 138 | { 139 | // Disable if we don't support image effects 140 | if (!SystemInfo.supportsImageEffects) 141 | { 142 | enabled = false; 143 | return; 144 | } 145 | 146 | // Disable the effect if no downsample shader is setup 147 | if( downsampleShader == null ) 148 | { 149 | Debug.Log ("No downsample shader assigned! Disabling glow."); 150 | enabled = false; 151 | } 152 | // Disable if any of the shaders can't run on the users graphics card 153 | else 154 | { 155 | if( !blurMaterial.shader.isSupported ) 156 | enabled = false; 157 | if( !compositeMaterial.shader.isSupported ) 158 | enabled = false; 159 | if( !downsampleMaterial.shader.isSupported ) 160 | enabled = false; 161 | } 162 | } 163 | 164 | // Performs one blur iteration. 165 | public void FourTapCone (RenderTexture source, RenderTexture dest, int iteration) 166 | { 167 | RenderTexture.active = dest; 168 | blurMaterial.SetTexture("_MainTex", source); 169 | 170 | float offsetX = (.5F+iteration*blurSpread) / (float)source.width; 171 | float offsetY = (.5F+iteration*blurSpread) / (float)source.height; 172 | GL.PushMatrix (); 173 | GL.LoadOrtho (); 174 | 175 | for (int i = 0; i < blurMaterial.passCount; i++) { 176 | blurMaterial.SetPass (i); 177 | Render4TapQuad( dest, offsetX, offsetY ); 178 | } 179 | GL.PopMatrix (); 180 | } 181 | 182 | // Downsamples the texture to a quarter resolution. 183 | private void DownSample4x (RenderTexture source, RenderTexture dest) 184 | { 185 | downsampleMaterial.color = new Color( glowTint.r, glowTint.g, glowTint.b, glowTint.a/4.0f ); 186 | ImageEffects.BlitWithMaterial( downsampleMaterial, source, dest ); 187 | } 188 | 189 | // Called by the camera to apply the image effect 190 | void OnRenderImage (RenderTexture source, RenderTexture destination) 191 | { 192 | // Clamp parameters to sane values 193 | glowIntensity = Mathf.Clamp( glowIntensity, 0.0f, 10.0f ); 194 | blurIterations = Mathf.Clamp( blurIterations, 0, 30 ); 195 | blurSpread = Mathf.Clamp( blurSpread, 0.5f, 1.0f ); 196 | 197 | RenderTexture buffer = RenderTexture.GetTemporary(source.width/4, source.height/4, 0); 198 | RenderTexture buffer2 = RenderTexture.GetTemporary(source.width/4, source.height/4, 0); 199 | 200 | // Copy source to the 4x4 smaller texture. 201 | DownSample4x (source, buffer); 202 | 203 | // Blur the small texture 204 | float extraBlurBoost = Mathf.Clamp01( (glowIntensity - 1.0f) / 4.0f ); 205 | blurMaterial.color = new Color( 1F, 1F, 1F, 0.25f + extraBlurBoost ); 206 | 207 | bool oddEven = true; 208 | for(int i = 0; i < blurIterations; i++) 209 | { 210 | if( oddEven ) 211 | FourTapCone (buffer, buffer2, i); 212 | else 213 | FourTapCone (buffer2, buffer, i); 214 | oddEven = !oddEven; 215 | } 216 | ImageEffects.Blit(source,destination); 217 | 218 | if( oddEven ) 219 | BlitGlow(buffer, destination); 220 | else 221 | BlitGlow(buffer2, destination); 222 | 223 | RenderTexture.ReleaseTemporary(buffer); 224 | RenderTexture.ReleaseTemporary(buffer2); 225 | } 226 | 227 | public void BlitGlow( RenderTexture source, RenderTexture dest ) 228 | { 229 | compositeMaterial.color = new Color(1F, 1F, 1F, Mathf.Clamp01(glowIntensity)); 230 | ImageEffects.BlitWithMaterial( compositeMaterial, source, dest ); 231 | } 232 | 233 | private static void Render4TapQuad( RenderTexture dest, float offsetX, float offsetY ) 234 | { 235 | GL.Begin( GL.QUADS ); 236 | 237 | // Direct3D needs interesting texel offsets! 238 | Vector2 off = Vector2.zero; 239 | if( dest != null ) 240 | off = dest.GetTexelOffset() * 0.75f; 241 | 242 | Set4TexCoords( off.x, off.y, offsetX, offsetY ); 243 | GL.Vertex3( 0,0, .1f ); 244 | 245 | Set4TexCoords( 1.0f + off.x, off.y, offsetX, offsetY ); 246 | GL.Vertex3( 1,0, .1f ); 247 | 248 | Set4TexCoords( 1.0f + off.x, 1.0f + off.y, offsetX, offsetY ); 249 | GL.Vertex3( 1,1,.1f ); 250 | 251 | Set4TexCoords( off.x, 1.0f + off.y, offsetX, offsetY ); 252 | GL.Vertex3( 0,1,.1f ); 253 | 254 | GL.End(); 255 | } 256 | 257 | private static void Set4TexCoords( float x, float y, float offsetX, float offsetY ) 258 | { 259 | GL.MultiTexCoord2( 0, x - offsetX, y - offsetY ); 260 | GL.MultiTexCoord2( 1, x + offsetX, y - offsetY ); 261 | GL.MultiTexCoord2( 2, x + offsetX, y + offsetY ); 262 | GL.MultiTexCoord2( 3, x - offsetX, y + offsetY ); 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/GlowEffect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 0d1352984e3c6465088f6cc7c4ce6e22 3 | MonoImporter: 4 | importerVersion: 1 5 | defaultReferences: 6 | downsampleShader: {fileID: 4800000, guid: b14b79b8936134d3f8238f0c2d40d634, type: 1} 7 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/GlowEffectDownsample.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP' 2 | // Upgrade NOTE: replaced 'glstate.matrix.texture[0]' with 'UNITY_MATRIX_TEXTURE0' 3 | // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D' 4 | // Upgrade NOTE: replaced 'texRECT' with 'tex2D' 5 | 6 | Shader "Hidden/Glow Downsample" { 7 | 8 | Properties { 9 | _Color ("Color", color) = (1,1,1,0) 10 | _MainTex ("", RECT) = "white" {} 11 | } 12 | 13 | CGINCLUDE 14 | #include "UnityCG.cginc" 15 | 16 | struct v2f { 17 | float4 pos : POSITION; 18 | float4 uv[4] : TEXCOORD0; 19 | }; 20 | 21 | float4 _MainTex_TexelSize; 22 | 23 | v2f vert (appdata_img v) 24 | { 25 | v2f o; 26 | o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 27 | float4 uv; 28 | uv.xy = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord); 29 | uv.zw = 0; 30 | float offX = _MainTex_TexelSize.x; 31 | float offY = _MainTex_TexelSize.y; 32 | 33 | // Direct3D9 needs some texel offset! 34 | #ifdef SHADER_API_D3D9 35 | uv.x += offX * 2.0f; 36 | uv.y += offY * 2.0f; 37 | #endif 38 | o.uv[0] = uv + float4(-offX,-offY,0,1); 39 | o.uv[1] = uv + float4( offX,-offY,0,1); 40 | o.uv[2] = uv + float4( offX, offY,0,1); 41 | o.uv[3] = uv + float4(-offX, offY,0,1); 42 | return o; 43 | } 44 | ENDCG 45 | 46 | 47 | Category { 48 | ZTest Always Cull Off ZWrite Off Fog { Mode Off } 49 | 50 | // ----------------------------------------------------------- 51 | // ARB fragment program 52 | 53 | Subshader { 54 | Pass { 55 | 56 | CGPROGRAM 57 | #pragma vertex vert 58 | #pragma fragment frag 59 | #pragma fragmentoption ARB_precision_hint_fastest 60 | 61 | sampler2D _MainTex; 62 | float4 _Color; 63 | 64 | half4 frag( v2f i ) : COLOR 65 | { 66 | half4 c; 67 | c = tex2D( _MainTex, i.uv[0].xy ); 68 | c += tex2D( _MainTex, i.uv[1].xy ); 69 | c += tex2D( _MainTex, i.uv[2].xy ); 70 | c += tex2D( _MainTex, i.uv[3].xy ); 71 | c /= 4; 72 | c.rgb *= _Color.rgb; 73 | c.rgb *= (c.a + _Color.a); 74 | c.a = 0; 75 | return c; 76 | } 77 | ENDCG 78 | 79 | } 80 | } 81 | 82 | // ----------------------------------------------------------- 83 | // Radeon 9000 84 | 85 | Subshader { 86 | Pass { 87 | 88 | 89 | CGPROGRAM 90 | // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs. 91 | #pragma exclude_renderers gles 92 | #pragma vertex vert 93 | // use the same vertex program as in FP path 94 | ENDCG 95 | 96 | 97 | // average 2x2 samples 98 | SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant alpha} 99 | SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous} 100 | SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous} 101 | SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous} 102 | // apply glow tint and add additional glow 103 | SetTexture [_MainTex] {constantColor[_Color] combine previous * constant, previous + constant} 104 | SetTexture [_MainTex] {constantColor (0,0,0,0) combine previous * previous alpha, constant} 105 | } 106 | } 107 | } 108 | 109 | Fallback off 110 | 111 | } 112 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/GlowEffectDownsample.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: b14b79b8936134d3f8238f0c2d40d634 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/GrayscaleEffect.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | [ExecuteInEditMode] 4 | [AddComponentMenu("Image Effects/Grayscale")] 5 | public class GrayscaleEffect : ImageEffectBase { 6 | public Texture textureRamp; 7 | public float rampOffset; 8 | 9 | // Called by camera to apply image effect 10 | void OnRenderImage (RenderTexture source, RenderTexture destination) { 11 | material.SetTexture("_RampTex", textureRamp); 12 | material.SetFloat("_RampOffset", rampOffset); 13 | ImageEffects.BlitWithMaterial (material, source, destination); 14 | } 15 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/GrayscaleEffect.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 243a781cad112c75d0008dfa8d76c639 3 | MonoImporter: 4 | importerVersion: 1 5 | defaultReferences: 6 | shader: {fileID: 4800000, guid: daf9781cad112c75d0008dfa8d76c639, type: 1} 7 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/GrayscaleEffect.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D' 2 | // Upgrade NOTE: replaced 'texRECT' with 'tex2D' 3 | 4 | Shader "Hidden/Grayscale Effect" { 5 | Properties { 6 | _MainTex ("Base (RGB)", RECT) = "white" {} 7 | _RampTex ("Base (RGB)", 2D) = "grayscaleRamp" {} 8 | } 9 | 10 | SubShader { 11 | Pass { 12 | ZTest Always Cull Off ZWrite Off 13 | Fog { Mode off } 14 | 15 | CGPROGRAM 16 | #pragma vertex vert_img 17 | #pragma fragment frag 18 | #pragma fragmentoption ARB_precision_hint_fastest 19 | #include "UnityCG.cginc" 20 | 21 | uniform sampler2D _MainTex; 22 | uniform sampler2D _RampTex; 23 | uniform float _RampOffset; 24 | 25 | float4 frag (v2f_img i) : COLOR 26 | { 27 | float4 original = tex2D(_MainTex, i.uv); 28 | float grayscale = Luminance(original.rgb); 29 | float2 remap = float2 (grayscale + _RampOffset, .5); 30 | float4 output = tex2D(_RampTex, remap); 31 | output.a = original.a; 32 | return output; 33 | } 34 | ENDCG 35 | 36 | } 37 | } 38 | 39 | Fallback off 40 | 41 | } -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/GrayscaleEffect.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: daf9781cad112c75d0008dfa8d76c639 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/ImageEffectBase.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | [RequireComponent (typeof(Camera))] 4 | [AddComponentMenu("")] 5 | public class ImageEffectBase : MonoBehaviour { 6 | /// Provides a shader property that is set in the inspector 7 | /// and a material instantiated from the shader 8 | public Shader shader; 9 | private Material m_Material; 10 | 11 | protected void Start () 12 | { 13 | // Disable if we don't support image effects 14 | if (!SystemInfo.supportsImageEffects) { 15 | enabled = false; 16 | return; 17 | } 18 | 19 | // Disable the image effect if the shader can't 20 | // run on the users graphics card 21 | if (!shader || !shader.isSupported) 22 | enabled = false; 23 | } 24 | 25 | protected Material material { 26 | get { 27 | if (m_Material == null) { 28 | m_Material = new Material (shader); 29 | m_Material.hideFlags = HideFlags.HideAndDontSave; 30 | } 31 | return m_Material; 32 | } 33 | } 34 | 35 | protected void OnDisable() { 36 | if( m_Material ) { 37 | DestroyImmediate( m_Material ); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/ImageEffectBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: f6469eb0ad1119d6d00011d98d76c639 3 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Image Based/ImageEffects.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | /// Blending modes use by the ImageEffects.Blit functions. 4 | public enum BlendMode { 5 | Copy, 6 | Multiply, 7 | MultiplyDouble, 8 | Add, 9 | AddSmoooth, 10 | Blend 11 | } 12 | 13 | /// A Utility class for performing various image based rendering tasks. 14 | [AddComponentMenu("")] 15 | public class ImageEffects { 16 | static Material[] m_BlitMaterials = {null, null, null, null, null, null}; 17 | 18 | static public Material GetBlitMaterial (BlendMode mode) { 19 | int index = (int)mode; 20 | 21 | if (m_BlitMaterials[index] != null) 22 | return m_BlitMaterials[index]; 23 | 24 | // Blit Copy Material 25 | m_BlitMaterials[0] = new Material ( 26 | "Shader \"BlitCopy\" {\n" + 27 | " SubShader { Pass {\n" + 28 | " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" + 29 | " SetTexture [__RenderTex] { combine texture}" + 30 | " }}\n" + 31 | "Fallback Off }" 32 | ); 33 | // Blit Multiply 34 | m_BlitMaterials[1] = new Material ( 35 | "Shader \"BlitMultiply\" {\n" + 36 | " SubShader { Pass {\n" + 37 | " Blend DstColor Zero\n" + 38 | " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" + 39 | " SetTexture [__RenderTex] { combine texture }" + 40 | " }}\n" + 41 | "Fallback Off }" 42 | ); 43 | // Blit Multiply 2X 44 | m_BlitMaterials[2] = new Material ( 45 | "Shader \"BlitMultiplyDouble\" {\n" + 46 | " SubShader { Pass {\n" + 47 | " Blend DstColor SrcColor\n" + 48 | " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" + 49 | " SetTexture [__RenderTex] { combine texture }" + 50 | " }}\n" + 51 | "Fallback Off }" 52 | ); 53 | // Blit Add 54 | m_BlitMaterials[3] = new Material ( 55 | "Shader \"BlitAdd\" {\n" + 56 | " SubShader { Pass {\n" + 57 | " Blend One One\n" + 58 | " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" + 59 | " SetTexture [__RenderTex] { combine texture }" + 60 | " }}\n" + 61 | "Fallback Off }" 62 | ); 63 | // Blit AddSmooth 64 | m_BlitMaterials[4] = new Material ( 65 | "Shader \"BlitAddSmooth\" {\n" + 66 | " SubShader { Pass {\n" + 67 | " Blend OneMinusDstColor One\n" + 68 | " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" + 69 | " SetTexture [__RenderTex] { combine texture }" + 70 | " }}\n" + 71 | "Fallback Off }" 72 | ); 73 | // Blit Blend 74 | m_BlitMaterials[5] = new Material ( 75 | "Shader \"BlitBlend\" {\n" + 76 | " SubShader { Pass {\n" + 77 | " Blend SrcAlpha OneMinusSrcAlpha\n" + 78 | " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" + 79 | " SetTexture [__RenderTex] { combine texture }" + 80 | " }}\n" + 81 | "Fallback Off }" 82 | ); 83 | for( int i = 0; i < m_BlitMaterials.Length; ++i ) { 84 | m_BlitMaterials[i].hideFlags = HideFlags.HideAndDontSave; 85 | m_BlitMaterials[i].shader.hideFlags = HideFlags.HideAndDontSave; 86 | } 87 | return m_BlitMaterials[index]; 88 | } 89 | 90 | 91 | /// Copies one render texture onto another. 92 | /// This function copies /source/ onto /dest/, optionally using a custom blend mode. 93 | /// If /blendMode/ is left out, the default operation is simply to copy one texture on to another. 94 | /// This function will copy the whole source texture on to the whole destination texture. If the sizes differ, 95 | /// the image in the source texture will get stretched to fit. 96 | /// The source and destination textures cannot be the same. 97 | public static void Blit (RenderTexture source, RenderTexture dest, BlendMode blendMode) { 98 | Blit (source, new Rect (0,0,1,1), dest, new Rect (0,0,1,1), blendMode); 99 | } 100 | public static void Blit (RenderTexture source, RenderTexture dest) { 101 | Blit (source, dest, BlendMode.Copy); 102 | } 103 | 104 | /// Copies one render texture onto another. 105 | public static void Blit (RenderTexture source, Rect sourceRect, RenderTexture dest, Rect destRect, BlendMode blendMode) { 106 | // Make the destination texture the target for all rendering 107 | RenderTexture.active = dest; 108 | // Assign the source texture to a property from a shader 109 | source.SetGlobalShaderProperty ("__RenderTex"); 110 | // Set up the simple Matrix 111 | GL.PushMatrix (); 112 | GL.LoadOrtho (); 113 | Material blitMaterial = GetBlitMaterial(blendMode); 114 | for (int i = 0; i < blitMaterial.passCount; i++) { 115 | blitMaterial.SetPass (i); 116 | DrawQuad(); 117 | } 118 | GL.PopMatrix (); 119 | } 120 | 121 | 122 | public static void BlitWithMaterial (Material material, RenderTexture source, RenderTexture destination) 123 | { 124 | RenderTexture.active = destination; 125 | material.SetTexture("_MainTex", source); 126 | 127 | GL.PushMatrix (); 128 | GL.LoadOrtho (); 129 | 130 | for (int i = 0; i < material.passCount; i++) { 131 | material.SetPass (i); 132 | ImageEffects.DrawQuad(); 133 | } 134 | GL.PopMatrix (); 135 | } 136 | 137 | 138 | public static void RenderDistortion (Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius) 139 | { 140 | Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one); 141 | 142 | material.SetMatrix("_RotationMatrix", rotationMatrix); 143 | material.SetVector("_CenterRadius", new Vector4(center.x,center.y,radius.x,radius.y) ); 144 | material.SetFloat("_Angle", angle * Mathf.Deg2Rad); 145 | 146 | ImageEffects.BlitWithMaterial( material, source, destination ); 147 | } 148 | 149 | 150 | public static void DrawQuad() 151 | { 152 | GL.Begin (GL.QUADS); 153 | GL.TexCoord2( 0.0f, 0.0f ); GL.Vertex3( 0.0f, 0.0f, 0.1f ); 154 | GL.TexCoord2( 1.0f, 0.0f ); GL.Vertex3( 1.0f, 0.0f, 0.1f ); 155 | GL.TexCoord2( 1.0f, 1.0f ); GL.Vertex3( 1.0f, 1.0f, 0.1f ); 156 | GL.TexCoord2( 0.0f, 1.0f ); GL.Vertex3( 0.0f, 1.0f, 0.1f ); 157 | GL.End(); 158 | } 159 | 160 | public static void DrawGrid (int xSize, int ySize) 161 | { 162 | GL.Begin (GL.QUADS); 163 | 164 | float xDelta = 1.0F / xSize; 165 | float yDelta = 1.0F / ySize; 166 | 167 | for (int y=0;y Camera table 22 | private Hashtable m_RefractionCameras = new Hashtable(); // Camera -> Camera table 23 | 24 | private RenderTexture m_ReflectionTexture = null; 25 | private RenderTexture m_RefractionTexture = null; 26 | private WaterMode m_HardwareWaterSupport = WaterMode.Refractive; 27 | private int m_OldReflectionTextureSize = 0; 28 | private int m_OldRefractionTextureSize = 0; 29 | 30 | private static bool s_InsideWater = false; 31 | 32 | // This is called when it's known that the object will be rendered by some 33 | // camera. We render reflections / refractions and do other updates here. 34 | // Because the script executes in edit mode, reflections for the scene view 35 | // camera will just work! 36 | public void OnWillRenderObject() 37 | { 38 | if( !enabled || !renderer || !renderer.sharedMaterial || !renderer.enabled ) 39 | return; 40 | 41 | Camera cam = Camera.current; 42 | if( !cam ) 43 | return; 44 | 45 | // Safeguard from recursive water reflections. 46 | if( s_InsideWater ) 47 | return; 48 | s_InsideWater = true; 49 | 50 | // Actual water rendering mode depends on both the current setting AND 51 | // the hardware support. There's no point in rendering refraction textures 52 | // if they won't be visible in the end. 53 | m_HardwareWaterSupport = FindHardwareWaterSupport(); 54 | WaterMode mode = GetWaterMode(); 55 | 56 | Camera reflectionCamera, refractionCamera; 57 | CreateWaterObjects( cam, out reflectionCamera, out refractionCamera ); 58 | 59 | // find out the reflection plane: position and normal in world space 60 | Vector3 pos = transform.position; 61 | Vector3 normal = transform.up; 62 | 63 | // Optionally disable pixel lights for reflection/refraction 64 | int oldPixelLightCount = QualitySettings.pixelLightCount; 65 | if( m_DisablePixelLights ) 66 | QualitySettings.pixelLightCount = 0; 67 | 68 | UpdateCameraModes( cam, reflectionCamera ); 69 | UpdateCameraModes( cam, refractionCamera ); 70 | 71 | // Render reflection if needed 72 | if( mode >= WaterMode.Reflective ) 73 | { 74 | // Reflect camera around reflection plane 75 | float d = -Vector3.Dot (normal, pos) - m_ClipPlaneOffset; 76 | Vector4 reflectionPlane = new Vector4 (normal.x, normal.y, normal.z, d); 77 | 78 | Matrix4x4 reflection = Matrix4x4.zero; 79 | CalculateReflectionMatrix (ref reflection, reflectionPlane); 80 | Vector3 oldpos = cam.transform.position; 81 | Vector3 newpos = reflection.MultiplyPoint( oldpos ); 82 | reflectionCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection; 83 | 84 | // Setup oblique projection matrix so that near plane is our reflection 85 | // plane. This way we clip everything below/above it for free. 86 | Vector4 clipPlane = CameraSpacePlane( reflectionCamera, pos, normal, 1.0f ); 87 | Matrix4x4 projection = cam.projectionMatrix; 88 | CalculateObliqueMatrix (ref projection, clipPlane); 89 | reflectionCamera.projectionMatrix = projection; 90 | 91 | reflectionCamera.cullingMask = ~(1<<4) & m_ReflectLayers.value; // never render water layer 92 | reflectionCamera.targetTexture = m_ReflectionTexture; 93 | GL.SetRevertBackfacing (true); 94 | reflectionCamera.transform.position = newpos; 95 | Vector3 euler = cam.transform.eulerAngles; 96 | reflectionCamera.transform.eulerAngles = new Vector3(0, euler.y, euler.z); 97 | reflectionCamera.Render(); 98 | reflectionCamera.transform.position = oldpos; 99 | GL.SetRevertBackfacing (false); 100 | renderer.sharedMaterial.SetTexture( "_ReflectionTex", m_ReflectionTexture ); 101 | } 102 | 103 | // Render refraction 104 | if( mode >= WaterMode.Refractive ) 105 | { 106 | refractionCamera.worldToCameraMatrix = cam.worldToCameraMatrix; 107 | 108 | // Setup oblique projection matrix so that near plane is our reflection 109 | // plane. This way we clip everything below/above it for free. 110 | Vector4 clipPlane = CameraSpacePlane( refractionCamera, pos, normal, -1.0f ); 111 | Matrix4x4 projection = cam.projectionMatrix; 112 | CalculateObliqueMatrix (ref projection, clipPlane); 113 | refractionCamera.projectionMatrix = projection; 114 | 115 | refractionCamera.cullingMask = ~(1<<4) & m_RefractLayers.value; // never render water layer 116 | refractionCamera.targetTexture = m_RefractionTexture; 117 | refractionCamera.transform.position = cam.transform.position; 118 | refractionCamera.transform.rotation = cam.transform.rotation; 119 | refractionCamera.Render(); 120 | renderer.sharedMaterial.SetTexture( "_RefractionTex", m_RefractionTexture ); 121 | } 122 | 123 | // Restore pixel light count 124 | if( m_DisablePixelLights ) 125 | QualitySettings.pixelLightCount = oldPixelLightCount; 126 | 127 | // Setup shader keywords based on water mode 128 | switch( mode ) 129 | { 130 | case WaterMode.Simple: 131 | Shader.EnableKeyword( "WATER_SIMPLE" ); 132 | Shader.DisableKeyword( "WATER_REFLECTIVE" ); 133 | Shader.DisableKeyword( "WATER_REFRACTIVE" ); 134 | break; 135 | case WaterMode.Reflective: 136 | Shader.DisableKeyword( "WATER_SIMPLE" ); 137 | Shader.EnableKeyword( "WATER_REFLECTIVE" ); 138 | Shader.DisableKeyword( "WATER_REFRACTIVE" ); 139 | break; 140 | case WaterMode.Refractive: 141 | Shader.DisableKeyword( "WATER_SIMPLE" ); 142 | Shader.DisableKeyword( "WATER_REFLECTIVE" ); 143 | Shader.EnableKeyword( "WATER_REFRACTIVE" ); 144 | break; 145 | } 146 | 147 | s_InsideWater = false; 148 | } 149 | 150 | 151 | // Cleanup all the objects we possibly have created 152 | void OnDisable() 153 | { 154 | if( m_ReflectionTexture ) { 155 | DestroyImmediate( m_ReflectionTexture ); 156 | m_ReflectionTexture = null; 157 | } 158 | if( m_RefractionTexture ) { 159 | DestroyImmediate( m_RefractionTexture ); 160 | m_RefractionTexture = null; 161 | } 162 | foreach( DictionaryEntry kvp in m_ReflectionCameras ) 163 | DestroyImmediate( ((Camera)kvp.Value).gameObject ); 164 | m_ReflectionCameras.Clear(); 165 | foreach( DictionaryEntry kvp in m_RefractionCameras ) 166 | DestroyImmediate( ((Camera)kvp.Value).gameObject ); 167 | m_RefractionCameras.Clear(); 168 | } 169 | 170 | 171 | // This just sets up some matrices in the material; for really 172 | // old cards to make water texture scroll. 173 | void Update() 174 | { 175 | if( !renderer ) 176 | return; 177 | Material mat = renderer.sharedMaterial; 178 | if( !mat ) 179 | return; 180 | 181 | Vector4 waveSpeed = mat.GetVector( "WaveSpeed" ); 182 | float waveScale = mat.GetFloat( "_WaveScale" ); 183 | Vector4 waveScale4 = new Vector4(waveScale, waveScale, waveScale * 0.4f, waveScale * 0.45f); 184 | 185 | // Time since level load, and do intermediate calculations with doubles 186 | double t = Time.timeSinceLevelLoad / 20.0; 187 | Vector4 offsetClamped = new Vector4( 188 | (float)System.Math.IEEERemainder(waveSpeed.x * waveScale4.x * t, 1.0), 189 | (float)System.Math.IEEERemainder(waveSpeed.y * waveScale4.y * t, 1.0), 190 | (float)System.Math.IEEERemainder(waveSpeed.z * waveScale4.z * t, 1.0), 191 | (float)System.Math.IEEERemainder(waveSpeed.w * waveScale4.w * t, 1.0) 192 | ); 193 | 194 | mat.SetVector( "_WaveOffset", offsetClamped ); 195 | mat.SetVector( "_WaveScale4", waveScale4 ); 196 | 197 | Vector3 waterSize = renderer.bounds.size; 198 | Vector3 scale = new Vector3( waterSize.x*waveScale4.x, waterSize.z*waveScale4.y, 1 ); 199 | Matrix4x4 scrollMatrix = Matrix4x4.TRS( new Vector3(offsetClamped.x,offsetClamped.y,0), Quaternion.identity, scale ); 200 | mat.SetMatrix( "_WaveMatrix", scrollMatrix ); 201 | 202 | scale = new Vector3( waterSize.x*waveScale4.z, waterSize.z*waveScale4.w, 1 ); 203 | scrollMatrix = Matrix4x4.TRS( new Vector3(offsetClamped.z,offsetClamped.w,0), Quaternion.identity, scale ); 204 | mat.SetMatrix( "_WaveMatrix2", scrollMatrix ); 205 | } 206 | 207 | private void UpdateCameraModes( Camera src, Camera dest ) 208 | { 209 | if( dest == null ) 210 | return; 211 | // set water camera to clear the same way as current camera 212 | dest.clearFlags = src.clearFlags; 213 | dest.backgroundColor = src.backgroundColor; 214 | if( src.clearFlags == CameraClearFlags.Skybox ) 215 | { 216 | Skybox sky = src.GetComponent(typeof(Skybox)) as Skybox; 217 | Skybox mysky = dest.GetComponent(typeof(Skybox)) as Skybox; 218 | if( !sky || !sky.material ) 219 | { 220 | mysky.enabled = false; 221 | } 222 | else 223 | { 224 | mysky.enabled = true; 225 | mysky.material = sky.material; 226 | } 227 | } 228 | // update other values to match current camera. 229 | // even if we are supplying custom camera&projection matrices, 230 | // some of values are used elsewhere (e.g. skybox uses far plane) 231 | dest.farClipPlane = src.farClipPlane; 232 | dest.nearClipPlane = src.nearClipPlane; 233 | dest.orthographic = src.orthographic; 234 | dest.fieldOfView = src.fieldOfView; 235 | dest.aspect = src.aspect; 236 | dest.orthographicSize = src.orthographicSize; 237 | } 238 | 239 | // On-demand create any objects we need for water 240 | private void CreateWaterObjects( Camera currentCamera, out Camera reflectionCamera, out Camera refractionCamera ) 241 | { 242 | WaterMode mode = GetWaterMode(); 243 | 244 | reflectionCamera = null; 245 | refractionCamera = null; 246 | 247 | if( mode >= WaterMode.Reflective ) 248 | { 249 | // Reflection render texture 250 | if( !m_ReflectionTexture || m_OldReflectionTextureSize != m_TextureSize ) 251 | { 252 | if( m_ReflectionTexture ) 253 | DestroyImmediate( m_ReflectionTexture ); 254 | m_ReflectionTexture = new RenderTexture( m_TextureSize, m_TextureSize, 16 ); 255 | m_ReflectionTexture.name = "__WaterReflection" + GetInstanceID(); 256 | m_ReflectionTexture.isPowerOfTwo = true; 257 | m_ReflectionTexture.hideFlags = HideFlags.DontSave; 258 | m_OldReflectionTextureSize = m_TextureSize; 259 | } 260 | 261 | // Camera for reflection 262 | reflectionCamera = m_ReflectionCameras[currentCamera] as Camera; 263 | if( !reflectionCamera ) // catch both not-in-dictionary and in-dictionary-but-deleted-GO 264 | { 265 | GameObject go = new GameObject( "Water Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox) ); 266 | reflectionCamera = go.camera; 267 | reflectionCamera.enabled = false; 268 | reflectionCamera.transform.position = transform.position; 269 | reflectionCamera.transform.rotation = transform.rotation; 270 | reflectionCamera.gameObject.AddComponent("FlareLayer"); 271 | go.hideFlags = HideFlags.HideAndDontSave; 272 | m_ReflectionCameras[currentCamera] = reflectionCamera; 273 | } 274 | } 275 | 276 | if( mode >= WaterMode.Refractive ) 277 | { 278 | // Refraction render texture 279 | if( !m_RefractionTexture || m_OldRefractionTextureSize != m_TextureSize ) 280 | { 281 | if( m_RefractionTexture ) 282 | DestroyImmediate( m_RefractionTexture ); 283 | m_RefractionTexture = new RenderTexture( m_TextureSize, m_TextureSize, 16 ); 284 | m_RefractionTexture.name = "__WaterRefraction" + GetInstanceID(); 285 | m_RefractionTexture.isPowerOfTwo = true; 286 | m_RefractionTexture.hideFlags = HideFlags.DontSave; 287 | m_OldRefractionTextureSize = m_TextureSize; 288 | } 289 | 290 | // Camera for refraction 291 | refractionCamera = m_RefractionCameras[currentCamera] as Camera; 292 | if( !refractionCamera ) // catch both not-in-dictionary and in-dictionary-but-deleted-GO 293 | { 294 | GameObject go = new GameObject( "Water Refr Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox) ); 295 | refractionCamera = go.camera; 296 | refractionCamera.enabled = false; 297 | refractionCamera.transform.position = transform.position; 298 | refractionCamera.transform.rotation = transform.rotation; 299 | refractionCamera.gameObject.AddComponent("FlareLayer"); 300 | go.hideFlags = HideFlags.HideAndDontSave; 301 | m_RefractionCameras[currentCamera] = refractionCamera; 302 | } 303 | } 304 | } 305 | 306 | private WaterMode GetWaterMode() 307 | { 308 | if( m_HardwareWaterSupport < m_WaterMode ) 309 | return m_HardwareWaterSupport; 310 | else 311 | return m_WaterMode; 312 | } 313 | 314 | private WaterMode FindHardwareWaterSupport() 315 | { 316 | if( !SystemInfo.supportsRenderTextures || !renderer ) 317 | return WaterMode.Simple; 318 | 319 | Material mat = renderer.sharedMaterial; 320 | if( !mat ) 321 | return WaterMode.Simple; 322 | 323 | string mode = mat.GetTag("WATERMODE", false); 324 | if( mode == "Refractive" ) 325 | return WaterMode.Refractive; 326 | if( mode == "Reflective" ) 327 | return WaterMode.Reflective; 328 | 329 | return WaterMode.Simple; 330 | } 331 | 332 | // Extended sign: returns -1, 0 or 1 based on sign of a 333 | private static float sgn(float a) 334 | { 335 | if (a > 0.0f) return 1.0f; 336 | if (a < 0.0f) return -1.0f; 337 | return 0.0f; 338 | } 339 | 340 | // Given position/normal of the plane, calculates plane in camera space. 341 | private Vector4 CameraSpacePlane (Camera cam, Vector3 pos, Vector3 normal, float sideSign) 342 | { 343 | Vector3 offsetPos = pos + normal * m_ClipPlaneOffset; 344 | Matrix4x4 m = cam.worldToCameraMatrix; 345 | Vector3 cpos = m.MultiplyPoint( offsetPos ); 346 | Vector3 cnormal = m.MultiplyVector( normal ).normalized * sideSign; 347 | return new Vector4( cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos,cnormal) ); 348 | } 349 | 350 | // Adjusts the given projection matrix so that near plane is the given clipPlane 351 | // clipPlane is given in camera space. See article in Game Programming Gems 5 and 352 | // http://aras-p.info/texts/obliqueortho.html 353 | private static void CalculateObliqueMatrix (ref Matrix4x4 projection, Vector4 clipPlane) 354 | { 355 | Vector4 q = projection.inverse * new Vector4( 356 | sgn(clipPlane.x), 357 | sgn(clipPlane.y), 358 | 1.0f, 359 | 1.0f 360 | ); 361 | Vector4 c = clipPlane * (2.0F / (Vector4.Dot (clipPlane, q))); 362 | // third row = clip plane - fourth row 363 | projection[2] = c.x - projection[3]; 364 | projection[6] = c.y - projection[7]; 365 | projection[10] = c.z - projection[11]; 366 | projection[14] = c.w - projection[15]; 367 | } 368 | 369 | // Calculates reflection matrix around the given plane 370 | private static void CalculateReflectionMatrix (ref Matrix4x4 reflectionMat, Vector4 plane) 371 | { 372 | reflectionMat.m00 = (1F - 2F*plane[0]*plane[0]); 373 | reflectionMat.m01 = ( - 2F*plane[0]*plane[1]); 374 | reflectionMat.m02 = ( - 2F*plane[0]*plane[2]); 375 | reflectionMat.m03 = ( - 2F*plane[3]*plane[0]); 376 | 377 | reflectionMat.m10 = ( - 2F*plane[1]*plane[0]); 378 | reflectionMat.m11 = (1F - 2F*plane[1]*plane[1]); 379 | reflectionMat.m12 = ( - 2F*plane[1]*plane[2]); 380 | reflectionMat.m13 = ( - 2F*plane[3]*plane[1]); 381 | 382 | reflectionMat.m20 = ( - 2F*plane[2]*plane[0]); 383 | reflectionMat.m21 = ( - 2F*plane[2]*plane[1]); 384 | reflectionMat.m22 = (1F - 2F*plane[2]*plane[2]); 385 | reflectionMat.m23 = ( - 2F*plane[3]*plane[2]); 386 | 387 | reflectionMat.m30 = 0F; 388 | reflectionMat.m31 = 0F; 389 | reflectionMat.m32 = 0F; 390 | reflectionMat.m33 = 1F; 391 | } 392 | } 393 | -------------------------------------------------------------------------------- /Assets/Pro Standard Assets/Water/Sources/Water.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: a3d3ef1a5bbfb4e0a910fbbe5830b1f9 3 | -------------------------------------------------------------------------------- /Assets/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 54a7e01a692944a17b4da6ff68ab1968 3 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 2d9fbb64fd1274cbe9b2ad4eebfb8a73 3 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/Bump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Resources/Ocean/Bump.png -------------------------------------------------------------------------------- /Assets/Resources/Ocean/Bump.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: e382dceeec6e9486585789e34848f611 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 0 28 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/DeepWaterBelow.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position 2 | // Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION' 3 | // Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP' 4 | 5 | Shader "DeepWaterBelow" 6 | { 7 | Properties 8 | { 9 | _Color ("Main Color", Color) = (1,1,1,1) 10 | _UnderWaterRefraction ("UnderWaterRefraction (RGB)", 2D) = "white" {} 11 | _UnderWaterBump ("UnderWaterBump (RGB)", 2D) = "bump" {} 12 | _Fresnel ("Fresnel (A) ", 2D) = "gray" {} 13 | _Size ("Size", Vector) = (1, 1, 1, 1) 14 | } 15 | SubShader { 16 | Pass { 17 | 18 | CGPROGRAM 19 | // Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct v2f members viewDir,projTexCoord,bumpTexCoord) 20 | #pragma exclude_renderers xbox360 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | #pragma fragmentoption ARB_fog_exp2 24 | #include "UnityCG.cginc" 25 | 26 | struct v2f 27 | { 28 | float4 pos : SV_POSITION; 29 | float3 viewDir; 30 | // float3 normal; 31 | float4 projTexCoord; 32 | float4 bumpTexCoord; 33 | }; 34 | 35 | float4 _Size; 36 | 37 | v2f vert (appdata_tan v) 38 | { 39 | v2f o; 40 | 41 | 42 | //Need to offset a bit in height, so we don't completely miss the 43 | //water intersection filter. 44 | v.vertex.y += 0.5; 45 | 46 | 47 | float4 projSource = float4(v.vertex.x, 0.0, v.vertex.z, 1.0); 48 | float4 tmpProj = mul( UNITY_MATRIX_MVP, projSource); 49 | o.projTexCoord = tmpProj; 50 | 51 | o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 52 | 53 | o.bumpTexCoord.xy = v.vertex.xz/float2(_Size.x, _Size.z)*10; 54 | 55 | float3 objSpaceViewDir = ObjSpaceViewDir(v.vertex); 56 | // o.normal = -v.normal; 57 | 58 | float3 binormal = cross( normalize(v.normal), normalize(v.tangent.xyz) ); 59 | float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal ); 60 | 61 | o.viewDir = mul(rotation, objSpaceViewDir); 62 | 63 | return o; 64 | } 65 | 66 | sampler2D _UnderWaterRefraction; 67 | sampler2D _UnderWaterBump; 68 | sampler2D _Fresnel; 69 | 70 | 71 | half4 frag (v2f i) : COLOR 72 | { 73 | float2 projTexCoord = 0.5 * i.projTexCoord.xy * float2(1, _ProjectionParams.x) / i.projTexCoord.w + float2(0.5, 0.5); 74 | 75 | half4 buv = half4(i.bumpTexCoord.x + _Time.x * 0.03, i.bumpTexCoord.y + _SinTime.x * 0.2, i.bumpTexCoord.x + _Time.y * 0.04, i.bumpTexCoord.y + _SinTime.y * 0.5); 76 | 77 | 78 | half3 tangentNormal0 = (tex2D(_UnderWaterBump, buv.xy).rgb * 2.0) - 1; 79 | half3 tangentNormal1 = (tex2D(_UnderWaterBump, buv.zw).rgb * 2.0) - 1; 80 | half3 tangentNormal = -normalize(tangentNormal0 + tangentNormal1); 81 | 82 | half3 refraction = tex2D(_UnderWaterRefraction, projTexCoord.xy + tangentNormal.xy * 0.2).rgb; 83 | 84 | half3 normViewDir = normalize(i.viewDir); 85 | //half3 normNormal = normalize(i.normal); 86 | 87 | float fresnelLookup = dot(tangentNormal, normViewDir); 88 | 89 | //float fresnelTerm = tex2D(_Fresnel, float2(fresnelLookup, 0.5)).a; 90 | 91 | float bias = 0.0; 92 | float power = 1.0; 93 | float fresnelTerm = bias + (1.0-bias)*pow(1.0 - fresnelLookup, power); 94 | 95 | half4 clr; 96 | 97 | clr.rgb = lerp(refraction, float3(0.3, 0.3, 0.3), fresnelTerm);// * 0.001 + fresnelTerm; 98 | clr.a = 1.0; 99 | 100 | return clr; 101 | } 102 | ENDCG 103 | 104 | } 105 | } 106 | Fallback "VertexLit" 107 | } 108 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/DeepWaterBelow.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: e125839d7a8c4455cba2bbf6f2d2dfea 3 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/Foam.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Resources/Ocean/Foam.tif -------------------------------------------------------------------------------- /Assets/Resources/Ocean/Foam.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: cfe51ecfbb07d4ae99e53857cd32cc62 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 9 26 | mipmapBias: 0 27 | wrapMode: 0 28 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/Fresnel.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Resources/Ocean/Fresnel.psd -------------------------------------------------------------------------------- /Assets/Resources/Ocean/Fresnel.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 270fbb7f89d54438cbb9f28cf8b001fc 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: 1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 0 28 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/OceanReflectionRefraction.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position 2 | // Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION' 3 | // Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP' 4 | 5 | Shader "OceanReflectionRefraction" 6 | { 7 | Properties 8 | { 9 | _SurfaceColor ("SurfaceColor", Color) = (1,1,1,1) 10 | _WaterColor ("WaterColor", Color) = (1,1,1,1) 11 | _Refraction ("Refraction (RGB)", 2D) = "white" {} 12 | _Reflection ("Reflection (RGB)", 2D) = "white" {} 13 | _Fresnel ("Fresnel (A) ", 2D) = "gray" {} 14 | _Bump ("Bump (RGB)", 2D) = "bump" {} 15 | _Foam ("Foam (RGB)", 2D) = "white" {} 16 | _Size ("Size", Vector) = (1, 1, 1, 1) 17 | _SunDir ("SunDir", Vector) = (0.3, -0.6, -1, 0) 18 | } 19 | SubShader { 20 | Pass { 21 | 22 | CGPROGRAM 23 | // Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct v2f members projTexCoord,bumpTexCoord,viewDir,lightDir,objSpaceNormal,foamStrengthAndDistance) 24 | #pragma exclude_renderers xbox360 25 | #pragma vertex vert 26 | #pragma fragment frag 27 | #pragma fragmentoption ARB_fog_exp2 28 | #include "UnityCG.cginc" 29 | 30 | struct v2f 31 | { 32 | float4 pos : SV_POSITION; 33 | float4 projTexCoord; 34 | float2 bumpTexCoord; 35 | float3 viewDir; 36 | float3 lightDir; 37 | float3 objSpaceNormal; 38 | float2 foamStrengthAndDistance; 39 | }; 40 | 41 | float4 _Size; 42 | float4 _SunDir; 43 | 44 | v2f vert (appdata_tan v) 45 | { 46 | v2f o; 47 | 48 | 49 | o.bumpTexCoord.xy = v.vertex.xz/float2(_Size.x, _Size.z)*10; 50 | 51 | 52 | o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 53 | 54 | o.foamStrengthAndDistance.x = v.tangent.w; 55 | o.foamStrengthAndDistance.y = clamp(o.pos.z, 0, 1.0); 56 | 57 | 58 | float4 projSource = float4(v.vertex.x, 0.0, v.vertex.z, 1.0); 59 | float4 tmpProj = mul( UNITY_MATRIX_MVP, projSource); 60 | o.projTexCoord = tmpProj; 61 | /* 62 | //Bias matrix for converting clip-space vertex positions 63 | //to texture coordinates. 64 | float3x4 mat = float3x4( 65 | 0.5, 0.0, 0.0, 0.5, 66 | 0.0, 0.5 * _ProjectionParams.x, 0.0, 0.5, 67 | 0.0, 0.0, 0.5, 0.5 68 | ); 69 | 70 | o.projTexCoord.xy = mul(mat, tmpProj).xy; 71 | o.projTexCoord.xy /= tmpProj.w; 72 | */ 73 | float3 objSpaceViewDir = ObjSpaceViewDir(v.vertex); 74 | 75 | //o.normal = v.normal; 76 | float3 binormal = cross( normalize(v.normal), normalize(v.tangent.xyz) ); 77 | float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal ); 78 | 79 | o.objSpaceNormal = v.normal; 80 | o.viewDir = mul(rotation, objSpaceViewDir); 81 | 82 | o.lightDir = mul(rotation, float3(_SunDir.xyz)); 83 | 84 | return o; 85 | } 86 | 87 | sampler2D _Refraction; 88 | sampler2D _Reflection; 89 | sampler2D _Fresnel; 90 | sampler2D _Bump; 91 | sampler2D _Foam; 92 | half4 _SurfaceColor; 93 | half4 _WaterColor; 94 | 95 | half4 frag (v2f i) : COLOR 96 | { 97 | half3 normViewDir = normalize(i.viewDir); 98 | 99 | half4 buv = half4(i.bumpTexCoord.x + _Time.x * 0.03, i.bumpTexCoord.y + _SinTime.x * 0.2, i.bumpTexCoord.x + _Time.y * 0.04, i.bumpTexCoord.y + _SinTime.y * 0.5); 100 | 101 | half3 tangentNormal0 = (tex2D(_Bump, buv.xy).rgb * 2.0) - 1; 102 | half3 tangentNormal1 = (tex2D(_Bump, buv.zw).rgb * 2.0) - 1; 103 | half3 tangentNormal = normalize(tangentNormal0 + tangentNormal1); 104 | 105 | float2 projTexCoord = 0.5 * i.projTexCoord.xy * float2(1, _ProjectionParams.x) / i.projTexCoord.w + float2(0.5, 0.5); 106 | 107 | half4 result = half4(0, 0, 0, 1); 108 | 109 | float2 bumpSampleOffset = i.objSpaceNormal.xz * 0.05 + tangentNormal.xy * 0.05; 110 | 111 | 112 | half3 reflection = tex2D(_Reflection, projTexCoord.xy + bumpSampleOffset).rgb * _SurfaceColor.rgb; 113 | half3 refraction = tex2D(_Refraction, projTexCoord.xy + bumpSampleOffset).rgb * _WaterColor.rgb; 114 | 115 | float fresnelLookup = dot(tangentNormal, normViewDir); 116 | 117 | //float fresnelTerm = tex2D(_Fresnel, float2(fresnelLookup, 0.5)).a; 118 | 119 | float bias = 0.06; 120 | float power = 4.0; 121 | float fresnelTerm = bias + (1.0-bias)*pow(1.0 - fresnelLookup, power); 122 | 123 | float foamStrength = i.foamStrengthAndDistance.x * 1.8; 124 | 125 | half4 foam = clamp(tex2D(_Foam, i.bumpTexCoord.xy * 1.0) - 0.5, 0.0, 1.0) * foamStrength; 126 | 127 | 128 | float3 halfVec = normalize(normViewDir - normalize(i.lightDir)); 129 | float specular = pow(max(dot(halfVec, tangentNormal.xyz), 0.0), 250.0); 130 | 131 | result.rgb = lerp(refraction, reflection, fresnelTerm) + clamp(foam.r, 0.0, 1.0) + specular; 132 | 133 | result.rgb = result.rgb;//*0.001 + fresnelTerm;// * 0.001 + fresnelTerm; 134 | result.a = 1.0; 135 | 136 | return result; 137 | } 138 | ENDCG 139 | 140 | } 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/OceanReflectionRefraction.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 01170220c6c9d45f7ae3b4fef8af5fdb 3 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/WaterComposition.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position 2 | // Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION' 3 | // Upgrade NOTE: replaced 'samplerRect' with 'sampler2D' 4 | // Upgrade NOTE: replaced 'texRECT' with 'tex2D' 5 | 6 | Shader "WaterComposition" { 7 | Properties 8 | { 9 | _MainTex ("Overwater (RGB)", Rect) = "white" {} 10 | _DepthTex ("Depth (RGB)", 2D) = "black" {} 11 | _UnderwaterTex ("Underwater (RGB)", 2D) = "white" {} 12 | _UnderwaterDistortionTex ("Underwater Distortion (RGB)", 2D) = "bump" {} 13 | _MainTexSize ("MainTexSize", Vector) = (512,512,0,0) 14 | _WaterColor ("WaterColor", Color) = (0.2, 0.3, 0.2, 1.0) 15 | } 16 | SubShader 17 | { 18 | Pass { 19 | Cull Off 20 | 21 | CGPROGRAM 22 | // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices 23 | #pragma exclude_renderers gles 24 | // Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct v2f members maskSpacePos,uv) 25 | #pragma exclude_renderers xbox360 26 | #pragma vertex vert 27 | #pragma fragment frag 28 | #pragma fragmentoption ARB_fog_exp2 29 | #include "UnityCG.cginc" 30 | 31 | struct v2f 32 | { 33 | float4 pos : SV_POSITION; 34 | float4 maskSpacePos; 35 | float4 uv; 36 | }; 37 | 38 | 39 | sampler2D _MainTex; 40 | sampler2D _DepthTex; 41 | sampler2D _UnderwaterTex; 42 | sampler2D _UnderwaterDistortionTex; 43 | 44 | uniform float4x4 _DepthCamMV; 45 | uniform float4x4 _DepthCamProj; 46 | float4 _WaterColor; 47 | 48 | uniform float4 _MainTex_TexelSize; 49 | 50 | v2f vert (appdata_base v) 51 | { 52 | v2f o; 53 | 54 | o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 55 | 56 | o.uv.xy = v.texcoord.xy; 57 | o.uv.zw = v.texcoord.xy; 58 | 59 | #if SHADER_API_D3D9 60 | if (_MainTex_TexelSize.y < 0) 61 | { 62 | o.uv.w = 1.0 - o.uv.w; 63 | } 64 | 65 | o.uv.zw += float2(_MainTex_TexelSize.x * 0.5, abs(_MainTex_TexelSize.y) * 0.5); 66 | #endif 67 | 68 | //The plane is already defined in world space. 69 | float4 tmpModelView = mul(_DepthCamMV, v.vertex); 70 | float4 tmpProj = mul(_DepthCamProj, tmpModelView); 71 | 72 | 73 | //Bias matrix for converting clip-space vertex positions 74 | //to texture coordinates. 75 | float3x4 mat = float3x4( 76 | 0.5, 0.0, 0.0, 0.5, 77 | 0.0, 0.5 * _ProjectionParams.x, 0.0, 0.5, 78 | 0.0, 0.0, 0.0, 0.0 79 | ); 80 | 81 | o.maskSpacePos.xy = mul(mat, tmpProj).xy; 82 | 83 | //Note: 20.0 is to keep viewspace values in the 0-1 range. This is because the depth camera has 84 | //a view distance of 20.0. Also, -0.3 is to offset the water intersection a bit, this can be 85 | //tweaked until it "feels" right. This is somewhat related to the offset in DeepWaterBelow.shader. 86 | o.maskSpacePos.z = -(tmpModelView.z - 0.3)/20.0; 87 | 88 | return o; 89 | } 90 | 91 | half4 frag (v2f i) : COLOR 92 | { 93 | half3 source = tex2D(_MainTex, i.uv.zw).rgb; 94 | float depth = tex2D(_DepthTex, i.maskSpacePos.xy).r; 95 | 96 | //Yann's tweak 97 | float2 uvscaled = i.uv.xy*0.03 + _Time.x/10.0; 98 | float2 distort = ((tex2D(_UnderwaterDistortionTex, uvscaled).rg * 4.0) - 2.2); 99 | 100 | half3 underwater = tex2D(_UnderwaterTex, i.uv.xy + distort * 0.05).rgb; 101 | 102 | 103 | 104 | float delta = i.maskSpacePos.z - depth; 105 | 106 | float underwaterFactor = 0.0; 107 | 108 | if (delta >= 0) 109 | underwaterFactor = 1.0; 110 | 111 | //Smooth out the water/air intersection. This can be used to sample from a foam texture 112 | //for improved effect. 113 | underwaterFactor += (0.01 - clamp(abs(delta), 0, 0.01)) * 100; 114 | 115 | underwaterFactor = clamp(underwaterFactor, 0, 1); 116 | 117 | half3 result = lerp(source, underwater * _WaterColor, underwaterFactor); 118 | 119 | 120 | return half4(result, 1.0); 121 | } 122 | ENDCG 123 | 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /Assets/Resources/Ocean/WaterComposition.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 8d9762c07cedb4fc9b986d7e60d07edf 3 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/WaterHeight.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position 2 | // Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION' 3 | // Upgrade NOTE: replaced 'glstate.matrix.modelview[0]' with 'UNITY_MATRIX_MV' 4 | 5 | Shader "WaterHeight" 6 | { 7 | Properties 8 | { 9 | } 10 | SubShader 11 | { 12 | Pass { 13 | Cull Off 14 | 15 | CGPROGRAM 16 | // Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct v2f members depth) 17 | #pragma exclude_renderers xbox360 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | #pragma fragmentoption ARB_fog_exp2 21 | #include "UnityCG.cginc" 22 | 23 | struct v2f 24 | { 25 | float4 pos : SV_POSITION; 26 | float depth; 27 | }; 28 | 29 | v2f vert (appdata_base v) 30 | { 31 | v2f o; 32 | 33 | 34 | o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 35 | 36 | 37 | o.depth = -mul(UNITY_MATRIX_MV, v.vertex).z/20.0;//(o.pos.z + 1)/2.0; 38 | 39 | 40 | return o; 41 | } 42 | 43 | float4 frag (v2f i) : COLOR 44 | { 45 | return float4(i.depth); 46 | } 47 | ENDCG 48 | 49 | } 50 | } 51 | FallBack "Diffuse", 1 52 | } 53 | -------------------------------------------------------------------------------- /Assets/Resources/Ocean/WaterHeight.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: a43f3f7d02f624e11a87e4bc1ead6cde 3 | -------------------------------------------------------------------------------- /Assets/Skyboxes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 35687b3e309d549bea31a61a20c35eb2 3 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 7d9ef5e81de1845d4b2331ded2645c48 3 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Skyboxes/Source Images/Sunset Back.jpg -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Back.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 6a7a34f9875164d96bbe245cc42d0838 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 1 28 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Down.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Skyboxes/Source Images/Sunset Down.jpg -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Down.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 33c85e5f6b39a40aba65488cc60a910b 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 1 28 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Skyboxes/Source Images/Sunset Front.jpg -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Front.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 4c8e02a564be64cec99c7ae4d32b6f35 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 1 28 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Skyboxes/Source Images/Sunset Left.jpg -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Left.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 3efd155bdea174f219e6ce1c1521c6f1 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 1 28 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Skyboxes/Source Images/Sunset Right.jpg -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Right.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 860d034cc1607405390a2d5433a6eef5 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 1 28 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Up.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Skyboxes/Source Images/Sunset Up.jpg -------------------------------------------------------------------------------- /Assets/Skyboxes/Source Images/Sunset Up.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 9c8237c2157e9461e9bd8f8df1d34cf5 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: -1 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 1 28 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Sunset.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Skyboxes/Sunset.mat -------------------------------------------------------------------------------- /Assets/Skyboxes/Sunset.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 06d1925a9ac3c496591de0c316e36338 3 | -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: ac865f55780124eeabc4a99d6d0b0115 3 | -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 5710a1f47af2947699139509aae39149 3 | -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 527393b10fb66418bbaa072e104f5a30 3 | -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/Materials/palmbark.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Trees Ambient-Occlusion/Palm/Materials/palmbark.mat -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/Materials/palmbark.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: e5bdb6135a74b444d8cebd065dbf9d08 3 | -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/Materials/palmbranch.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Trees Ambient-Occlusion/Palm/Materials/palmbranch.mat -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/Materials/palmbranch.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 3186f38ca67e7441e8299da2e169f9f9 3 | -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/Palm.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Trees Ambient-Occlusion/Palm/Palm.fbx -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/Palm.fbx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 4c85abd0a4d974473b97e81d10a3a6bc 3 | ModelImporter: 4 | importerVersion: 7 5 | meshes: 6 | scaleFactor: 1 7 | useFileUnits: 1 8 | meshCompression: 0 9 | generateColliders: 0 10 | swapUVs: 0 11 | tangentSpace: 12 | normalImportMode: 0 13 | tangentImportMode: 1 14 | smoothingAngle: 60 15 | splitTangents: 0 16 | materials: 17 | generation: 1 18 | animations: 19 | generation: 0 20 | bakeAnimations: 0 21 | animationCompression: 1 22 | animationWrapMode: 0 23 | splitAnimations: 1 24 | nodeInfo: 25 | //RootNode: 26 | - 100000 27 | - 400000 28 | - 3300000 29 | - 2300000 30 | AssetImporter: 31 | importerVersion: 1 32 | fileIDToRecycleName: 33 | 4300000: polySurface1 34 | -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/PalmBark.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Trees Ambient-Occlusion/Palm/PalmBark.psd -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/PalmBark.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: f7d5f039a8e7848e889e1546d37dc39e 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: 10 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 0 28 | -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/PalmBranch.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/Trees Ambient-Occlusion/Palm/PalmBranch.psd -------------------------------------------------------------------------------- /Assets/Trees Ambient-Occlusion/Palm/PalmBranch.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 54e03e659ab274dd9b12c0538a9c4983 3 | TextureImporter: 4 | importerVersion: 1 5 | maxTextureSize: 1024 6 | textureFormat: 12 7 | grayscaleToAlpha: 0 8 | npotScale: 0 9 | generateCubemap: 0 10 | isReadable: 0 11 | mipmaps: 12 | generation: 1 13 | correctGamma: 0 14 | border: 0 15 | filter: 0 16 | fadeout: 0 17 | fadeoutStart: 2 18 | fadeoutEnd: 3 19 | bumpmap: 20 | generation: 0 21 | bumpyness: 0.25 22 | filter: 0 23 | textureSettings: 24 | filterMode: 1 25 | anisoLevel: 1 26 | mipmapBias: 0 27 | wrapMode: 0 28 | -------------------------------------------------------------------------------- /Assets/scene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Assets/scene.unity -------------------------------------------------------------------------------- /Assets/scene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: f994a6a08f67b49418497852380d60b4 3 | -------------------------------------------------------------------------------- /Library/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/AudioManager.asset -------------------------------------------------------------------------------- /Library/BuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/BuildSettings.asset -------------------------------------------------------------------------------- /Library/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/DynamicsManager.asset -------------------------------------------------------------------------------- /Library/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Library/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/EditorSettings.asset -------------------------------------------------------------------------------- /Library/EditorUserBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/EditorUserBuildSettings.asset -------------------------------------------------------------------------------- /Library/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/InputManager.asset -------------------------------------------------------------------------------- /Library/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/NetworkManager.asset -------------------------------------------------------------------------------- /Library/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/ProjectSettings.asset -------------------------------------------------------------------------------- /Library/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/QualitySettings.asset -------------------------------------------------------------------------------- /Library/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/TagManager.asset -------------------------------------------------------------------------------- /Library/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trond/Unity-Community-Ocean/642d62163907b7b49a77b557670c5351ecea0d35/Library/TimeManager.asset -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This is based on TwinFox's excellent FFT water from the Unity forums 2 | (http://forum.unity3d.com/threads/16540-Wanted-Ocean-shader) 3 | 4 | Known issues: 5 | -Only works on Pro as is. 6 | -(Somewhat improved) The water tiles don't tile particularly well with lower LODs. This works well for a stationary camera, 7 | but for a moving one you'd want to shift the tiles as the camera moves. 8 | -The water tiles sometimes get culled, probably because the bounds for the mesh 9 | are not updated/compensating for the animated vertex offset. 10 | -When the camera is very close to the reflection plane, the reflection looks like garbage. This 11 | effect is even more noticable using the skybox provided in the sample scene, because it starts 12 | sampling from the black area in these cases. 13 | -If the water tiles are rotated, the reflection/refraction will not work since the reflection 14 | plane is hardcoded to be XZ-aligned. 15 | -This will most likely not run at all on lower-end hardware and most likely result in 16 | low framerate on anything else. 17 | -The underwater pass is now rendered even if there is no chance of the camera being under water. 18 | Also, the underwater pass does not clip anything above the sealevel, which is also an optimization 19 | that should have been there (see how the reflection/refraction passes do this). The opposite is 20 | true for the overwater pass. 21 | 22 | Any improvements are more than welcome (and necessary :)! --------------------------------------------------------------------------------