コード例 #1
0
 public void RenderLocalFoam(CommandBuffer commandBuffer, DynamicWaterCameraData overlays)
 {
     if (this._DetectContactArea)
     {
         Bounds bounds = this._MeshFilters[0].GetComponent <MeshRenderer>().bounds;
         for (int i = this._MeshFilters.Length - 1; i > 0; i--)
         {
             bounds.Encapsulate(this._MeshFilters[i].GetComponent <MeshRenderer>().bounds);
         }
         Vector3 center  = bounds.center;
         Vector3 extents = bounds.extents;
         extents.x += this._FoamRange;
         extents.y += this._FoamRange;
         extents.z += this._FoamRange;
         center.y  -= extents.y + 1f;
         commandBuffer.GetTemporaryRT(this._OcclusionMap2Hash, this._FoamOcclusionMapResolution, this._FoamOcclusionMapResolution, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
         commandBuffer.SetRenderTarget(this._OcclusionMap2Hash);
         commandBuffer.ClearRenderTarget(false, true, new Color(0f, 0f, 0f, 0f));
         Camera effectsCamera = overlays.Camera.EffectsCamera;
         effectsCamera.transform.position = center;
         effectsCamera.transform.rotation = Quaternion.LookRotation(Vector3.up, Vector3.forward);
         effectsCamera.orthographic       = true;
         effectsCamera.orthographicSize   = Mathf.Max(extents.x, extents.z);
         effectsCamera.nearClipPlane      = 1f;
         effectsCamera.farClipPlane       = extents.y * 2f + 10f;
         Matrix4x4 matrix4x = effectsCamera.projectionMatrix * effectsCamera.worldToCameraMatrix;
         commandBuffer.SetGlobalMatrix(this._OcclusionMapProjectionMatrixHash, matrix4x);
         commandBuffer.SetViewProjectionMatrices(Matrix4x4.identity, matrix4x);
         for (int j = this._MeshFilters.Length - 1; j >= 0; j--)
         {
             commandBuffer.DrawMesh(this._MeshFilters[j].sharedMesh, this._MeshFilters[j].transform.localToWorldMatrix, this._Material, 0, 1);
         }
         commandBuffer.GetTemporaryRT(this._OcclusionMapHash, this._FoamOcclusionMapResolution, this._FoamOcclusionMapResolution, 0, FilterMode.Bilinear, RenderTextureFormat.R8, RenderTextureReadWrite.Linear);
         commandBuffer.Blit(this._OcclusionMap2Hash, this._OcclusionMapHash, this._Material, 2);
         commandBuffer.ReleaseTemporaryRT(this._OcclusionMap2Hash);
         commandBuffer.SetRenderTarget(overlays.FoamMap);
         Camera planeProjectorCamera = overlays.Camera.PlaneProjectorCamera;
         commandBuffer.SetViewProjectionMatrices(planeProjectorCamera.worldToCameraMatrix, planeProjectorCamera.projectionMatrix);
     }
     for (int k = this._MeshFilters.Length - 1; k >= 0; k--)
     {
         commandBuffer.DrawMesh(this._MeshFilters[k].sharedMesh, this._MeshFilters[k].transform.localToWorldMatrix, this._Material, 0, (!this._DetectContactArea) ? 3 : 0, overlays.DynamicWater.Water.Renderer.PropertyBlock);
     }
     if (this._DetectContactArea)
     {
         commandBuffer.ReleaseTemporaryRT(this._OcclusionMapHash);
     }
     if (this._Waves && this._WaveEmissionFrequency != 0f)
     {
         DynamicWaterInteraction._MatrixTemp[0] = base.transform.localToWorldMatrix;
         this._ObjectToWorld.SetData(DynamicWaterInteraction._MatrixTemp);
         this._ColliderInteractionShader.SetVector("_LocalMapsCoords", overlays.Camera.LocalMapsShaderCoords);
         this._ColliderInteractionShader.SetTexture(0, "TotalDisplacementMap", overlays.GetTotalDisplacementMap());
         this._ColliderInteractionShader.SetBuffer(0, "Vertices", this._ColliderVerticesBuffer);
         this._ColliderInteractionShader.SetBuffer(0, "Particles", this._Water.ParticlesBuffer);
         this._ColliderInteractionShader.SetBuffer(0, "ObjectToWorld", this._ObjectToWorld);
         this._ColliderInteractionShader.Dispatch(0, Mathf.CeilToInt((float)(this._ColliderVerticesBuffer.count >> 1) / 256f), 1, 1);
     }
 }
コード例 #2
0
        public void RenderLocalMask(CommandBuffer commandBuffer, DynamicWaterCameraData overlays)
        {
            float   farClipPlane = overlays.Camera.CameraComponent.farClipPlane;
            Vector3 position     = overlays.Camera.transform.position;

            position.y = overlays.DynamicWater.Water.transform.position.y;
            this._InteractionMaskRenderer.transform.position   = position;
            this._InteractionMaskRenderer.transform.localScale = new Vector3(farClipPlane, farClipPlane, farClipPlane);
            this._InteractionMaskMaterial.SetVector("_OffsetScale", new Vector4(0.5f + this._WorldUnitsOffset.x / this._WorldUnitsSize.x, 0.5f + this._WorldUnitsOffset.y / this._WorldUnitsSize.y, 1f / this._WorldUnitsSize.x, 1f / this._WorldUnitsSize.y));
            commandBuffer.DrawMesh(this._InteractionMaskRenderer.GetComponent <MeshFilter>().sharedMesh, this._InteractionMaskRenderer.transform.localToWorldMatrix, this._InteractionMaskMaterial, 0, 0);
        }
コード例 #3
0
ファイル: Foam.cs プロジェクト: looki666/Green-Hell
        public void RenderOverlays(DynamicWaterCameraData overlays)
        {
            if (!Application.isPlaying || !this.CheckPreresquisites())
            {
                return;
            }
            WaterCamera camera = overlays.Camera;

            if (camera.Type != WaterCamera.CameraType.Normal)
            {
                return;
            }
            int layer = this._Water.gameObject.layer;

            Foam.CameraRenderData cameraRenderData;
            if (!Foam._LayerUpdateFrames.TryGetValue(camera, out cameraRenderData))
            {
                cameraRenderData = (Foam._LayerUpdateFrames[camera] = new Foam.CameraRenderData());
                WaterCamera waterCamera = camera;
                if (Foam.< > f__mg$cache0 == null)
                {
                    Foam.< > f__mg$cache0 = new Action <WaterCamera>(Foam.OnCameraDestroyed);
                }
                waterCamera.Destroyed += Foam.< > f__mg$cache0;
            }
            int frameCount = Time.frameCount;

            if (cameraRenderData.RenderFramePerLayer[layer] < frameCount)
            {
                cameraRenderData.RenderFramePerLayer[layer] = frameCount;
                if (this._Water.WindWaves.FinalRenderMode == WaveSpectrumRenderMode.FullFFT)
                {
                    RenderTexture[] displacementDeltaMaps = this.GetDisplacementDeltaMaps();
                    float           y = this._FoamThreshold * (float)this._Resolution / 2048f * 0.5f;
                    this._GlobalFoamSimulationMaterial.SetVector(ShaderVariables.FoamParameters, new Vector4(this._FoamIntensity * 0.6f, y, 0f, this._FoamFadingFactor));
                    for (int i = 0; i < 4; i++)
                    {
                        Texture       displacementMap = this._Water.WindWaves.WaterWavesFFT.GetDisplacementMap(i);
                        RenderTexture dest            = displacementDeltaMaps[i];
                        this._GlobalFoamSimulationMaterial.SetFloat(ShaderVariables.WaterTileSizeInvSrt, this._Water.WindWaves.TileSizesInv[i]);
                        Graphics.Blit(displacementMap, dest, this._GlobalFoamSimulationMaterial, 1);
                    }
                    Shader.SetGlobalTexture("_FoamMapPrevious", overlays.FoamMapPrevious);
                    Shader.SetGlobalVector("_WaterOffsetDelta", this._Water.SurfaceOffset - cameraRenderData.LastSurfaceOffset);
                    cameraRenderData.LastSurfaceOffset = this._Water.SurfaceOffset;
                    Camera planeProjectorCamera = camera.PlaneProjectorCamera;
                    planeProjectorCamera.cullingMask = 1 << layer;
                    planeProjectorCamera.GetComponent <WaterCamera>().RenderWaterWithShader("[PW Water] Foam", overlays.FoamMap, this._LocalFoamSimulationShader, this._Water);
                }
            }
            this._Water.Renderer.PropertyBlock.SetTexture("_FoamMap", overlays.FoamMap);
        }