Added water, added EasterEggs, fixed city count, added hud button functions, v1.2.0

This commit is contained in:
Nicola Sovic
2022-04-11 16:21:17 +02:00
parent 8266248281
commit cb7541ce85
353 changed files with 11866 additions and 19 deletions

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: 8269a010592f549af8f11b1683d9e794
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,154 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 3
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: WaterPlaneMaterial
m_Shader: {fileID: 45, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
- _LIGHTMAPPING_STATIC_LIGHTMAPS
- _UVSEC_UV1
m_CustomRenderQueue: -1
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
data:
first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _EmissionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _ParallaxMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _Occlusion
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _SpecGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _DetailMask
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
data:
first:
name: _Lightmapping
second: 0
data:
first:
name: _SrcBlend
second: 1
data:
first:
name: _DstBlend
second: 0
data:
first:
name: _Parallax
second: .0199999996
data:
first:
name: _ZWrite
second: 1
data:
first:
name: _AlphaTestRef
second: .5
data:
first:
name: _Glossiness
second: 0
data:
first:
name: _BumpScale
second: 1
data:
first:
name: _OcclusionStrength
second: 1
data:
first:
name: _DetailNormalMapScale
second: 1
data:
first:
name: _UVSec
second: 0
data:
first:
name: _Mode
second: 0
data:
first:
name: _EmissionScaleUI
second: 1
m_Colors:
data:
first:
name: _Color
second: {r: .5, g: .5, b: .5, a: 1}
data:
first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
data:
first:
name: _SpecularColor
second: {r: .200000003, g: .200000003, b: .200000003, a: 1}
data:
first:
name: _EmissionColorUI
second: {r: 0, g: 0, b: 0, a: 1}
data:
first:
name: _EmissionColorWithMapUI
second: {r: 1, g: 1, b: 1, a: 1}

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: f1bc741ea0e69a241896582ddb633d55
NativeFormatImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,68 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: WaterProDaytime
m_Shader: {fileID: 4800000, guid: 1cac2e0bcc34e4b3cbb4bd85982eba83, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 2800000, guid: 2dd3788f8589b40bf82a92d76ffc5091, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _Fresnel:
m_Texture: {fileID: 2800000, guid: 5b5c5575fd4c74abd9f7b30862fb76a3, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: e6f8288974c664a309d6c66de636978c, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ReflectionTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ReflectiveColor:
m_Texture: {fileID: 2800000, guid: ab97f9ab7c2ce724ebc9446060a819a4, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ReflectiveColorCube:
m_Texture: {fileID: 8900000, guid: 9cda328e4b6954d70841a8a66f42ec08, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _RefractionTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _ReflDistort: 0.44
- _RefrDistort: 0.4
- _WaveScale: 0.118
m_Colors:
- WaveSpeed: {r: 9, g: 4.5, b: -8, a: -3.5}
- _BumpMap_ST: {r: 1, g: 1, b: 0, a: 0}
- _Fresnel_ST: {r: 1, g: 1, b: 0, a: 0}
- _HorizonColor: {r: 0.13575952, g: 0.22810712, b: 0.3810788, a: 0}
- _MainTex_ST: {r: 1, g: 1, b: 0, a: 0}
- _ReflectionTex_ST: {r: 1, g: 1, b: 0, a: 0}
- _ReflectiveColorCube_ST: {r: 1, g: 1, b: 0, a: 0}
- _ReflectiveColor_ST: {r: 1, g: 1, b: 0, a: 0}
- _RefrColor: {r: 0.9372549, g: 0.9372549, b: 0.9372549, a: 1}
- _RefractionTex_ST: {r: 1, g: 1, b: 0, a: 0}
m_BuildTextureStacks: []
--- !u!1002 &2100001
EditorExtensionImpl:
serializedVersion: 6

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 7350b65a6431f604a8496c39db1ac9c5
NativeFormatImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,125 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 3
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: WaterProNighttime
m_Shader: {fileID: 4800000, guid: 1cac2e0bcc34e4b3cbb4bd85982eba83, type: 3}
m_ShaderKeywords: []
m_CustomRenderQueue: -1
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
data:
first:
name: _MainTex
second:
m_Texture: {fileID: 2800000, guid: e6f8288974c664a309d6c66de636978c, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _BumpMap
second:
m_Texture: {fileID: 2800000, guid: 2dd3788f8589b40bf82a92d76ffc5091, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _Fresnel
second:
m_Texture: {fileID: 2800000, guid: 5b5c5575fd4c74abd9f7b30862fb76a3, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _ReflectiveColor
second:
m_Texture: {fileID: 2800000, guid: b725b62cfc9d04e4886735ab2a8107d1, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _ReflectionTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _RefractionTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
data:
first:
name: _ReflectiveColorCube
second:
m_Texture: {fileID: 8900000, guid: 15c6acc4f11254a04b03849245d80574, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
data:
first:
name: _WaveScale
second: .063000001
data:
first:
name: _ReflDistort
second: .439999998
data:
first:
name: _RefrDistort
second: .400000006
m_Colors:
data:
first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
data:
first:
name: _RefrColor
second: {r: 1, g: 1, b: 1, a: 1}
data:
first:
name: _Fresnel_ST
second: {r: 1, g: 1, b: 0, a: 0}
data:
first:
name: _BumpMap_ST
second: {r: 1, g: 1, b: 0, a: 0}
data:
first:
name: WaveSpeed
second: {r: 9, g: 4.5, b: -8, a: -3.5}
data:
first:
name: _ReflectiveColor_ST
second: {r: 1, g: 1, b: 0, a: 0}
data:
first:
name: _HorizonColor
second: {r: .149019614, g: .282352954, b: .380392164, a: 0}
data:
first:
name: _ReflectionTex_ST
second: {r: 1, g: 1, b: 0, a: 0}
data:
first:
name: _RefractionTex_ST
second: {r: 1, g: 1, b: 0, a: 0}
data:
first:
name: _MainTex_ST
second: {r: 1, g: 1, b: 0, a: 0}
data:
first:
name: _ReflectiveColorCube_ST
second: {r: 1, g: 1, b: 0, a: 0}
--- !u!1002 &2100001
EditorExtensionImpl:
serializedVersion: 6

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: e633a20421c47426aa04444234225b69
NativeFormatImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: fe5d00245bc1d42a7927f4b2879026b8
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,71 @@
fileFormatVersion: 2
guid: ba6a41dc489914734857bb5924eb70ad
ModelImporter:
serializedVersion: 18
fileIDToRecycleName:
100000: //RootNode
400000: //RootNode
2300000: //RootNode
3300000: //RootNode
4300000: pPlane1
4300002: nurbsToPoly1
4300004: pCylinder1
4300006: waterPlaneMesh
11100000: //RootNode
materials:
importMaterials: 1
materialName: 1
materialSearch: 1
animations:
legacyGenerateAnimations: 0
bakeSimulation: 0
optimizeGameObjects: 0
motionNodeName:
pivotNodeName:
animationCompression: 1
animationRotationError: .5
animationPositionError: .5
animationScaleError: .5
animationWrapMode: 0
extraExposedTransformPaths: []
clipAnimations: []
isReadable: 1
meshes:
lODScreenPercentages: []
globalScale: 1
meshCompression: 0
addColliders: 0
importBlendShapes: 1
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 0
optimizeMeshForGPU: 1
weldVertices: 1
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15
secondaryUVHardAngle: 88
secondaryUVPackMargin: 4
useFileScale: 0
tangentSpace:
normalSmoothAngle: 60
splitTangentsAcrossUV: 0
normalImportMode: 0
tangentImportMode: 1
importAnimation: 1
copyAvatar: 0
humanDescription:
human: []
skeleton: []
armTwist: .5
foreArmTwist: .5
upperLegTwist: .5
legTwist: .5
armStretch: .0500000007
legStretch: .0500000007
feetSpacing: 0
rootMotionBoneName:
lastHumanDescriptionAvatarSource: {instanceID: 0}
animationType: 1
additionalBone: 1
userData:
assetBundleName:

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: 2dc67c8fe799ae845add403087340bd1
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,102 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &100000
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 400000}
- component: {fileID: 3300000}
- component: {fileID: 2300000}
- component: {fileID: 11400000}
m_Layer: 4
m_Name: WaterProDaytime
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &400000
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 16, y: 1, z: 16}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &3300000
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Mesh: {fileID: 4300006, guid: ba6a41dc489914734857bb5924eb70ad, type: 3}
--- !u!23 &2300000
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 7350b65a6431f604a8496c39db1ac9c5, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a3d3ef1a5bbfb4e0a910fbbe5830b1f9, type: 3}
m_Name:
m_EditorClassIdentifier:
waterMode: 2
disablePixelLights: 1
textureSize: 256
clipPlaneOffset: 0.07
reflectLayers:
serializedVersion: 2
m_Bits: 4294967295
refractLayers:
serializedVersion: 2
m_Bits: 4294967295

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 780611a67e8e941a2b3aa96e5915a793
NativeFormatImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,102 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &100000
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 400000}
- component: {fileID: 3300000}
- component: {fileID: 2300000}
- component: {fileID: 11400000}
m_Layer: 4
m_Name: WaterProNighttime
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &400000
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 16, y: 1, z: 16}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &3300000
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Mesh: {fileID: 4300006, guid: ba6a41dc489914734857bb5924eb70ad, type: 3}
--- !u!23 &2300000
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: e633a20421c47426aa04444234225b69, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a3d3ef1a5bbfb4e0a910fbbe5830b1f9, type: 3}
m_Name:
m_EditorClassIdentifier:
waterMode: 2
disablePixelLights: 1
textureSize: 256
clipPlaneOffset: 0.07
reflectLayers:
serializedVersion: 2
m_Bits: 4294967295
refractLayers:
serializedVersion: 2
m_Bits: 4294967295

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: bcae914220acd4907840a029bb9d9aec
NativeFormatImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: b5b8c0f9acc2944f086c02cb83f4ae76
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,36 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Water
{
[ExecuteInEditMode]
[RequireComponent(typeof(WaterBase))]
public class Displace : MonoBehaviour
{
public void Awake()
{
if (enabled)
{
OnEnable();
}
else
{
OnDisable();
}
}
public void OnEnable()
{
Shader.EnableKeyword("WATER_VERTEX_DISPLACEMENT_ON");
Shader.DisableKeyword("WATER_VERTEX_DISPLACEMENT_OFF");
}
public void OnDisable()
{
Shader.EnableKeyword("WATER_VERTEX_DISPLACEMENT_OFF");
Shader.DisableKeyword("WATER_VERTEX_DISPLACEMENT_ON");
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c62b7d87755b447919138e67f8e22e0c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,9 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Water
{
[ExecuteInEditMode]
[RequireComponent(typeof(WaterBase))]
public class GerstnerDisplace : Displace { }
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 42e7f46d0e5a84171a3909479c1646ba
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,27 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Water
{
public class MeshContainer
{
public Mesh mesh;
public Vector3[] vertices;
public Vector3[] normals;
public MeshContainer(Mesh m)
{
mesh = m;
vertices = m.vertices;
normals = m.normals;
}
public void Update()
{
mesh.vertices = vertices;
mesh.normals = normals;
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 951d74f7d57bed84cb623c62436bd064
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,284 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityStandardAssets.Water
{
[ExecuteInEditMode]
[RequireComponent(typeof(WaterBase))]
public class PlanarReflection : MonoBehaviour
{
public LayerMask reflectionMask;
public bool reflectSkybox = false;
public Color clearColor = Color.grey;
public String reflectionSampler = "_ReflectionTex";
public float clipPlaneOffset = 0.07F;
Vector3 m_Oldpos;
Camera m_ReflectionCamera;
Material m_SharedMaterial;
Dictionary<Camera, bool> m_HelperCameras;
public void Start()
{
m_SharedMaterial = ((WaterBase)gameObject.GetComponent(typeof(WaterBase))).sharedMaterial;
}
Camera CreateReflectionCameraFor(Camera cam)
{
String reflName = gameObject.name + "Reflection" + cam.name;
GameObject go = GameObject.Find(reflName);
if (!go)
{
go = new GameObject(reflName, typeof(Camera));
}
if (!go.GetComponent(typeof(Camera)))
{
go.AddComponent(typeof(Camera));
}
Camera reflectCamera = go.GetComponent<Camera>();
reflectCamera.backgroundColor = clearColor;
reflectCamera.clearFlags = reflectSkybox ? CameraClearFlags.Skybox : CameraClearFlags.SolidColor;
SetStandardCameraParameter(reflectCamera, reflectionMask);
if (!reflectCamera.targetTexture)
{
reflectCamera.targetTexture = CreateTextureFor(cam);
}
return reflectCamera;
}
void SetStandardCameraParameter(Camera cam, LayerMask mask)
{
cam.cullingMask = mask & ~(1 << LayerMask.NameToLayer("Water"));
cam.backgroundColor = Color.black;
cam.enabled = false;
}
RenderTexture CreateTextureFor(Camera cam)
{
RenderTexture rt = new RenderTexture(Mathf.FloorToInt(cam.pixelWidth * 0.5F),
Mathf.FloorToInt(cam.pixelHeight * 0.5F), 24);
rt.hideFlags = HideFlags.DontSave;
return rt;
}
public void RenderHelpCameras(Camera currentCam)
{
if (null == m_HelperCameras)
{
m_HelperCameras = new Dictionary<Camera, bool>();
}
if (!m_HelperCameras.ContainsKey(currentCam))
{
m_HelperCameras.Add(currentCam, false);
}
if (m_HelperCameras[currentCam])
{
return;
}
if (!m_ReflectionCamera)
{
m_ReflectionCamera = CreateReflectionCameraFor(currentCam);
}
RenderReflectionFor(currentCam, m_ReflectionCamera);
m_HelperCameras[currentCam] = true;
}
public void LateUpdate()
{
if (null != m_HelperCameras)
{
m_HelperCameras.Clear();
}
}
public void WaterTileBeingRendered(Transform tr, Camera currentCam)
{
RenderHelpCameras(currentCam);
if (m_ReflectionCamera && m_SharedMaterial)
{
m_SharedMaterial.SetTexture(reflectionSampler, m_ReflectionCamera.targetTexture);
}
}
public void OnEnable()
{
Shader.EnableKeyword("WATER_REFLECTIVE");
Shader.DisableKeyword("WATER_SIMPLE");
}
public void OnDisable()
{
Shader.EnableKeyword("WATER_SIMPLE");
Shader.DisableKeyword("WATER_REFLECTIVE");
}
void RenderReflectionFor(Camera cam, Camera reflectCamera)
{
if (!reflectCamera)
{
return;
}
if (m_SharedMaterial && !m_SharedMaterial.HasProperty(reflectionSampler))
{
return;
}
reflectCamera.cullingMask = reflectionMask & ~(1 << LayerMask.NameToLayer("Water"));
SaneCameraSettings(reflectCamera);
reflectCamera.backgroundColor = clearColor;
reflectCamera.clearFlags = reflectSkybox ? CameraClearFlags.Skybox : CameraClearFlags.SolidColor;
if (reflectSkybox)
{
if (cam.gameObject.GetComponent(typeof(Skybox)))
{
Skybox sb = (Skybox)reflectCamera.gameObject.GetComponent(typeof(Skybox));
if (!sb)
{
sb = (Skybox)reflectCamera.gameObject.AddComponent(typeof(Skybox));
}
sb.material = ((Skybox)cam.GetComponent(typeof(Skybox))).material;
}
}
GL.invertCulling = true;
Transform reflectiveSurface = transform; //waterHeight;
Vector3 eulerA = cam.transform.eulerAngles;
reflectCamera.transform.eulerAngles = new Vector3(-eulerA.x, eulerA.y, eulerA.z);
reflectCamera.transform.position = cam.transform.position;
Vector3 pos = reflectiveSurface.transform.position;
pos.y = reflectiveSurface.position.y;
Vector3 normal = reflectiveSurface.transform.up;
float d = -Vector3.Dot(normal, pos) - clipPlaneOffset;
Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);
Matrix4x4 reflection = Matrix4x4.zero;
reflection = CalculateReflectionMatrix(reflection, reflectionPlane);
m_Oldpos = cam.transform.position;
Vector3 newpos = reflection.MultiplyPoint(m_Oldpos);
reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;
Vector4 clipPlane = CameraSpacePlane(reflectCamera, pos, normal, 1.0f);
Matrix4x4 projection = cam.projectionMatrix;
projection = CalculateObliqueMatrix(projection, clipPlane);
reflectCamera.projectionMatrix = projection;
reflectCamera.transform.position = newpos;
Vector3 euler = cam.transform.eulerAngles;
reflectCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
reflectCamera.Render();
GL.invertCulling = false;
}
void SaneCameraSettings(Camera helperCam)
{
helperCam.depthTextureMode = DepthTextureMode.None;
helperCam.backgroundColor = Color.black;
helperCam.clearFlags = CameraClearFlags.SolidColor;
helperCam.renderingPath = RenderingPath.Forward;
}
static Matrix4x4 CalculateObliqueMatrix(Matrix4x4 projection, Vector4 clipPlane)
{
Vector4 q = projection.inverse * new Vector4(
Sgn(clipPlane.x),
Sgn(clipPlane.y),
1.0F,
1.0F
);
Vector4 c = clipPlane * (2.0F / (Vector4.Dot(clipPlane, q)));
// third row = clip plane - fourth row
projection[2] = c.x - projection[3];
projection[6] = c.y - projection[7];
projection[10] = c.z - projection[11];
projection[14] = c.w - projection[15];
return projection;
}
static Matrix4x4 CalculateReflectionMatrix(Matrix4x4 reflectionMat, Vector4 plane)
{
reflectionMat.m00 = (1.0F - 2.0F * plane[0] * plane[0]);
reflectionMat.m01 = (- 2.0F * plane[0] * plane[1]);
reflectionMat.m02 = (- 2.0F * plane[0] * plane[2]);
reflectionMat.m03 = (- 2.0F * plane[3] * plane[0]);
reflectionMat.m10 = (- 2.0F * plane[1] * plane[0]);
reflectionMat.m11 = (1.0F - 2.0F * plane[1] * plane[1]);
reflectionMat.m12 = (- 2.0F * plane[1] * plane[2]);
reflectionMat.m13 = (- 2.0F * plane[3] * plane[1]);
reflectionMat.m20 = (- 2.0F * plane[2] * plane[0]);
reflectionMat.m21 = (- 2.0F * plane[2] * plane[1]);
reflectionMat.m22 = (1.0F - 2.0F * plane[2] * plane[2]);
reflectionMat.m23 = (- 2.0F * plane[3] * plane[2]);
reflectionMat.m30 = 0.0F;
reflectionMat.m31 = 0.0F;
reflectionMat.m32 = 0.0F;
reflectionMat.m33 = 1.0F;
return reflectionMat;
}
static float Sgn(float a)
{
if (a > 0.0F)
{
return 1.0F;
}
if (a < 0.0F)
{
return -1.0F;
}
return 0.0F;
}
Vector4 CameraSpacePlane(Camera cam, Vector3 pos, Vector3 normal, float sideSign)
{
Vector3 offsetPos = pos + normal * clipPlaneOffset;
Matrix4x4 m = cam.worldToCameraMatrix;
Vector3 cpos = m.MultiplyPoint(offsetPos);
Vector3 cnormal = m.MultiplyVector(normal).normalized * sideSign;
return new Vector4(cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos, cnormal));
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4185bc77c7194462ca3b1097ef4a5de0
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,33 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Water
{
[RequireComponent(typeof(WaterBase))]
[ExecuteInEditMode]
public class SpecularLighting : MonoBehaviour
{
public Transform specularLight;
private WaterBase m_WaterBase;
public void Start()
{
m_WaterBase = (WaterBase)gameObject.GetComponent(typeof(WaterBase));
}
public void Update()
{
if (!m_WaterBase)
{
m_WaterBase = (WaterBase)gameObject.GetComponent(typeof(WaterBase));
}
if (specularLight && m_WaterBase.sharedMaterial)
{
m_WaterBase.sharedMaterial.SetVector("_WorldLightDir", specularLight.transform.forward);
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: de2ab2b9ac93bb544b9552e49030371b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,403 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityStandardAssets.Water
{
[ExecuteInEditMode] // Make water live-update even when not in play mode
public class Water : MonoBehaviour
{
public enum WaterMode
{
Simple = 0,
Reflective = 1,
Refractive = 2,
};
public WaterMode waterMode = WaterMode.Refractive;
public bool disablePixelLights = true;
public int textureSize = 256;
public float clipPlaneOffset = 0.07f;
public LayerMask reflectLayers = -1;
public LayerMask refractLayers = -1;
private Dictionary<Camera, Camera> m_ReflectionCameras = new Dictionary<Camera, Camera>(); // Camera -> Camera table
private Dictionary<Camera, Camera> m_RefractionCameras = new Dictionary<Camera, Camera>(); // Camera -> Camera table
private RenderTexture m_ReflectionTexture;
private RenderTexture m_RefractionTexture;
private WaterMode m_HardwareWaterSupport = WaterMode.Refractive;
private int m_OldReflectionTextureSize;
private int m_OldRefractionTextureSize;
private static bool s_InsideWater;
// This is called when it's known that the object will be rendered by some
// camera. We render reflections / refractions and do other updates here.
// Because the script executes in edit mode, reflections for the scene view
// camera will just work!
public void OnWillRenderObject()
{
if (!enabled || !GetComponent<Renderer>() || !GetComponent<Renderer>().sharedMaterial ||
!GetComponent<Renderer>().enabled)
{
return;
}
Camera cam = Camera.current;
if (!cam)
{
return;
}
// Safeguard from recursive water reflections.
if (s_InsideWater)
{
return;
}
s_InsideWater = true;
// Actual water rendering mode depends on both the current setting AND
// the hardware support. There's no point in rendering refraction textures
// if they won't be visible in the end.
m_HardwareWaterSupport = FindHardwareWaterSupport();
WaterMode mode = GetWaterMode();
Camera reflectionCamera, refractionCamera;
CreateWaterObjects(cam, out reflectionCamera, out refractionCamera);
// find out the reflection plane: position and normal in world space
Vector3 pos = transform.position;
Vector3 normal = transform.up;
// Optionally disable pixel lights for reflection/refraction
int oldPixelLightCount = QualitySettings.pixelLightCount;
if (disablePixelLights)
{
QualitySettings.pixelLightCount = 0;
}
UpdateCameraModes(cam, reflectionCamera);
UpdateCameraModes(cam, refractionCamera);
// Render reflection if needed
if (mode >= WaterMode.Reflective)
{
// Reflect camera around reflection plane
float d = -Vector3.Dot(normal, pos) - clipPlaneOffset;
Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);
Matrix4x4 reflection = Matrix4x4.zero;
CalculateReflectionMatrix(ref reflection, reflectionPlane);
Vector3 oldpos = cam.transform.position;
Vector3 newpos = reflection.MultiplyPoint(oldpos);
reflectionCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;
// Setup oblique projection matrix so that near plane is our reflection
// plane. This way we clip everything below/above it for free.
Vector4 clipPlane = CameraSpacePlane(reflectionCamera, pos, normal, 1.0f);
reflectionCamera.projectionMatrix = cam.CalculateObliqueMatrix(clipPlane);
// Set custom culling matrix from the current camera
reflectionCamera.cullingMatrix = cam.projectionMatrix * cam.worldToCameraMatrix;
reflectionCamera.cullingMask = ~(1 << 4) & reflectLayers.value; // never render water layer
reflectionCamera.targetTexture = m_ReflectionTexture;
bool oldCulling = GL.invertCulling;
GL.invertCulling = !oldCulling;
reflectionCamera.transform.position = newpos;
Vector3 euler = cam.transform.eulerAngles;
reflectionCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
reflectionCamera.Render();
reflectionCamera.transform.position = oldpos;
GL.invertCulling = oldCulling;
GetComponent<Renderer>().sharedMaterial.SetTexture("_ReflectionTex", m_ReflectionTexture);
}
// Render refraction
if (mode >= WaterMode.Refractive)
{
refractionCamera.worldToCameraMatrix = cam.worldToCameraMatrix;
// Setup oblique projection matrix so that near plane is our reflection
// plane. This way we clip everything below/above it for free.
Vector4 clipPlane = CameraSpacePlane(refractionCamera, pos, normal, -1.0f);
refractionCamera.projectionMatrix = cam.CalculateObliqueMatrix(clipPlane);
// Set custom culling matrix from the current camera
refractionCamera.cullingMatrix = cam.projectionMatrix * cam.worldToCameraMatrix;
refractionCamera.cullingMask = ~(1 << 4) & refractLayers.value; // never render water layer
refractionCamera.targetTexture = m_RefractionTexture;
refractionCamera.transform.position = cam.transform.position;
refractionCamera.transform.rotation = cam.transform.rotation;
refractionCamera.Render();
GetComponent<Renderer>().sharedMaterial.SetTexture("_RefractionTex", m_RefractionTexture);
}
// Restore pixel light count
if (disablePixelLights)
{
QualitySettings.pixelLightCount = oldPixelLightCount;
}
// Setup shader keywords based on water mode
switch (mode)
{
case WaterMode.Simple:
Shader.EnableKeyword("WATER_SIMPLE");
Shader.DisableKeyword("WATER_REFLECTIVE");
Shader.DisableKeyword("WATER_REFRACTIVE");
break;
case WaterMode.Reflective:
Shader.DisableKeyword("WATER_SIMPLE");
Shader.EnableKeyword("WATER_REFLECTIVE");
Shader.DisableKeyword("WATER_REFRACTIVE");
break;
case WaterMode.Refractive:
Shader.DisableKeyword("WATER_SIMPLE");
Shader.DisableKeyword("WATER_REFLECTIVE");
Shader.EnableKeyword("WATER_REFRACTIVE");
break;
}
s_InsideWater = false;
}
// Cleanup all the objects we possibly have created
void OnDisable()
{
if (m_ReflectionTexture)
{
DestroyImmediate(m_ReflectionTexture);
m_ReflectionTexture = null;
}
if (m_RefractionTexture)
{
DestroyImmediate(m_RefractionTexture);
m_RefractionTexture = null;
}
foreach (var kvp in m_ReflectionCameras)
{
DestroyImmediate((kvp.Value).gameObject);
}
m_ReflectionCameras.Clear();
foreach (var kvp in m_RefractionCameras)
{
DestroyImmediate((kvp.Value).gameObject);
}
m_RefractionCameras.Clear();
}
// This just sets up some matrices in the material; for really
// old cards to make water texture scroll.
void Update()
{
if (!GetComponent<Renderer>())
{
return;
}
Material mat = GetComponent<Renderer>().sharedMaterial;
if (!mat)
{
return;
}
Vector4 waveSpeed = mat.GetVector("WaveSpeed");
float waveScale = mat.GetFloat("_WaveScale");
Vector4 waveScale4 = new Vector4(waveScale, waveScale, waveScale * 0.4f, waveScale * 0.45f);
// Time since level load, and do intermediate calculations with doubles
double t = Time.timeSinceLevelLoad / 20.0;
Vector4 offsetClamped = new Vector4(
(float)Math.IEEERemainder(waveSpeed.x * waveScale4.x * t, 1.0),
(float)Math.IEEERemainder(waveSpeed.y * waveScale4.y * t, 1.0),
(float)Math.IEEERemainder(waveSpeed.z * waveScale4.z * t, 1.0),
(float)Math.IEEERemainder(waveSpeed.w * waveScale4.w * t, 1.0)
);
mat.SetVector("_WaveOffset", offsetClamped);
mat.SetVector("_WaveScale4", waveScale4);
}
void UpdateCameraModes(Camera src, Camera dest)
{
if (dest == null)
{
return;
}
// set water camera to clear the same way as current camera
dest.clearFlags = src.clearFlags;
dest.backgroundColor = src.backgroundColor;
if (src.clearFlags == CameraClearFlags.Skybox)
{
Skybox sky = src.GetComponent<Skybox>();
Skybox mysky = dest.GetComponent<Skybox>();
if (!sky || !sky.material)
{
mysky.enabled = false;
}
else
{
mysky.enabled = true;
mysky.material = sky.material;
}
}
// update other values to match current camera.
// even if we are supplying custom camera&projection matrices,
// some of values are used elsewhere (e.g. skybox uses far plane)
dest.farClipPlane = src.farClipPlane;
dest.nearClipPlane = src.nearClipPlane;
dest.orthographic = src.orthographic;
dest.fieldOfView = src.fieldOfView;
dest.aspect = src.aspect;
dest.orthographicSize = src.orthographicSize;
}
// On-demand create any objects we need for water
void CreateWaterObjects(Camera currentCamera, out Camera reflectionCamera, out Camera refractionCamera)
{
WaterMode mode = GetWaterMode();
reflectionCamera = null;
refractionCamera = null;
if (mode >= WaterMode.Reflective)
{
// Reflection render texture
if (!m_ReflectionTexture || m_OldReflectionTextureSize != textureSize)
{
if (m_ReflectionTexture)
{
DestroyImmediate(m_ReflectionTexture);
}
m_ReflectionTexture = new RenderTexture(textureSize, textureSize, 16);
m_ReflectionTexture.name = "__WaterReflection" + GetInstanceID();
m_ReflectionTexture.isPowerOfTwo = true;
m_ReflectionTexture.hideFlags = HideFlags.DontSave;
m_OldReflectionTextureSize = textureSize;
}
// Camera for reflection
m_ReflectionCameras.TryGetValue(currentCamera, out reflectionCamera);
if (!reflectionCamera) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
{
GameObject go = new GameObject("Water Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox));
reflectionCamera = go.GetComponent<Camera>();
reflectionCamera.enabled = false;
reflectionCamera.transform.position = transform.position;
reflectionCamera.transform.rotation = transform.rotation;
reflectionCamera.gameObject.AddComponent<FlareLayer>();
go.hideFlags = HideFlags.HideAndDontSave;
m_ReflectionCameras[currentCamera] = reflectionCamera;
}
}
if (mode >= WaterMode.Refractive)
{
// Refraction render texture
if (!m_RefractionTexture || m_OldRefractionTextureSize != textureSize)
{
if (m_RefractionTexture)
{
DestroyImmediate(m_RefractionTexture);
}
m_RefractionTexture = new RenderTexture(textureSize, textureSize, 16);
m_RefractionTexture.name = "__WaterRefraction" + GetInstanceID();
m_RefractionTexture.isPowerOfTwo = true;
m_RefractionTexture.hideFlags = HideFlags.DontSave;
m_OldRefractionTextureSize = textureSize;
}
// Camera for refraction
m_RefractionCameras.TryGetValue(currentCamera, out refractionCamera);
if (!refractionCamera) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
{
GameObject go =
new GameObject("Water Refr Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(),
typeof(Camera), typeof(Skybox));
refractionCamera = go.GetComponent<Camera>();
refractionCamera.enabled = false;
refractionCamera.transform.position = transform.position;
refractionCamera.transform.rotation = transform.rotation;
refractionCamera.gameObject.AddComponent<FlareLayer>();
go.hideFlags = HideFlags.HideAndDontSave;
m_RefractionCameras[currentCamera] = refractionCamera;
}
}
}
WaterMode GetWaterMode()
{
if (m_HardwareWaterSupport < waterMode)
{
return m_HardwareWaterSupport;
}
return waterMode;
}
WaterMode FindHardwareWaterSupport()
{
if (!GetComponent<Renderer>())
{
return WaterMode.Simple;
}
Material mat = GetComponent<Renderer>().sharedMaterial;
if (!mat)
{
return WaterMode.Simple;
}
string mode = mat.GetTag("WATERMODE", false);
if (mode == "Refractive")
{
return WaterMode.Refractive;
}
if (mode == "Reflective")
{
return WaterMode.Reflective;
}
return WaterMode.Simple;
}
// Given position/normal of the plane, calculates plane in camera space.
Vector4 CameraSpacePlane(Camera cam, Vector3 pos, Vector3 normal, float sideSign)
{
Vector3 offsetPos = pos + normal * clipPlaneOffset;
Matrix4x4 m = cam.worldToCameraMatrix;
Vector3 cpos = m.MultiplyPoint(offsetPos);
Vector3 cnormal = m.MultiplyVector(normal).normalized * sideSign;
return new Vector4(cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos, cnormal));
}
// Calculates reflection matrix around the given plane
static void CalculateReflectionMatrix(ref Matrix4x4 reflectionMat, Vector4 plane)
{
reflectionMat.m00 = (1F - 2F * plane[0] * plane[0]);
reflectionMat.m01 = (- 2F * plane[0] * plane[1]);
reflectionMat.m02 = (- 2F * plane[0] * plane[2]);
reflectionMat.m03 = (- 2F * plane[3] * plane[0]);
reflectionMat.m10 = (- 2F * plane[1] * plane[0]);
reflectionMat.m11 = (1F - 2F * plane[1] * plane[1]);
reflectionMat.m12 = (- 2F * plane[1] * plane[2]);
reflectionMat.m13 = (- 2F * plane[3] * plane[1]);
reflectionMat.m20 = (- 2F * plane[2] * plane[0]);
reflectionMat.m21 = (- 2F * plane[2] * plane[1]);
reflectionMat.m22 = (1F - 2F * plane[2] * plane[2]);
reflectionMat.m23 = (- 2F * plane[3] * plane[2]);
reflectionMat.m30 = 0F;
reflectionMat.m31 = 0F;
reflectionMat.m32 = 0F;
reflectionMat.m33 = 1F;
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a3d3ef1a5bbfb4e0a910fbbe5830b1f9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,78 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Water
{
public enum WaterQuality
{
High = 2,
Medium = 1,
Low = 0,
}
[ExecuteInEditMode]
public class WaterBase : MonoBehaviour
{
public Material sharedMaterial;
public WaterQuality waterQuality = WaterQuality.High;
public bool edgeBlend = true;
public void UpdateShader()
{
if (waterQuality > WaterQuality.Medium)
{
sharedMaterial.shader.maximumLOD = 501;
}
else if (waterQuality > WaterQuality.Low)
{
sharedMaterial.shader.maximumLOD = 301;
}
else
{
sharedMaterial.shader.maximumLOD = 201;
}
// If the system does not support depth textures (ie. NaCl), turn off edge bleeding,
// as the shader will render everything as transparent if the depth texture is not valid.
if (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth))
{
edgeBlend = false;
}
if (edgeBlend)
{
Shader.EnableKeyword("WATER_EDGEBLEND_ON");
Shader.DisableKeyword("WATER_EDGEBLEND_OFF");
// just to make sure (some peeps might forget to add a water tile to the patches)
if (Camera.main)
{
Camera.main.depthTextureMode |= DepthTextureMode.Depth;
}
}
else
{
Shader.EnableKeyword("WATER_EDGEBLEND_OFF");
Shader.DisableKeyword("WATER_EDGEBLEND_ON");
}
}
public void WaterTileBeingRendered(Transform tr, Camera currentCam)
{
if (currentCam && edgeBlend)
{
currentCam.depthTextureMode |= DepthTextureMode.Depth;
}
}
public void Update()
{
if (sharedMaterial)
{
UpdateShader();
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a1da353243062479a9b31c85074a796b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,67 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.Water
{
[ExecuteInEditMode]
public class WaterTile : MonoBehaviour
{
public PlanarReflection reflection;
public WaterBase waterBase;
public void Start()
{
AcquireComponents();
}
void AcquireComponents()
{
if (!reflection)
{
if (transform.parent)
{
reflection = transform.parent.GetComponent<PlanarReflection>();
}
else
{
reflection = transform.GetComponent<PlanarReflection>();
}
}
if (!waterBase)
{
if (transform.parent)
{
waterBase = transform.parent.GetComponent<WaterBase>();
}
else
{
waterBase = transform.GetComponent<WaterBase>();
}
}
}
#if UNITY_EDITOR
public void Update()
{
AcquireComponents();
}
#endif
public void OnWillRenderObject()
{
if (reflection)
{
reflection.WaterTileBeingRendered(transform, Camera.current);
}
if (waterBase)
{
waterBase.WaterTileBeingRendered(transform, Camera.current);
}
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2a91e8dd37cdd41efb4859b65aced7a2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: e70b47c0cfc1d4b12a3c663d7582a523
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,163 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "FX/Water" {
Properties {
_WaveScale ("Wave scale", Range (0.02,0.15)) = 0.063
_ReflDistort ("Reflection distort", Range (0,1.5)) = 0.44
_RefrDistort ("Refraction distort", Range (0,1.5)) = 0.40
_RefrColor ("Refraction color", COLOR) = ( .34, .85, .92, 1)
[NoScaleOffset] _Fresnel ("Fresnel (A) ", 2D) = "gray" {}
[NoScaleOffset] _BumpMap ("Normalmap ", 2D) = "bump" {}
WaveSpeed ("Wave speed (map1 x,y; map2 x,y)", Vector) = (19,9,-16,-7)
[NoScaleOffset] _ReflectiveColor ("Reflective color (RGB) fresnel (A) ", 2D) = "" {}
_HorizonColor ("Simple water horizon color", COLOR) = ( .172, .463, .435, 1)
[HideInInspector] _ReflectionTex ("Internal Reflection", 2D) = "" {}
[HideInInspector] _RefractionTex ("Internal Refraction", 2D) = "" {}
}
// -----------------------------------------------------------
// Fragment program cards
Subshader {
Tags { "WaterMode"="Refractive" "RenderType"="Opaque" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile WATER_REFRACTIVE WATER_REFLECTIVE WATER_SIMPLE
#if defined (WATER_REFLECTIVE) || defined (WATER_REFRACTIVE)
#define HAS_REFLECTION 1
#endif
#if defined (WATER_REFRACTIVE)
#define HAS_REFRACTION 1
#endif
#include "UnityCG.cginc"
uniform float4 _WaveScale4;
uniform float4 _WaveOffset;
#if HAS_REFLECTION
uniform float _ReflDistort;
#endif
#if HAS_REFRACTION
uniform float _RefrDistort;
#endif
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f {
float4 pos : SV_POSITION;
#if defined(HAS_REFLECTION) || defined(HAS_REFRACTION)
float4 ref : TEXCOORD0;
float2 bumpuv0 : TEXCOORD1;
float2 bumpuv1 : TEXCOORD2;
float3 viewDir : TEXCOORD3;
#else
float2 bumpuv0 : TEXCOORD0;
float2 bumpuv1 : TEXCOORD1;
float3 viewDir : TEXCOORD2;
#endif
UNITY_FOG_COORDS(4)
};
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
// scroll bump waves
float4 temp;
float4 wpos = mul (unity_ObjectToWorld, v.vertex);
temp.xyzw = wpos.xzxz * _WaveScale4 + _WaveOffset;
o.bumpuv0 = temp.xy;
o.bumpuv1 = temp.wz;
// object space view direction (will normalize per pixel)
o.viewDir.xzy = WorldSpaceViewDir(v.vertex);
#if defined(HAS_REFLECTION) || defined(HAS_REFRACTION)
o.ref = ComputeNonStereoScreenPos(o.pos);
#endif
UNITY_TRANSFER_FOG(o,o.pos);
return o;
}
#if defined (WATER_REFLECTIVE) || defined (WATER_REFRACTIVE)
sampler2D _ReflectionTex;
#endif
#if defined (WATER_REFLECTIVE) || defined (WATER_SIMPLE)
sampler2D _ReflectiveColor;
#endif
#if defined (WATER_REFRACTIVE)
sampler2D _Fresnel;
sampler2D _RefractionTex;
uniform float4 _RefrColor;
#endif
#if defined (WATER_SIMPLE)
uniform float4 _HorizonColor;
#endif
sampler2D _BumpMap;
half4 frag( v2f i ) : SV_Target
{
i.viewDir = normalize(i.viewDir);
// combine two scrolling bumpmaps into one
half3 bump1 = UnpackNormal(tex2D( _BumpMap, i.bumpuv0 )).rgb;
half3 bump2 = UnpackNormal(tex2D( _BumpMap, i.bumpuv1 )).rgb;
half3 bump = (bump1 + bump2) * 0.5;
// fresnel factor
half fresnelFac = dot( i.viewDir, bump );
// perturb reflection/refraction UVs by bumpmap, and lookup colors
#if HAS_REFLECTION
float4 uv1 = i.ref; uv1.xy += bump * _ReflDistort;
half4 refl = tex2Dproj( _ReflectionTex, UNITY_PROJ_COORD(uv1) );
#endif
#if HAS_REFRACTION
float4 uv2 = i.ref; uv2.xy -= bump * _RefrDistort;
half4 refr = tex2Dproj( _RefractionTex, UNITY_PROJ_COORD(uv2) ) * _RefrColor;
#endif
// final color is between refracted and reflected based on fresnel
half4 color;
#if defined(WATER_REFRACTIVE)
half fresnel = UNITY_SAMPLE_1CHANNEL( _Fresnel, float2(fresnelFac,fresnelFac) );
color = lerp( refr, refl, fresnel );
#endif
#if defined(WATER_REFLECTIVE)
half4 water = tex2D( _ReflectiveColor, float2(fresnelFac,fresnelFac) );
color.rgb = lerp( water.rgb, refl.rgb, water.a );
color.a = refl.a * water.a;
#endif
#if defined(WATER_SIMPLE)
half4 water = tex2D( _ReflectiveColor, float2(fresnelFac,fresnelFac) );
color.rgb = lerp( water.rgb, _HorizonColor.rgb, water.a );
color.a = _HorizonColor.a;
#endif
UNITY_APPLY_FOG(i.fogCoord, color);
return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: 1cac2e0bcc34e4b3cbb4bd85982eba83
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: c22094bc116524b2a95c9aae09278b22
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

View File

@@ -0,0 +1,52 @@
fileFormatVersion: 2
guid: 2dd3788f8589b40bf82a92d76ffc5091
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 1
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 1
externalNormalMap: 1
heightScale: .0164516103
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 512
textureSettings:
filterMode: 1
aniso: 3
mipBias: 0
wrapMode: 0
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: 1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:

View File

@@ -0,0 +1,52 @@
fileFormatVersion: 2
guid: 5b5c5575fd4c74abd9f7b30862fb76a3
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 1
mipBias: 0
wrapMode: 0
nPOTScale: 0
lightmap: 0
rGBM: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:

View File

@@ -0,0 +1,52 @@
fileFormatVersion: 2
guid: ab97f9ab7c2ce724ebc9446060a819a4
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .100000001
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 32
textureSettings:
filterMode: 1
aniso: 1
mipBias: 0
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: 0
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:

View File

@@ -0,0 +1,52 @@
fileFormatVersion: 2
guid: b725b62cfc9d04e4886735ab2a8107d1
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .100000001
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 32
textureSettings:
filterMode: 1
aniso: 1
mipBias: 0
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: 0
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName: