static Material CreateLightMaterial(Light2D light, bool isVolume)
        {
            bool     isShape = light.IsShapeLight();
            Material material;

            if (isVolume)
            {
                material = CoreUtils.CreateEngineMaterial(isShape ? s_RendererData.shapeLightVolumeShader : s_RendererData.pointLightVolumeShader);
            }
            else
            {
                material = CoreUtils.CreateEngineMaterial(isShape ? s_RendererData.shapeLightShader : s_RendererData.pointLightShader);

                if (!light.alphaBlendOnOverlap)
                {
                    SetBlendModes(material, BlendMode.One, BlendMode.One);
                    material.EnableKeyword(k_UseAdditiveBlendingKeyword);
                }
                else
                {
                    SetBlendModes(material, BlendMode.SrcAlpha, BlendMode.OneMinusSrcAlpha);
                }
            }

            if (light.lightType == Light2D.LightType.Sprite)
            {
                material.EnableKeyword(k_SpriteLightKeyword);
            }

            if (!isShape && light.lightCookieSprite != null && light.lightCookieSprite.texture != null)
            {
                material.EnableKeyword(k_UsePointLightCookiesKeyword);
            }

            if (!isShape && light.pointLightQuality == Light2D.PointLightQuality.Fast)
            {
                material.EnableKeyword(k_LightQualityFastKeyword);
            }

            if (light.useNormalMap)
            {
                material.EnableKeyword(k_UseNormalMap);
            }

            return(material);
        }
Example #2
0
        // The constructor of the pass. Here you can set any material properties that do not need to be updated on a per-frame basis.
        public TemplatePass(TemplateFeature.PassSettings passSettings)
        {
            this.passSettings = passSettings;

            // Set the render pass event.
            renderPassEvent = passSettings.renderPassEvent;

            // We create a material that will be used during our pass. You can do it like this using the 'CreateEngineMaterial' method, giving it
            // a shader path as an input or you can use a 'public Material material;' field in your pass settings and access it here through 'passSettings.material'.
            if (material == null)
            {
                material = CoreUtils.CreateEngineMaterial("Hidden/Blur");
            }

            // Set any material properties based on our pass settings.
            material.SetInt(BlurStrengthProperty, passSettings.blurStrength);
        }
Example #3
0
        private void InitDefaultRenderState(ref ForwardRendererData data)
        {
            m_BlitMaterial               = CoreUtils.CreateEngineMaterial(data.shaders.blitPS);
            m_CustomBlitMaterail         = CoreUtils.CreateEngineMaterial(data.shaders.customBlitPS);
            m_CopyDepthMaterial          = CoreUtils.CreateEngineMaterial(data.shaders.copyDepthPS);
            m_SamplingMaterial           = CoreUtils.CreateEngineMaterial(data.shaders.samplingPS);
            m_ScreenspaceShadowsMaterial = CoreUtils.CreateEngineMaterial(data.shaders.screenSpaceShadowPS);

            StencilStateData stencilData = data.defaultStencilState;

            m_DefaultStencilState         = StencilState.defaultValue;
            m_DefaultStencilState.enabled = stencilData.overrideStencilState;
            m_DefaultStencilState.SetCompareFunction(stencilData.stencilCompareFunction);
            m_DefaultStencilState.SetPassOperation(stencilData.passOperation);
            m_DefaultStencilState.SetFailOperation(stencilData.failOperation);
            m_DefaultStencilState.SetZFailOperation(stencilData.zFailOperation);
        }
Example #4
0
    public override void Create()
    {
        scriptablePass = new SSAORenderPass("SSAO");

        m_Shader = Shader.Find(m_ShaderName);
        if (!m_Material)
        {
            m_Material = CoreUtils.CreateEngineMaterial(m_Shader);
        }
        scriptablePass.SSAOMaterial = m_Material;

        scriptablePass.intensity   = settings.intensity;
        scriptablePass.radius      = settings.radius;
        scriptablePass.sampleCount = settings.sampleCount;

        scriptablePass.renderPassEvent = settings.renderPassEvent;
    }
        public MipGenerator(HDRenderPipelineAsset asset)
        {
            m_TempColorTargets = new RTHandle[kernelCount];
            m_DepthPyramidCS   = asset.renderPipelineResources.shaders.depthPyramidCS;
            m_ColorPyramidCS   = asset.renderPipelineResources.shaders.colorPyramidCS;

            m_DepthDownsampleKernel         = m_DepthPyramidCS.FindKernel("KDepthDownsample8DualUav");
            m_ColorDownsampleKernel         = InitColorKernel("KColorDownsample");
            m_ColorDownsampleKernelCopyMip0 = InitColorKernel("KColorDownsampleCopyMip0");
            m_ColorGaussianKernel           = InitColorKernel("KColorGaussian");

            m_SrcOffset         = new int[4];
            m_DstOffset         = new int[4];
            m_ColorPyramidPS    = asset.renderPipelineResources.shaders.colorPyramidPS;
            m_ColorPyramidPSMat = CoreUtils.CreateEngineMaterial(m_ColorPyramidPS);
            m_PropertyBlock     = new MaterialPropertyBlock();
        }
