示例#1
0
        void SetDepthDirty(WaterDepthRenderable wdr)
        {
            waterDepthRenderables.Add(wdr);

            if (builder == null || builder.waveCams.Length < 1)
            {
                depthSet = false;
                return;
            }

            foreach (WaveCam wc in builder.waveCams)
            {
                wc.SetDepthRendererDirty();
            }
            depthSet = true;
        }
示例#2
0
        void Update()
        {
            //COMBINE SHAPES
            renderData.posSnappedLast = renderData.posSnapped;
            if (lodIndex == 0)
            {
                if (cbCombineShapes == null)
                {
                    cbCombineShapes = new CommandBuffer();
                    cam.AddCommandBuffer(CameraEvent.AfterEverything, cbCombineShapes);
                    cbCombineShapes.name = "Combine Shapes";

                    Camera[] cams = waterRenderer.builder.shapeCams;
                    for (int combineCam = cams.Length - 2; combineCam >= 0; combineCam--)
                    {
                        Material matCombine = waterRenderer.builder.waveCams[combineCam].matCombineShapes;
                        cbCombineShapes.Blit(cams[combineCam + 1].targetTexture, cams[combineCam].targetTexture, matCombine);
                    }
                }
            }

            if (depthRenderersDirty)
            {
                //Scales wave height based on proximity to underlying geometry.
                WaterDepthRenderable[] wdrs = new WaterDepthRenderable[waterRenderer.waterDepthRenderables.Count];
                int incrementor             = 0;
                foreach (WaterDepthRenderable wdr in waterRenderer.waterDepthRenderables)
                {
                    wdrs[incrementor] = wdr;
                    incrementor++;
                }

                // if there is nothing in the scene tagged up for depth rendering then there is no depth rendering required
                if (wdrs.Length < 1)
                {
                    if (cbWaterDepth != null)
                    {
                        cbWaterDepth.Clear();
                    }
                    return;
                }

                if (!rtWaterDepth)
                {
                    rtWaterDepth            = new RenderTexture(cam.targetTexture.width, cam.targetTexture.height, 0);
                    rtWaterDepth.name       = gameObject.name + "_waterDepth";
                    rtWaterDepth.format     = RenderTextureFormat.RHalf;
                    rtWaterDepth.useMipMap  = false;
                    rtWaterDepth.anisoLevel = 0;
                }

                if (cbWaterDepth == null)
                {
                    cbWaterDepth = new CommandBuffer();
                    cam.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, cbWaterDepth);
                    cbWaterDepth.name = "Water Depth";
                }

                cbWaterDepth.Clear();
                cbWaterDepth.SetRenderTarget(rtWaterDepth);
                cbWaterDepth.ClearRenderTarget(false, true, Color.red * 10000f);

                foreach (WaterDepthRenderable wdr in wdrs)
                {
                    if (!wdr.enabled)
                    {
                        continue;
                    }
                    var r = wdr.GetComponent <Renderer>();
                    if (r == null)
                    {
                        Debug.LogError("GameObject " + wdr.gameObject.name +
                                       " must have a renderer component attached. " +
                                       "Unity Terrain objects are not supported", wdr);
                    }

                    cbWaterDepth.DrawRenderer(r, matWaterDepth);
                }
                depthRenderersDirty = false;
            }
        }