Ejemplo n.º 1
0
 public extern void RemoveCommandBuffers(CameraEvent evt);
Ejemplo n.º 2
0
 public extern void AddCommandBuffer(CameraEvent evt, CommandBuffer buffer);
Ejemplo n.º 3
0
 public extern CommandBuffer[] GetCommandBuffers(CameraEvent evt);
Ejemplo n.º 4
0
 public extern void RemoveCommandBuffer(CameraEvent evt, CommandBuffer buffer);
    private void OnPreRender()
    {
        int size = (int)Mathf.Max((float)m_camera.pixelWidth, (float)m_camera.pixelHeight);

        size          = (int)Mathf.Min((float)Mathf.NextPowerOfTwo(size), (float)MAXIMUM_BUFFER_SIZE);
        textureSize.x = size;
        textureSize.y = size;
        m_LODCount    = (int)Mathf.Floor(Mathf.Log(size, 2f));

        bool isCommandBufferInvalid = false;

        if (m_LODCount == 0)
        {
            return;
        }

        if (m_HiZDepthTexture == null ||
            (m_HiZDepthTexture.width != size ||
             m_HiZDepthTexture.height != size) ||
            m_lastCameraEvent != m_CameraEvent
            )
        {
            if (m_HiZDepthTexture != null)
            {
                m_HiZDepthTexture.Release();
            }

            m_HiZDepthTexture            = new RenderTexture(size, size, 0, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear);
            m_HiZDepthTexture.filterMode = FilterMode.Point;

            m_HiZDepthTexture.useMipMap        = true;
            m_HiZDepthTexture.autoGenerateMips = false;

            m_HiZDepthTexture.Create();

            m_HiZDepthTexture.hideFlags = HideFlags.HideAndDontSave;
            m_lastCameraEvent           = m_CameraEvent;

            isCommandBufferInvalid = true;
        }

        if (m_CommandBuffer == null || isCommandBufferInvalid == true)
        {
            m_Temporaries = new int[m_LODCount];

            if (m_CommandBuffer != null)
            {
                m_camera.RemoveCommandBuffer(m_CameraEvent, m_CommandBuffer);
            }

            m_CommandBuffer      = new CommandBuffer();
            m_CommandBuffer.name = "Hi-Z Buffer";

            RenderTargetIdentifier id = new RenderTargetIdentifier(m_HiZDepthTexture);

            m_CommandBuffer.Blit(null, id, m_generateBufferMaterial, (int)Pass.Blit);

            for (int i = 0; i < m_LODCount; ++i)
            {
                m_Temporaries[i] = Shader.PropertyToID("_09659d57_Temporaries" + i.ToString());

                size >>= 1;

                if (size == 0)
                {
                    size = 1;
                }

                m_CommandBuffer.GetTemporaryRT(m_Temporaries[i], size, size, 0, FilterMode.Point, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear);

                if (i == 0)
                {
                    m_CommandBuffer.Blit(id, m_Temporaries[0], m_generateBufferMaterial, (int)Pass.Reduce);
                }
                else
                {
                    m_CommandBuffer.Blit(m_Temporaries[i - 1], m_Temporaries[i], m_generateBufferMaterial, (int)Pass.Reduce);
                }

                m_CommandBuffer.CopyTexture(m_Temporaries[i], 0, 0, id, 0, i + 1);

                if (i >= 1)
                {
                    m_CommandBuffer.ReleaseTemporaryRT(m_Temporaries[i - 1]);
                }
            }

            m_CommandBuffer.ReleaseTemporaryRT(m_Temporaries[m_LODCount - 1]);
            m_camera.AddCommandBuffer(m_CameraEvent, m_CommandBuffer);
        }
    }
Ejemplo n.º 6
0
 protected RenderingProgram(CameraEvent hook)
 {
     this.hook = hook;
 }