Example #6
0
        private static Material CreateLightMaterial(Renderer2DData rendererData, Light2D light, bool isVolume)
        {
            var      isPoint = light.isPointLight;
            Material material;

            if (isVolume)
            {
                material = CoreUtils.CreateEngineMaterial(isPoint ? rendererData.pointLightVolumeShader : rendererData.shapeLightVolumeShader);
            }
            else
            {
                material = CoreUtils.CreateEngineMaterial(isPoint ? rendererData.pointLightShader : rendererData.shapeLightShader);

                if (light.overlapOperation == Light2D.OverlapOperation.Additive)
                {
                    SetBlendModes(material, BlendMode.One, BlendMode.One);
                    material.EnableKeyword(k_UseAdditiveBlendingKeyword);
                }
                else
                {
                    SetBlendModes(material, BlendMode.SrcAlpha, BlendMode.OneMinusSrcAlpha);
                }
            }

            if (light.lightType == Light2D.LightType.Sprite)
            {
                material.EnableKeyword(k_SpriteLightKeyword);
            }

            if (isPoint && light.lightCookieSprite != null && light.lightCookieSprite.texture != null)
            {
                material.EnableKeyword(k_UsePointLightCookiesKeyword);
            }

            if (isPoint && light.normalMapQuality == Light2D.NormalMapQuality.Fast)
            {
                material.EnableKeyword(k_LightQualityFastKeyword);
            }

            if (light.normalMapQuality != Light2D.NormalMapQuality.Disabled)
            {
                material.EnableKeyword(k_UseNormalMap);
            }

            return(material);
        }
Example #7
0
        public void Build(HDRenderPipelineAsset hdAsset, RenderPipelineResources defaultResources, IBLFilterBSDF[] iblFilterBSDFArray)
        {
            m_SkyRenderingContext = new SkyRenderingContext(iblFilterBSDFArray, (int)hdAsset.currentPlatformRenderPipelineSettings.lightLoopSettings.skyReflectionSize, true);
#if UNITY_EDITOR
            m_PreviewSkyRenderingContext = new SkyRenderingContext(iblFilterBSDFArray, (int)hdAsset.currentPlatformRenderPipelineSettings.lightLoopSettings.skyReflectionSize, true);
#endif

            m_StandardSkyboxMaterial      = CoreUtils.CreateEngineMaterial(defaultResources.shaders.skyboxCubemapPS);
            m_BlitCubemapMaterial         = CoreUtils.CreateEngineMaterial(defaultResources.shaders.blitCubemapPS);
            m_OpaqueAtmScatteringMaterial = CoreUtils.CreateEngineMaterial(defaultResources.shaders.opaqueAtmosphericScatteringPS);

            m_OpaqueAtmScatteringBlock = new MaterialPropertyBlock();

            m_LightingOverrideVolumeStack       = VolumeManager.instance.CreateStack();
            m_LightingOverrideLayerMask         = hdAsset.currentPlatformRenderPipelineSettings.lightLoopSettings.skyLightingOverrideLayerMask;
            m_StaticLightingSkyRenderingContext = new SkyRenderingContext(iblFilterBSDFArray, (int)hdAsset.currentPlatformRenderPipelineSettings.lightLoopSettings.skyReflectionSize, false);
        }
Example #8
0
        public Renderer2D(Renderer2DData data) : base(data)
        {
            m_BlitMaterial = CoreUtils.CreateEngineMaterial(data.blitShader);

            m_ColorGradingLutPass  = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingOpaques, data.postProcessData);
            m_Render2DLightingPass = new Render2DLightingPass(data);
            m_PostProcessPass      = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, data.postProcessData);
            m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing, data.postProcessData);
            m_FinalBlitPass        = new FinalBlitPass(RenderPassEvent.AfterRendering, m_BlitMaterial);

            m_UseDepthStencilBuffer = data.useDepthStencilBuffer;

            m_AfterPostProcessColorHandle.Init("_AfterPostProcessTexture");
            m_ColorGradingLutHandle.Init("_InternalGradingLut");

            m_Renderer2DData = data;
        }
    public StochasticRasterizerInstance()
    {
        m_PostProcessRenderContext = new PostProcessRenderContext();

        int w = Screen.width; int h = Screen.height;

        // Initial state of the RTHandle system.
        // Tells the system that we will require MSAA or not so that we can avoid wasteful render texture allocation.
        // TODO: Might want to initialize to at least the window resolution to avoid un-necessary re-alloc in the player
        RTHandles.Initialize(1, 1, true, (MSAASamples)k_MSAASamples);
        RTHandles.SetReferenceSize(w, h, (MSAASamples)k_MSAASamples);

        InitializeBuffers();

        // Our final pass is stored in Pass 4 of stochastic material.
        m_FinalPass = CoreUtils.CreateEngineMaterial(Shader.Find("StochasticRasterizer/UnlitStochastic"));
    }
Example #10
0
        void InitializeSubsurfaceScattering()
        {
            // Disney SSS (compute + combine)
            string kernelName = "SubsurfaceScattering";

            m_SubsurfaceScatteringCS     = defaultResources.shaders.subsurfaceScatteringCS;
            m_SubsurfaceScatteringKernel = m_SubsurfaceScatteringCS.FindKernel(kernelName);
            m_CombineLightingPass        = CoreUtils.CreateEngineMaterial(defaultResources.shaders.combineLightingPS);
            m_CombineLightingPass.SetInt(HDShaderIDs._StencilRef, (int)StencilUsage.SubsurfaceScattering);
            m_CombineLightingPass.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.SubsurfaceScattering);

            m_SSSCopyStencilForSplitLighting = CoreUtils.CreateEngineMaterial(defaultResources.shaders.copyStencilBufferPS);
            m_SSSCopyStencilForSplitLighting.SetInt(HDShaderIDs._StencilRef, (int)StencilUsage.SubsurfaceScattering);
            m_SSSCopyStencilForSplitLighting.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.SubsurfaceScattering);

            m_SSSDefaultDiffusionProfile = defaultResources.assets.defaultDiffusionProfile;
        }
