public override void OnInspectorGUI() { serObj.Update(); var go = ((SpecularLighting)serObj.targetObject).gameObject; var 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(); }
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("WalkSpeed", 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(); }
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?")); EditorGUILayout.Separator(); bool hasShore = oceanMaterial.HasProperty("_ShoreTex"); GUILayout.Label("Main Colors", EditorStyles.boldLabel); GUILayout.Label("Alpha values define blending with realtime textures", EditorStyles.miniBoldLabel); EditorGUILayout.BeginHorizontal(); WaterEditorUtility.SetMaterialColor("_BaseColor", EditorGUILayout.ColorField("Refraction", WaterEditorUtility.GetMaterialColor("_BaseColor", oceanMaterial)), oceanMaterial); WaterEditorUtility.SetMaterialColor("_ReflectionColor", EditorGUILayout.ColorField("Reflection", WaterEditorUtility.GetMaterialColor("_ReflectionColor", oceanMaterial)), oceanMaterial); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); GUILayout.Label("Main Textures", EditorStyles.boldLabel); GUILayout.Label("Used for small waves (bumps), foam and white caps", EditorStyles.miniBoldLabel); EditorGUILayout.BeginHorizontal(); 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); } EditorGUILayout.EndHorizontal(); 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); EditorGUILayout.BeginHorizontal(); firstTiling.x = EditorGUILayout.FloatField("1st Tiling U", firstTiling.x); firstTiling.y = EditorGUILayout.FloatField("1st Tiling V", firstTiling.y); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); secondTiling.x = EditorGUILayout.FloatField("2nd Tiling U", secondTiling.x); secondTiling.y = EditorGUILayout.FloatField("2nd Tiling V", secondTiling.y); EditorGUILayout.EndHorizontal(); firstDirection = new Vector2(animationDirection.x, animationDirection.y); secondDirection = new Vector2(animationDirection.z, animationDirection.w); EditorGUILayout.BeginHorizontal(); firstDirection.x = EditorGUILayout.FloatField("1st Animation U", firstDirection.x); firstDirection.y = EditorGUILayout.FloatField("1st Animation V", firstDirection.y); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); secondDirection.x = EditorGUILayout.FloatField("2nd Animation U", secondDirection.x); secondDirection.y = EditorGUILayout.FloatField("2nd Animation V", secondDirection.y); EditorGUILayout.EndHorizontal(); 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.0f, 0.3f); if (hasShore) { fade.y = EditorGUILayout.Slider("Shore fade", fade.y, 0.0f, 0.3f); } 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(); }
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 to 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); float amplitudeA = amplitude.x; float amplitudeB = amplitude.y; float amplitudeC = amplitude.z; float amplitudeD = amplitude.w; float frequencyA = frequency.x; float frequencyB = frequency.y; float frequencyC = frequency.z; float frequencyD = frequency.w; float steepnessA = steepness.x; float steepnessB = steepness.y; float steepnessC = steepness.z; float steepnessD = steepness.w; float speedA = speed.x; float speedB = speed.y; float speedC = speed.z; float speedD = speed.w; float xDirectionA = directionAB.x; float yDirectionA = directionAB.y; float xDirectionB = directionAB.z; float yDirectionB = directionAB.w; float xDirectionC = directionCD.x; float yDirectionC = directionCD.y; float xDirectionD = directionCD.z; float yDirectionD = directionCD.w; GUILayout.Label("Wave A", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); amplitudeA = EditorGUILayout.FloatField("Amplitude", amplitudeA); frequencyA = EditorGUILayout.FloatField("Frequency", frequencyA); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); steepnessA = EditorGUILayout.FloatField("Steepness", steepnessA); speedA = EditorGUILayout.FloatField("Speed", speedA); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); xDirectionA = EditorGUILayout.FloatField("Direction (X)", xDirectionA); yDirectionA = EditorGUILayout.FloatField("Direction (Y)", yDirectionA); EditorGUILayout.EndHorizontal(); GUILayout.Label("Wave B", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); amplitudeB = EditorGUILayout.FloatField("Amplitude", amplitudeB); frequencyB = EditorGUILayout.FloatField("Frequency", frequencyB); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); steepnessB = EditorGUILayout.FloatField("Steepness", steepnessB); speedB = EditorGUILayout.FloatField("Speed", speedB); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); xDirectionB = EditorGUILayout.FloatField("Direction (X)", xDirectionB); yDirectionB = EditorGUILayout.FloatField("Direction (Y)", yDirectionB); EditorGUILayout.EndHorizontal(); GUILayout.Label("Wave C", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); amplitudeC = EditorGUILayout.FloatField("Amplitude", amplitudeC); frequencyC = EditorGUILayout.FloatField("Frequency", frequencyC); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); steepnessC = EditorGUILayout.FloatField("Steepness", steepnessC); speedC = EditorGUILayout.FloatField("Speed", speedC); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); xDirectionC = EditorGUILayout.FloatField("Direction (X)", xDirectionC); yDirectionC = EditorGUILayout.FloatField("Direction (Y)", yDirectionC); EditorGUILayout.EndHorizontal(); GUILayout.Label("Wave D", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); amplitudeD = EditorGUILayout.FloatField("Amplitude", amplitudeD); frequencyD = EditorGUILayout.FloatField("Frequency", frequencyD); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); steepnessD = EditorGUILayout.FloatField("Steepness", steepnessD); speedD = EditorGUILayout.FloatField("Speed", speedD); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); xDirectionD = EditorGUILayout.FloatField("Direction (X)", xDirectionD); yDirectionD = EditorGUILayout.FloatField("Direction (Y)", yDirectionD); EditorGUILayout.EndHorizontal(); amplitude = new Vector4(amplitudeA, amplitudeB, amplitudeC, amplitudeD); frequency = new Vector4(frequencyA, frequencyB, frequencyC, frequencyD); steepness = new Vector4(steepnessA, steepnessB, steepnessC, steepnessD); speed = new Vector4(speedA, speedB, speedC, speedD); float dirALen = 1.0f; float dirBLen = 1.0f; float dirCLen = 1.0f; float dirDLen = 1.0f; directionAB = new Vector4(xDirectionA / dirALen, yDirectionA / dirALen, xDirectionB / dirBLen, yDirectionB / dirBLen); directionCD = new Vector4(xDirectionC / dirCLen, yDirectionC / dirCLen, xDirectionD / dirDLen, yDirectionD / dirDLen); 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(); }