public LightweightRenderPipeline(LightweightRenderPipelineAsset asset)
        {
            SetSupportedRenderingFeatures();

            PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
            PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");

            PerFrameBuffer._Time           = Shader.PropertyToID("_Time");
            PerFrameBuffer._SinTime        = Shader.PropertyToID("_SinTime");
            PerFrameBuffer._CosTime        = Shader.PropertyToID("_CosTime");
            PerFrameBuffer.unity_DeltaTime = Shader.PropertyToID("unity_DeltaTime");
            PerFrameBuffer._TimeParameters = Shader.PropertyToID("_TimeParameters");

            PerCameraBuffer._InvCameraViewProj   = Shader.PropertyToID("_InvCameraViewProj");
            PerCameraBuffer._ScreenParams        = Shader.PropertyToID("_ScreenParams");
            PerCameraBuffer._ScaledScreenParams  = Shader.PropertyToID("_ScaledScreenParams");
            PerCameraBuffer._WorldSpaceCameraPos = Shader.PropertyToID("_WorldSpaceCameraPos");

            // Let engine know we have MSAA on for cases where we support MSAA backbuffer
            if (QualitySettings.antiAliasing != asset.msaaSampleCount)
            {
                QualitySettings.antiAliasing = asset.msaaSampleCount;
            }

            Shader.globalRenderPipeline = "LightweightPipeline";

            Lightmapping.SetDelegate(lightsDelegate);

            CameraCaptureBridge.enabled = true;

            RenderingUtils.ClearSystemInfoCache();
        }
Beispiel #2
0
        public LightweightRenderPipeline(LightweightRenderPipelineAsset asset)
        {
            settings = PipelineSettings.Create(asset);
            renderer = new ScriptableRenderer(asset);

            SetSupportedRenderingFeatures();

            GraphicsSettings.useScriptableRenderPipelineBatching = asset.useSRPBatcher;

            PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
            PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");

            PerCameraBuffer._InvCameraViewProj  = Shader.PropertyToID("_InvCameraViewProj");
            PerCameraBuffer._ScaledScreenParams = Shader.PropertyToID("_ScaledScreenParams");

            // Let engine know we have MSAA on for cases where we support MSAA backbuffer
            if (QualitySettings.antiAliasing != settings.msaaSampleCount)
            {
                QualitySettings.antiAliasing = settings.msaaSampleCount;
            }

            Shader.globalRenderPipeline = "LightweightPipeline";

            Lightmapping.SetDelegate(lightsDelegate);

            CameraCaptureBridge.enabled = true;
        }
Beispiel #3
0
        private Camera CreateMirrorObjects(Camera currentCamera)
        {
            LightweightRenderPipelineAsset lwAsset = (LightweightRenderPipelineAsset)GraphicsSettings.renderPipelineAsset;
            var resMulti = lwAsset.renderScale * GetScaleValue();

            m_TextureSize.x = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelWidth * resMulti, 2)));
            m_TextureSize.y = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelHeight * resMulti, 2)));
            // Reflection render texture
            if (Int2Compare(m_TextureSize, m_OldReflectionTextureSize) || !m_ReflectionTexture)
            {
                if (m_ReflectionTexture)
                {
                    DestroyImmediate(m_ReflectionTexture);
                }

                bool useHDR10 = Application.isMobilePlatform &&
                                SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGB111110Float);
                RenderTextureFormat hdrFormat = (useHDR10) ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR;

                m_ReflectionTexture = new RenderTexture(m_TextureSize.x, m_TextureSize.y, 0,
                                                        currentCamera.allowHDR ? hdrFormat : RenderTextureFormat.Default);
                m_ReflectionTexture.useMipMap        = m_ReflectionTexture.autoGenerateMips = false;
                m_ReflectionTexture.autoGenerateMips = false; // no need for mips(unless wanting cheap roughness)
                m_ReflectionTexture.name             = "_PlanarReflection" + GetInstanceID();
                m_ReflectionTexture.isPowerOfTwo     = true;
                m_ReflectionTexture.hideFlags        = HideFlags.DontSave;
                m_ReflectionTexture.depth            = 32;
                m_OldReflectionTextureSize           = m_TextureSize;
            }

            m_ReflectionTexture.DiscardContents();

            GameObject go =
                new GameObject("Planar Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(),
                               typeof(Camera), typeof(Skybox));
            LWRPAdditionalCameraData lwrpCamData =
                go.AddComponent(typeof(LWRPAdditionalCameraData)) as LWRPAdditionalCameraData;

            lwrpCamData.renderShadows       = false; // turn off shadows for the reflection camera
            lwrpCamData.requiresColorOption = CameraOverrideOption.Off;
            lwrpCamData.requiresDepthOption = CameraOverrideOption.Off;
            var reflectionCamera = go.GetComponent <Camera>();

            reflectionCamera.transform.SetPositionAndRotation(transform.position, transform.rotation);
            reflectionCamera.targetTexture = m_ReflectionTexture;
            reflectionCamera.allowMSAA     = currentCamera.allowMSAA;
            reflectionCamera.depth         = -10;
            reflectionCamera.enabled       = false;
            reflectionCamera.allowHDR      = currentCamera.allowHDR;
            go.hideFlags = HideFlags.DontSave;

            Shader.SetGlobalTexture("_PlanarReflectionTexture", m_ReflectionTexture);
            return(reflectionCamera);
        }