Example #11
0
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
        if (stencilShader == null)
        {
            stencilShader = Shader.Find("Hidden/Renderers/SeeThroughStencil");
        }

        stencilMaterial = CoreUtils.CreateEngineMaterial(stencilShader);

        shaderTags = new ShaderTagId[4]
        {
            new ShaderTagId("Forward"),
            new ShaderTagId("ForwardOnly"),
            new ShaderTagId("SRPDefaultUnlit"),
            new ShaderTagId("FirstPass"),
        };
    }
        public ForwardRenderer(ForwardRendererData data) : base(data)
        {
            Downsampling downsamplingMethod = LightweightRenderPipeline.asset.opaqueDownsampling;

            Material blitMaterial = CoreUtils.CreateEngineMaterial(data.blitShader);
            Material copyDepthMaterial = CoreUtils.CreateEngineMaterial(data.copyDepthShader);
            Material samplingMaterial = CoreUtils.CreateEngineMaterial(data.samplingShader);
            Material screenspaceShadowsMaterial = CoreUtils.CreateEngineMaterial(data.screenSpaceShadowShader);

            StencilStateData stencilData = data.defaultStencilState;
            m_DefaultStencilState = StencilState.defaultValue;
            m_DefaultStencilState.enabled = stencilData.overrideStencilState;
            m_DefaultStencilState.SetCompareFunction(stencilData.stencilCompareFunction);
            m_DefaultStencilState.SetPassOperation(stencilData.passOperation);
            m_DefaultStencilState.SetFailOperation(stencilData.failOperation);
            m_DefaultStencilState.SetZFailOperation(stencilData.zFailOperation);

            // Note: Since all custom render passes inject first and we have stable sort,
            // we inject the builtin passes in the before events.
            m_MainLightShadowCasterPass = new MainLightShadowCasterPass(RenderPassEvent.BeforeRenderingShadows);
            m_AdditionalLightsShadowCasterPass = new AdditionalLightsShadowCasterPass(RenderPassEvent.BeforeRenderingShadows);
            m_DepthPrepass = new DepthOnlyPass(RenderPassEvent.BeforeRenderingPrepasses, RenderQueueRange.opaque, data.opaqueLayerMask);
            m_ScreenSpaceShadowResolvePass = new ScreenSpaceShadowResolvePass(RenderPassEvent.BeforeRenderingPrepasses, screenspaceShadowsMaterial);
            m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, data.opaqueLayerMask, m_DefaultStencilState, stencilData.stencilReference);
            m_CopyDepthPass = new CopyDepthPass(RenderPassEvent.BeforeRenderingOpaques, copyDepthMaterial);
            m_OpaquePostProcessPass = new PostProcessPass(RenderPassEvent.BeforeRenderingOpaques, true);
            m_DrawSkyboxPass = new DrawSkyboxPass(RenderPassEvent.BeforeRenderingSkybox);
            m_CopyColorPass = new CopyColorPass(RenderPassEvent.BeforeRenderingTransparents, samplingMaterial, downsamplingMethod);
            m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, data.transparentLayerMask, m_DefaultStencilState, stencilData.stencilReference);
            m_PostProcessPass = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing);
            m_CapturePass = new CapturePass(RenderPassEvent.AfterRendering);
            m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering, blitMaterial);

#if UNITY_EDITOR
            m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(RenderPassEvent.AfterRendering + 9, copyDepthMaterial);
#endif

            // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
            // Samples (MSAA) depend on camera and pipeline
            m_CameraColorAttachment.Init("_CameraColorTexture");
            m_CameraDepthAttachment.Init("_CameraDepthAttachment");
            m_DepthTexture.Init("_CameraDepthTexture");
            m_OpaqueColor.Init("_CameraOpaqueTexture");
            m_ForwardLights = new ForwardLights();
        }
        public override void Create()
        {
            if (m_targetPrecomputeFrustumsCS)
            {
                if (m_precomputeFrustumsPass != null)
                {
                    m_precomputeFrustumsPass.Release();
                }

                m_precomputeFrustumsPass = new PrecomputeFrustumsPass(
                    m_targetPrecomputeFrustumsCS);
            }

            m_depthOnlyPass = new DepthOnlyPass();

            m_copyDepthPass = new CopyDepthPass();

            if (m_targetForwardPlusLightCullingCS)
            {
                if (m_tileLightCullingPass != null)
                {
                    m_tileLightCullingPass.Release();
                }

                m_tileLightCullingPass = new TileLightCullingPass(
                    m_targetForwardPlusLightCullingCS);
            }

            if (m_samplingShader)
            {
                Material samplingMaterial = CoreUtils.CreateEngineMaterial(
                    m_samplingShader);
                m_copyColorPass = new CopyColorPass(
                    RenderPassEvent.BeforeRenderingPostProcessing, samplingMaterial);
            }

            if (m_showTileLightGridShader && m_heatMap)
            {
                m_showDebugTileLightGridMaterial = CoreUtils.CreateEngineMaterial(
                    m_showTileLightGridShader);
                m_showDebugTileLightGridMaterial.SetTexture("_HeatMap", m_heatMap);
                m_showLightGridsPass = new ShowLightGridsPass(m_showDebugTileLightGridMaterial);
            }
            m_backgroundRT.Init("_BackGroundRT");
        }
