Ejemplo n.º 1
0
 public void SetUp(RenderTargetHandle colorHandle, RenderTexture texture,
                   ref LookingGlassRenderingInfo dinfo, ref LookingGlassDeviceConfig dconfig)
 {
     this.colorAttachmentHandle = colorHandle;
     tiledTexture = texture;
     drawInfo     = dinfo;
     deviceConfig = dconfig;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Setup the pass
 /// </summary>
 /// <param name="baseDescriptor"></param>
 /// <param name="colorAttachmentHandle">Source of rendering to execute the post on</param>
 /// <param name="destination">Destination target for the final blit</param>
 public void Setup(
     RenderTextureDescriptor baseDescriptor,
     RenderTargetHandle colorAttachmentHandle,
     RenderTargetIdentifier destination)
 {
     this.colorAttachmentHandle = colorAttachmentHandle;
     this.destination           = destination;
     descriptor = baseDescriptor;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Configure the pass
 /// </summary>
 public void Setup(
     RenderTextureDescriptor baseDescriptor,
     RenderTargetHandle colorAttachmentHandle,
     RenderTargetHandle depthAttachmentHandle,
     SampleCount samples)
 {
     this.colorAttachmentHandle = colorAttachmentHandle;
     this.depthAttachmentHandle = depthAttachmentHandle;
     this.samples = samples;
     descriptor   = baseDescriptor;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Configure the pass before execution
 /// </summary>
 /// <param name="baseDescriptor">Current target descriptor</param>
 /// <param name="colorAttachmentHandle">Color attachment to render into</param>
 /// <param name="depthAttachmentHandle">Depth attachment to render into</param>
 /// <param name="configuration">Specific render configuration</param>
 public void Setup(
     RenderTextureDescriptor baseDescriptor,
     RenderTargetHandle colorAttachmentHandle,
     RenderTargetHandle depthAttachmentHandle,
     RendererConfiguration configuration)
 {
     this.colorAttachmentHandle = colorAttachmentHandle;
     this.depthAttachmentHandle = depthAttachmentHandle;
     descriptor            = baseDescriptor;
     rendererConfiguration = configuration;
 }
Ejemplo n.º 5
0
 /// <inheritdoc/>
 public override void FrameCleanup(CommandBuffer cmd)
 {
     if (cmd == null)
         throw new ArgumentNullException("cmd");
     
     if (destination != RenderTargetHandle.CameraTarget)
     {
         cmd.ReleaseTemporaryRT(destination.id);
         destination = RenderTargetHandle.CameraTarget;
     }
 }
Ejemplo n.º 6
0
        public bool Setup(RenderTargetHandle destination, ref RenderingData renderingData)
        {
            Clear();
            this.destination = destination;

            int shadowLightIndex = renderingData.lightData.mainLightIndex;

            if (shadowLightIndex == -1)
            {
                return(false);
            }

            VisibleLight shadowLight = renderingData.lightData.visibleLights[shadowLightIndex];
            Light        light       = shadowLight.light;

            if (light.shadows == LightShadows.None)
            {
                return(false);
            }

            if (shadowLight.lightType != LightType.Directional)
            {
                Debug.LogWarning("Only directional lights are supported as main light.");
            }

            Bounds bounds;

            if (!renderingData.cullResults.GetShadowCasterBounds(shadowLightIndex, out bounds))
            {
                return(false);
            }

            m_ShadowCasterCascadesCount = renderingData.shadowData.mainLightShadowCascadesCount;

            int shadowResolution = ShadowUtils.GetMaxTileResolutionInAtlas(renderingData.shadowData.mainLightShadowmapWidth,
                                                                           renderingData.shadowData.mainLightShadowmapHeight, m_ShadowCasterCascadesCount);

            for (int cascadeIndex = 0; cascadeIndex < m_ShadowCasterCascadesCount; ++cascadeIndex)
            {
                bool success = ShadowUtils.ExtractDirectionalLightMatrix(ref renderingData.cullResults, ref renderingData.shadowData,
                                                                         shadowLightIndex, cascadeIndex, shadowResolution, light.shadowNearPlane,
                                                                         out m_CascadeSplitDistances[cascadeIndex], out m_CascadeSlices[cascadeIndex], out m_CascadeSlices[cascadeIndex].viewMatrix, out m_CascadeSlices[cascadeIndex].projectionMatrix);

                if (!success)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Configure the pass before execution
 /// </summary>
 /// <param name="baseDescriptor">Current target descriptor</param>
 /// <param name="colorAttachmentHandle">Color attachment to render into</param>
 /// <param name="depthAttachmentHandle">Depth attachment to render into</param>
 /// <param name="clearFlag">Camera clear flag</param>
 /// <param name="clearColor">Camera clear color</param>
 /// <param name="configuration">Specific render configuration</param>
 public void Setup(
     RenderTextureDescriptor baseDescriptor,
     RenderTargetHandle colorAttachmentHandle,
     RenderTargetHandle depthAttachmentHandle,
     ClearFlag clearFlag,
     Color clearColor,
     RendererConfiguration configuration)
 {
     this.colorAttachmentHandle = colorAttachmentHandle;
     this.depthAttachmentHandle = depthAttachmentHandle;
     this.clearColor            = CoreUtils.ConvertSRGBToActiveColorSpace(clearColor);
     this.clearFlag             = clearFlag;
     descriptor = baseDescriptor;
     this.rendererConfiguration = configuration;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Configure the pass
        /// </summary>
        public void Setup(
            RenderTextureDescriptor baseDescriptor,
            RenderTargetHandle depthAttachmentHandle,
            SampleCount samples)
        {
            this.depthAttachmentHandle     = depthAttachmentHandle;
            baseDescriptor.colorFormat     = RenderTextureFormat.Depth;
            baseDescriptor.depthBufferBits = kDepthBufferBits;

            if ((int)samples > 1)
            {
                baseDescriptor.bindMS      = false;
                baseDescriptor.msaaSamples = (int)samples;
            }

            descriptor = baseDescriptor;
        }
Ejemplo n.º 9
0
        public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData)
        {
            Init();

            Camera camera = renderingData.cameraData.camera;

            renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData);
            RenderTextureDescriptor baseDescriptor   = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
            RenderTextureDescriptor shadowDescriptor = baseDescriptor;
            ClearFlag clearFlag = ScriptableRenderer.GetCameraClearFlag(renderingData.cameraData.camera);

            shadowDescriptor.dimension = TextureDimension.Tex2D;

            bool requiresRenderToTexture = ScriptableRenderer.RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor);

            RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget;
            RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget;

            if (requiresRenderToTexture)
            {
                colorHandle = ColorAttachment;
                depthHandle = DepthAttachment;

                var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples;
                m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount);
                renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass);
            }


            bool mainLightShadows = false;

            if (renderingData.shadowData.supportsMainLightShadows)
            {
                mainLightShadows = m_MainLightShadowCasterPass.Setup(MainLightShadowmap, ref renderingData);
                if (mainLightShadows)
                {
                    renderer.EnqueuePass(m_MainLightShadowCasterPass);
                }
            }



            renderer.EnqueuePass(m_SetupForwardRenderingPass);


            RendererConfiguration rendererConfiguration = ScriptableRenderer.GetRendererConfiguration(renderingData.lightData.additionalLightsCount);

            m_SetupLightweightConstants.Setup(renderer.maxVisibleAdditionalLights, renderer.perObjectLightIndices);
            renderer.EnqueuePass(m_SetupLightweightConstants);
            // GameView at LGRP
            if (!renderingData.cameraData.isSceneViewCamera)
            {
                LookingGlassRenderingInfo       info = renderingData.cameraData.lookingGlassInfo;
                LookingGlassDeviceConfig        config;
                LookingGlassRenderInfoPerCamera perCameraInfo;

                var cameraDeviceInfo = camera.GetComponent <LookingGlassCameraInfo>();
                if (cameraDeviceInfo != null)
                {
                    config        = cameraDeviceInfo.config;
                    perCameraInfo = cameraDeviceInfo.renderInfo;
                }
                else
                {
                    config = new LookingGlassDeviceConfig();
                    config.SetUpDefault();
                    perCameraInfo = new LookingGlassRenderInfoPerCamera();
                    perCameraInfo.SetupDefault();
                }

                int depthValue = (info.renderMethod == LookingGlassRenderingInfo.RenderingMethod.RenderMultiPass) ? 0 : 32;
                if (tileTexture != null && oldLookingRenderInfo.HaveToRemakeRenderTexture(ref info))
                {
                    tileTexture.Release();
                    tileTexture = null;
                    Debug.Log("Recreate RenderTexture");
                }

                if (tileTexture == null || !tileTexture)
                {
                    tileTexture      = new RenderTexture(info.renderTargetW, info.renderTargetH, depthValue);
                    tileTexture.name = "LookingGlassQuiltTexture";
                }

                // tile texture draw( changed by method)
                switch (info.renderMethod)
                {
                case LookingGlassRenderingInfo.RenderingMethod.RenderMultiPass:
                    m_LookingMultiTexturePass.Setup(tileTexture, ref info, ref perCameraInfo);
                    renderer.EnqueuePass(m_LookingMultiTexturePass);
                    break;

                case LookingGlassRenderingInfo.RenderingMethod.RenderSinglePassInstancing:
                    m_LookingInstancingRenderPass.Setup(tileTexture, ref info, ref perCameraInfo);
                    renderer.EnqueuePass(m_LookingInstancingRenderPass);
                    break;
                }

                m_LookingFinalPass.SetUp(colorHandle, tileTexture, ref info, ref config);
                renderer.EnqueuePass(m_LookingFinalPass);
                // info setup
                oldLookingRenderInfo = info;
            }
            // SceneView
            else
            {
                m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, clearFlag, camera.backgroundColor, rendererConfiguration);
                renderer.EnqueuePass(m_RenderOpaqueForwardPass);
                if (camera.clearFlags == CameraClearFlags.Skybox && RenderSettings.skybox != null)
                {
                    m_DrawSkyboxPass.Setup(colorHandle, depthHandle);
                    renderer.EnqueuePass(m_DrawSkyboxPass);
                }
                m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration);
                renderer.EnqueuePass(m_RenderTransparentForwardPass);
                if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget)
                {
                    m_FinalBlitPass.Setup(baseDescriptor, colorHandle);
                    renderer.EnqueuePass(m_FinalBlitPass);
                }
            }