Beispiel #4
0
        public static void InitializeRenderingData(LightweightRenderPipelineAsset settings, ref CameraData cameraData, ref CullingResults cullResults,
                                                   out RenderingData renderingData)
        {
            var visibleLights = cullResults.visibleLights;

            int  mainLightIndex              = GetMainLightIndex(settings, visibleLights);
            bool mainLightCastShadows        = false;
            bool additionalLightsCastShadows = false;

            if (cameraData.maxShadowDistance > 0.0f)
            {
                mainLightCastShadows = (mainLightIndex != -1 && visibleLights[mainLightIndex].light != null &&
                                        visibleLights[mainLightIndex].light.shadows != LightShadows.None);

                // If additional lights are shaded per-pixel they cannot cast shadows
                if (settings.additionalLightsRenderingMode == LightRenderingMode.PerPixel)
                {
                    for (int i = 0; i < visibleLights.Length; ++i)
                    {
                        if (i == mainLightIndex)
                        {
                            continue;
                        }

                        Light light = visibleLights[i].light;

                        // LWRP doesn't support additional directional lights or point light shadows yet
                        if (visibleLights[i].lightType == LightType.Spot && light != null && light.shadows != LightShadows.None)
                        {
                            additionalLightsCastShadows = true;
                            break;
                        }
                    }
                }
            }

            renderingData.cullResults = cullResults;
            renderingData.cameraData  = cameraData;
            renderingData.uiCmaera    = null;
            InitializeLightData(settings, visibleLights, mainLightIndex, out renderingData.lightData);
            InitializeShadowData(settings, visibleLights, mainLightCastShadows, additionalLightsCastShadows && !renderingData.lightData.shadeAdditionalLightsPerVertex, out renderingData.shadowData);
            renderingData.supportsDynamicBatching = settings.supportsDynamicBatching;
            renderingData.perObjectData           = GetPerObjectLightFlags(renderingData.lightData.additionalLightsCount);
            renderingData.pipelineAsset           = settings;

            bool platformNeedsToKillAlpha = Application.platform == RuntimePlatform.IPhonePlayer ||
                                            Application.platform == RuntimePlatform.Android ||
                                            Application.platform == RuntimePlatform.tvOS;

            renderingData.killAlphaInFinalBlit = !Graphics.preserveFramebufferAlpha && platformNeedsToKillAlpha;
        }
        private void CreateGlossyTexture(Camera currentCamera, float reflectionBufferScale)
        {
            LightweightRenderPipelineAsset lwAsset = (LightweightRenderPipelineAsset)GraphicsSettings.renderPipelineAsset;
            var resMulti          = reflectionBufferScale * GetGlossyScaleValue();
            int glossyTextureSize = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelWidth * resMulti, 2)));

            if (!m_ReflectionBlurTexture)
            {
                DestroyImmediate(m_ReflectionBlurTexture);
            }
            if (!m_ReflectionDepthTexture)
            {
                DestroyImmediate(m_ReflectionDepthTexture);
            }

            bool useHDR10 = Application.isMobilePlatform &&
                            SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB2101010);
            RenderTextureFormat hdrFormat = (useHDR10) ? RenderTextureFormat.ARGB2101010 : RenderTextureFormat.DefaultHDR;

            if (m_ReflectionBlurTexture)
            {
                DestroyImmediate(m_ReflectionBlurTexture);
            }
            m_ReflectionBlurTexture = new RenderTexture(m_TextureSize, m_TextureSize, 16,
                                                        currentCamera.allowHDR ? hdrFormat : RenderTextureFormat.Default);
            m_ReflectionBlurTexture.useMipMap        = m_ReflectionBlurTexture.autoGenerateMips = true;
            m_ReflectionBlurTexture.autoGenerateMips = true; // no need for mips(unless wanting cheap roughness)
            m_ReflectionBlurTexture.name             = "_PlanarReflection blur" + GetInstanceID();
            m_ReflectionBlurTexture.isPowerOfTwo     = true;
            m_ReflectionBlurTexture.hideFlags        = HideFlags.DontSave;
            m_ReflectionBlurTexture.filterMode       = FilterMode.Trilinear;

            if (m_ReflectionDepthTexture)
            {
                DestroyImmediate(m_ReflectionDepthTexture);
            }
            m_ReflectionDepthTexture = new RenderTexture(m_TextureSize, m_TextureSize, 0, RenderTextureFormat.RHalf);
            // m_ReflectionDepthTexture = new RenderTexture(m_TextureSize, m_TextureSize, 0, RenderTextureFormat.R8);
            m_ReflectionDepthTexture.name         = "__MirrorReflectionDepth" + GetInstanceID();
            m_ReflectionDepthTexture.isPowerOfTwo = true;
            m_ReflectionDepthTexture.hideFlags    = HideFlags.DontSave;
            m_ReflectionDepthTexture.filterMode   = FilterMode.Bilinear;
            Shader.SetGlobalTexture("_PlanarReflectionBlurTexture", m_ReflectionBlurTexture);
            Shader.SetGlobalTexture("_PlanarReflectionDepth", m_ReflectionDepthTexture);
        }
        private void CreateTextureIfNone(Camera currentCamera)
        {
            LightweightRenderPipelineAsset lwAsset = (LightweightRenderPipelineAsset)GraphicsSettings.renderPipelineAsset;
            var resMulti = lwAsset.renderScale * GetScaleValue();

            m_TextureSize = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelWidth * resMulti, 2)));
            //m_TextureSize.y = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelHeight * resMulti, 2)));

            // Reflection render texture
            //if (Int2Compare(m_TextureSize, m_OldReflectionTextureSize) || !m_ReflectionTexture)
            if (!m_ReflectionTexture || m_OldReflectionTextureSize != m_TextureSize)
            {
                if (m_ReflectionTexture)
                {
                    DestroyImmediate(m_ReflectionTexture);
                }

                bool useHDR10 = Application.isMobilePlatform &&
                                SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB2101010);
                RenderTextureFormat hdrFormat = (useHDR10) ? RenderTextureFormat.ARGB2101010 : RenderTextureFormat.DefaultHDR;

                m_ReflectionTexture = new RenderTexture(m_TextureSize, m_TextureSize, 16,
                                                        currentCamera.allowHDR ? hdrFormat : RenderTextureFormat.Default);
                m_ReflectionTexture.useMipMap        = m_ReflectionTexture.autoGenerateMips = true;
                m_ReflectionTexture.autoGenerateMips = true; // no need for mips(unless wanting cheap roughness)
                m_ReflectionTexture.name             = "_PlanarReflection" + GetInstanceID();
                m_ReflectionTexture.isPowerOfTwo     = true;
                m_ReflectionTexture.hideFlags        = HideFlags.DontSave;
                m_ReflectionTexture.filterMode       = FilterMode.Trilinear;

                m_OldReflectionTextureSize = m_TextureSize;
                if (m_settings.m_glossy_enalbe)
                {
                    CreateGlossyTexture(currentCamera, resMulti);
                }
                else
                {
                    DestroyGlossyBuffers();
                }
            }
            m_ReflectionTexture.DiscardContents();
            Shader.SetGlobalTexture("_PlanarReflectionTexture", m_ReflectionTexture);
        }
        // Main Light is always a directional light
        static int GetMainLightIndex(LightweightRenderPipelineAsset settings, NativeArray <VisibleLight> visibleLights)
        {
            int totalVisibleLights = visibleLights.Length;

            if (totalVisibleLights == 0 || settings.mainLightRenderingMode != LightRenderingMode.PerPixel)
            {
                return(-1);
            }

            Light sunLight = RenderSettings.sun;
            int   brightestDirectionalLightIndex = -1;
            float brightestLightIntensity        = 0.0f;

            for (int i = 0; i < totalVisibleLights; ++i)
            {
                VisibleLight currVisibleLight = visibleLights[i];
                Light        currLight        = currVisibleLight.light;

                // Particle system lights have the light property as null. We sort lights so all particles lights
                // come last. Therefore, if first light is particle light then all lights are particle lights.
                // In this case we either have no main light or already found it.
                if (currLight == null)
                {
                    break;
                }

                if (currLight == sunLight)
                {
                    return(i);
                }

                // In case no shadow light is present we will return the brightest directional light
                if (currVisibleLight.lightType == LightType.Directional && currLight.intensity > brightestLightIntensity)
                {
                    brightestLightIntensity        = currLight.intensity;
                    brightestDirectionalLightIndex = i;
                }
            }

            return(brightestDirectionalLightIndex);
        }