Example #14
0
        public override void OnEnable()
        {
            base.OnEnable();

            m_EnableLuxIntensityMode = true;

            // HDRI sky does not have control over sun display.
            m_CommonUIElementsMask = 0xFFFFFFFF & ~(uint)(SkySettingsUIElement.IncludeSunInBaking);

            var o = new PropertyFetcher <HDRISky>(serializedObject);

            m_hdriSky = Unpack(o.Find(x => x.hdriSky));
            m_UpperHemisphereLuxValue = Unpack(o.Find(x => x.upperHemisphereLuxValue));
            m_UpperHemisphereLuxColor = Unpack(o.Find(x => x.upperHemisphereLuxColor));

            m_EnableCloudMotion   = Unpack(o.Find(x => x.enableDistortion));
            m_Procedural          = Unpack(o.Find(x => x.procedural));
            m_Flowmap             = Unpack(o.Find(x => x.flowmap));
            m_UpperHemisphereOnly = Unpack(o.Find(x => x.upperHemisphereOnly));
            m_ScrollDirection     = Unpack(o.Find(x => x.scrollDirection));
            m_ScrollSpeed         = Unpack(o.Find(x => x.scrollSpeed));

            m_EnableBackplate    = Unpack(o.Find(x => x.enableBackplate));
            m_BackplateType      = Unpack(o.Find(x => x.backplateType));
            m_GroundLevel        = Unpack(o.Find(x => x.groundLevel));
            m_Scale              = Unpack(o.Find(x => x.scale));
            m_ProjectionDistance = Unpack(o.Find(x => x.projectionDistance));
            m_PlateRotation      = Unpack(o.Find(x => x.plateRotation));
            m_PlateTexRotation   = Unpack(o.Find(x => x.plateTexRotation));
            m_PlateTexOffset     = Unpack(o.Find(x => x.plateTexOffset));
            m_BlendAmount        = Unpack(o.Find(x => x.blendAmount));
            m_PointLightShadow   = Unpack(o.Find(x => x.pointLightShadow));
            m_DirLightShadow     = Unpack(o.Find(x => x.dirLightShadow));
            m_RectLightShadow    = Unpack(o.Find(x => x.rectLightShadow));
            m_ShadowTint         = Unpack(o.Find(x => x.shadowTint));

            m_IntensityTexture = RTHandles.Alloc(1, 1, colorFormat: GraphicsFormat.R32G32B32A32_SFloat);
            var hdrp = HDRenderPipeline.defaultAsset;

            if (hdrp != null)
            {
                m_IntegrateHDRISkyMaterial = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.shaders.integrateHdriSkyPS);
            }
            m_ReadBackTexture = new Texture2D(1, 1, GraphicsFormat.R32G32B32A32_SFloat, TextureCreationFlags.None);
        }
