@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: da3ccee8576aaae438180c440466b71b | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 91571d1d2601647498e27c944d9c6852 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 66207ff69de6b4d73a445036c3a195f6 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,103 @@ | |||
using UnityEngine; | |||
using System; | |||
using UnityEditor; | |||
[CustomEditor(typeof(GerstnerDisplace))] | |||
public class GerstnerDisplaceEditor : Editor | |||
{ | |||
private SerializedObject serObj; | |||
public void OnEnable () | |||
{ | |||
serObj = new SerializedObject (target); | |||
} | |||
public override void OnInspectorGUI () | |||
{ | |||
serObj.Update(); | |||
GameObject go = ((GerstnerDisplace)serObj.targetObject).gameObject; | |||
WaterBase wb = (WaterBase)go.GetComponent(typeof(WaterBase)); | |||
Material sharedWaterMaterial = wb.sharedMaterial; | |||
GUILayout.Label ("Animates vertices using up 4 generated waves", EditorStyles.miniBoldLabel); | |||
if(sharedWaterMaterial) | |||
{ | |||
Vector4 amplitude = WaterEditorUtility.GetMaterialVector("_GAmplitude", sharedWaterMaterial); | |||
Vector4 frequency = WaterEditorUtility.GetMaterialVector("_GFrequency", sharedWaterMaterial); | |||
Vector4 steepness = WaterEditorUtility.GetMaterialVector("_GSteepness", sharedWaterMaterial); | |||
Vector4 speed = WaterEditorUtility.GetMaterialVector("_GSpeed", sharedWaterMaterial); | |||
Vector4 directionAB = WaterEditorUtility.GetMaterialVector("_GDirectionAB", sharedWaterMaterial); | |||
Vector4 directionCD = WaterEditorUtility.GetMaterialVector("_GDirectionCD", sharedWaterMaterial); | |||
amplitude = EditorGUILayout.Vector4Field("Amplitude (Height offset)", amplitude); | |||
frequency = EditorGUILayout.Vector4Field("Frequency (Tiling)", frequency); | |||
steepness = EditorGUILayout.Vector4Field("Steepness", steepness); | |||
speed = EditorGUILayout.Vector4Field("Speed", speed); | |||
directionAB = EditorGUILayout.Vector4Field("Direction scale (Wave 1 (X,Y) and 2 (Z,W))", directionAB); | |||
directionCD = EditorGUILayout.Vector4Field("Direction scale (Wave 3 (X,Y) and 4 (Z,W))", directionCD); | |||
if (GUI.changed) { | |||
WaterEditorUtility.SetMaterialVector("_GAmplitude", amplitude, sharedWaterMaterial); | |||
WaterEditorUtility.SetMaterialVector("_GFrequency", frequency, sharedWaterMaterial); | |||
WaterEditorUtility.SetMaterialVector("_GSteepness", steepness, sharedWaterMaterial); | |||
WaterEditorUtility.SetMaterialVector("_GSpeed", speed, sharedWaterMaterial); | |||
WaterEditorUtility.SetMaterialVector("_GDirectionAB", directionAB, sharedWaterMaterial); | |||
WaterEditorUtility.SetMaterialVector("_GDirectionCD", directionCD, sharedWaterMaterial); | |||
} | |||
/* | |||
Vector4 animationTiling = WaterEditorUtility.GetMaterialVector("_AnimationTiling", sharedWaterMaterial); | |||
Vector4 animationDirection = WaterEditorUtility.GetMaterialVector("_AnimationDirection", sharedWaterMaterial); | |||
float firstTilingU = animationTiling.x*100.0F; | |||
float firstTilingV = animationTiling.y*100.0F; | |||
float firstDirectionU = animationDirection.x; | |||
float firstDirectionV = animationDirection.y; | |||
float secondTilingU = animationTiling.z*100.0F; | |||
float secondTilingV = animationTiling.w*100.0F; | |||
float secondDirectionU = animationDirection.z; | |||
float secondDirectionV = animationDirection.w; | |||
EditorGUILayout.BeginHorizontal (); | |||
firstTilingU = EditorGUILayout.FloatField("First Tiling U", firstTilingU); | |||
firstTilingV = EditorGUILayout.FloatField("First Tiling V", firstTilingV); | |||
EditorGUILayout.EndHorizontal (); | |||
EditorGUILayout.BeginHorizontal (); | |||
secondTilingU = EditorGUILayout.FloatField("Second Tiling U", secondTilingU); | |||
secondTilingV = EditorGUILayout.FloatField("Second Tiling V", secondTilingV); | |||
EditorGUILayout.EndHorizontal (); | |||
EditorGUILayout.BeginHorizontal (); | |||
firstDirectionU = EditorGUILayout.FloatField("1st Animation U", firstDirectionU); | |||
firstDirectionV = EditorGUILayout.FloatField("1st Animation V", firstDirectionV); | |||
EditorGUILayout.EndHorizontal (); | |||
EditorGUILayout.BeginHorizontal (); | |||
secondDirectionU = EditorGUILayout.FloatField("2nd Animation U", secondDirectionU); | |||
secondDirectionV = EditorGUILayout.FloatField("2nd Animation V", secondDirectionV); | |||
EditorGUILayout.EndHorizontal (); | |||
animationDirection = new Vector4(firstDirectionU,firstDirectionV, secondDirectionU,secondDirectionV); | |||
animationTiling = new Vector4(firstTilingU/100.0F,firstTilingV/100.0F, secondTilingU/100.0F,secondTilingV/100.0F); | |||
WaterEditorUtility.SetMaterialVector("_AnimationTiling", animationTiling, sharedWaterMaterial); | |||
WaterEditorUtility.SetMaterialVector("_AnimationDirection", animationDirection, sharedWaterMaterial); | |||
EditorGUILayout.Separator (); | |||
GUILayout.Label ("Displacement Strength", EditorStyles.boldLabel); | |||
float heightDisplacement = WaterEditorUtility.GetMaterialFloat("_HeightDisplacement", sharedWaterMaterial); | |||
heightDisplacement = EditorGUILayout.Slider("Height", heightDisplacement, 0.0F, 5.0F); | |||
WaterEditorUtility.SetMaterialFloat("_HeightDisplacement", heightDisplacement, sharedWaterMaterial); | |||
*/ | |||
} | |||
serObj.ApplyModifiedProperties(); | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 1dfa22e5547fb4a4585ba225887d89dd | |||
MonoImporter: | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: |
@ -0,0 +1,60 @@ | |||
using UnityEngine; | |||
using UnityEditor; | |||
[CustomEditor(typeof(PlanarReflection))] | |||
public class PlanarReflectionEditor : Editor | |||
{ | |||
private SerializedObject serObj; | |||
//private SerializedProperty wavesFrequency; | |||
// reflection | |||
private SerializedProperty reflectionMask; | |||
private SerializedProperty reflectSkybox; | |||
private SerializedProperty clearColor; | |||
bool showKidsWithReflectionHint = false; | |||
public void OnEnable () { | |||
serObj = new SerializedObject (target); | |||
reflectionMask = serObj.FindProperty("reflectionMask"); | |||
reflectSkybox = serObj.FindProperty("reflectSkybox"); | |||
clearColor = serObj.FindProperty("clearColor"); | |||
} | |||
public override void OnInspectorGUI () | |||
{ | |||
GUILayout.Label ("Render planar reflections and use GrabPass for refractions", EditorStyles.miniBoldLabel); | |||
if(!SystemInfo.supportsRenderTextures) | |||
EditorGUILayout.HelpBox("Realtime reflections not supported", MessageType.Warning); | |||
serObj.Update(); | |||
EditorGUILayout.PropertyField(reflectionMask, new GUIContent("Reflection layers")); | |||
EditorGUILayout.PropertyField(reflectSkybox, new GUIContent("Use skybox")); | |||
EditorGUILayout.PropertyField(clearColor, new GUIContent("Clear color")); | |||
showKidsWithReflectionHint = EditorGUILayout.BeginToggleGroup("Show all tiles", showKidsWithReflectionHint); | |||
if (showKidsWithReflectionHint) { | |||
int i = 0; | |||
foreach(Transform t in ((PlanarReflection)target).transform) { | |||
if (t.GetComponent<WaterTile>()) { | |||
if(i%2==0) | |||
EditorGUILayout.BeginHorizontal(); | |||
EditorGUILayout.ObjectField(t, typeof(Transform), true); | |||
if(i%2==1) | |||
EditorGUILayout.EndHorizontal(); | |||
i = (i+1)%2; | |||
} | |||
} | |||
if(i>0) | |||
EditorGUILayout.EndHorizontal(); | |||
} | |||
EditorGUILayout.EndToggleGroup(); | |||
serObj.ApplyModifiedProperties(); | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: ff3b0e14a61014f50be83e1a18c6d43e | |||
MonoImporter: | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: |
@ -0,0 +1,47 @@ | |||
using UnityEngine; | |||
using UnityEditor; | |||
[CustomEditor(typeof(SpecularLighting))] | |||
public class SpecularLightingEditor : Editor | |||
{ | |||
private SerializedObject serObj; | |||
private SerializedProperty specularLight; | |||
public void OnEnable () { | |||
serObj = new SerializedObject (target); | |||
specularLight = serObj.FindProperty("specularLight"); | |||
} | |||
public override void OnInspectorGUI () | |||
{ | |||
serObj.Update(); | |||
GameObject go = ((SpecularLighting)serObj.targetObject).gameObject; | |||
WaterBase wb = (WaterBase)go.GetComponent(typeof(WaterBase)); | |||
if(!wb.sharedMaterial) | |||
return; | |||
if(wb.sharedMaterial.HasProperty("_WorldLightDir")) { | |||
GUILayout.Label ("Transform casting specular highlights", EditorStyles.miniBoldLabel); | |||
EditorGUILayout.PropertyField(specularLight, new GUIContent("Specular light")); | |||
if(wb.sharedMaterial.HasProperty("_SpecularColor")) | |||
WaterEditorUtility.SetMaterialColor( | |||
"_SpecularColor", | |||
EditorGUILayout.ColorField("Specular", | |||
WaterEditorUtility.GetMaterialColor("_SpecularColor", wb.sharedMaterial)), | |||
wb.sharedMaterial); | |||
if(wb.sharedMaterial.HasProperty("_Shininess")) | |||
WaterEditorUtility.SetMaterialFloat("_Shininess", EditorGUILayout.Slider( | |||
"Specular power", | |||
WaterEditorUtility.GetMaterialFloat("_Shininess", wb.sharedMaterial), | |||
0.0F, 500.0F), wb.sharedMaterial); | |||
} | |||
else | |||
GUILayout.Label ("The shader doesn't have the needed _WorldLightDir property.", EditorStyles.miniBoldLabel); | |||
serObj.ApplyModifiedProperties(); | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 33f51eb21122c4ca6a199d561065ae30 | |||
MonoImporter: | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: |
@ -0,0 +1,188 @@ | |||
using UnityEngine; | |||
using UnityEditor; | |||
[CustomEditor(typeof(WaterBase))] | |||
public class WaterBaseEditor : Editor | |||
{ | |||
public GameObject oceanBase; | |||
private WaterBase waterBase; | |||
private Material oceanMaterial = null; | |||
private SerializedObject serObj; | |||
private SerializedProperty sharedMaterial; | |||
public SerializedProperty waterQuality; | |||
public SerializedProperty edgeBlend; | |||
public void OnEnable () | |||
{ | |||
serObj = new SerializedObject (target); | |||
sharedMaterial = serObj.FindProperty("sharedMaterial"); | |||
waterQuality = serObj.FindProperty("waterQuality"); | |||
edgeBlend = serObj.FindProperty("edgeBlend"); | |||
} | |||
public override void OnInspectorGUI () | |||
{ | |||
serObj.Update(); | |||
waterBase = (WaterBase)serObj.targetObject; | |||
oceanBase = ((WaterBase)serObj.targetObject).gameObject; | |||
if(!oceanBase) | |||
return; | |||
GUILayout.Label ("This script helps adjusting water material properties", EditorStyles.miniBoldLabel); | |||
EditorGUILayout.PropertyField(sharedMaterial, new GUIContent("Material")); | |||
oceanMaterial = (Material)sharedMaterial.objectReferenceValue; | |||
if (!oceanMaterial) { | |||
sharedMaterial.objectReferenceValue = (Object)WaterEditorUtility.LocateValidWaterMaterial(oceanBase.transform); | |||
serObj.ApplyModifiedProperties(); | |||
oceanMaterial = (Material)sharedMaterial.objectReferenceValue; | |||
if (!oceanMaterial) | |||
return; | |||
} | |||
EditorGUILayout.Separator (); | |||
GUILayout.Label ("Overall Quality", EditorStyles.boldLabel); | |||
EditorGUILayout.PropertyField(waterQuality, new GUIContent("Quality")); | |||
EditorGUILayout.PropertyField(edgeBlend, new GUIContent("Edge blend?")); | |||
if(waterQuality.intValue > (int)WaterQuality.Low && !SystemInfo.supportsRenderTextures) | |||
EditorGUILayout.HelpBox("Water features not supported", MessageType.Warning); | |||
if(edgeBlend.boolValue && !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth)) | |||
EditorGUILayout.HelpBox("Edge blend not supported", MessageType.Warning); | |||
EditorGUILayout.Separator (); | |||
bool hasShore = oceanMaterial.HasProperty("_ShoreTex"); | |||
GUILayout.Label ("Main Colors", EditorStyles.boldLabel); | |||
GUILayout.Label ("Alpha values define blending with realtime textures", EditorStyles.miniBoldLabel); | |||
WaterEditorUtility.SetMaterialColor("_BaseColor", EditorGUILayout.ColorField("Refraction", WaterEditorUtility.GetMaterialColor("_BaseColor", oceanMaterial)), oceanMaterial); | |||
WaterEditorUtility.SetMaterialColor("_ReflectionColor", EditorGUILayout.ColorField("Reflection", WaterEditorUtility.GetMaterialColor("_ReflectionColor", oceanMaterial)), oceanMaterial); | |||
EditorGUILayout.Separator (); | |||
GUILayout.Label ("Main Textures", EditorStyles.boldLabel); | |||
GUILayout.Label ("Used for small waves (bumps), foam and white caps", EditorStyles.miniBoldLabel); | |||
WaterEditorUtility.SetMaterialTexture("_BumpMap",(Texture)EditorGUILayout.ObjectField("Normals", WaterEditorUtility.GetMaterialTexture("_BumpMap", waterBase.sharedMaterial), typeof(Texture), false), waterBase.sharedMaterial); | |||
if (hasShore) | |||
WaterEditorUtility.SetMaterialTexture("_ShoreTex", (Texture)EditorGUILayout.ObjectField("Shore & Foam", WaterEditorUtility.GetMaterialTexture("_ShoreTex", waterBase.sharedMaterial), typeof(Texture), false), waterBase.sharedMaterial); | |||
Vector4 animationTiling; | |||
Vector4 animationDirection; | |||
Vector2 firstTiling; | |||
Vector2 secondTiling; | |||
Vector2 firstDirection; | |||
Vector2 secondDirection; | |||
animationTiling = WaterEditorUtility.GetMaterialVector("_BumpTiling", oceanMaterial); | |||
animationDirection = WaterEditorUtility.GetMaterialVector("_BumpDirection", oceanMaterial); | |||
firstTiling = new Vector2(animationTiling.x*100.0F,animationTiling.y*100.0F); | |||
secondTiling = new Vector2(animationTiling.z*100.0F,animationTiling.w*100.0F); | |||
firstTiling = EditorGUILayout.Vector2Field("Tiling 1", firstTiling); | |||
secondTiling = EditorGUILayout.Vector2Field("Tiling 2", secondTiling); | |||
//firstTiling.x = EditorGUILayout.FloatField("1st Tiling U", firstTiling.x); | |||
//firstTiling.y = EditorGUILayout.FloatField("1st Tiling V", firstTiling.y); | |||
//secondTiling.x = EditorGUILayout.FloatField("2nd Tiling U", secondTiling.x); | |||
//secondTiling.y = EditorGUILayout.FloatField("2nd Tiling V", secondTiling.y); | |||
firstDirection = new Vector2(animationDirection.x,animationDirection.y); | |||
secondDirection = new Vector2(animationDirection.z,animationDirection.w); | |||
//firstDirection.x = EditorGUILayout.FloatField("1st Animation U", firstDirection.x); | |||
//firstDirection.y = EditorGUILayout.FloatField("1st Animation V", firstDirection.y); | |||
//secondDirection.x = EditorGUILayout.FloatField("2nd Animation U", secondDirection.x); | |||
//secondDirection.y = EditorGUILayout.FloatField("2nd Animation V", secondDirection.y); | |||
firstDirection = EditorGUILayout.Vector2Field("Direction 1", firstDirection); | |||
secondDirection = EditorGUILayout.Vector2Field("Direction 2", secondDirection); | |||
animationTiling = new Vector4(firstTiling.x/100.0F,firstTiling.y/100.0F, secondTiling.x/100.0F,secondTiling.y/100.0F); | |||
animationDirection = new Vector4(firstDirection.x,firstDirection.y, secondDirection.x,secondDirection.y); | |||
WaterEditorUtility.SetMaterialVector("_BumpTiling", animationTiling, oceanMaterial); | |||
WaterEditorUtility.SetMaterialVector("_BumpDirection", animationDirection, oceanMaterial); | |||
Vector4 displacementParameter = WaterEditorUtility.GetMaterialVector("_DistortParams", oceanMaterial); | |||
Vector4 fade = WaterEditorUtility.GetMaterialVector("_InvFadeParemeter", oceanMaterial); | |||
EditorGUILayout.Separator (); | |||
GUILayout.Label ("Normals", EditorStyles.boldLabel); | |||
GUILayout.Label ("Displacement for fresnel, specular and reflection/refraction", EditorStyles.miniBoldLabel); | |||
float gerstnerNormalIntensity = WaterEditorUtility.GetMaterialFloat("_GerstnerIntensity", oceanMaterial); | |||
gerstnerNormalIntensity = EditorGUILayout.Slider("Per Vertex", gerstnerNormalIntensity, -2.5F, 2.5F); | |||
WaterEditorUtility.SetMaterialFloat("_GerstnerIntensity", gerstnerNormalIntensity, oceanMaterial); | |||
displacementParameter.x = EditorGUILayout.Slider("Per Pixel", displacementParameter.x, -4.0F, 4.0F); | |||
displacementParameter.y = EditorGUILayout.Slider("Distortion", displacementParameter.y, -0.5F, 0.5F); | |||
// fade.z = EditorGUILayout.Slider("Distance fade", fade.z, 0.0f, 0.5f); | |||
EditorGUILayout.Separator (); | |||
GUILayout.Label ("Fresnel", EditorStyles.boldLabel); | |||
GUILayout.Label ("Defines reflection to refraction relation", EditorStyles.miniBoldLabel); | |||
if(!oceanMaterial.HasProperty("_Fresnel")) { | |||
if(oceanMaterial.HasProperty("_FresnelScale")) { | |||
float fresnelScale = EditorGUILayout.Slider("Intensity", WaterEditorUtility.GetMaterialFloat("_FresnelScale", oceanMaterial), 0.1F, 4.0F); | |||
WaterEditorUtility.SetMaterialFloat("_FresnelScale", fresnelScale, oceanMaterial); | |||
} | |||
displacementParameter.z = EditorGUILayout.Slider("Power", displacementParameter.z, 0.1F, 10.0F); | |||
displacementParameter.w = EditorGUILayout.Slider("Bias", displacementParameter.w, -3.0F, 3.0F); | |||
} | |||
else | |||
{ | |||
Texture fresnelTex = (Texture)EditorGUILayout.ObjectField( | |||
"Ramp", | |||
(Texture)WaterEditorUtility.GetMaterialTexture("_Fresnel", | |||
oceanMaterial), | |||
typeof(Texture), | |||
false); | |||
WaterEditorUtility.SetMaterialTexture("_Fresnel", fresnelTex, oceanMaterial); | |||
} | |||
EditorGUILayout.Separator (); | |||
WaterEditorUtility.SetMaterialVector("_DistortParams", displacementParameter, oceanMaterial); | |||
if (edgeBlend.boolValue) | |||
{ | |||
GUILayout.Label ("Fading", EditorStyles.boldLabel); | |||
fade.x = EditorGUILayout.Slider("Edge fade", fade.x, 0.001f, 3.0f); | |||
if(hasShore) | |||
fade.y = EditorGUILayout.Slider("Shore fade", fade.y, 0.001f, 3.0f); | |||
fade.w = EditorGUILayout.Slider("Extinction fade", fade.w, 0.0f, 2.5f); | |||
WaterEditorUtility.SetMaterialVector("_InvFadeParemeter", fade, oceanMaterial); | |||
} | |||
EditorGUILayout.Separator (); | |||
if(oceanMaterial.HasProperty("_Foam")) { | |||
GUILayout.Label ("Foam", EditorStyles.boldLabel); | |||
Vector4 foam = WaterEditorUtility.GetMaterialVector("_Foam", oceanMaterial); | |||
foam.x = EditorGUILayout.Slider("Intensity", foam.x, 0.0F, 1.0F); | |||
foam.y = EditorGUILayout.Slider("Cutoff", foam.y, 0.0F, 1.0F); | |||
WaterEditorUtility.SetMaterialVector("_Foam", foam, oceanMaterial); | |||
} | |||
serObj.ApplyModifiedProperties(); | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 9c2c627f6fe3945b39581fc103d32251 | |||
MonoImporter: | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: |
@ -0,0 +1,75 @@ | |||
using UnityEngine; | |||
using UnityEditor; | |||
class WaterEditorUtility | |||
{ | |||
// helper functions to retrieve & set material values | |||
public static float GetMaterialFloat(System.String name, Material mat) { | |||
return mat.GetFloat(name); | |||
} | |||
public static void SetMaterialFloat(System.String name, float f, Material mat) { | |||
mat.SetFloat(name, f); | |||
} | |||
public static Color GetMaterialColor(System.String name, Material mat) { | |||
return mat.GetColor(name); | |||
} | |||
public static void SetMaterialColor(System.String name, Color color, Material mat) { | |||
mat.SetColor(name, color); | |||
} | |||
public static Vector4 GetMaterialVector(System.String name, Material mat) { | |||
return mat.GetVector(name); | |||
} | |||
public static void SetMaterialVector(System.String name, Vector4 vector, Material mat) { | |||
mat.SetVector(name, vector); | |||
} | |||
public static Texture GetMaterialTexture(System.String theName, Material mat) { | |||
return mat.GetTexture(theName); | |||
} | |||
public static void SetMaterialTexture(System.String theName, Texture parameter, Material mat) { | |||
mat.SetTexture(theName, parameter); | |||
} | |||
public static Material LocateValidWaterMaterial(Transform parent) | |||
{ | |||
if(parent.renderer && parent.renderer.sharedMaterial) | |||
return parent.renderer.sharedMaterial; | |||
foreach( Transform t in parent) | |||
{ | |||
if(t.renderer && t.renderer.sharedMaterial) | |||
return t.renderer.sharedMaterial; | |||
} | |||
return null; | |||
} | |||
public static void CurveGui (System.String name, SerializedObject serObj, Color color) | |||
{ | |||
AnimationCurve curve = new AnimationCurve(new Keyframe(0, 0.0f, 1.0f, 1.0f), new Keyframe(1, 1.0f, 1.0f, 1.0f)); | |||
curve = EditorGUILayout.CurveField(new GUIContent (name), curve, color, new Rect (0.0f,0.0f,1.0f,1.0f)); | |||
//if (GUI.changed) { | |||
// AnimationCurveChanged(((WaterBase)serObj.targetObject).sharedMaterial, curve); | |||
//((WaterBase)serObj.targetObject).gameObject.SendMessage ("AnimationCurveChanged", SendMessageOptions.DontRequireReceiver); | |||
//} | |||
} | |||
/* | |||
public static void AnimationCurveChanged(Material sharedMaterial, AnimationCurve fresnelCurve) | |||
{ | |||
Debug.Log("AnimationCurveChanged"); | |||
Texture2D fresnel = (Texture2D)sharedMaterial.GetTexture("_Fresnel"); | |||
if(!fresnel) | |||
fresnel = new Texture2D(256,1); | |||
for (int i = 0; i < 256; i++) | |||
{ | |||
float val = Mathf.Clamp01(fresnelCurve.Evaluate((float)i)/255.0f); | |||
Debug.Log(""+(((float)i)/255.0f) +": "+val); | |||
fresnel.SetPixel(i, 0, new Color(val,val,val,val)); | |||
} | |||
fresnel.Apply(); | |||
sharedMaterial.SetTexture("_Fresnel", fresnel); | |||
} */ | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: f67f2bac30f824d4f8270bb8bb0779df | |||
MonoImporter: | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: a2cdf2ef81f27984fa7b93bd6d364c16 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,48 @@ | |||
using UnityEngine; | |||
using System.Collections; | |||
public class Patrol : MonoBehaviour { | |||
public float patrolDistance; | |||
public int waitTime; | |||
public float speed; | |||
public bool startRight; | |||
public int direction = 1; | |||
private Vector3 startPosition; | |||
private int curWait = 0; | |||
// Use this for initialization | |||
void Start () { | |||
startPosition = transform.position; | |||
if (!startRight) { | |||
transform.Rotate (Vector3.up * 180); | |||
direction *= -1; | |||
} | |||
} | |||
// Update is called once per frame | |||
void Update () { | |||
Vector3 curPosition = transform.position; | |||
Vector3 move = new Vector3(1, 0.0f ,0.0f); | |||
move.x *= speed; | |||
move *= direction; | |||
if (curWait == 0) { | |||
if (Mathf.Abs(startPosition.x - curPosition.x) < patrolDistance) | |||
transform.position += move; | |||
else | |||
curWait = waitTime; | |||
} else if (curWait == 1) { | |||
transform.Rotate (Vector3.up * 180); | |||
direction *= -1; | |||
transform.position -= move; | |||
curWait--; | |||
} else | |||
curWait--; | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: afa701e8ac1b548478719de7f588c6d2 | |||
MonoImporter: | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: 09de098202ab0a7439f834e8df93e9d2 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: dc7abfa0435174ded902b073322d67cc | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: 9485b0c79d11e2e4d0007da98d76c639 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: 6b436d069d11415d1100ab9b44295342 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 70a4c3571f5624280bd8605def97056d | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 706eadfad28bc4c1c9bb137b31052b14 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: 52b7d70b1de7c4ce09662b77c14d9fda | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: c55afdc4a8a3b4890b07cc7d176510bb | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 2fd60b04f7c434a4dafd253d09bfa783 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 40b01469ebddf42bc84870ba2f3d8c4c | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: 30abebfd9bf1c49d8a2d26e61e66bc15 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,68 @@ | |||
fileFormatVersion: 2 | |||
guid: ce8d79c79d11b8f9d00076e98d76c639 | |||
ModelImporter: | |||
serializedVersion: 16 | |||
fileIDToRecycleName: | |||
100000: //RootNode | |||
400000: //RootNode | |||
2300000: //RootNode | |||
3300000: //RootNode | |||
4300000: pPlane1 | |||
4300002: nurbsToPoly1 | |||
4300004: pCylinder1 | |||
4300006: waterPlaneMesh | |||
11100000: //RootNode | |||
materials: | |||
importMaterials: 1 | |||
materialName: 3 | |||
materialSearch: 1 | |||
animations: | |||
legacyGenerateAnimations: 0 | |||
bakeSimulation: 0 | |||
optimizeGameObjects: 0 | |||
motionNodeName: | |||
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: 1 | |||
optimizeMeshForGPU: 1 | |||
weldVertices: 1 | |||
secondaryUVAngleDistortion: 8 | |||
secondaryUVAreaDistortion: 15 | |||
secondaryUVHardAngle: 88 | |||
secondaryUVPackMargin: 4 | |||
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: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: ac85670a1b2274f22905d6a43940371a | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,32 @@ | |||
using UnityEngine; | |||
// Sets up transformation matrices to scale&scroll water waves | |||
// for the case where graphics card does not support vertex programs. | |||
[ExecuteInEditMode] | |||
public class WaterSimple : MonoBehaviour | |||
{ | |||
void Update() | |||
{ | |||
if( !GetComponent<Renderer>() ) | |||
return; | |||
Material mat = GetComponent<Renderer>().sharedMaterial; | |||
if( !mat ) | |||
return; | |||
Vector4 waveSpeed = mat.GetVector( "WaveSpeed" ); | |||
float waveScale = mat.GetFloat( "_WaveScale" ); | |||
float t = Time.time / 20.0f; | |||
Vector4 offset4 = waveSpeed * (t * waveScale); | |||
Vector4 offsetClamped = new Vector4(Mathf.Repeat(offset4.x,1.0f), Mathf.Repeat(offset4.y,1.0f), Mathf.Repeat(offset4.z,1.0f), Mathf.Repeat(offset4.w,1.0f)); | |||
mat.SetVector( "_WaveOffset", offsetClamped ); | |||
Vector3 scale = new Vector3( 1.0f/waveScale, 1.0f/waveScale, 1 ); | |||
Matrix4x4 scrollMatrix = Matrix4x4.TRS( new Vector3(offsetClamped.x,offsetClamped.y,0), Quaternion.identity, scale ); | |||
mat.SetMatrix( "_WaveMatrix", scrollMatrix ); | |||
scrollMatrix = Matrix4x4.TRS( new Vector3(offsetClamped.z,offsetClamped.w,0), Quaternion.identity, scale * 0.45f ); | |||
mat.SetMatrix( "_WaveMatrix2", scrollMatrix ); | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 0d2f50a8e0bb841a5aaa90ae55db8849 | |||
MonoImporter: | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: c8e96a067d1ef4982b454cf5a686f648 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,140 @@ | |||
Shader "FX/Water (simple)" { | |||
Properties { | |||
_horizonColor ("Horizon color", COLOR) = ( .172 , .463 , .435 , 0) | |||
_WaveScale ("Wave scale", Range (0.02,0.15)) = .07 | |||
_ColorControl ("Reflective color (RGB) fresnel (A) ", 2D) = "" { } | |||
_ColorControlCube ("Reflective color cube (RGB) fresnel (A) ", Cube) = "" { TexGen CubeReflect } | |||
_BumpMap ("Waves Normalmap ", 2D) = "" { } | |||
WaveSpeed ("Wave speed (map1 x,y; map2 x,y)", Vector) = (19,9,-16,-7) | |||
_MainTex ("Fallback texture", 2D) = "" { } | |||
} | |||
CGINCLUDE | |||
// ----------------------------------------------------------- | |||
// This section is included in all program sections below | |||
#include "UnityCG.cginc" | |||
uniform float4 _horizonColor; | |||
uniform float4 WaveSpeed; | |||
uniform float _WaveScale; | |||
uniform float4 _WaveOffset; | |||
struct appdata { | |||
float4 vertex : POSITION; | |||
float3 normal : NORMAL; | |||
}; | |||
struct v2f { | |||
float4 pos : SV_POSITION; | |||
float2 bumpuv[2] : TEXCOORD0; | |||
float3 viewDir : TEXCOORD2; | |||
}; | |||
v2f vert(appdata v) | |||
{ | |||
v2f o; | |||
float4 s; | |||
o.pos = mul (UNITY_MATRIX_MVP, v.vertex); | |||
// scroll bump waves | |||
float4 temp; | |||
temp.xyzw = v.vertex.xzxz * _WaveScale / unity_Scale.w + _WaveOffset; | |||
o.bumpuv[0] = temp.xy * float2(.4, .45); | |||
o.bumpuv[1] = temp.wz; | |||
// object space view direction | |||
o.viewDir.xzy = normalize( ObjSpaceViewDir(v.vertex) ); | |||
return o; | |||
} | |||
ENDCG | |||
// ----------------------------------------------------------- | |||
// Fragment program | |||
Subshader { | |||
Tags { "RenderType"="Opaque" } | |||
Pass { | |||
CGPROGRAM | |||
#pragma vertex vert | |||
#pragma fragment frag | |||
#pragma fragmentoption ARB_precision_hint_fastest | |||
sampler2D _BumpMap; | |||
sampler2D _ColorControl; | |||
half4 frag( v2f i ) : COLOR | |||
{ | |||
half3 bump1 = UnpackNormal(tex2D( _BumpMap, i.bumpuv[0] )).rgb; | |||
half3 bump2 = UnpackNormal(tex2D( _BumpMap, i.bumpuv[1] )).rgb; | |||
half3 bump = (bump1 + bump2) * 0.5; | |||
half fresnel = dot( i.viewDir, bump ); | |||
half4 water = tex2D( _ColorControl, float2(fresnel,fresnel) ); | |||
half4 col; | |||
col.rgb = lerp( water.rgb, _horizonColor.rgb, water.a ); | |||
col.a = _horizonColor.a; | |||
return col; | |||
} | |||
ENDCG | |||
} | |||
} | |||
// ----------------------------------------------------------- | |||
// Old cards | |||
// three texture, cubemaps | |||
Subshader { | |||
Tags { "RenderType"="Opaque" } | |||
Pass { | |||
Color (0.5,0.5,0.5,0.5) | |||
SetTexture [_MainTex] { | |||
Matrix [_WaveMatrix] | |||
combine texture * primary | |||
} | |||
SetTexture [_MainTex] { | |||
Matrix [_WaveMatrix2] | |||
combine texture * primary + previous | |||
} | |||
SetTexture [_ColorControlCube] { | |||
combine texture +- previous, primary | |||
Matrix [_Reflection] | |||
} | |||
} | |||
} | |||
// dual texture, cubemaps | |||
Subshader { | |||
Tags { "RenderType"="Opaque" } | |||
Pass { | |||
Color (0.5,0.5,0.5,0.5) | |||
SetTexture [_MainTex] { | |||
Matrix [_WaveMatrix] | |||
combine texture | |||
} | |||
SetTexture [_ColorControlCube] { | |||
combine texture +- previous, primary | |||
Matrix [_Reflection] | |||
} | |||
} | |||
} | |||
// single texture | |||
Subshader { | |||
Tags { "RenderType"="Opaque" } | |||
Pass { | |||
Color (0.5,0.5,0.5,0) | |||
SetTexture [_MainTex] { | |||
Matrix [_WaveMatrix] | |||
combine texture, primary | |||
} | |||
} | |||
} | |||
} |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 9dccc8e8f0da4494991c26ef59019551 | |||
ShaderImporter: | |||
defaultTextures: [] | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: 5421734063b66ee4f8a180ecae8132bc | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 33850b67ffcaa4b6c9a7146e4be0b917 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,47 @@ | |||
fileFormatVersion: 2 | |||
guid: c2ef94ff9d11915d1100a04b44295342 | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 512 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 1 | |||
lightmap: 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: |
@ -0,0 +1,47 @@ | |||
fileFormatVersion: 2 | |||
guid: a53cf5449d11a15d1100a04b44295342 | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 512 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 3 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 1 | |||
lightmap: 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: |
@ -0,0 +1,48 @@ | |||
fileFormatVersion: 2 | |||
guid: 006a5f739d1105f6a000538a2aef8c59 | |||
TextureImporter: | |||
fileIDToRecycleName: | |||
8900000: generatedCubemap | |||
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: 3 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 32 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 0 | |||
lightmap: 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: |
@ -0,0 +1,47 @@ | |||
fileFormatVersion: 2 | |||
guid: 8403d3349d112ba4d000be1be39e7c39 | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 32 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 1 | |||
nPOTScale: 1 | |||
lightmap: 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: |
@ -0,0 +1,47 @@ | |||
fileFormatVersion: 2 | |||
guid: 047330f39d11745ad0004adb8d76c639 | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 32 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 1 | |||
nPOTScale: 1 | |||
lightmap: 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: |
@ -0,0 +1,48 @@ | |||
fileFormatVersion: 2 | |||
guid: 98c330f39d11745ad0004adb8d76c639 | |||
TextureImporter: | |||
fileIDToRecycleName: | |||
8900000: generatedCubemap | |||
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: 3 | |||
seamlessCubemap: 0 | |||
textureFormat: 12 | |||
maxTextureSize: 32 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 0 | |||
lightmap: 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: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 15577174a872740edb59495b6549a0c3 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: 780611a67e8e941a2b3aa96e5915a793 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: bcae914220acd4907840a029bb9d9aec | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 32569ca6b14e24176be40165ccaa300c | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 8269a010592f549af8f11b1683d9e794 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: ae162c0523ab4468bb03ef160eb672e2 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: e633a20421c47426aa04444234225b69 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: fe5d00245bc1d42a7927f4b2879026b8 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 1e68e75546e8d4feab8846bfaf8878d3 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,4 @@ | |||
fileFormatVersion: 2 | |||
guid: 358a87f082de94ddd810e929c00c8594 | |||
NativeFormatImporter: | |||
userData: |
@ -0,0 +1,68 @@ | |||
fileFormatVersion: 2 | |||
guid: ba6a41dc489914734857bb5924eb70ad | |||
ModelImporter: | |||
serializedVersion: 16 | |||
fileIDToRecycleName: | |||
100000: //RootNode | |||
400000: //RootNode | |||
2300000: //RootNode | |||
3300000: //RootNode | |||
4300000: pPlane1 | |||
4300002: nurbsToPoly1 | |||
4300004: pCylinder1 | |||
4300006: waterPlaneMesh | |||
11100000: //RootNode | |||
materials: | |||
importMaterials: 1 | |||
materialName: 3 | |||
materialSearch: 1 | |||
animations: | |||
legacyGenerateAnimations: 0 | |||
bakeSimulation: 0 | |||
optimizeGameObjects: 0 | |||
motionNodeName: | |||
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: 1 | |||
optimizeMeshForGPU: 1 | |||
weldVertices: 1 | |||
secondaryUVAngleDistortion: 8 | |||
secondaryUVAreaDistortion: 15 | |||
secondaryUVHardAngle: 88 | |||
secondaryUVPackMargin: 4 | |||
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: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: b5b8c0f9acc2944f086c02cb83f4ae76 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,369 @@ | |||
using UnityEngine; | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
[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 m_WaterMode = WaterMode.Refractive; | |||
public bool m_DisablePixelLights = true; | |||
public int m_TextureSize = 256; | |||
public float m_ClipPlaneOffset = 0.07f; | |||
public LayerMask m_ReflectLayers = -1; | |||
public LayerMask m_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 = null; | |||
private RenderTexture m_RefractionTexture = null; | |||
private WaterMode m_HardwareWaterSupport = WaterMode.Refractive; | |||
private int m_OldReflectionTextureSize = 0; | |||
private int m_OldRefractionTextureSize = 0; | |||
private static bool s_InsideWater = false; | |||
// 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 || !renderer || !renderer.sharedMaterial || !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( m_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) - m_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); | |||
reflectionCamera.cullingMask = ~(1<<4) & m_ReflectLayers.value; // never render water layer | |||
reflectionCamera.targetTexture = m_ReflectionTexture; | |||
GL.SetRevertBackfacing (true); | |||
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.SetRevertBackfacing (false); | |||
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); | |||
refractionCamera.cullingMask = ~(1<<4) & m_RefractLayers.value; // never render water layer | |||
refractionCamera.targetTexture = m_RefractionTexture; | |||
refractionCamera.transform.position = cam.transform.position; | |||
refractionCamera.transform.rotation = cam.transform.rotation; | |||
refractionCamera.Render(); | |||
renderer.sharedMaterial.SetTexture( "_RefractionTex", m_RefractionTexture ); | |||
} | |||
// Restore pixel light count | |||
if( m_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 (KeyValuePair<Camera, Camera> kvp in m_ReflectionCameras) | |||
DestroyImmediate( (kvp.Value).gameObject ); | |||
m_ReflectionCameras.Clear(); | |||
foreach (KeyValuePair<Camera, Camera> 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( !renderer ) | |||
return; | |||
Material mat = 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)System.Math.IEEERemainder(waveSpeed.x * waveScale4.x * t, 1.0), | |||
(float)System.Math.IEEERemainder(waveSpeed.y * waveScale4.y * t, 1.0), | |||
(float)System.Math.IEEERemainder(waveSpeed.z * waveScale4.z * t, 1.0), | |||
(float)System.Math.IEEERemainder(waveSpeed.w * waveScale4.w * t, 1.0) | |||
); | |||
mat.SetVector( "_WaveOffset", offsetClamped ); | |||
mat.SetVector( "_WaveScale4", waveScale4 ); | |||
Vector3 waterSize = renderer.bounds.size; | |||
Vector3 scale = new Vector3( waterSize.x*waveScale4.x, waterSize.z*waveScale4.y, 1 ); | |||
Matrix4x4 scrollMatrix = Matrix4x4.TRS( new Vector3(offsetClamped.x,offsetClamped.y,0), Quaternion.identity, scale ); | |||
mat.SetMatrix( "_WaveMatrix", scrollMatrix ); | |||
scale = new Vector3( waterSize.x*waveScale4.z, waterSize.z*waveScale4.w, 1 ); | |||
scrollMatrix = Matrix4x4.TRS( new Vector3(offsetClamped.z,offsetClamped.w,0), Quaternion.identity, scale ); | |||
mat.SetMatrix( "_WaveMatrix2", scrollMatrix ); | |||
} | |||
private 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(typeof(Skybox)) as Skybox; | |||
Skybox mysky = dest.GetComponent(typeof(Skybox)) as 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 | |||
private 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 != m_TextureSize ) | |||
{ | |||
if( m_ReflectionTexture ) | |||
DestroyImmediate( m_ReflectionTexture ); | |||
m_ReflectionTexture = new RenderTexture( m_TextureSize, m_TextureSize, 16 ); | |||
m_ReflectionTexture.name = "__WaterReflection" + GetInstanceID(); | |||
m_ReflectionTexture.isPowerOfTwo = true; | |||
m_ReflectionTexture.hideFlags = HideFlags.DontSave; | |||
m_OldReflectionTextureSize = m_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.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 != m_TextureSize ) | |||
{ | |||
if( m_RefractionTexture ) | |||
DestroyImmediate( m_RefractionTexture ); | |||
m_RefractionTexture = new RenderTexture( m_TextureSize, m_TextureSize, 16 ); | |||
m_RefractionTexture.name = "__WaterRefraction" + GetInstanceID(); | |||
m_RefractionTexture.isPowerOfTwo = true; | |||
m_RefractionTexture.hideFlags = HideFlags.DontSave; | |||
m_OldRefractionTextureSize = m_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.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; | |||
} | |||
} | |||
} | |||
private WaterMode GetWaterMode() | |||
{ | |||
if( m_HardwareWaterSupport < m_WaterMode ) | |||
return m_HardwareWaterSupport; | |||
else | |||
return m_WaterMode; | |||
} | |||
private WaterMode FindHardwareWaterSupport() | |||
{ | |||
if( !SystemInfo.supportsRenderTextures || !renderer ) | |||
return WaterMode.Simple; | |||
Material mat = 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; | |||
} | |||
// Extended sign: returns -1, 0 or 1 based on sign of a | |||
private static float sgn(float a) | |||
{ | |||
if (a > 0.0f) return 1.0f; | |||
if (a < 0.0f) return -1.0f; | |||
return 0.0f; | |||
} | |||
// Given position/normal of the plane, calculates plane in camera space. | |||
private Vector4 CameraSpacePlane (Camera cam, Vector3 pos, Vector3 normal, float sideSign) | |||
{ | |||
Vector3 offsetPos = pos + normal * m_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 | |||
private 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; | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: a3d3ef1a5bbfb4e0a910fbbe5830b1f9 | |||
MonoImporter: | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: e70b47c0cfc1d4b12a3c663d7582a523 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,211 @@ | |||
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) | |||
_Fresnel ("Fresnel (A) ", 2D) = "gray" {} | |||
_BumpMap ("Normalmap ", 2D) = "bump" {} | |||
WaveSpeed ("Wave speed (map1 x,y; map2 x,y)", Vector) = (19,9,-16,-7) | |||
_ReflectiveColor ("Reflective color (RGB) fresnel (A) ", 2D) = "" {} | |||
_ReflectiveColorCube ("Reflective color cube (RGB) fresnel (A)", Cube) = "" { TexGen CubeReflect } | |||
_HorizonColor ("Simple water horizon color", COLOR) = ( .172, .463, .435, 1) | |||
_MainTex ("Fallback texture", 2D) = "" {} | |||
_ReflectionTex ("Internal Reflection", 2D) = "" {} | |||
_RefractionTex ("Internal Refraction", 2D) = "" {} | |||
} | |||
// ----------------------------------------------------------- | |||
// Fragment program cards | |||
Subshader { | |||
Tags { "WaterMode"="Refractive" "RenderType"="Opaque" } | |||
Pass { | |||
CGPROGRAM | |||
#pragma vertex vert | |||
#pragma fragment frag | |||
#pragma fragmentoption ARB_precision_hint_fastest | |||
#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 | |||
}; | |||
v2f vert(appdata v) | |||
{ | |||
v2f o; | |||
o.pos = mul (UNITY_MATRIX_MVP, v.vertex); | |||
// scroll bump waves | |||
float4 temp; | |||
temp.xyzw = v.vertex.xzxz * _WaveScale4 / unity_Scale.w + _WaveOffset; | |||
o.bumpuv0 = temp.xy; | |||
o.bumpuv1 = temp.wz; | |||
// object space view direction (will normalize per pixel) | |||
o.viewDir.xzy = ObjSpaceViewDir(v.vertex); | |||
#if defined(HAS_REFLECTION) || defined(HAS_REFRACTION) | |||
o.ref = ComputeScreenPos(o.pos); | |||
#endif | |||
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 | |||
return color; | |||
} | |||
ENDCG | |||
} | |||
} | |||
// ----------------------------------------------------------- | |||
// Old cards | |||
// three texture, cubemaps | |||
Subshader { | |||
Tags { "WaterMode"="Simple" "RenderType"="Opaque" } | |||
Pass { | |||
Color (0.5,0.5,0.5,0.5) | |||
SetTexture [_MainTex] { | |||
Matrix [_WaveMatrix] | |||
combine texture * primary | |||
} | |||
SetTexture [_MainTex] { | |||
Matrix [_WaveMatrix2] | |||
combine texture * primary + previous | |||
} | |||
SetTexture [_ReflectiveColorCube] { | |||
combine texture +- previous, primary | |||
Matrix [_Reflection] | |||
} | |||
} | |||
} | |||
// dual texture, cubemaps | |||
Subshader { | |||
Tags { "WaterMode"="Simple" "RenderType"="Opaque" } | |||
Pass { | |||
Color (0.5,0.5,0.5,0.5) | |||
SetTexture [_MainTex] { | |||
Matrix [_WaveMatrix] | |||
combine texture | |||
} | |||
SetTexture [_ReflectiveColorCube] { | |||
combine texture +- previous, primary | |||
Matrix [_Reflection] | |||
} | |||
} | |||
} | |||
// single texture | |||
Subshader { | |||
Tags { "WaterMode"="Simple" "RenderType"="Opaque" } | |||
Pass { | |||
Color (0.5,0.5,0.5,0) | |||
SetTexture [_MainTex] { | |||
Matrix [_WaveMatrix] | |||
combine texture, primary | |||
} | |||
} | |||
} | |||
} |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 1cac2e0bcc34e4b3cbb4bd85982eba83 | |||
ShaderImporter: | |||
defaultTextures: [] | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: c22094bc116524b2a95c9aae09278b22 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,47 @@ | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: 1 | |||
maxTextureSize: 1024 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 0 | |||
lightmap: 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: |
@ -0,0 +1,47 @@ | |||
fileFormatVersion: 2 | |||
guid: e6f8288974c664a309d6c66de636978c | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 512 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 1 | |||
lightmap: 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: |
@ -0,0 +1,47 @@ | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 512 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 3 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 1 | |||
lightmap: 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: |
@ -0,0 +1,48 @@ | |||
fileFormatVersion: 2 | |||
guid: 15c6acc4f11254a04b03849245d80574 | |||
TextureImporter: | |||
fileIDToRecycleName: | |||
8900000: generatedCubemap | |||
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: 3 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 32 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 0 | |||
lightmap: 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: |
@ -0,0 +1,47 @@ | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 32 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 1 | |||
nPOTScale: 1 | |||
lightmap: 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: |
@ -0,0 +1,47 @@ | |||
fileFormatVersion: 2 | |||
guid: 17680dc3bf8f74b498b01cf1481e2593 | |||
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 | |||
seamlessCubemap: 0 | |||
textureFormat: -1 | |||
maxTextureSize: 32 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 1 | |||
nPOTScale: 1 | |||
lightmap: 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: |
@ -0,0 +1,48 @@ | |||
fileFormatVersion: 2 | |||
guid: 9cda328e4b6954d70841a8a66f42ec08 | |||
TextureImporter: | |||
fileIDToRecycleName: | |||
8900000: generatedCubemap | |||
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: 3 | |||
seamlessCubemap: 0 | |||
textureFormat: 12 | |||
maxTextureSize: 32 | |||
textureSettings: | |||
filterMode: 1 | |||
aniso: 1 | |||
mipBias: 0 | |||
wrapMode: 0 | |||
nPOTScale: 0 | |||
lightmap: 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: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 17e234879cb994b7f93d7437c10d23d6 | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 7097f369c5ba74821bd76c430889322a | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |
@ -0,0 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: a771af3b1958445078af5fe2e9ec726c | |||
folderAsset: yes | |||
DefaultImporter: | |||
userData: |