Beispiel #8
0
            public static PipelineSettings Create(LightweightRenderPipelineAsset asset)
            {
                var cache = new PipelineSettings();

                // General settings
                cache.supportsCameraDepthTexture  = asset.supportsCameraDepthTexture;
                cache.supportsCameraOpaqueTexture = asset.supportsCameraOpaqueTexture;
                cache.opaqueDownsampling          = asset.opaqueDownsampling;

                // Quality settings
                cache.msaaSampleCount = asset.msaaSampleCount;
                cache.supportsHDR     = asset.supportsHDR;
                cache.renderScale     = asset.renderScale;

                // Main directional light settings
                cache.mainLightRenderingMode       = asset.mainLightRenderingMode;
                cache.supportsMainLightShadows     = asset.supportsMainLightShadows;
                cache.mainLightShadowmapResolution = asset.mainLightShadowmapResolution;

                // Additional light settings
                cache.additionalLightsRenderingMode       = asset.additionalLightsRenderingMode;
                cache.maxAdditionalLights                 = asset.maxAdditionalLightsCount;
                cache.supportsAdditionalLightShadows      = asset.supportsAdditionalLightShadows;
                cache.additionalLightsShadowmapResolution = asset.additionalLightsShadowmapResolution;

                // Shadow settings
                cache.shadowDistance      = asset.shadowDistance;
                cache.shadowCascadeOption = asset.shadowCascadeOption;
                cache.cascade2Split       = asset.cascade2Split;
                cache.cascade4Split       = asset.cascade4Split;
                cache.shadowDepthBias     = asset.shadowDepthBias;
                cache.shadowNormalBias    = asset.shadowNormalBias;
                cache.supportsSoftShadows = asset.supportsSoftShadows;

                // Advanced settings
                cache.supportsDynamicBatching = asset.supportsDynamicBatching;
                cache.mixedLightingSupported  = asset.supportsMixedLighting;
                cache.rendererSetup           = new ForwardRendererSetup();

                return(cache);
            }