Example #15
0
        public void Initialize(CommandBuffer cmd)
        {
            if (!m_ComputeGgxIblSampleDataCS)
            {
                m_ComputeGgxIblSampleDataCS     = m_RenderPipelineResources.computeGgxIblSampleData;
                m_ComputeGgxIblSampleDataKernel = m_ComputeGgxIblSampleDataCS.FindKernel("ComputeGgxIblSampleData");
            }

            if (!m_BuildProbabilityTablesCS)
            {
                m_BuildProbabilityTablesCS   = m_RenderPipelineResources.buildProbabilityTables;
                m_ConditionalDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeConditionalDensities");
                m_MarginalRowDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeMarginalRowDensities");
            }

            if (!m_GgxConvolveMaterial)
            {
                m_GgxConvolveMaterial = CoreUtils.CreateEngineMaterial(m_RenderPipelineResources.GGXConvolve);
            }

            if (!m_GgxIblSampleData)
            {
                m_GgxIblSampleData                   = new RenderTexture(m_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
                m_GgxIblSampleData.useMipMap         = false;
                m_GgxIblSampleData.autoGenerateMips  = false;
                m_GgxIblSampleData.enableRandomWrite = true;
                m_GgxIblSampleData.filterMode        = FilterMode.Point;
                m_GgxIblSampleData.name              = CoreUtils.GetRenderTargetAutoName(m_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 1, RenderTextureFormat.ARGBHalf, "GGXIblSampleData");
                m_GgxIblSampleData.hideFlags         = HideFlags.HideAndDontSave;
                m_GgxIblSampleData.Create();

                m_ComputeGgxIblSampleDataCS.SetTexture(m_ComputeGgxIblSampleDataKernel, "output", m_GgxIblSampleData);

                using (new ProfilingSample(cmd, "Compute GGX IBL Sample Data"))
                {
                    cmd.DispatchCompute(m_ComputeGgxIblSampleDataCS, m_ComputeGgxIblSampleDataKernel, 1, 1, 1);
                }
            }

            for (int i = 0; i < 6; ++i)
            {
                var lookAt = Matrix4x4.LookAt(Vector3.zero, CoreUtils.lookAtList[i], CoreUtils.upVectorList[i]);
                m_faceWorldToViewMatrixMatrices[i] = lookAt * Matrix4x4.Scale(new Vector3(1.0f, 1.0f, -1.0f)); // Need to scale -1.0 on Z to match what is being done in the camera.wolrdToCameraMatrix API. ...
            }
        }
Example #16
0
    // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
    // When empty this render pass will render to the active camera render target.
    // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
    // The render pipeline will ensure target setup and clearing happens in an performance manner.
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
        Debug.Log("Alloc !");
        blurMaterial        = CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/FullScreen/BlurPasses"));
        compositingMaterial = CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/FullScreen/LiquidCompositing"));

        shaderTags = new ShaderTagId[4]
        {
            new ShaderTagId("Forward"),
            new ShaderTagId("ForwardOnly"),
            new ShaderTagId("SRPDefaultUnlit"),
            new ShaderTagId("FirstPass"),
        };

        // Allocate the buffers used for the blur in half resolution to save some memory
        downSampleBuffer = RTHandles.Alloc(
            Vector2.one * 0.5f, TextureXR.slices, dimension: TextureXR.dimension,
            colorFormat: GraphicsFormat.R16G16B16A16_SNorm,
            useDynamicScale: true, name: "DownSampleBuffer"
            );

        blurBuffer = RTHandles.Alloc(
            Vector2.one * 0.5f, TextureXR.slices, dimension: TextureXR.dimension,
            colorFormat: GraphicsFormat.R16G16B16A16_SNorm,
            useDynamicScale: true, name: "BlurBuffer"
            );

        targetColorBuffer = TargetBuffer.Custom;
        targetDepthBuffer = TargetBuffer.Custom;
        clearFlags        = ClearFlag.All;

        quad = new Mesh();
        quad.SetVertices(new List <Vector3> {
            new Vector3(-1, -1, 0),
            new Vector3(1, -1, 0),
            new Vector3(-1, 1, 0),
            new Vector3(1, 1, 0),
        });
        quad.SetTriangles(new List <int> {
            0, 3, 1, 0, 2, 3
        }, 0);
        quad.RecalculateBounds();

        quad.UploadMeshData(false);
    }
        public LightweightShadowPass(LightweightPipelineAsset pipelineAsset, int maxLocalLightsCount)
        {
            BuildShadowSettings(pipelineAsset);

            m_DirectionalShadowMatrices = new Matrix4x4[kMaxCascades + 1];
            m_CascadeSlices             = new ShadowSliceData[kMaxCascades];
            m_CascadeSplitDistances     = new Vector4[kMaxCascades];

            m_LocalShadowMatrices = new Matrix4x4[maxLocalLightsCount];
            m_LocalLightSlices    = new ShadowSliceData[maxLocalLightsCount];
            m_LocalShadowStrength = new float[maxLocalLightsCount];

            DirectionalShadowConstantBuffer._WorldToShadow             = Shader.PropertyToID("_WorldToShadow");
            DirectionalShadowConstantBuffer._ShadowData                = Shader.PropertyToID("_ShadowData");
            DirectionalShadowConstantBuffer._DirShadowSplitSpheres     = Shader.PropertyToID("_DirShadowSplitSpheres");
            DirectionalShadowConstantBuffer._DirShadowSplitSphereRadii = Shader.PropertyToID("_DirShadowSplitSphereRadii");
            DirectionalShadowConstantBuffer._ShadowOffset0             = Shader.PropertyToID("_ShadowOffset0");
            DirectionalShadowConstantBuffer._ShadowOffset1             = Shader.PropertyToID("_ShadowOffset1");
            DirectionalShadowConstantBuffer._ShadowOffset2             = Shader.PropertyToID("_ShadowOffset2");
            DirectionalShadowConstantBuffer._ShadowOffset3             = Shader.PropertyToID("_ShadowOffset3");
            DirectionalShadowConstantBuffer._ShadowmapSize             = Shader.PropertyToID("_ShadowmapSize");

            LocalShadowConstantBuffer._LocalWorldToShadowAtlas = Shader.PropertyToID("_LocalWorldToShadowAtlas");
            LocalShadowConstantBuffer._LocalShadowStrength     = Shader.PropertyToID("_LocalShadowStrength");
            LocalShadowConstantBuffer._LocalShadowOffset0      = Shader.PropertyToID("_LocalShadowOffset0");
            LocalShadowConstantBuffer._LocalShadowOffset1      = Shader.PropertyToID("_LocalShadowOffset1");
            LocalShadowConstantBuffer._LocalShadowOffset2      = Shader.PropertyToID("_LocalShadowOffset2");
            LocalShadowConstantBuffer._LocalShadowOffset3      = Shader.PropertyToID("_LocalShadowOffset3");
            LocalShadowConstantBuffer._LocalShadowmapSize      = Shader.PropertyToID("_LocalShadowmapSize");

            m_DirectionalShadowmapID      = Shader.PropertyToID("_ShadowMap");
            m_LocalShadowmapID            = Shader.PropertyToID("_LocalShadowMapAtlas");
            m_ScreenSpaceShadowmapID      = Shader.PropertyToID("_ScreenSpaceShadowMap");
            m_ScreenSpaceShadowmapTexture = new RenderTargetIdentifier(m_ScreenSpaceShadowmapID);

            m_DirectionalShadowmapDescriptor = new RenderTextureDescriptor(m_ShadowSettings.directionalShadowAtlasWidth,
                                                                           m_ShadowSettings.directionalShadowAtlasHeight, m_ShadowSettings.shadowmapTextureFormat, m_ShadowSettings.bufferBitCount);

            m_LocalShadowmapDescriptor = new RenderTextureDescriptor(m_ShadowSettings.localShadowAtlasWidth,
                                                                     m_ShadowSettings.localShadowAtlasHeight, m_ShadowSettings.shadowmapTextureFormat, m_ShadowSettings.bufferBitCount);

            m_ScreenSpaceShadowsMaterial = CoreUtils.CreateEngineMaterial(pipelineAsset.ScreenSpaceShadowShader);

            Clear();
        }
        void InitializePrepass(HDRenderPipelineAsset hdAsset)
        {
            m_DepthResolveMaterial = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.shaders.depthValuesPS);

            m_GBufferOutput     = new GBufferOutput();
            m_GBufferOutput.mrt = new TextureHandle[RenderGraph.kMaxMRTCount];

            m_DBufferOutput     = new DBufferOutput();
            m_DBufferOutput.mrt = new TextureHandle[(int)Decal.DBufferMaterial.Count];

            m_DepthBufferMipChainInfo = new HDUtils.PackedMipChainInfo();
            m_DepthBufferMipChainInfo.Allocate();

            m_DepthPyramidDesc = new TextureDesc(ComputeDepthBufferMipChainSize, true, true)
            {
                colorFormat = GraphicsFormat.R32_SFloat, enableRandomWrite = true, name = "CameraDepthBufferMipChain"
            };
        }
