private void LookForWaterCamera() { askedForWaterCamera = true; foreach (var camera in Camera.allCameras) { if (WaterCamera.GetWaterCamera(camera) != null) { return; } } if (Camera.main == null) { return; } switch (EditorUtility.DisplayDialogComplex("PlayWay Water - Missing water camera", "Your scene doesn't contain any cameras with WaterCamera component, but only such cameras may actually see the water. Would you like to add this component to camera named \"" + Camera.main.name + "\"? ", "Ok", "Cancel", "Don't ask again")) { case 0: { Camera.main.gameObject.AddComponent <WaterCamera>(); break; } case 2: { WaterProjectSettings.Instance.AskForWaterCameras = false; break; } } }
void Awake() { localCamera = GetComponent <Camera>(); localWaterCamera = GetComponent <WaterCamera>(); maskRT = Shader.PropertyToID("_UnderwaterMask"); maskRT2 = Shader.PropertyToID("_UnderwaterMask2"); OnValidate(); maskMaterial = new Material(underwaterMaskShader); maskMaterial.hideFlags = HideFlags.DontSave; imeMaterial = new Material(imeShader); imeMaterial.hideFlags = HideFlags.DontSave; noiseMaterial = new Material(noiseShader); noiseMaterial.hideFlags = HideFlags.DontSave; composeUnderwaterMaskMaterial = new Material(composeUnderwaterMaskShader); composeUnderwaterMaskMaterial.hideFlags = HideFlags.DontSave; reverbFilter = GetComponent <AudioReverbFilter>(); if (reverbFilter == null && underwaterAudio) { reverbFilter = gameObject.AddComponent <AudioReverbFilter>(); } }
private void UpdateParticles() { Vector2 windSpeed = windWaves.WindSpeed * 0.0008f; Vector3 gravity = Physics.gravity; float deltaTime = Time.deltaTime; if (overlays != null) { var overlaysData = overlays.GetCameraOverlaysData(Camera.main); sprayControllerShader.SetTexture(0, "LocalSlopeMap", overlaysData.SlopeMap); var mainWaterCamera = WaterCamera.GetWaterCamera(Camera.main); if (mainWaterCamera != null) { sprayControllerShader.SetVector("localMapsCoords", mainWaterCamera.LocalMapsShaderCoords); } } else { sprayControllerShader.SetTexture(0, "LocalSlopeMap", GetBlankWhiteTex()); } sprayControllerShader.SetFloat("deltaTime", deltaTime); sprayControllerShader.SetVector("externalForces", new Vector3((windSpeed.x + gravity.x) * deltaTime, gravity.y * deltaTime, (windSpeed.y + gravity.z) * deltaTime)); sprayControllerShader.SetVector("surfaceOffset", water.WaterMaterial.GetVector("_SurfaceOffset")); sprayControllerShader.SetVector("waterTileSize", water.WaterMaterial.GetVector("_WaterTileSize")); sprayControllerShader.SetTexture(0, "DisplacedHeightMap", windWaves.WaterWavesFFT.DisplacedHeightMap); sprayControllerShader.SetBuffer(0, "SourceParticles", particlesB); sprayControllerShader.SetBuffer(0, "TargetParticles", particlesA); sprayControllerShader.Dispatch(0, maxParticles / 128, 1, 1); }
void OnSomeCameraPreCull(Camera camera) { if (!resourcesReady) { return; } var waterCamera = WaterCamera.GetWaterCamera(camera); if (waterCamera != null) { sprayMaterial.SetBuffer("_Particles", particlesA); sprayMaterial.SetVector("_CameraUp", camera.transform.up); sprayMaterial.SetFloat("_SpecularFresnelBias", water.WaterMaterial.GetFloat("_SpecularFresnelBias")); sprayMaterial.SetVector("_WrapSubsurfaceScatteringPack", water.WaterMaterial.GetVector("_WrapSubsurfaceScatteringPack")); sprayMaterial.SetTexture("_SubtractiveMask", waterCamera.SubtractiveMask); sprayMaterial.SetFloat("_UniformWaterScale", water.UniformWaterScale); if (probeAnchor == null) { var probeAnchorGo = new GameObject("Spray Probe Anchor"); probeAnchorGo.hideFlags = HideFlags.HideAndDontSave; probeAnchor = probeAnchorGo.transform; } probeAnchor.position = camera.transform.position; int numMeshes = propertyBlocks.Length; for (int i = 0; i < numMeshes; ++i) { Graphics.DrawMesh(mesh, Matrix4x4.identity, sprayMaterial, 0, camera, 0, propertyBlocks[i], UnityEngine.Rendering.ShadowCastingMode.Off, false, probeAnchor); } } }
public void Render(Camera camera, WaterGeometryType geometryType) { if (water == null || water.WaterMaterial == null || !water.isActiveAndEnabled) { return; } if ((camera.cullingMask & (1 << water.gameObject.layer)) == 0) { return; } var waterCamera = WaterCamera.GetWaterCamera(camera); if ((!water.Volume.Boundless && water.Volume.HasRenderableAdditiveVolumes) && ((object)waterCamera == null || !waterCamera.RenderVolumes)) { return; } MaterialPropertyBlock propertyBlock; if ((object)waterCamera == null || !waterCamera.IsEffectCamera || waterCamera.MainCamera == null) { propertyBlock = GetMaterialPropertyBlock(camera); //RenderMasks(camera, waterCamera, propertyBlock); } else { propertyBlock = GetMaterialPropertyBlock(waterCamera.MainCamera); } if ((object)waterCamera != null && water.ReceiveShadows) { Vector2 min = new Vector2(0.0f, 0.0f); Vector2 max = new Vector2(1.0f, 1.0f); waterCamera.ReportShadowedWaterMinMaxRect(min, max); } water.OnWaterRender(camera); Matrix4x4 matrix; var meshes = water.Geometry.GetTransformedMeshes(camera, out matrix, geometryType, false, (object)waterCamera != null ? waterCamera.ForcedVertexCount : 0); for (int i = 0; i < meshes.Length; ++i) { Graphics.DrawMesh(meshes[i], matrix, water.WaterMaterial, water.gameObject.layer, camera, 0, propertyBlock, water.ShadowCastingMode, false, reflectionProbeAnchor == null ? water.transform : reflectionProbeAnchor); if ((object)waterCamera == null || (waterCamera.ContainingWater != null && !waterCamera.IsEffectCamera)) { Graphics.DrawMesh(meshes[i], matrix, water.WaterBackMaterial, water.gameObject.layer, camera, 0, propertyBlock, water.ShadowCastingMode, false, reflectionProbeAnchor == null ? water.transform : reflectionProbeAnchor); } } }
private void OnSomeCameraPreCull(Camera camera) { #if UNITY_EDITOR if (WaterCamera.IsSceneViewCamera(camera)) { if (WaterCamera.GetWaterCamera(camera, true) == null) { // changing hierarchy here ensures that added water camera to scene view camera will function properly; possibly there is some other way var g = new GameObject(); g.AddComponent <MeshFilter>(); g.AddComponent <MeshRenderer>(); Object.DestroyImmediate(g); } } #endif }
private void OnSubmersionStateChanged(WaterCamera waterCamera) { if (waterCamera.SubmersionState != SubmersionState.None) { if (maskCommandBuffer == null) { maskCommandBuffer = new CommandBuffer(); maskCommandBuffer.name = "Render Underwater Mask"; } } else { if (maskCommandBuffer != null) // remove command buffer if camera is out of water { var camera = GetComponent <Camera>(); camera.RemoveCommandBuffer(CameraEvent.AfterDepthTexture, maskCommandBuffer); camera.RemoveCommandBuffer(CameraEvent.AfterLighting, maskCommandBuffer); } } }
public WaterOverlaysData(WaterOverlays waveOverlays, WaterCamera camera, int resolution, int antialiasing) { this.waveOverlays = waveOverlays; this.camera = camera; this.initialization = true; dynamicDisplacementMap = CreateOverlayRT("Water Overlay: Displacement", RenderTextureFormat.ARGBHalf, resolution, antialiasing); slopeMapA = CreateOverlayRT("Water Overlay: Slope A", RenderTextureFormat.ARGBHalf, resolution, antialiasing); slopeMapB = CreateOverlayRT("Water Overlay: Slope B", RenderTextureFormat.ARGBHalf, resolution, antialiasing); totalDisplacementMap = CreateOverlayRT("Water Overlay: Total Displacement", RenderTextureFormat.ARGBHalf, resolution, antialiasing); if (waveOverlays.GetComponent <WaterSpray>() != null) { utilityMap = CreateOverlayRT("Water Overlay: Utility Map", RenderTextureFormat.RGHalf, resolution, antialiasing); } Graphics.SetRenderTarget(slopeMapA); GL.Clear(false, true, new Color(0.0f, 0.0f, 0.0f, 1.0f)); Graphics.SetRenderTarget(null); }
public WaterOverlaysData GetCameraOverlaysData(Camera camera) { WaterOverlaysData overlaysData; if (!buffers.TryGetValue(camera, out overlaysData)) { int resolution = Mathf.NextPowerOfTwo((camera.pixelWidth + camera.pixelHeight) >> 1); buffers[camera] = overlaysData = new WaterOverlaysData(this, WaterCamera.GetWaterCamera(camera), resolution, antialiasing); RenderInteractions(overlaysData); overlaysData.SwapSlopeMaps(); for (int i = 0; i < overlayRenderers.Length; ++i) { overlayRenderers[i].RenderOverlays(overlaysData); } overlaysData.Initialization = false; } return(overlaysData); }
void Awake() { waterCamera = GetComponent <WaterCamera>(); underwaterIME = GetComponent <UnderwaterIME>(); OnValidate(); }
public void OnWaterRender(Camera camera) { var waterCamera = camera.GetComponent <WaterCamera>(); if (waterCamera == null || waterCamera.IsEffectCamera || !enabled || !Application.isPlaying || WaterCamera.IsSceneViewCamera(camera)) { return; } var overlays = GetCameraOverlaysData(camera); overlays.lastFrameUsed = Time.frameCount; overlays.ClearOverlays(); RenderInteractions(overlays); for (int i = 0; i < overlayRenderers.Length; ++i) { overlayRenderers[i].RenderOverlays(overlays); } water.WaterMaterial.SetTexture("_LocalDisplacementMap", overlays.DynamicDisplacementMap); water.WaterMaterial.SetTexture("_LocalSlopeMap", overlays.SlopeMap); water.WaterMaterial.SetTexture("_TotalDisplacementMap", overlays.GetTotalDisplacementMap()); water.WaterBackMaterial.SetTexture("_LocalDisplacementMap", overlays.DynamicDisplacementMap); water.WaterBackMaterial.SetTexture("_LocalSlopeMap", overlays.SlopeMap); water.WaterBackMaterial.SetTexture("_TotalDisplacementMap", overlays.GetTotalDisplacementMap()); }