#if UNITY_EDITOR
            if (renderingData.cameraData.isSceneViewCamera)
            {
                m_SceneViewDepthCopyPass.Setup(DepthTexture);
                renderer.EnqueuePass(m_SceneViewDepthCopyPass);
            }
#endif
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Configure the pass with the source and destination to execute on.
 /// </summary>
 /// <param name="source">Source Render Target</param>
 /// <param name="destination">Destination Render Targt</param>
 public void Setup(RenderTargetHandle source, RenderTargetHandle destination)
 {
     this.source      = source;
     this.destination = destination;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Configure the pass
 /// </summary>
 /// <param name="baseDescriptor"></param>
 /// <param name="colorAttachmentHandle"></param>
 public void Setup(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorAttachmentHandle)
 {
     this.colorAttachmentHandle = colorAttachmentHandle;
     this.descriptor            = baseDescriptor;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Configure the color and depth passes to use when rendering the skybox
 /// </summary>
 /// <param name="colorHandle">Color buffer to use</param>
 /// <param name="depthHandle">Depth buffer to use</param>
 public void Setup(RenderTargetHandle colorHandle, RenderTargetHandle depthHandle)
 {
     this.colorAttachmentHandle = colorHandle;
     this.depthAttachmentHandle = depthHandle;
 }
Ejemplo n.º 13
0
        public bool Setup(RenderTargetHandle destination, ref RenderingData renderingData, int maxVisibleAdditinalLights)
        {
            Clear();
            this.destination = destination;

            if (m_AdditionalLightShadowMatrices.Length != maxVisibleAdditinalLights)
            {
                m_AdditionalLightShadowMatrices  = new Matrix4x4[maxVisibleAdditinalLights];
                m_AdditionalLightSlices          = new ShadowSliceData[maxVisibleAdditinalLights];
                m_AdditionalLightsShadowStrength = new float[maxVisibleAdditinalLights];
            }
            m_AdditionalShadowCastingLightIndices.Clear();

            Bounds bounds;
            List <VisibleLight> visibleLights = renderingData.lightData.visibleLights;
            int additionalLightsCount         = renderingData.lightData.additionalLightsCount;

            for (int i = 0; i < visibleLights.Count && m_AdditionalShadowCastingLightIndices.Count < additionalLightsCount; ++i)
            {
                if (i == renderingData.lightData.mainLightIndex)
                {
                    continue;
                }

                VisibleLight shadowLight = visibleLights[i];
                Light        light       = shadowLight.light;

                if (shadowLight.lightType == LightType.Spot && light != null && light.shadows != LightShadows.None)
                {
                    if (renderingData.cullResults.GetShadowCasterBounds(i, out bounds))
                    {
                        m_AdditionalShadowCastingLightIndices.Add(i);
                    }
                }
            }

            int shadowCastingLightsCount = m_AdditionalShadowCastingLightIndices.Count;

            if (shadowCastingLightsCount == 0)
            {
                return(false);
            }

            // TODO: Add support to point light shadows. We make a simplification here that only works
            // for spot lights and with max spot shadows per pass.
            int atlasWidth      = renderingData.shadowData.additionalLightsShadowmapWidth;
            int atlasHeight     = renderingData.shadowData.additionalLightsShadowmapHeight;
            int sliceResolution = ShadowUtils.GetMaxTileResolutionInAtlas(atlasWidth, atlasHeight, shadowCastingLightsCount);

            bool anyShadows         = false;
            int  shadowSlicesPerRow = (atlasWidth / sliceResolution);

            for (int i = 0; i < shadowCastingLightsCount; ++i)
            {
                int          shadowLightIndex = m_AdditionalShadowCastingLightIndices[i];
                VisibleLight shadowLight      = visibleLights[shadowLightIndex];

                // Currently Only Spot Lights are supported in additional lights
                Debug.Assert(shadowLight.lightType == LightType.Spot);
                Matrix4x4 shadowTransform;
                bool      success = ShadowUtils.ExtractSpotLightMatrix(ref renderingData.cullResults, ref renderingData.shadowData,
                                                                       shadowLightIndex, out shadowTransform, out m_AdditionalLightSlices[i].viewMatrix, out m_AdditionalLightSlices[i].projectionMatrix);

                if (success)
                {
                    // TODO: We need to pass bias and scale list to shader to be able to support multiple
                    // shadow casting additional lights.
                    m_AdditionalLightSlices[i].offsetX         = (i % shadowSlicesPerRow) * sliceResolution;
                    m_AdditionalLightSlices[i].offsetY         = (i / shadowSlicesPerRow) * sliceResolution;
                    m_AdditionalLightSlices[i].resolution      = sliceResolution;
                    m_AdditionalLightSlices[i].shadowTransform = shadowTransform;

                    m_AdditionalLightsShadowStrength[i] = shadowLight.light.shadowStrength;
                    anyShadows = true;
                }
                else
                {
                    m_AdditionalShadowCastingLightIndices.RemoveAt(i--);
                }
            }

            return(anyShadows);
        }
Ejemplo n.º 14
0
 public void Setup(RenderTargetHandle source)
 {
     this.source = source;
 }
Ejemplo n.º 15
0
 public bool Equals(RenderTargetHandle other)
 {
     return(id == other.id);
 }