Ejemplo n.º 7
0
 public extern void RemoveCommandBuffers(CameraEvent evt);
        private void CreateCommandBuffer()
        {
            CommandBuffer commandBuffer;

            FinalVignetteMaterial = null;
            EnsureMaterials();

            TrySetUniforms();
            CameraEvent cameraEvent = GetCameraEvent(IntegrationStage);

            if (cameraEventsRegistered.TryGetValue(cameraEvent, out commandBuffer))
            {
                commandBuffer.Clear();
            }
            else
            {
                commandBuffer = new CommandBuffer();
                myCamera.AddCommandBuffer(cameraEvent, commandBuffer);

                commandBuffer.name = "Final Vignette";

                // Register
                cameraEventsRegistered[cameraEvent] = commandBuffer;
            }

            int cameraWidth  = this.destinationWidth;
            int cameraHeight = this.destinationHeight;

            if (cameraWidth <= 0)
            {
                cameraWidth = myCamera.pixelWidth;
            }
            if (cameraHeight <= 0)
            {
                cameraHeight = myCamera.pixelHeight;
            }

            int screenTextureWidth  = cameraWidth;
            int screenTextureHeight = cameraHeight;

            int?screenTexture = null;

            if (EnableSaturationVignette || VignetteMode == VignetteModeType.CustomColors)
            {
                RenderTextureFormat screenTextureFormat = isHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;

                screenTexture = Shader.PropertyToID("screenTextureRT");
                commandBuffer.GetTemporaryRT(screenTexture.Value, cameraWidth, cameraHeight, 0, FilterMode.Bilinear, screenTextureFormat, RenderTextureReadWrite.Linear);

                // Remember input
                commandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, screenTexture.Value);
            }

            // Perform actual effects
            DoEffect(commandBuffer, null, null, screenTexture, screenTextureWidth, screenTextureHeight);

            // Cleanup
            if (screenTexture != null)
            {
                commandBuffer.ReleaseTemporaryRT(screenTexture.Value);
            }
        }
Ejemplo n.º 9
0
 public extern void AddCommandBuffer(CameraEvent evt, CommandBuffer buffer);
Ejemplo n.º 10
0
 public extern void RemoveCommandBuffer(CameraEvent evt, CommandBuffer buffer);
Ejemplo n.º 11
0
        private void RenderUnderwaterMask()
        {
            if (this._MaskCommandBuffer == null)
            {
                return;
            }
            this._MaskCommandBuffer.Clear();
            Water  water           = (!this._HasWaterOverride) ? this._LocalWaterCamera.ContainingWater : this._WaterOverride;
            Camera current         = Camera.current;
            int    underwaterMask  = ShaderVariables.UnderwaterMask;
            int    underwaterMask2 = ShaderVariables.UnderwaterMask2;

            if (this._UnderwaterMask == null)
            {
                int width  = Mathf.RoundToInt((float)current.pixelWidth * this._MaskResolution);
                int height = Mathf.RoundToInt((float)current.pixelHeight * this._MaskResolution);
                this._UnderwaterMask = new RenderTexture(width, height, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear)
                {
                    filterMode = FilterMode.Bilinear,
                    name       = "[UWS] UnderwaterIME - Mask"
                };
                this._UnderwaterMask.Create();
            }
            if (this._RenderUnderwaterMask || (water != null && water.Renderer.MaskCount > 0))
            {
                int width2  = Mathf.RoundToInt((float)current.pixelWidth * this._MaskResolution);
                int height2 = Mathf.RoundToInt((float)current.pixelHeight * this._MaskResolution);
                this._MaskCommandBuffer.GetTemporaryRT(underwaterMask, width2, height2, 0, FilterMode.Bilinear, RenderTextureFormat.R8, RenderTextureReadWrite.Linear, 1);
                this._MaskCommandBuffer.GetTemporaryRT(underwaterMask2, width2, height2, 0, FilterMode.Point, RenderTextureFormat.R8, RenderTextureReadWrite.Linear, 1);
            }
            else
            {
                this._MaskCommandBuffer.GetTemporaryRT(underwaterMask, 4, 4, 0, FilterMode.Point, RenderTextureFormat.R8, RenderTextureReadWrite.Linear, 1);
            }
            if (this._RenderUnderwaterMask && water != null)
            {
                this._MaskMaterial.CopyPropertiesFromMaterial(water.Materials.SurfaceMaterial);
                this._MaskCommandBuffer.SetRenderTarget(underwaterMask2);
                this._MaskCommandBuffer.ClearRenderTarget(false, true, Color.black);
                WaterGeometry geometry = water.Geometry;
                Matrix4x4     matrix;
                Mesh[]        transformedMeshes = geometry.GetTransformedMeshes(this._LocalCamera, out matrix, (geometry.GeometryType != WaterGeometry.Type.ProjectionGrid) ? WaterGeometryType.Auto : WaterGeometryType.RadialGrid, true, geometry.ComputeVertexCountForCamera(current));
                for (int i = transformedMeshes.Length - 1; i >= 0; i--)
                {
                    this._MaskCommandBuffer.DrawMesh(transformedMeshes[i], matrix, this._MaskMaterial, 0, 0, water.Renderer.PropertyBlock);
                }
                this._MaskCommandBuffer.SetRenderTarget(underwaterMask);
                this._MaskCommandBuffer.DrawMesh(Quads.BipolarXInversedY, Matrix4x4.identity, this._ImeMaterial, 0, 3, water.Renderer.PropertyBlock);
                this._MaskCommandBuffer.ReleaseTemporaryRT(underwaterMask2);
            }
            else
            {
                this._MaskCommandBuffer.SetRenderTarget(underwaterMask);
                this._MaskCommandBuffer.ClearRenderTarget(false, true, Color.white);
            }
            this._MaskCommandBuffer.Blit(underwaterMask, this._UnderwaterMask);
            Shader.SetGlobalTexture(underwaterMask, this._UnderwaterMask);
            if (water != null && water.Renderer.MaskCount != 0 && this._LocalWaterCamera.RenderVolumes)
            {
                this._MaskCommandBuffer.Blit("_SubtractiveMask", underwaterMask, this._ComposeUnderwaterMaskMaterial, 0);
            }
            CameraEvent evt = (this._LocalCamera.actualRenderingPath != RenderingPath.Forward) ? CameraEvent.BeforeLighting : ((!WaterProjectSettings.Instance.SinglePassStereoRendering) ? CameraEvent.AfterDepthTexture : CameraEvent.BeforeForwardOpaque);

            this._LocalCamera.RemoveCommandBuffer(evt, this._MaskCommandBuffer);
            this._LocalCamera.AddCommandBuffer(evt, this._MaskCommandBuffer);
        }