Example #19
0
        public void InitData(RenderPipelineResources renderPipelineResources)
        {
            m_DebugLightVolumeMaterial       = CoreUtils.CreateEngineMaterial(renderPipelineResources.shaders.debugLightVolumePS);
            m_DebugLightVolumeCompute        = renderPipelineResources.shaders.debugLightVolumeCS;
            m_DebugLightVolumeGradientKernel = m_DebugLightVolumeCompute.FindKernel("LightVolumeGradient");
            m_DebugLightVolumeColorsKernel   = m_DebugLightVolumeCompute.FindKernel("LightVolumeColors");
            m_ColorGradientTexture           = renderPipelineResources.textures.colorGradient;

            m_Blit = CoreUtils.CreateEngineMaterial(renderPipelineResources.shaders.blitPS);

            m_LightCountBuffer         = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R32_SFloat, enableRandomWrite: false, useMipMap: false, xrInstancing: true, name: "LightVolumeCount");
            m_ColorAccumulationBuffer  = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: false, useMipMap: false, xrInstancing: true, name: "LightVolumeColorAccumulation");
            m_DebugLightVolumesTexture = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useMipMap: false, xrInstancing: true, name: "LightVolumeDebugLightVolumesTexture");
            m_DepthBuffer = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.None, colorFormat: GraphicsFormat.R8_UNorm, filterMode: FilterMode.Point, xrInstancing: true, name: "LightVolumeDepth");
            // Fill the render target array
            m_RTIDs[0] = m_LightCountBuffer;
            m_RTIDs[1] = m_ColorAccumulationBuffer;
        }
Example #20
0
        internal void InitializeXRSystemData(XRSystemData data)
        {
            if (data)
            {
                if (occlusionMeshMaterial != null)
                {
                    CoreUtils.Destroy(occlusionMeshMaterial);
                }

                if (mirrorViewMaterial != null)
                {
                    CoreUtils.Destroy(mirrorViewMaterial);
                }

                occlusionMeshMaterial = CoreUtils.CreateEngineMaterial(data.shaders.xrOcclusionMeshPS);
                mirrorViewMaterial    = CoreUtils.CreateEngineMaterial(data.shaders.xrMirrorViewPS);
            }
        }
        void InitializeSubsurfaceScattering()
        {
            // Disney SSS (compute + combine)
            string kernelName     = asset.currentPlatformRenderPipelineSettings.increaseSssSampleCount ? "SubsurfaceScatteringHQ" : "SubsurfaceScatteringMQ";
            string kernelNameMSAA = asset.currentPlatformRenderPipelineSettings.increaseSssSampleCount ? "SubsurfaceScatteringHQ_MSAA" : "SubsurfaceScatteringMQ_MSAA";

            m_SubsurfaceScatteringCS         = defaultResources.shaders.subsurfaceScatteringCS;
            m_SubsurfaceScatteringKernel     = m_SubsurfaceScatteringCS.FindKernel(kernelName);
            m_SubsurfaceScatteringKernelMSAA = m_SubsurfaceScatteringCS.FindKernel(kernelNameMSAA);
            m_CombineLightingPass            = CoreUtils.CreateEngineMaterial(defaultResources.shaders.combineLightingPS);
            m_CombineLightingPass.SetInt(HDShaderIDs._StencilMask, (int)HDRenderPipeline.StencilBitMask.LightingMask);

            m_SSSCopyStencilForSplitLighting = CoreUtils.CreateEngineMaterial(defaultResources.shaders.copyStencilBufferPS);
            m_SSSCopyStencilForSplitLighting.SetInt(HDShaderIDs._StencilRef, (int)StencilLightingUsage.SplitLighting);
            m_SSSCopyStencilForSplitLighting.SetInt(HDShaderIDs._StencilMask, (int)HDRenderPipeline.StencilBitMask.LightingMask);

            m_SSSDefaultDiffusionProfile = defaultResources.assets.defaultDiffusionProfile;
        }
Example #22
0
        public OverdrawPass(string profilerTag, RenderQueueRange renderQueueRange, Shader shader, bool isOpaque)
        {
            this.profilerTag = profilerTag;
            this.isOpaque    = isOpaque;

#if UNITY_2020_2_OR_NEWER
            profilingSampler = new ProfilingSampler(nameof(OverdrawPass));
            sampler          = new ProfilingSampler(profilerTag);
#else
            profilingSampler = new ProfilingSampler(profilerTag);
#endif
            tagIdList.Add(new ShaderTagId("UniversalForward"));
            tagIdList.Add(new ShaderTagId("LightweightForward"));
            tagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
            filteringSettings = new FilteringSettings(renderQueueRange, LayerMask.NameToLayer("Everything"));

            material = CoreUtils.CreateEngineMaterial(shader);
        }
Example #23
0
            public void Setup(Shader shader, ScriptableRenderer renderer, RenderingData renderingData)
            {
                if (material == null)
                {
                    material = CoreUtils.CreateEngineMaterial(shader);
                }

#if !URP_10_0_0_OR_NEWER
                source     = renderer.cameraColorTarget;
                cameraData = renderingData.cameraData;

                // Configures where the render pass should be injected.
                FetchVolumeComponent();
                renderPassEvent = hbao.debugMode.value == HBAO.DebugMode.Disabled ?
                                  RenderPassEvent.BeforeRenderingTransparents :
                                  RenderPassEvent.AfterRenderingTransparents;
#endif
            }