Beispiel #9
0
        static void InitializeLightData(LightweightRenderPipelineAsset settings, NativeArray <VisibleLight> visibleLights, int mainLightIndex, int maxAdditionalLights,
                                        int maxPerObjectAdditionalLights, out LightData lightData)
        {
            lightData.mainLightIndex = mainLightIndex;

            if (settings.additionalLightsRenderingMode != LightRenderingMode.Disabled)
            {
                lightData.additionalLightsCount =
                    Math.Min((mainLightIndex != -1) ? visibleLights.Length - 1 : visibleLights.Length,
                             maxAdditionalLights);
                lightData.maxPerObjectAdditionalLightsCount = Math.Min(settings.maxAdditionalLightsCount, maxPerObjectAdditionalLights);
            }
            else
            {
                lightData.additionalLightsCount             = 0;
                lightData.maxPerObjectAdditionalLightsCount = 0;
            }

            lightData.shadeAdditionalLightsPerVertex = settings.additionalLightsRenderingMode == LightRenderingMode.PerVertex;
            lightData.visibleLights         = visibleLights;
            lightData.supportsMixedLighting = settings.supportsMixedLighting;
        }
Beispiel #10
0
        public LightweightRenderPipeline(LightweightRenderPipelineAsset asset)
        {
            SetSupportedRenderingFeatures();

            PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
            PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");

            PerCameraBuffer._InvCameraViewProj  = Shader.PropertyToID("_InvCameraViewProj");
            PerCameraBuffer._ScaledScreenParams = Shader.PropertyToID("_ScaledScreenParams");

            // Let engine know we have MSAA on for cases where we support MSAA backbuffer
            if (QualitySettings.antiAliasing != asset.msaaSampleCount)
            {
                QualitySettings.antiAliasing = asset.msaaSampleCount;
            }

            Shader.globalRenderPipeline = "LightweightPipeline";

            Lightmapping.SetDelegate(lightsDelegate);

            CameraCaptureBridge.enabled = true;
            VxShadowMapsManager.Instance.Build(); //seongdae;vxsm
        }
 public LightweightRenderPipeline(LightweightRenderPipelineAsset asset)
 {
 }
        static void InitializeShadowData(LightweightRenderPipelineAsset settings, NativeArray <VisibleLight> visibleLights, bool mainLightCastShadows, bool additionalLightsCastShadows, out ShadowData shadowData)
        {
            m_ShadowBiasData.Clear();

            for (int i = 0; i < visibleLights.Length; ++i)
            {
                Light light = visibleLights[i].light;
                LWRPAdditionalLightData data =
                    (light != null) ? light.gameObject.GetComponent <LWRPAdditionalLightData>() : null;

                if (data && !data.usePipelineSettings)
                {
                    m_ShadowBiasData.Add(new Vector4(light.shadowBias, light.shadowNormalBias, 0.0f, 0.0f));
                }
                else
                {
                    m_ShadowBiasData.Add(new Vector4(settings.shadowDepthBias, settings.shadowNormalBias, 0.0f, 0.0f));
                }
            }

            shadowData.bias = m_ShadowBiasData;

            // Until we can have keyword stripping forcing single cascade hard shadows on gles2
            bool supportsScreenSpaceShadows = SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2;

            shadowData.supportsMainLightShadows = settings.supportsMainLightShadows && mainLightCastShadows;

            // we resolve shadows in screenspace when cascades are enabled to save ALU as computing cascade index + shadowCoord on fragment is expensive
            shadowData.requiresScreenSpaceShadowResolve = false;

            int shadowCascadesCount;

            switch (settings.shadowCascadeOption)
            {
            case ShadowCascadesOption.FourCascades:
                shadowCascadesCount = 4;
                break;

            case ShadowCascadesOption.TwoCascades:
                shadowCascadesCount = 2;
                break;

            default:
                shadowCascadesCount = 1;
                break;
            }

            shadowData.mainLightShadowCascadesCount = shadowCascadesCount;
            shadowData.mainLightShadowmapWidth      = settings.mainLightShadowmapResolution;
            shadowData.mainLightShadowmapHeight     = settings.mainLightShadowmapResolution;

            switch (shadowData.mainLightShadowCascadesCount)
            {
            case 1:
                shadowData.mainLightShadowCascadesSplit = new Vector3(1.0f, 0.0f, 0.0f);
                break;

            case 2:
                shadowData.mainLightShadowCascadesSplit = new Vector3(settings.cascade2Split, 1.0f, 0.0f);
                break;

            default:
                shadowData.mainLightShadowCascadesSplit = settings.cascade4Split;
                break;
            }

            shadowData.supportsAdditionalLightShadows = settings.supportsAdditionalLightShadows && additionalLightsCastShadows;
            shadowData.additionalLightsShadowmapWidth = shadowData.additionalLightsShadowmapHeight = settings.additionalLightsShadowmapResolution;
            shadowData.supportsSoftShadows            = settings.supportsSoftShadows && (shadowData.supportsMainLightShadows || shadowData.supportsAdditionalLightShadows);
            shadowData.shadowmapDepthBufferBits       = 16;
        }
        static void InitializeCameraData(LightweightRenderPipelineAsset settings, Camera camera, LWRPAdditionalCameraData additionalCameraData, out CameraData cameraData)
        {
            const float kRenderScaleThreshold = 0.05f;

            cameraData.camera = camera;

            int msaaSamples = 1;

            if (camera.allowMSAA && settings.msaaSampleCount > 1)
            {
                msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : settings.msaaSampleCount;
            }

            if (Camera.main == camera && camera.cameraType == CameraType.Game && camera.targetTexture == null)
            {
                // There's no exposed API to control how a backbuffer is created with MSAA
                // By settings antiAliasing we match what the amount of samples in camera data with backbuffer
                // We only do this for the main camera and this only takes effect in the beginning of next frame.
                // This settings should not be changed on a frame basis so that's fine.
                QualitySettings.antiAliasing = msaaSamples;
            }

            cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView;
            cameraData.isStereoEnabled   = IsStereoEnabled(camera);

            cameraData.isHdrEnabled = camera.allowHDR && settings.supportsHDR;

            cameraData.postProcessLayer   = camera.GetComponent <PostProcessLayer>();
            cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled;

            // Disables postprocessing in mobile VR. It's stable on mobile yet.
            if (cameraData.isStereoEnabled && Application.isMobilePlatform)
            {
                cameraData.postProcessEnabled = false;
            }

            Rect cameraRect = camera.rect;

            cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f ||
                                              Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f));

            // If XR is enabled, use XR renderScale.
            // Discard variations lesser than kRenderScaleThreshold.
            // Scale is only enabled for gameview.
            float usedRenderScale = XRGraphics.enabled ? XRGraphics.eyeTextureResolutionScale : settings.renderScale;

            cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale;
            cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f;

            bool anyShadowsEnabled = settings.supportsMainLightShadows || settings.supportsAdditionalLightShadows;

            cameraData.maxShadowDistance = (anyShadowsEnabled) ? settings.shadowDistance : 0.0f;

            if (additionalCameraData != null)
            {
                cameraData.maxShadowDistance     = (additionalCameraData.renderShadows) ? cameraData.maxShadowDistance : 0.0f;
                cameraData.requiresDepthTexture  = additionalCameraData.requiresDepthTexture;
                cameraData.requiresOpaqueTexture = additionalCameraData.requiresColorTexture;
            }
            else
            {
                cameraData.requiresDepthTexture  = settings.supportsCameraDepthTexture;
                cameraData.requiresOpaqueTexture = settings.supportsCameraOpaqueTexture;
            }

            cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || cameraData.postProcessEnabled;

            var  commonOpaqueFlags        = SortingCriteria.CommonOpaque;
            var  noFrontToBackOpaqueFlags = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges | SortingCriteria.CanvasOrder;
            bool hasHSRGPU = SystemInfo.hasHiddenSurfaceRemovalOnGPU;
            bool canSkipFrontToBackSorting = (camera.opaqueSortMode == OpaqueSortMode.Default && hasHSRGPU) || camera.opaqueSortMode == OpaqueSortMode.NoDistanceSort;

            cameraData.defaultOpaqueSortFlags = canSkipFrontToBackSorting ? noFrontToBackOpaqueFlags : commonOpaqueFlags;
            cameraData.captureActions         = CameraCaptureBridge.GetCaptureActions(camera);

            cameraData.cameraTargetDescriptor = CreateRenderTextureDescriptor(camera, cameraData.renderScale,
                                                                              cameraData.isStereoEnabled, cameraData.isHdrEnabled, msaaSamples);
        }
        static void InitializeCameraData(LightweightRenderPipelineAsset settings, Camera camera, LWRPAdditionalCameraData additionalCameraData, out CameraData cameraData)
        {
            const float kRenderScaleThreshold = 0.05f;

            cameraData.camera          = camera;
            cameraData.isStereoEnabled = IsStereoEnabled(camera);

            int msaaSamples = 1;

            if (camera.allowMSAA && settings.msaaSampleCount > 1)
            {
                msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : settings.msaaSampleCount;
            }

            cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView;
            cameraData.isHdrEnabled      = camera.allowHDR && settings.supportsHDR;
#if UNITY_2019_2_OR_NEWER
            camera.TryGetComponent(out cameraData.postProcessLayer);
#else
            cameraData.postProcessLayer = camera.GetComponent <PostProcessLayer>();
#endif
            cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled;

            // On Android, Postprocessing v2 works with single-pass double-wide mode and is disabled for multiview
            var xrDesc = UnityEngine.XR.XRSettings.eyeTextureDesc;
            if (cameraData.isStereoEnabled && Application.isMobilePlatform && Application.platform == RuntimePlatform.Android && xrDesc.dimension == TextureDimension.Tex2DArray)
            {
                cameraData.postProcessEnabled = false;
            }

            Rect cameraRect = camera.rect;
            cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f ||
                                              Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f));

            // If XR is enabled, use XR renderScale.
            // Discard variations lesser than kRenderScaleThreshold.
            // Scale is only enabled for gameview.
            float usedRenderScale = XRGraphics.enabled ? XRGraphics.eyeTextureResolutionScale : settings.renderScale;
            cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale;
            cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f;

            bool anyShadowsEnabled = settings.supportsMainLightShadows || settings.supportsAdditionalLightShadows;
            cameraData.maxShadowDistance = Mathf.Min(settings.shadowDistance, camera.farClipPlane);
            cameraData.maxShadowDistance = (anyShadowsEnabled && cameraData.maxShadowDistance >= camera.nearClipPlane) ?
                                           cameraData.maxShadowDistance : 0.0f;

            if (additionalCameraData != null)
            {
                cameraData.maxShadowDistance     = (additionalCameraData.renderShadows) ? cameraData.maxShadowDistance : 0.0f;
                cameraData.requiresDepthTexture  = additionalCameraData.requiresDepthTexture;
                cameraData.requiresOpaqueTexture = additionalCameraData.requiresColorTexture;
            }
            else
            {
                cameraData.requiresDepthTexture  = settings.supportsCameraDepthTexture;
                cameraData.requiresOpaqueTexture = settings.supportsCameraOpaqueTexture;
            }

            cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || cameraData.postProcessEnabled;

            var  commonOpaqueFlags        = SortingCriteria.CommonOpaque;
            var  noFrontToBackOpaqueFlags = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges | SortingCriteria.CanvasOrder;
            bool hasHSRGPU = SystemInfo.hasHiddenSurfaceRemovalOnGPU;
            bool canSkipFrontToBackSorting = (camera.opaqueSortMode == OpaqueSortMode.Default && hasHSRGPU) || camera.opaqueSortMode == OpaqueSortMode.NoDistanceSort;

            cameraData.defaultOpaqueSortFlags = canSkipFrontToBackSorting ? noFrontToBackOpaqueFlags : commonOpaqueFlags;
            cameraData.captureActions         = CameraCaptureBridge.GetCaptureActions(camera);

            cameraData.cameraTargetDescriptor = CreateRenderTextureDescriptor(camera, cameraData.renderScale,
                                                                              cameraData.isStereoEnabled, cameraData.isHdrEnabled, msaaSamples);
        }