Ejemplo n.º 12
0
 private void createCommandBuffer(ref AmplifyOcclusionBase.CmdBuffer aCmdBuffer, string aCmdBufferName, CameraEvent aCameraEvent)
 {
     if (aCmdBuffer.cmdBuffer != null)
     {
         this.cleanupCommandBuffer(ref aCmdBuffer);
     }
     aCmdBuffer.cmdBufferName  = aCmdBufferName;
     aCmdBuffer.cmdBuffer      = new CommandBuffer();
     aCmdBuffer.cmdBuffer.name = aCmdBufferName;
     aCmdBuffer.cmdBufferEvent = aCameraEvent;
     this.m_targetCamera.AddCommandBuffer(aCameraEvent, aCmdBuffer.cmdBuffer);
 }
Ejemplo n.º 13
0
 public RenderPath(Camera camera, CameraEvent cameraEvent, int renderId)
 {
     this.camera      = camera;
     this.renderId    = renderId;
     this.cameraEvent = cameraEvent;
 }
    private static bool HasCommandBuffer(Camera setCamera, CameraEvent evt, string name) {
        foreach (var buf in setCamera.GetCommandBuffers(evt)) {
            if (buf.name == name) {
                return true;
            }
        }

        return false;
    }
Ejemplo n.º 15
0
 public extern CommandBuffer[] GetCommandBuffers(CameraEvent evt);
Ejemplo n.º 16
0
 void OnEnable()
 {
     OnDisable();
     var camera = GetComponent<Camera>();
     commandBuffer = new CommandBuffer();
     commandBuffer.name = "SkyMesh";
     commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
     var matrix = Matrix4x4.TRS(m_position, Quaternion.Euler(m_rotation), m_scale);
     commandBuffer.DrawMesh(m_mesh, matrix, m_material);
     camera.AddCommandBuffer(m_cameraEvent, commandBuffer);
     lastCameraEvent = m_cameraEvent;
 }
Ejemplo n.º 17
0
 public CustomRendererInfo(CommandBuffer cb, CameraEvent pass)
 {
     this.cb   = cb;
     this.pass = pass;
 }