Example #24
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),
            };

            postProcessingContext = new PostProcessRenderContext();
        }
        public ForwardRendererSetup(ForwardRendererData data)
        {
            Material blitMaterial               = CoreUtils.CreateEngineMaterial(data.blitShader);
            Material copyDepthMaterial          = CoreUtils.CreateEngineMaterial(data.copyDepthShader);
            Material samplingMaterial           = CoreUtils.CreateEngineMaterial(data.samplingShader);
            Material screenspaceShadowsMaterial = CoreUtils.CreateEngineMaterial(data.screenSpaceShadowShader);

            m_DepthOnlyPass                       = new DepthOnlyPass();
            m_MainLightShadowCasterPass           = new MainLightShadowCasterPass();
            m_AdditionalLightsShadowCasterPass    = new AdditionalLightsShadowCasterPass();
            m_SetupForwardRenderingPass           = new SetupForwardRenderingPass();
            m_ScreenSpaceShadowResolvePass        = new ScreenSpaceShadowResolvePass(screenspaceShadowsMaterial);
            m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass();
            m_BeginXrRenderingPass                = new BeginXRRenderingPass();
            m_SetupLightweightConstants           = new SetupLightweightConstanstPass();
            m_RenderOpaqueForwardPass             = new RenderOpaqueForwardPass();
            m_OpaquePostProcessPass               = new PostProcessPass();
            m_DrawSkyboxPass                      = new DrawSkyboxPass();
            m_CopyDepthPass                       = new CopyDepthPass(copyDepthMaterial);
            m_CopyColorPass                       = new CopyColorPass(samplingMaterial);
            m_RenderTransparentForwardPass        = new RenderTransparentForwardPass();
            m_PostProcessPass                     = new PostProcessPass();
            m_FinalBlitPass                       = new FinalBlitPass(blitMaterial);
            m_CapturePass        = new CapturePass();
            m_EndXrRenderingPass = new EndXRRenderingPass();

#if UNITY_EDITOR
            m_SceneViewDepthCopyPass  = new SceneViewDepthCopyPass(copyDepthMaterial);
            m_LitGizmoRenderingPass   = new GizmoRenderingPass();
            m_UnlitGizmoRenderingPass = new GizmoRenderingPass();
#endif

            // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
            // Samples (MSAA) depend on camera and pipeline
            m_ColorAttachment.Init("_CameraColorTexture");
            m_ColorAttachmentAfterOpaquePost.Init("_CameraColorTextureAfterOpaquePost");
            m_ColorAttachmentAfterTransparentPost.Init("_CameraColorTextureAfterTransparentPost");
            m_DepthAttachment.Init("_CameraDepthAttachment");
            m_DepthTexture.Init("_CameraDepthTexture");
            m_OpaqueColor.Init("_CameraOpaqueTexture");
            m_MainLightShadowmap.Init("_MainLightShadowmapTexture");
            m_AdditionalLightsShadowmap.Init("_AdditionalLightsShadowmapTexture");
            m_ScreenSpaceShadowmap.Init("_ScreenSpaceShadowmapTexture");
        }
