public static PipelineSettings Create(LightweightRenderPipelineAsset asset)
            {
                var cache = new PipelineSettings();

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

                cache.supportsOIT      = asset.supportsOIT;
                cache.momentsCount     = asset.momentsCount;
                cache.momentsPrecision = asset.momentsPrecision;

                // 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.cascadeCount                     = asset.cascadeCount;
                cache.cascade2Split                    = asset.cascade2Split;
                cache.cascade4Split                    = asset.cascade4Split;
                cache.shadowDepthBias                  = asset.shadowDepthBias;
                cache.shadowNormalBias                 = asset.shadowNormalBias;
                cache.supportsSoftShadows              = asset.supportsSoftShadows;
                cache.supportsMainCharacterShadows     = asset.supportsMainCharacterShadows;
                cache.mainCharacterShadowmapResolution = asset.mainCharacterShadowmapResolution;
                cache.supportsDeepShadowMaps           = asset.supportsDeepShadowMaps;
                cache.deepShadowMapsSize               = asset.deepShadowMapsSize;
                cache.deepShadowMapsDepth              = asset.deepShadowMapsDepth;
                cache.deepShadowMapsBlurOffset         = asset.deepShadowMapsBlurOffset;

                // Advanced settings
                cache.supportsDynamicBatching = asset.supportsDynamicBatching;
                cache.mixedLightingSupported  = asset.supportsMixedLighting;

                return(cache);
            }
            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.cascadeCount        = asset.cascadeCount;
                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.savedXRGraphicsConfig               = asset.savedXRGraphicsConfig;
                cache.savedXRGraphicsConfig.renderScale   = cache.renderScale;
                cache.savedXRGraphicsConfig.viewportScale = 1.0f; // Placeholder until viewportScale is all hooked up
                // Apply any changes to XRGConfig prior to this point
                cache.savedXRGraphicsConfig.SetConfig();

                return(cache);
            }
Пример #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);
                }
                m_ReflectionTexture = new RenderTexture(m_TextureSize.x, m_TextureSize.y, 16,
                                                        currentCamera.allowHDR ? RenderTextureFormat.DefaultHDR : 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_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
            var reflectionCamera = go.GetComponent <Camera>();

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

            Shader.SetGlobalTexture("_PlanarReflectionTexture", m_ReflectionTexture);
            return(reflectionCamera);
        }
        public ScriptableRenderer(LightweightRenderPipelineAsset pipelineAsset)
        {
            if (pipelineAsset == null)
            {
                throw new ArgumentNullException("pipelineAsset");
            }

            m_Materials = new[]
            {
                CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"),
                CoreUtils.CreateEngineMaterial(pipelineAsset.copyDepthShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.samplingShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.blitShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceShadowShader),
            };

            postProcessingContext = new PostProcessRenderContext();
        }
Пример #5
0
        public ScriptableRenderer(LightweightRenderPipelineAsset pipelineAsset)
        {
            if (pipelineAsset == null)
            {
                throw new ArgumentNullException("pipelineAsset");
            }

            m_Materials = new[]
            {
                CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"),
                CoreUtils.CreateEngineMaterial(pipelineAsset.copyDepthShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.samplingShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.blitShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceShadowShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceDeepShadowMapsShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.gaussianBlurShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.oitCompositeShader),
                CoreUtils.CreateEngineMaterial(pipelineAsset.momentOITCompositeShader),
            };

            _Computes = new[]
            {
                pipelineAsset.resetDeepShadowDataCompute,
            };

            ComputeBuffer DeepShadowMapsCountBuffer = null;
            ComputeBuffer DeepShadowMapsDataBuffer  = null;

            if (pipelineAsset.supportsDeepShadowMaps)
            {
                DeepShadowMapsCountBuffer = new ComputeBuffer(pipelineAsset.deepShadowMapsSize * pipelineAsset.deepShadowMapsSize, sizeof(uint));
                DeepShadowMapsDataBuffer  = new ComputeBuffer(pipelineAsset.deepShadowMapsSize * pipelineAsset.deepShadowMapsSize * pipelineAsset.deepShadowMapsDepth, sizeof(uint));
            }
            _Buffers = new[]
            {
                DeepShadowMapsCountBuffer,
                DeepShadowMapsDataBuffer,
            };

            postProcessingContext = new PostProcessRenderContext();
        }
        public LightweightRenderPipeline(LightweightRenderPipelineAsset asset)
        {
            settings = PipelineSettings.Create(asset);
            renderer = new ScriptableRenderer(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 != settings.msaaSampleCount)
            {
                QualitySettings.antiAliasing = settings.msaaSampleCount;
            }

            Shader.globalRenderPipeline = "LightweightPipeline";

            Lightmapping.SetDelegate(lightsDelegate);
        }
Пример #7
0
        public static void SetSupportedShaderFeatures(LightweightRenderPipelineAsset pipelineAsset)
        {
            s_ShaderFeatures = ShaderFeatures.MainLight;

            if (pipelineAsset.supportsMainLightShadows)
            {
                s_ShaderFeatures |= ShaderFeatures.MainLightShadows;
            }

            if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerVertex)
            {
                s_ShaderFeatures |= ShaderFeatures.AdditionalLights;
                s_ShaderFeatures |= ShaderFeatures.VertexLighting;
            }
            else if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel)
            {
                s_ShaderFeatures |= ShaderFeatures.AdditionalLights;

                if (pipelineAsset.supportsAdditionalLightShadows)
                {
                    s_ShaderFeatures |= ShaderFeatures.AdditionalLightShadows;
                }
            }

            bool anyShadows = pipelineAsset.supportsMainLightShadows ||
                              CoreUtils.HasFlag(s_ShaderFeatures, ShaderFeatures.AdditionalLightShadows);

            if (pipelineAsset.supportsSoftShadows && anyShadows)
            {
                s_ShaderFeatures |= ShaderFeatures.SoftShadows;
            }

            if (pipelineAsset.supportsMixedLighting)
            {
                s_ShaderFeatures |= ShaderFeatures.MixedLighting;
            }
        }