Beispiel #15
0
        static void InitializeShadowData(LightweightRenderPipelineAsset settings, NativeArray <VisibleLight> visibleLights, bool mainLightCastShadows, bool additionalLightsCastShadows, out ShadowData shadowData)
        {
            m_ShadowBiasData.Clear();

            for (int i = 0; i < visibleLights.Length; ++i)
            {
                Light light = visibleLights[i].light;
                LWRPAdditionalLightData data =
                    (light != null) ? light.gameObject.GetComponent <LWRPAdditionalLightData>() : null;

                if (data && !data.usePipelineSettings)
                {
                    m_ShadowBiasData.Add(new Vector4(light.shadowBias, light.shadowNormalBias, 0.0f, 0.0f));
                }
                else
                {
                    m_ShadowBiasData.Add(new Vector4(settings.shadowDepthBias, settings.shadowNormalBias, 0.0f, 0.0f));
                }
            }

            shadowData.bias = m_ShadowBiasData;

            // Until we can have keyword stripping forcing single cascade hard shadows on gles2
            bool supportsScreenSpaceShadows = SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2;

            //seongdae;vxsm
            // compute shader for screen space shadows.
            // todo : need to fix retransform for world space in screen space on OpenGLES3.1
            bool supportsComputeScreenSpaceShadows =
                SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2 &&
                SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES3;

            //seongdae;vxsm

            shadowData.supportsMainLightShadows   = settings.supportsMainLightShadows && mainLightCastShadows;
            shadowData.supportsMainLightVxShadows = settings.supportsVxShadows && mainLightCastShadows; //seongdae;vxsm

            // we resolve shadows in screenspace when cascades are enabled to save ALU as computing cascade index + shadowCoord on fragment is expensive
            shadowData.requiresScreenSpaceShadowResolve = shadowData.supportsMainLightShadows && supportsScreenSpaceShadows && settings.shadowCascadeOption != ShadowCascadesOption.NoCascades;
            shadowData.requiresScreenSpaceShadowCompute = shadowData.supportsMainLightVxShadows && supportsComputeScreenSpaceShadows; //seongdae;vxsm

            int shadowCascadesCount;

            switch (settings.shadowCascadeOption)
            {
            case ShadowCascadesOption.FourCascades:
                shadowCascadesCount = 4;
                break;

            case ShadowCascadesOption.TwoCascades:
                shadowCascadesCount = 2;
                break;

            default:
                shadowCascadesCount = 1;
                break;
            }

            shadowData.mainLightShadowCascadesCount = (shadowData.requiresScreenSpaceShadowResolve) ? shadowCascadesCount : 1;
            shadowData.mainLightShadowmapWidth      = settings.mainLightShadowmapResolution;
            shadowData.mainLightShadowmapHeight     = settings.mainLightShadowmapResolution;

            switch (shadowData.mainLightShadowCascadesCount)
            {
            case 1:
                shadowData.mainLightShadowCascadesSplit = new Vector3(1.0f, 0.0f, 0.0f);
                break;

            case 2:
                shadowData.mainLightShadowCascadesSplit = new Vector3(settings.cascade2Split, 1.0f, 0.0f);
                break;

            default:
                shadowData.mainLightShadowCascadesSplit = settings.cascade4Split;
                break;
            }

            //seongdae;vxsm
            if (shadowData.supportsMainLightShadows && settings.supportsVxShadows)
            {
                int mainLightIndex = GetMainLightIndex(settings, visibleLights);
                var mainLight      = visibleLights[mainLightIndex].light;
                var dirVxShadowMap = mainLight.GetComponent <DirectionalVxShadowMap>();

                bool dirVxShadowMapIsValid = dirVxShadowMap != null && dirVxShadowMap.IsValid();

                shadowData.requiresScreenSpaceShadowCompute = dirVxShadowMapIsValid;
                shadowData.mainLightVxShadowQuality         = (int)settings.vxShadowsQuality;
            }
            else
            {
                shadowData.requiresScreenSpaceShadowCompute = false;
                shadowData.mainLightVxShadowQuality         = 0;
            }
            //seongdae;vxsm

            shadowData.supportsAdditionalLightShadows = settings.supportsAdditionalLightShadows && additionalLightsCastShadows;
            shadowData.additionalLightsShadowmapWidth = shadowData.additionalLightsShadowmapHeight = settings.additionalLightsShadowmapResolution;
            shadowData.supportsSoftShadows            = settings.supportsSoftShadows && (shadowData.supportsMainLightShadows || shadowData.supportsAdditionalLightShadows);
            shadowData.shadowmapDepthBufferBits       = 16;
        }
        static void InitializeCameraData(LightweightRenderPipelineAsset settings, Camera camera, out CameraData cameraData)
        {
            const float kRenderScaleThreshold = 0.05f;

            cameraData.camera = camera;

            bool msaaEnabled = camera.allowMSAA && settings.msaaSampleCount > 1;

            if (msaaEnabled)
            {
                cameraData.msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : settings.msaaSampleCount;
            }
            else
            {
                cameraData.msaaSamples = 1;
            }

            cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView;
            cameraData.isStereoEnabled   = IsStereoEnabled(camera);

            cameraData.isHdrEnabled = camera.allowHDR && settings.supportsHDR;

            cameraData.postProcessLayer   = camera.GetComponent <PostProcessLayer>();
            cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled;

            Rect cameraRect = camera.rect;

            cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f ||
                                              Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f));

            // If XR is enabled, use XR renderScale.
            // Discard variations lesser than kRenderScaleThreshold.
            // Scale is only enabled for gameview.
            float usedRenderScale = XRGraphics.enabled ? XRGraphics.eyeTextureResolutionScale : settings.renderScale;

            cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale;
            cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f;

            cameraData.opaqueTextureDownsampling = settings.opaqueDownsampling;

            bool anyShadowsEnabled = settings.supportsMainLightShadows || settings.supportsAdditionalLightShadows;

            cameraData.maxShadowDistance = (anyShadowsEnabled) ? settings.shadowDistance : 0.0f;

            LWRPAdditionalCameraData additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>();

            if (additionalCameraData != null)
            {
                cameraData.maxShadowDistance     = (additionalCameraData.renderShadows) ? cameraData.maxShadowDistance : 0.0f;
                cameraData.requiresDepthTexture  = additionalCameraData.requiresDepthTexture;
                cameraData.requiresOpaqueTexture = additionalCameraData.requiresColorTexture;
            }
            else
            {
                cameraData.requiresDepthTexture  = settings.supportsCameraDepthTexture;
                cameraData.requiresOpaqueTexture = settings.supportsCameraOpaqueTexture;
            }

            cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || cameraData.postProcessEnabled;

            var  commonOpaqueFlags        = SortingCriteria.CommonOpaque;
            var  noFrontToBackOpaqueFlags = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges | SortingCriteria.CanvasOrder;
            bool hasHSRGPU = SystemInfo.hasHiddenSurfaceRemovalOnGPU;
            bool canSkipFrontToBackSorting = (camera.opaqueSortMode == OpaqueSortMode.Default && hasHSRGPU) || camera.opaqueSortMode == OpaqueSortMode.NoDistanceSort;

            cameraData.defaultOpaqueSortFlags = canSkipFrontToBackSorting ? noFrontToBackOpaqueFlags : commonOpaqueFlags;
            cameraData.captureActions         = CameraCaptureBridge.GetCaptureActions(camera);
        }