Ejemplo n.º 1
0
        public void RenderReflectionsT1(HDCamera hdCamera, CommandBuffer cmd, RTHandleSystem.RTHandle outputTexture, ScriptableRenderContext renderContext, int frameCount)
        {
            // First thing to check is: Do we have a valid ray-tracing environment?
            HDRaytracingEnvironment rtEnvironment  = m_RaytracingManager.CurrentEnvironment();
            HDRenderPipeline        renderPipeline = m_RaytracingManager.GetRenderPipeline();
            BlueNoise        blueNoise             = m_RaytracingManager.GetBlueNoiseManager();
            ComputeShader    reflectionFilter      = m_PipelineAsset.renderPipelineRayTracingResources.reflectionBilateralFilterCS;
            RayTracingShader reflectionShader      = m_PipelineAsset.renderPipelineRayTracingResources.reflectionRaytracing;

            bool invalidState = rtEnvironment == null || blueNoise == null ||
                                reflectionFilter == null || reflectionShader == null ||
                                m_PipelineResources.textures.owenScrambledTex == null || m_PipelineResources.textures.scramblingTex == null;

            // If no acceleration structure available, end it now
            if (invalidState)
            {
                return;
            }

            var          settings             = VolumeManager.instance.stack.GetComponent <ScreenSpaceReflection>();
            LightCluster lightClusterSettings = VolumeManager.instance.stack.GetComponent <LightCluster>();

            // Grab the acceleration structures and the light cluster to use
            RayTracingAccelerationStructure accelerationStructure = m_RaytracingManager.RequestAccelerationStructure(rtEnvironment.reflLayerMask);
            HDRaytracingLightCluster        lightCluster          = m_RaytracingManager.RequestLightCluster(rtEnvironment.reflLayerMask);

            // Compute the actual resolution that is needed base on the quality
            string targetRayGen = m_RayGenHalfResName;

            // Define the shader pass to use for the reflection pass
            cmd.SetRayTracingShaderPass(reflectionShader, "IndirectDXR");

            // Set the acceleration structure for the pass
            cmd.SetRayTracingAccelerationStructure(reflectionShader, HDShaderIDs._RaytracingAccelerationStructureName, accelerationStructure);

            // Inject the ray-tracing sampling data
            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._OwenScrambledTexture, m_PipelineResources.textures.owenScrambledTex);
            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._ScramblingTexture, m_PipelineResources.textures.scramblingTex);

            // Global reflection parameters
            cmd.SetRayTracingFloatParams(reflectionShader, HDShaderIDs._RaytracingIntensityClamp, settings.clampValue.value);
            cmd.SetRayTracingFloatParams(reflectionShader, HDShaderIDs._RaytracingReflectionMinSmoothness, settings.minSmoothness.value);
            cmd.SetRayTracingIntParams(reflectionShader, HDShaderIDs._RaytracingReflectSky, settings.reflectSky.value ? 1 : 0);

            // Inject the ray generation data
            cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rtEnvironment.rayBias);
            cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayMaxLength, settings.rayLength.value);
            cmd.SetRayTracingIntParams(reflectionShader, HDShaderIDs._RaytracingNumSamples, settings.numSamples.value);
            int frameIndex = hdCamera.IsTAAEnabled() ? hdCamera.taaFrameIndex : (int)frameCount % 8;

            cmd.SetGlobalInt(HDShaderIDs._RaytracingFrameIndex, frameIndex);

            // Set the data for the ray generation
            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._SsrLightingTextureRW, m_LightingTexture);
            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._SsrHitPointTexture, m_HitPdfTexture);
            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer());
            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer());

            // Set ray count tex
            cmd.SetRayTracingIntParam(reflectionShader, HDShaderIDs._RayCountEnabled, m_RaytracingManager.rayCountManager.RayCountIsEnabled());
            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._RayCountTexture, m_RaytracingManager.rayCountManager.rayCountTexture);

            // Compute the pixel spread value
            float pixelSpreadAngle = Mathf.Atan(2.0f * Mathf.Tan(hdCamera.camera.fieldOfView * Mathf.PI / 360.0f) / Mathf.Min(hdCamera.actualWidth, hdCamera.actualHeight));

            cmd.SetRayTracingFloatParam(reflectionShader, HDShaderIDs._RaytracingPixelSpreadAngle, pixelSpreadAngle);

            // LightLoop data
            cmd.SetGlobalBuffer(HDShaderIDs._RaytracingLightCluster, lightCluster.GetCluster());
            cmd.SetGlobalBuffer(HDShaderIDs._LightDatasRT, lightCluster.GetLightDatas());
            cmd.SetGlobalVector(HDShaderIDs._MinClusterPos, lightCluster.GetMinClusterPos());
            cmd.SetGlobalVector(HDShaderIDs._MaxClusterPos, lightCluster.GetMaxClusterPos());
            cmd.SetGlobalInt(HDShaderIDs._LightPerCellCount, lightClusterSettings.maxNumLightsPercell.value);
            cmd.SetGlobalInt(HDShaderIDs._PunctualLightCountRT, lightCluster.GetPunctualLightCount());
            cmd.SetGlobalInt(HDShaderIDs._AreaLightCountRT, lightCluster.GetAreaLightCount());

            // Note: Just in case, we rebind the directional light data (in case they were not)
            cmd.SetGlobalBuffer(HDShaderIDs._DirectionalLightDatas, renderPipeline.m_LightLoopLightData.directionalLightData);
            cmd.SetGlobalInt(HDShaderIDs._DirectionalLightCount, renderPipeline.m_lightList.directionalLights.Count);

            // Evaluate the clear coat mask texture based on the lit shader mode
            RenderTargetIdentifier clearCoatMaskTexture = hdCamera.frameSettings.litShaderMode == LitShaderMode.Deferred ? m_GbufferManager.GetBuffersRTI()[2] : TextureXR.GetBlackTexture();

            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._SsrClearCoatMaskTexture, clearCoatMaskTexture);

            // Set the data for the ray miss
            cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._SkyTexture, m_SkyManager.skyReflection);

            // Compute the actual resolution that is needed base on the quality
            uint widthResolution  = (uint)hdCamera.actualWidth / 2;
            uint heightResolution = (uint)hdCamera.actualHeight / 2;

            // Force to disable specular lighting
            cmd.SetGlobalInt(HDShaderIDs._EnableSpecularLighting, 0);

            // Run the computation
            cmd.DispatchRays(reflectionShader, targetRayGen, widthResolution, heightResolution, 1);

            // Restore the previous state of specular lighting
            cmd.SetGlobalInt(HDShaderIDs._EnableSpecularLighting, hdCamera.frameSettings.IsEnabled(FrameSettingsField.SpecularLighting) ? 1 : 0);

            using (new ProfilingSample(cmd, "Filter Reflection", CustomSamplerId.RaytracingFilterReflection.GetSampler()))
            {
                // Fetch the right filter to use
                int currentKernel = reflectionFilter.FindKernel("RaytracingReflectionFilter");

                // Inject all the parameters for the compute
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._SsrLightingTextureRW, m_LightingTexture);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._SsrHitPointTexture, m_HitPdfTexture);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer());
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer());
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, "_NoiseTexture", blueNoise.textureArray16RGB);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, "_VarianceTexture", m_VarianceBuffer);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, "_MinColorRangeTexture", m_MinBoundBuffer);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, "_MaxColorRangeTexture", m_MaxBoundBuffer);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, "_RaytracingReflectionTexture", outputTexture);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._ScramblingTexture, m_PipelineResources.textures.scramblingTex);
                cmd.SetComputeIntParam(reflectionFilter, HDShaderIDs._SpatialFilterRadius, settings.spatialFilterRadius.value);
                cmd.SetComputeFloatParam(reflectionFilter, HDShaderIDs._RaytracingReflectionMinSmoothness, settings.minSmoothness.value);

                // Texture dimensions
                int texWidth  = outputTexture.rt.width;
                int texHeight = outputTexture.rt.height;

                // Evaluate the dispatch parameters
                int areaTileSize = 8;
                int numTilesXHR  = (texWidth + (areaTileSize - 1)) / areaTileSize;
                int numTilesYHR  = (texHeight + (areaTileSize - 1)) / areaTileSize;

                // Bind the right texture for clear coat support
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._SsrClearCoatMaskTexture, clearCoatMaskTexture);

                // Compute the texture
                cmd.DispatchCompute(reflectionFilter, currentKernel, numTilesXHR, numTilesYHR, 1);

                int numTilesXFR = (texWidth + (areaTileSize - 1)) / areaTileSize;
                int numTilesYFR = (texHeight + (areaTileSize - 1)) / areaTileSize;

                RTHandleSystem.RTHandle history = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedReflection)
                                                  ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedReflection, ReflectionHistoryBufferAllocatorFunction, 1);

                // Fetch the right filter to use
                currentKernel = reflectionFilter.FindKernel("TemporalAccumulationFilter");
                cmd.SetComputeFloatParam(reflectionFilter, HDShaderIDs._TemporalAccumuationWeight, settings.temporalAccumulationWeight.value);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._AccumulatedFrameTexture, history);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._CurrentFrameTexture, outputTexture);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, "_MinColorRangeTexture", m_MinBoundBuffer);
                cmd.SetComputeTextureParam(reflectionFilter, currentKernel, "_MaxColorRangeTexture", m_MaxBoundBuffer);
                cmd.DispatchCompute(reflectionFilter, currentKernel, numTilesXFR, numTilesYFR, 1);
            }
        }
 public void setup(RenderTargetIdentifier source)
 {
     this.Sour = source;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Configure the pass with the source and destination to execute on.
 /// </summary>
 /// <param name="source">Source Render Target</param>
 /// <param name="destination">Destination Render Target</param>
 public void Setup(RenderTargetIdentifier source, UnityEngine.Rendering.Universal.RenderTargetHandle destination, RenderTexture setTexTo)
 {
     this.source       = source;
     this.destination  = destination;
     this.setMainTexTo = setTexTo;
 }
 public static void CopyDepthTexture(this CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material mat, int pass = 0, bool clear = false)
 {
     cmd.SetGlobalTexture(ShaderIDs.CameraDepthBuffer, source);
     cmd.SetRenderTarget(dest, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
     if (clear)
     {
         cmd.ClearRenderTarget(true, true, Color.clear);
     }
     cmd.DrawMesh(fullScreenTriangle, Matrix4x4.identity, mat, 0, pass);
 }
Ejemplo n.º 5
0
            public void ProcessImage(PostProcessingContext context, CommandBuffer cb, ref Settings settings, RenderTargetIdentifier source, RenderTargetIdentifier destination, Material material)
            {
                const float kMaxBlurRadius = 5f;

                // Calculate the maximum blur radius in pixels.
                int maxBlurPixels = (int)(kMaxBlurRadius * context.height / 100);

                // Calculate the TileMax size.
                // It should be a multiple of 8 and larger than maxBlur.
                int tileSize = ((maxBlurPixels - 1) / 8 + 1) * 8;

                // Pass 1 - Velocity/depth packing
                // Motion vectors are scaled by an empirical factor of 1.45.
                var velocityScale = settings.shutterAngle / 360f * 1.45f;

                cb.SetGlobalFloat(Uniforms._VelocityScale, velocityScale);
                cb.SetGlobalFloat(Uniforms._MaxBlurRadius, maxBlurPixels);

                int vbuffer = Uniforms._VelocityTex;

                cb.GetTemporaryRT(vbuffer, context.width, context.height, 0, FilterMode.Point, m_PackedRTFormat, RenderTextureReadWrite.Linear);
                cb.Blit((Texture)null, vbuffer, material, (int)Pass.VelocitySetup);

                // Pass 2 - First TileMax filter (1/4 downsize)
                int tile4 = Uniforms._Tile4RT;

                cb.GetTemporaryRT(tile4, context.width / 4, context.height / 4, 0, FilterMode.Point, m_VectorRTFormat, RenderTextureReadWrite.Linear);
                cb.SetGlobalTexture(Uniforms._MainTex, vbuffer);
                cb.Blit(vbuffer, tile4, material, (int)Pass.TileMax4);

                // Pass 3 - Second TileMax filter (1/2 downsize)
                int tile8 = Uniforms._Tile8RT;

                cb.GetTemporaryRT(tile8, context.width / 8, context.height / 8, 0, FilterMode.Point, m_VectorRTFormat, RenderTextureReadWrite.Linear);
                cb.SetGlobalTexture(Uniforms._MainTex, tile4);
                cb.Blit(tile4, tile8, material, (int)Pass.TileMax2);
                cb.ReleaseTemporaryRT(tile4);

                // Pass 4 - Third TileMax filter (reduce to tileSize)
                var tileMaxOffs = Vector2.one * (tileSize / 8f - 1f) * -0.5f;

                cb.SetGlobalVector(Uniforms._TileMaxOffs, tileMaxOffs);
                cb.SetGlobalFloat(Uniforms._TileMaxLoop, (int)(tileSize / 8f));

                int tile = Uniforms._TileVRT;

                cb.GetTemporaryRT(tile, context.width / tileSize, context.height / tileSize, 0, FilterMode.Point, m_VectorRTFormat, RenderTextureReadWrite.Linear);
                cb.SetGlobalTexture(Uniforms._MainTex, tile8);
                cb.Blit(tile8, tile, material, (int)Pass.TileMaxV);
                cb.ReleaseTemporaryRT(tile8);

                // Pass 5 - NeighborMax filter
                int neighborMax       = Uniforms._NeighborMaxTex;
                int neighborMaxWidth  = context.width / tileSize;
                int neighborMaxHeight = context.height / tileSize;

                cb.GetTemporaryRT(neighborMax, neighborMaxWidth, neighborMaxHeight, 0, FilterMode.Point, m_VectorRTFormat, RenderTextureReadWrite.Linear);
                cb.SetGlobalTexture(Uniforms._MainTex, tile);
                cb.Blit(tile, neighborMax, material, (int)Pass.NeighborMax);
                cb.ReleaseTemporaryRT(tile);

                // Pass 6 - Reconstruction pass
                cb.SetGlobalFloat(Uniforms._LoopCount, Mathf.Clamp(settings.sampleCount / 2, 1, 64));
                cb.SetGlobalFloat(Uniforms._MaxBlurRadius, maxBlurPixels);
                cb.SetGlobalTexture(Uniforms._MainTex, source);

                cb.Blit(source, destination, material, m_UseUnrolledShader ? (int)Pass.ReconstructionUnroll : (int)Pass.Reconstruction);

                cb.ReleaseTemporaryRT(vbuffer);
                cb.ReleaseTemporaryRT(neighborMax);
            }
Ejemplo n.º 6
0
        static private void RenderShadows(CommandBuffer cmdBuffer, int layerToRender, Light2D light, float shadowIntensity, RenderTargetIdentifier renderTexture)
        {
            // Render light's shadows
            cmdBuffer.SetRenderTarget(s_ShadowsRenderTarget.Identifier()); // This isn't efficient if this light doesn't cast shadow.
            cmdBuffer.ClearRenderTarget(true, true, Color.black);

            cmdBuffer.SetGlobalFloat("_ShadowIntensity", 1 - light.shadowIntensity);
            cmdBuffer.SetGlobalFloat("_ShadowVolumeIntensity", 1 - light.shadowVolumeIntensity);

            // TODO: We need an alternate (more efficient) code path if the light has a shadowIntensity of 0
            if (shadowIntensity > 0)
            {
                BoundingSphere lightBounds = light.GetBoundingSphere(); // Gets the local bounding sphere...

                cmdBuffer.SetGlobalVector("_LightPos", light.transform.position);
                cmdBuffer.SetGlobalFloat("_LightRadius", lightBounds.radius);

                Material shadowMaterial                       = GetShadowMaterial(1);
                Material removeSelfShadowMaterial             = GetRemoveSelfShadowMaterial(1);
                List <ShadowCasterGroup2D> shadowCasterGroups = ShadowCasterGroup2DManager.shadowCasterGroups;
                if (shadowCasterGroups != null && shadowCasterGroups.Count > 0)
                {
                    int previousShadowGroupIndex = -1;
                    int incrementingGroupIndex   = 0;
                    for (int group = 0; group < shadowCasterGroups.Count; group++)
                    {
                        ShadowCasterGroup2D shadowCasterGroup = shadowCasterGroups[group];

                        List <ShadowCaster2D> shadowCasters = shadowCasterGroup.GetShadowCasters();

                        int shadowGroupIndex = shadowCasterGroup.GetShadowGroup();
                        if (LightUtility.CheckForChange(shadowGroupIndex, ref previousShadowGroupIndex) || shadowGroupIndex == 0)
                        {
                            incrementingGroupIndex++;
                            shadowMaterial           = GetShadowMaterial(incrementingGroupIndex);
                            removeSelfShadowMaterial = GetRemoveSelfShadowMaterial(incrementingGroupIndex);
                        }

                        if (shadowCasters != null)
                        {
                            // Draw the shadow casting group first, then draw the silhouttes..
                            for (int i = 0; i < shadowCasters.Count; i++)
                            {
                                ShadowCaster2D shadowCaster = (ShadowCaster2D)shadowCasters[i];

                                if (shadowCaster != null && shadowMaterial != null && shadowCaster.IsShadowedLayer(layerToRender))
                                {
                                    if (shadowCaster.castsShadows)
                                    {
                                        cmdBuffer.DrawMesh(shadowCaster.mesh, shadowCaster.transform.localToWorldMatrix, shadowMaterial);
                                    }
                                }
                            }

                            for (int i = 0; i < shadowCasters.Count; i++)
                            {
                                ShadowCaster2D shadowCaster = (ShadowCaster2D)shadowCasters[i];

                                if (shadowCaster != null && shadowMaterial != null && shadowCaster.IsShadowedLayer(layerToRender))
                                {
                                    if (shadowCaster.useRendererSilhouette)
                                    {
                                        Renderer renderer = shadowCaster.GetComponent <Renderer>();
                                        if (renderer != null)
                                        {
                                            if (!shadowCaster.selfShadows)
                                            {
                                                cmdBuffer.DrawRenderer(renderer, removeSelfShadowMaterial);
                                            }
                                            else
                                            {
                                                cmdBuffer.DrawRenderer(renderer, shadowMaterial, 0, 1);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (!shadowCaster.selfShadows)
                                        {
                                            Matrix4x4 meshMat = shadowCaster.transform.localToWorldMatrix;
                                            cmdBuffer.DrawMesh(shadowCaster.mesh, meshMat, removeSelfShadowMaterial);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            cmdBuffer.SetRenderTarget(renderTexture);
        }
Ejemplo n.º 7
0
        static private void RenderLightVolumeSet(Camera camera, int blendStyleIndex, CommandBuffer cmdBuffer, int layerToRender, RenderTargetIdentifier renderTexture, List <Light2D> lights)
        {
            if (lights.Count > 0)
            {
                for (int i = 0; i < lights.Count; i++)
                {
                    Light2D light = lights[i];

                    int topMostLayer = light.GetTopMostLitLayer();
                    if (layerToRender == topMostLayer)
                    {
                        if (light != null && light.lightType != Light2D.LightType.Global && light.volumeOpacity > 0.0f && light.blendStyleIndex == blendStyleIndex && light.IsLitLayer(layerToRender) && light.IsLightVisible(camera))
                        {
                            Material lightVolumeMaterial = GetLightMaterial(light, true);
                            if (lightVolumeMaterial != null)
                            {
                                Mesh lightMesh = light.GetMesh();
                                if (lightMesh != null)
                                {
                                    RenderShadows(cmdBuffer, layerToRender, light, light.shadowVolumeIntensity, renderTexture);

                                    if (light.lightType == Light2D.LightType.Sprite && light.lightCookieSprite != null && light.lightCookieSprite.texture != null)
                                    {
                                        cmdBuffer.SetGlobalTexture("_CookieTex", light.lightCookieSprite.texture);
                                    }

                                    cmdBuffer.SetGlobalFloat("_FalloffIntensity", light.falloffIntensity);
                                    cmdBuffer.SetGlobalFloat("_FalloffDistance", light.shapeLightFalloffSize);
                                    cmdBuffer.SetGlobalVector("_FalloffOffset", light.shapeLightFalloffOffset);
                                    cmdBuffer.SetGlobalColor("_LightColor", light.intensity * light.color);
                                    cmdBuffer.SetGlobalFloat("_VolumeOpacity", light.volumeOpacity);

                                    // Is this needed
                                    if (light.useNormalMap || light.lightType == Light2D.LightType.Point)
                                    {
                                        RendererLighting.SetPointLightShaderGlobals(cmdBuffer, light);
                                    }

                                    // Could be combined...
                                    if (light.lightType == Light2D.LightType.Parametric || light.lightType == Light2D.LightType.Freeform || light.lightType == Light2D.LightType.Sprite)
                                    {
                                        cmdBuffer.DrawMesh(lightMesh, light.transform.localToWorldMatrix, lightVolumeMaterial);
                                    }
                                    else if (light.lightType == Light2D.LightType.Point)
                                    {
                                        Vector3   scale  = new Vector3(light.pointLightOuterRadius, light.pointLightOuterRadius, light.pointLightOuterRadius);
                                        Matrix4x4 matrix = Matrix4x4.TRS(light.transform.position, Quaternion.identity, scale);
                                        cmdBuffer.DrawMesh(lightMesh, matrix, lightVolumeMaterial);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd)
        {
            using (new Utilities.ProfilingSample("Sky Pass", cmd))
            {
                if (IsSkyValid())
                {
                    m_BuiltinParameters.commandBuffer     = cmd;
                    m_BuiltinParameters.sunLight          = sunLight;
                    m_BuiltinParameters.invViewProjMatrix = camera.viewProjMatrix.inverse;
                    m_BuiltinParameters.cameraPosWS       = camera.camera.transform.position;
                    m_BuiltinParameters.screenSize        = camera.screenSize;
                    m_BuiltinParameters.skyMesh           = BuildSkyMesh(camera.camera.GetComponent <Transform>().position, m_BuiltinParameters.invViewProjMatrix);
                    m_BuiltinParameters.colorBuffer       = colorBuffer;
                    m_BuiltinParameters.depthBuffer       = depthBuffer;

                    m_Renderer.SetRenderTargets(m_BuiltinParameters);
                    m_Renderer.RenderSky(m_BuiltinParameters, skySettings, false);
                }
            }
        }
Ejemplo n.º 9
0
        public static void RenderPostProcess(CommandBuffer cmd, PostProcessRenderContext context, ref CameraData cameraData, RenderTextureFormat colorFormat, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool opaqueOnly)
        {
            context.Reset();
            context.camera       = cameraData.camera;
            context.source       = source;
            context.sourceFormat = colorFormat;
            context.destination  = dest;
            context.command      = cmd;
            context.flip         = cameraData.camera.targetTexture == null;

            if (opaqueOnly)
            {
                cameraData.postProcessLayer.RenderOpaqueOnly(context);
            }
            else
            {
                cameraData.postProcessLayer.Render(context);
            }
        }
Ejemplo n.º 10
0
 void DoColorCorrect(RenderTargetIdentifier source, RenderTargetIdentifier dest)
 {
     Draw(source, dest, Pass.ColorCorrect);
 }
Ejemplo n.º 11
0
 void DoGrayscale(RenderTargetIdentifier source, RenderTargetIdentifier dest)
 {
     Draw(source, dest, Pass.Grayscale);
 }
Ejemplo n.º 12
0
 public void Prepare(RenderTargetIdentifier ping, RenderTargetIdentifier pong)
 {
     _ping = ping;
     _pong = pong;
 }
Ejemplo n.º 13
0
        public void DrawTerrain(ref RenderClusterOptions ops, Material terrainMat, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer)
        {
            if (referenceBuffer.Length <= 0)
            {
                return;
            }
            ComputeShader sh = ops.terrainCompute;
            CommandBuffer bf = ops.command;

            bf.SetComputeBufferParam(sh, frustumCullKernel, ShaderIDs.clusterBuffer, clusterBuffer);
            bf.SetComputeBufferParam(sh, frustumCullKernel, ShaderIDs.resultBuffer, resultBuffer);
            bf.SetComputeBufferParam(sh, frustumCullKernel, ShaderIDs.instanceCountBuffer, instanceCountBuffer);
            bf.SetComputeBufferParam(sh, clearCullKernel, ShaderIDs.instanceCountBuffer, instanceCountBuffer);
            bf.SetComputeVectorArrayParam(sh, ShaderIDs.planes, ops.frustumPlanes);
            bf.SetGlobalInt(ShaderIDs._MeshSize, meshSize);
            bf.DispatchCompute(sh, clearCullKernel, 1, 1, 1);
            ComputeShaderUtility.Dispatch(sh, bf, frustumCullKernel, referenceBuffer.Length, 64);
            bf.SetGlobalBuffer(ShaderIDs.heightMapBuffer, heightMapBuffer);
            bf.SetGlobalBuffer(ShaderIDs.triangleBuffer, triangleBuffer);
            bf.SetGlobalBuffer(ShaderIDs.verticesBuffer, verticesBuffer);
            bf.SetGlobalBuffer(ShaderIDs.clusterBuffer, clusterBuffer);
            bf.SetGlobalBuffer(ShaderIDs.resultBuffer, resultBuffer);
            bf.SetRenderTarget(colorBuffer, depthBuffer);
            bf.DrawProceduralIndirect(Matrix4x4.identity, terrainMat, 0, MeshTopology.Triangles, instanceCountBuffer);
        }
    private void renderDeferredShading()
    {
        CommandBuffer _bufA = null;
        CameraEvent   _evA  = CameraEvent.AfterForwardOpaque;

        if (this.m_cameraCommandBuffers.ContainsKey(_evA))
        {
            _bufA = this.m_cameraCommandBuffers[_evA];
            _bufA.Clear();
        }
        else
        {
            _bufA      = new CommandBuffer();
            _bufA.name = "Override Eye";
            this.m_cameraCommandBuffers.Add(_evA, _bufA);
            this.m_camera.AddCommandBuffer(_evA, _bufA);
        }

        OverrideEyeSystem system = OverrideEyeSystem.instance;

        int _rt0 = Shader.PropertyToID("_rt0");
        int _rt1 = Shader.PropertyToID("_rt1");
        int _rt2 = Shader.PropertyToID("_rt2");
        int _rt3 = Shader.PropertyToID("_rt3");

        _bufA.GetTemporaryRT(_rt0, -1, -1, 24, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
        _bufA.GetTemporaryRT(_rt1, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
        _bufA.GetTemporaryRT(_rt2, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
        _bufA.GetTemporaryRT(_rt3, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);


        RenderTargetIdentifier[] _rts = new RenderTargetIdentifier[4]
        {
            _rt0,
            _rt1,
            _rt2,
            _rt3
        };
        _bufA.SetRenderTarget(_rts, new RenderTargetIdentifier(_rt0));
        _bufA.ClearRenderTarget(true, true, Color.clear);

        foreach (OverrideEye eyeObj in system.m_eyeObjs)
        {
            if (eyeObj.Type == OverrideEye.RenderType.MASK)
            {
                this.drawOverrideEyeMat(_bufA, eyeObj, 0);
            }
            else if (eyeObj.Type == OverrideEye.RenderType.OVERRIDE)
            {
                this.drawSlefMat(_bufA, eyeObj, 0);
            }
        }

        // Clip
        int _rt4 = Shader.PropertyToID("_rt4");

        _bufA.GetTemporaryRT(_rt4, -1, -1, 24, FilterMode.Point, RenderTextureFormat.R8, RenderTextureReadWrite.Default);
        _bufA.SetRenderTarget(_rt4, _rt4);
        _bufA.ClearRenderTarget(true, true, Color.clear);

        foreach (OverrideEye eyeObj in system.m_eyeObjs)
        {
            if (eyeObj.Type == OverrideEye.RenderType.CLIP)
            {
                this.drawOverrideEyeMat(_bufA, eyeObj, 5);
            }
            else
            {
                this.drawOverrideEyeMat(_bufA, eyeObj, 0);
            }
        }

        _bufA.SetGlobalTexture("_DeferredClipTex", _rt4);


        // Mask
        int _rt5 = Shader.PropertyToID("_rt5");

        _bufA.GetTemporaryRT(_rt5, -1, -1, 24, FilterMode.Point, RenderTextureFormat.R8, RenderTextureReadWrite.Default);
        _bufA.SetRenderTarget(_rt5, _rt5);
        _bufA.ClearRenderTarget(true, true, Color.clear);

        foreach (OverrideEye eyeObj in system.m_eyeObjs)
        {
            if (eyeObj.Type == OverrideEye.RenderType.MASK)
            {
                drawOverrideEyeMat(_bufA, eyeObj, 0);
            }
            else if (eyeObj.Type == OverrideEye.RenderType.OVERRIDE)
            {
                drawOverrideEyeMat(_bufA, eyeObj, 5);
            }
        }

        _bufA.SetGlobalTexture("_DeferredMaskTex", _rt5);


        // for StandardShader
        //_bufA.Blit(_rt0, BuiltinRenderTextureType.GBuffer0, this.m_overrideEyeMat, 1);
        //_bufA.Blit(_rt1, BuiltinRenderTextureType.GBuffer1, this.m_overrideEyeMat, 2);
        //_bufA.Blit(_rt2, BuiltinRenderTextureType.GBuffer2, this.m_overrideEyeMat, 3);
        //_bufA.Blit(_rt3, BuiltinRenderTextureType.CameraTarget, this.m_overrideEyeMat, 4);

        // for unitychanShader
        _bufA.Blit(_rt0, BuiltinRenderTextureType.CameraTarget, this.m_overrideEyeMat, 1);


        _bufA.ReleaseTemporaryRT(_rt0);
        _bufA.ReleaseTemporaryRT(_rt1);
        _bufA.ReleaseTemporaryRT(_rt2);
        _bufA.ReleaseTemporaryRT(_rt3);
        _bufA.ReleaseTemporaryRT(_rt4);
        _bufA.ReleaseTemporaryRT(_rt5);
    }
Ejemplo n.º 15
0
 public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifier destination, RenderTargetIdentifier?depthMap, bool invert)
 {
 }
Ejemplo n.º 16
0
 public void SetDepthTexture(RenderTargetIdentifier depth)
 {
     _depth = depth;
 }
Ejemplo n.º 17
0
 // This particular case is for blitting a camera-scaled texture into a non scaling texture. So we setup the full viewport (implicit in cmd.Blit) but have to scale the input UVs.
 public static void BlitCameraTexture(CommandBuffer cmd, HDCamera camera, RTHandleSystem.RTHandle source, RenderTargetIdentifier destination)
 {
     cmd.Blit(source, destination, new Vector2(camera.viewportScale.x, camera.viewportScale.y), Vector2.zero);
 }
Ejemplo n.º 18
0
        public void Setup(RenderTargetIdentifier source)
        {
            this.source = source;

            material = new Material(Shader.Find("SnapshotProURP/SNES"));
        }
Ejemplo n.º 19
0
        static private bool RenderLightSet(Camera camera, int blendStyleIndex, CommandBuffer cmdBuffer, int layerToRender, RenderTargetIdentifier renderTexture, List <Light2D> lights)
        {
            bool renderedAnyLight = false;

            foreach (var light in lights)
            {
                if (light != null && light.lightType != Light2D.LightType.Global && light.blendStyleIndex == blendStyleIndex && light.IsLitLayer(layerToRender) && light.IsLightVisible(camera))
                {
                    // Render light
                    Material lightMaterial = GetLightMaterial(light, false);
                    if (lightMaterial != null)
                    {
                        Mesh lightMesh = light.GetMesh();
                        if (lightMesh != null)
                        {
                            RenderShadows(cmdBuffer, layerToRender, light, light.shadowIntensity, renderTexture);

                            renderedAnyLight = true;

                            if (light.lightType == Light2D.LightType.Sprite && light.lightCookieSprite != null && light.lightCookieSprite.texture != null)
                            {
                                cmdBuffer.SetGlobalTexture("_CookieTex", light.lightCookieSprite.texture);
                            }

                            cmdBuffer.SetGlobalFloat("_FalloffIntensity", light.falloffIntensity);
                            cmdBuffer.SetGlobalFloat("_FalloffDistance", light.shapeLightFalloffSize);
                            cmdBuffer.SetGlobalVector("_FalloffOffset", light.shapeLightFalloffOffset);
                            cmdBuffer.SetGlobalColor("_LightColor", light.intensity * light.color);
                            cmdBuffer.SetGlobalFloat("_VolumeOpacity", light.volumeOpacity);

                            if (light.useNormalMap || light.lightType == Light2D.LightType.Point)
                            {
                                RendererLighting.SetPointLightShaderGlobals(cmdBuffer, light);
                            }

                            // Light code could be combined...
                            if (light.lightType == Light2D.LightType.Parametric || light.lightType == Light2D.LightType.Freeform || light.lightType == Light2D.LightType.Sprite)
                            {
                                cmdBuffer.DrawMesh(lightMesh, light.transform.localToWorldMatrix, lightMaterial);
                            }
                            else if (light.lightType == Light2D.LightType.Point)
                            {
                                Vector3   scale  = new Vector3(light.pointLightOuterRadius, light.pointLightOuterRadius, light.pointLightOuterRadius);
                                Matrix4x4 matrix = Matrix4x4.TRS(light.transform.position, Quaternion.identity, scale);
                                cmdBuffer.DrawMesh(lightMesh, matrix, lightMaterial);
                            }
                        }
                    }
                }
            }

            return(renderedAnyLight);
        }
 public static void DrawFullScreen(this CommandBuffer CmdBuffer, RTHandle Source, RenderTargetIdentifier Desc, MaterialPropertyBlock MaterialPropertyBlock = null)
 {
     CmdBuffer.SetRenderTarget(Desc);
     MaterialPropertyBlock.SetTexture(InfinityShaderIDs.RT_MainTexture, Source);
     CmdBuffer.DrawMesh(FullScreenMesh, Matrix4x4.identity, BlitMaterial, 0, 1, MaterialPropertyBlock);
 }
Ejemplo n.º 21
0
        static public void RenderLightVolumes(Camera camera, CommandBuffer cmdBuffer, int layerToRender, RenderTargetIdentifier renderTarget)
        {
            for (int i = 0; i < s_BlendStyles.Length; ++i)
            {
                if (!s_BlendStyles[i].enabled)
                {
                    continue;
                }

                string sampleName = s_BlendStyles[i].name;
                cmdBuffer.BeginSample(sampleName);

                RenderLightVolumeSet(
                    camera,
                    i,
                    cmdBuffer,
                    layerToRender,
                    renderTarget,
                    Light2D.GetLightsByBlendStyle(i)
                    );

                cmdBuffer.EndSample(sampleName);
            }
        }
 public static void DrawFullScreen(this CommandBuffer CmdBuffer, RenderTargetIdentifier Source, RenderTargetIdentifier Desc, int DrawPass)
 {
     CmdBuffer.SetRenderTarget(Desc);
     CmdBuffer.SetGlobalTexture(InfinityShaderIDs.RT_MainTexture, Source);
     CmdBuffer.DrawMesh(FullScreenMesh, Matrix4x4.identity, BlitMaterial, 0, DrawPass);
 }
Ejemplo n.º 23
0
            public void BlendFrames(CommandBuffer cb, float strength, RenderTargetIdentifier source, RenderTargetIdentifier destination, Material material)
            {
                var t = Time.time;

                var f1 = GetFrameRelative(-1);
                var f2 = GetFrameRelative(-2);
                var f3 = GetFrameRelative(-3);
                var f4 = GetFrameRelative(-4);

                cb.SetGlobalTexture(Uniforms._History1LumaTex, f1.lumaTexture);
                cb.SetGlobalTexture(Uniforms._History2LumaTex, f2.lumaTexture);
                cb.SetGlobalTexture(Uniforms._History3LumaTex, f3.lumaTexture);
                cb.SetGlobalTexture(Uniforms._History4LumaTex, f4.lumaTexture);

                cb.SetGlobalTexture(Uniforms._History1ChromaTex, f1.chromaTexture);
                cb.SetGlobalTexture(Uniforms._History2ChromaTex, f2.chromaTexture);
                cb.SetGlobalTexture(Uniforms._History3ChromaTex, f3.chromaTexture);
                cb.SetGlobalTexture(Uniforms._History4ChromaTex, f4.chromaTexture);

                cb.SetGlobalFloat(Uniforms._History1Weight, f1.CalculateWeight(strength, t));
                cb.SetGlobalFloat(Uniforms._History2Weight, f2.CalculateWeight(strength, t));
                cb.SetGlobalFloat(Uniforms._History3Weight, f3.CalculateWeight(strength, t));
                cb.SetGlobalFloat(Uniforms._History4Weight, f4.CalculateWeight(strength, t));

                cb.SetGlobalTexture(Uniforms._MainTex, source);
                cb.Blit(source, destination, material, m_UseCompression ? (int)Pass.FrameBlendingChroma : (int)Pass.FrameBlendingRaw);
            }
 public static void DrawFullScreen(this CommandBuffer CmdBuffer, RenderTargetIdentifier ColorBuffer, Material DrawMaterial, int DrawPass, MaterialPropertyBlock MaterialPropertyBlock = null)
 {
     CmdBuffer.SetRenderTarget(ColorBuffer);
     CmdBuffer.DrawMesh(FullScreenMesh, Matrix4x4.identity, DrawMaterial, 0, DrawPass, MaterialPropertyBlock);
 }
Ejemplo n.º 25
0
 public void Process(CommandBuffer cmd, RenderTargetIdentifier rt)
 {
     Process(cmd, rt, 0, CurrentWidth, 0, CurrentHeight, 0, 0);
 }
 public static void DrawFullScreen(this CommandBuffer CmdBuffer, RenderTargetIdentifier ColorBuffer, RenderTargetIdentifier DepthBuffer, Material DrawMaterial, int DrawPass)
 {
     CmdBuffer.SetRenderTarget(ColorBuffer, DepthBuffer);
     CmdBuffer.DrawMesh(FullScreenMesh, Matrix4x4.identity, DrawMaterial, 0, DrawPass);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Configure the pass with the source and destination to execute on.
 /// </summary>
 /// <param name="source">Source Render Target</param>
 /// <param name="destination">Destination Render Target</param>
 public void Setup(RenderTargetIdentifier source, UnityEngine.Rendering.Universal.RenderTargetHandle destination)
 {
     this.source      = source;
     this.destination = destination;
 }
Ejemplo n.º 28
0
        void PushUpsampleCommands(CommandBuffer cmd, int lowResDepth, int interleavedAO, int highResDepth, int?highResAO, RenderTargetIdentifier dest, Vector3 lowResDepthSize, Vector2 highResDepthSize, bool invert = false)
        {
            var cs     = m_Resources.computeShaders.multiScaleAOUpsample;
            int kernel = cs.FindKernel(highResAO == null
                ? invert
                    ? "main_invert"
                    : "main"
                : "main_blendout");

            float stepSize   = 1920f / lowResDepthSize.x;
            float bTolerance = 1f - Mathf.Pow(10f, m_Settings.blurTolerance.value) * stepSize;

            bTolerance *= bTolerance;
            float uTolerance        = Mathf.Pow(10f, m_Settings.upsampleTolerance.value);
            float noiseFilterWeight = 1f / (Mathf.Pow(10f, m_Settings.noiseFilterTolerance.value) + uTolerance);

            cmd.SetComputeVectorParam(cs, "InvLowResolution", new Vector2(1f / lowResDepthSize.x, 1f / lowResDepthSize.y));
            cmd.SetComputeVectorParam(cs, "InvHighResolution", new Vector2(1f / highResDepthSize.x, 1f / highResDepthSize.y));
            cmd.SetComputeVectorParam(cs, "AdditionalParams", new Vector4(noiseFilterWeight, stepSize, bTolerance, uTolerance));

            cmd.SetComputeTextureParam(cs, kernel, "LoResDB", lowResDepth);
            cmd.SetComputeTextureParam(cs, kernel, "HiResDB", highResDepth);
            cmd.SetComputeTextureParam(cs, kernel, "LoResAO1", interleavedAO);

            if (highResAO != null)
            {
                cmd.SetComputeTextureParam(cs, kernel, "HiResAO", highResAO.Value);
            }

            cmd.SetComputeTextureParam(cs, kernel, "AoResult", dest);

            int xcount = ((int)highResDepthSize.x + 17) / 16;
            int ycount = ((int)highResDepthSize.y + 17) / 16;

            cmd.DispatchCompute(cs, kernel, xcount, ycount, 1);
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Configure the pass with the source and destination to execute on.
 /// </summary>
 /// <param name="source">Source Render Target</param>
 /// <param name="destination">Destination Render Target</param>
 public void Setup(RenderTargetIdentifier source, RenderTargetHandle destination)
 {
     this.source      = source;
     this.destination = destination;
 }
Ejemplo n.º 30
0
        public static void RenderNormals(this IRenderPass2D pass, ScriptableRenderContext context, RenderingData renderingData, DrawingSettings drawSettings, FilteringSettings filterSettings, RenderTargetIdentifier depthTarget, CommandBuffer cmd, LightStats lightStats)
        {
            using (new ProfilingScope(cmd, m_ProfilingSampler))
            {
                // figure out the scale
                var normalRTScale = 0.0f;

                if (depthTarget != BuiltinRenderTextureType.None)
                {
                    normalRTScale = 1.0f;
                }
                else
                {
                    normalRTScale = Mathf.Clamp(pass.rendererData.lightRenderTextureScale, 0.01f, 1.0f);
                }

                pass.CreateNormalMapRenderTexture(renderingData, cmd, normalRTScale);

                if (depthTarget != BuiltinRenderTextureType.None)
                {
                    cmd.SetRenderTarget(
                        pass.rendererData.normalsRenderTarget.Identifier(),
                        RenderBufferLoadAction.DontCare,
                        RenderBufferStoreAction.Store,
                        depthTarget,
                        RenderBufferLoadAction.Load,
                        RenderBufferStoreAction.Store);
                }
                else
                {
                    cmd.SetRenderTarget(pass.rendererData.normalsRenderTarget.Identifier(), RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
                }

                cmd.ClearRenderTarget(false, true, k_NormalClearColor);

                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                drawSettings.SetShaderPassName(0, k_NormalsRenderingPassName);
                context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filterSettings);
            }
        }