Example #26
0
        // Compute the lux value in the upper hemisphere of the HDRI skybox
        public void GetUpperHemisphereLuxValue()
        {
            // null material can happen when no HDRP asset was present at startup
            if (m_IntegrateHDRISkyMaterial == null)
            {
                if (HDRenderPipeline.isReady)
                {
                    m_IntegrateHDRISkyMaterial = CoreUtils.CreateEngineMaterial(HDRenderPipelineGlobalSettings.instance.renderPipelineResources.shaders.integrateHdriSkyPS);
                }
                else
                {
                    return;
                }
            }

            Cubemap hdri = m_hdriSky.value.objectReferenceValue as Cubemap;

            if (hdri == null)
            {
                return;
            }

            m_IntegrateHDRISkyMaterial.SetTexture(HDShaderIDs._Cubemap, hdri);

            Graphics.Blit(Texture2D.whiteTexture, m_IntensityTexture.rt, m_IntegrateHDRISkyMaterial);

            // Copy the rendertexture containing the lux value inside a Texture2D
            RenderTexture.active = m_IntensityTexture.rt;
            m_ReadBackTexture.ReadPixels(new Rect(0.0f, 0.0f, 1, 1), 0, 0);
            RenderTexture.active = null;

            // And then the value inside this texture
            Color hdriIntensity = m_ReadBackTexture.GetPixel(0, 0);

            m_UpperHemisphereLuxValue.value.floatValue = hdriIntensity.a;
            float max = Mathf.Max(hdriIntensity.r, hdriIntensity.g, hdriIntensity.b);

            if (max == 0.0f)
            {
                max = 1.0f;
            }
            m_UpperHemisphereLuxColor.value.vector3Value  = new Vector3(hdriIntensity.r / max, hdriIntensity.g / max, hdriIntensity.b / max);
            m_UpperHemisphereLuxColor.value.vector3Value *= 0.5f; // Arbitrary 25% to not have too dark or too bright shadow
        }
        public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException("renderer");
            }

            var pass = new CopyColorPass(CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/Lightweight Render Pipeline/Sampling")));

            pass.Setup(colorHandle, afterAll);
            pass.Execute(renderer, context, ref renderingData);

            CommandBuffer cmd = CommandBufferPool.Get("Blit Pass");

            cmd.SetRenderTarget(colorHandle.id, depthHandle.id);
            cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);

            cmd.SetViewport(new Rect(0, renderingData.cameraData.camera.pixelRect.height / 2.0f, renderingData.cameraData.camera.pixelRect.width / 3.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f));
            cmd.SetGlobalTexture("_BlitTex", beforeAll.Identifier());
            ScriptableRenderer.RenderFullscreenQuad(cmd, m_BlitMaterial);

            cmd.SetViewport(new Rect(renderingData.cameraData.camera.pixelRect.width / 3.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f, renderingData.cameraData.camera.pixelRect.width / 3.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f));
            cmd.SetGlobalTexture("_BlitTex", afterOpaque.Identifier());
            ScriptableRenderer.RenderFullscreenQuad(cmd, m_BlitMaterial);

            cmd.SetViewport(new Rect(renderingData.cameraData.camera.pixelRect.width / 3.0f * 2.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f, renderingData.cameraData.camera.pixelRect.width / 3.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f));
            cmd.SetGlobalTexture("_BlitTex", afterOpaquePost.Identifier());
            ScriptableRenderer.RenderFullscreenQuad(cmd, m_BlitMaterial);

            cmd.SetViewport(new Rect(0f, 0f, renderingData.cameraData.camera.pixelRect.width / 3.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f));
            cmd.SetGlobalTexture("_BlitTex", afterSkybox.Identifier());
            ScriptableRenderer.RenderFullscreenQuad(cmd, m_BlitMaterial);

            cmd.SetViewport(new Rect(renderingData.cameraData.camera.pixelRect.width / 3.0f, 0f, renderingData.cameraData.camera.pixelRect.width / 3.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f));
            cmd.SetGlobalTexture("_BlitTex", afterTransparent.Identifier());
            ScriptableRenderer.RenderFullscreenQuad(cmd, m_BlitMaterial);

            cmd.SetViewport(new Rect(renderingData.cameraData.camera.pixelRect.width / 3.0f * 2.0f, 0f, renderingData.cameraData.camera.pixelRect.width / 3.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f));
            cmd.SetGlobalTexture("_BlitTex", afterAll.Identifier());
            ScriptableRenderer.RenderFullscreenQuad(cmd, m_BlitMaterial);

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        public HDShadowManager(int width, int height, int maxShadowRequests, DepthBits atlasDepthBits, Shader clearShader)
        {
            Material clearMaterial = CoreUtils.CreateEngineMaterial(clearShader);

            // Prevent the list from resizing their internal container when we add shadow requests
            m_ShadowDatas.Capacity = maxShadowRequests;
            m_ShadowResolutionRequests.Capacity = maxShadowRequests;
            m_ShadowRequests = new HDShadowRequest[maxShadowRequests];

            // The cascade atlas will be allocated only if there is a directional light
            m_Atlas = new HDShadowAtlas(width, height, HDShaderIDs._ShadowAtlasSize, clearMaterial, depthBufferBits: atlasDepthBits, name: "Shadow Map Atlas");
            // Cascade atlas render texture will only be allocated if there is a shadow casting directional light
            m_CascadeAtlas = new HDShadowAtlas(1, 1, HDShaderIDs._CascadeShadowAtlasSize, clearMaterial, depthBufferBits: atlasDepthBits, name: "Cascade Shadow Map Atlas");

            m_ShadowDataBuffer            = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
            m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));

            m_MaxShadowRequests = maxShadowRequests;
        }
Example #29
0
        public MotionBlurPass(MotionBlurSettings settings)
        {
            this.renderPassEvent        = settings.Event;
            this.isSupportedFloatBuffer = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB2101010);

            this.blitMaterial  = CoreUtils.CreateEngineMaterial(settings.shader);
            this.resetHistory  = true;
            this.triangle      = new Mesh();
            this.triangle.name = "Fullscreen Triangle";
            // Because we have to support older platforms (GLES2/3, DX9 etc) we can't do all of
            // this directly in the vertex shader using vertex ids :(
            this.triangle.SetVertices(new[] {
                new Vector3(-1f, -1f, 0f),
                new Vector3(-1f, 3f, 0f),
                new Vector3(3f, -1f, 0f)
            });
            this.triangle.SetIndices(new[] { 0, 1, 2 }, MeshTopology.Triangles, 0, false);
            this.triangle.UploadMeshData(true);
        }
        protected override void OnEnable()
        {
            base.OnEnable();

            // These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime
            m_ProfileMaterial       = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawSssProfile");
            m_TransmittanceMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawTransmittanceGraph");

            int count = SssConstants.SSS_N_PROFILES - 1;

            m_Profiles = new List <Profile>();

            m_UseDisneySSS = properties.Find(x => x.useDisneySSS);
            var serializedProfiles = properties.Find(x => x.profiles);

            for (int i = 0; i < count; i++)
            {
                var serializedProfile = serializedProfiles.GetArrayElementAtIndex(i);
                var rp = new RelativePropertyFetcher <SubsurfaceScatteringProfile>(serializedProfile);

                var profile = new Profile
                {
                    self         = serializedProfile,
                    objReference = m_Target.profiles[i],

                    name = rp.Find(x => x.name),

                    scatteringDistance = rp.Find(x => x.scatteringDistance),
                    transmissionTint   = rp.Find(x => x.transmissionTint),
                    texturingMode      = rp.Find(x => x.texturingMode),
                    transmissionMode   = rp.Find(x => x.transmissionMode),
                    thicknessRemap     = rp.Find(x => x.thicknessRemap),
                    worldScale         = rp.Find(x => x.worldScale),
                    fresnel0           = rp.Find(x => x.fresnel0),

                    scatterDistance1 = rp.Find(x => x.scatterDistance1),
                    scatterDistance2 = rp.Find(x => x.scatterDistance2),
                    lerpWeight       = rp.Find(x => x.lerpWeight)
                };

                m_Profiles.Add(profile);
            }
        }