コード例 #1
0
 void ToneMapping(CommandBuffer cb, RenderTargetIdentifier sourceId, RenderTargetIdentifier destinationId)
 {
     cb.BeginSample("Tone Mapping");
     cb.SetGlobalFloat("_ReinhardModifier", 1f / (toneMappingRange * toneMappingRange));
     Blit(cb, sourceId, destinationId, Pass.ToneMapping);
     cb.EndSample("Tone Mapping");
 }
コード例 #2
0
ファイル: Shadows.cs プロジェクト: AdamWu/Shader4Unity
    void RenderDirectionalShadows()
    {
        int atlasSize = (int)settings.directional.atlasSize;

        buffer.GetTemporaryRT(dirShadowAtlasId, atlasSize, atlasSize, 32, FilterMode.Bilinear, RenderTextureFormat.Shadowmap);
        buffer.SetRenderTarget(dirShadowAtlasId, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
        buffer.ClearRenderTarget(true, false, Color.clear);
        buffer.BeginSample(bufferName);
        ExecuteBuffer();

        int tiles    = ShadowedDirectionalLightCount * settings.directional.cascadeCount;
        int split    = tiles <= 1 ? 1 : tiles <= 4 ? 2 : 4;
        int tileSize = atlasSize / split;

        for (int i = 0; i < ShadowedDirectionalLightCount; i++)
        {
            RenderDirectionalShadows(i, split, tileSize);
        }

        // constants
        buffer.SetGlobalInt(cascadeCountId, settings.directional.cascadeCount);
        buffer.SetGlobalVectorArray(cascadeCullingSpheresId, cascadeCullingSpheres);
        buffer.SetGlobalVectorArray(cascadeDataId, cascadeData);
        buffer.SetGlobalMatrixArray(dirShadowMatricesId, dirShadowMatrices);
        float f = 1f - settings.directional.cascadeFade;

        buffer.SetGlobalVector(shadowDistanceFadeId, new Vector4(
                                   1f / settings.maxDistance, 1f / settings.distanceFade,
                                   1f / (1f - f * f)));
        SetKeywords(directionalFilterKeywords, (int)settings.directional.filter - 1);
        SetKeywords(cascadeBlendKeywords, (int)settings.directional.cascadeBlend - 1);
        buffer.SetGlobalVector(shadowAtlasSizeId, new Vector4(atlasSize, 1f / atlasSize));
        buffer.EndSample(bufferName);
        ExecuteBuffer();
    }
コード例 #3
0
        public int CaptureScreen(int id)
        {
            if (commandBuffer == null)
            {
                commandBuffer      = new CommandBuffer();
                commandBuffer.name = "ScreenCapture";
            }
            commandBuffer.Clear();

            for (int i = 0; i < FRAME_NUM; ++i)
            {
                if (!IsAvailable(i))
                {
                    continue;
                }
                frames[i].id = id;
                this.WriteToTagInfo(id, 0);
                this.WriteToTagInfoShort(Screen.width, 8);
                this.WriteToTagInfoShort(Screen.height, 10);
                Profiler.EmitFrameMetaData(ScreenShotToProfiler.MetadataGuid, ScreenShotToProfiler.InfoTag, tagInfo);
                var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32);
                ScreenCapture.CaptureScreenshotIntoRenderTexture(rt);
                commandBuffer.BeginSample(CAPTURE_CMD_SAMPLE);
                commandBuffer.Blit(rt, frames[i].renderTexture);
                commandBuffer.EndSample(CAPTURE_CMD_SAMPLE);
                Graphics.ExecuteCommandBuffer(commandBuffer);
                RenderTexture.ReleaseTemporary(rt);
                commandBuffer.Clear();
                return(i);
            }
            return(-1);
        }
コード例 #4
0
        static public void RenderLightVolumes(Camera camera, CommandBuffer cmdBuffer, int layerToRender, RenderTargetIdentifier renderTarget, RenderTargetIdentifier depthTarget, uint blendStylesUsed)
        {
            for (int i = 0; i < s_BlendStyles.Length; ++i)
            {
                if ((blendStylesUsed & (uint)(1 << i)) == 0)
                {
                    continue;
                }

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

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

                cmdBuffer.EndSample(sampleName);
            }
        }
コード例 #5
0
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer cmd   = context.command;
            PropertySheet sheet = context.propertySheets.Get(shader);

            cmd.BeginSample(PROFILER_TAG);

            TimeX += Time.deltaTime;
            if (TimeX > 100)
            {
                TimeX = 0;
            }

            sheet.properties.SetVector(ShaderIDs.Params, new Vector3(TimeX * settings.Speed, settings.Amount, settings.Fade));
            sheet.properties.SetVector(ShaderIDs.Params2, new Vector4(settings.BlockLayer1_U, settings.BlockLayer1_V, settings.BlockLayer2_U, settings.BlockLayer2_V));
            sheet.properties.SetVector(ShaderIDs.Params3, new Vector3(settings.RGBSplitIndensity, settings.BlockLayer1_Indensity, settings.BlockLayer2_Indensity));

            if (settings.BlockVisualizeDebug)
            {
                //debug
                cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 1);
            }
            else
            {
                cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
            }



            cmd.EndSample(PROFILER_TAG);
        }
コード例 #6
0
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer cmd   = context.command;
            PropertySheet sheet = context.propertySheets.Get(shader);

            cmd.BeginSample(PROFILER_TAG);

            UpdateNoiseTexture(settings.frequncy, settings.noiseTextureWidth, settings.noiseTextureHeight, settings.stripeLength);

            sheet.properties.SetFloat(ShaderIDs.indensity, settings.intensity);

            if (_noiseTexture != null)
            {
                sheet.properties.SetTexture(ShaderIDs.noiseTex, _noiseTexture);
            }

            if (settings.needStripColorAdjust == true)
            {
                sheet.EnableKeyword("NEED_TRASH_FRAME");
                sheet.properties.SetColor(ShaderIDs.StripColorAdjustColor, settings.StripColorAdjustColor);
                sheet.properties.SetFloat(ShaderIDs.StripColorAdjustIndensity, settings.StripColorAdjustIndensity);
            }
            else
            {
                sheet.DisableKeyword("NEED_TRASH_FRAME");
            }

            context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
            cmd.EndSample(PROFILER_TAG);
        }
コード例 #7
0
        void DrawOpaque(ref ScriptableRenderContext context, Camera camera, ref CullingResults cullingResults)
        {
            buffer.BeginSample("Opaque");
            var sortingSettings = new SortingSettings(camera);

            sortingSettings.criteria = SortingCriteria.CommonOpaque;

            var drawSettings = new DrawingSettings(ShaderPassTags.Forward, sortingSettings)
            {
                enableDynamicBatching = true,
                enableInstancing      = true,
                perObjectData         = PerObjectData.Lightmaps | PerObjectData.LightProbe
            };

            var filterSettings = FilteringSettings.defaultValue;

            filterSettings.renderQueueRange = RenderQueueRange.opaque;
            filterSettings.layerMask        = ~0;

            RenderStateBlock stateBlock = new RenderStateBlock(RenderStateMask.Nothing);

            context.DrawRenderers(cullingResults, ref drawSettings, ref filterSettings);
            buffer.EndSample("Opaque");
            context.ExecuteCommandBuffer(buffer);
            buffer.Clear();
        }
コード例 #8
0
    void Blur(CommandBuffer cb, int cameraColorId, int width, int height)
    {
        cb.BeginSample("Blur");
        if (blurStrength == 1)
        {
            Blit(
                cb, cameraColorId, BuiltinRenderTextureType.CameraTarget, Pass.Blur
                );
            cb.EndSample("Blur");
            return;
        }

        cb.GetTemporaryRT(tempTexId, width, height, 0, FilterMode.Bilinear);
        int passesLeft;

        for (passesLeft = blurStrength; passesLeft > 2; passesLeft -= 2)
        {
            Blit(cb, cameraColorId, tempTexId, Pass.Blur);
            Blit(cb, tempTexId, cameraColorId, Pass.Blur);
        }

        if (passesLeft > 1)
        {
            Blit(cb, cameraColorId, tempTexId, Pass.Blur);
            Blit(cb, tempTexId, BuiltinRenderTextureType.CameraTarget, Pass.Blur);
        }
        else
        {
            Blit(
                cb, cameraColorId, BuiltinRenderTextureType.CameraTarget, Pass.Blur
                );
        }
        cb.ReleaseTemporaryRT(tempTexId);
        cb.EndSample("Blur");
    }
コード例 #9
0
    void RenderDirectionalShadows()
    {
        int atlasSize = (int)shadowSettings.directional.atlasSize;

        ///First is the amount of bits for the depth buffer. We want this to be as high as possible, so let's use 32.
        ///Second is the filter mode, for which we use the default bilinear filtering.
        ///Third is the render texture type, which has to be RenderTextureFormat.Shadowmap.
        ///This gives us a texture suitable for rendering shadow maps, though the exact format depends on the target platform.
        buffer.GetTemporaryRT(dirShadowAtlasId, atlasSize, atlasSize, 32, FilterMode.Bilinear, RenderTextureFormat.Shadowmap);
        ///We don't care about its initial state as we'll immediately clear it, so we'll use RenderBufferLoadAction.DontCare.
        ///And the purpose of the texture is to contain the shadow data, so we'll need to use RenderBufferStoreAction.Store as the third argument.
        buffer.SetRenderTarget(dirShadowAtlasId, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);

        buffer.ClearRenderTarget(true, false, Color.clear);

        buffer.BeginSample(bufferName);
        ExecuteBuffer();

        for (int i = 0; i < ShadowedDirectionalLightCount; i++)
        {
            RenderDirectionalShadows(i, atlasSize);
        }

        buffer.EndSample(bufferName);
        ExecuteBuffer();
    }
コード例 #10
0
        public void RenderDirectionalShadows()
        {
            int atlasSize = (int)shadowParams.settings.directional.atlasSize;

            //申请渲染纹理缓冲
            buffer.GetTemporaryRT(dirShadowAtlasId, atlasSize, atlasSize, 32, FilterMode.Bilinear, RenderTextureFormat.Shadowmap);
            //设置_DirectionalShadowAtlas纹理为相机渲染目标
            buffer.SetRenderTarget(dirShadowAtlasId, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
            //此时相机渲染的或许是shadowmap,为保证后续渲染真实的世界需要clear depth buffer,但是color缓冲会被后续的渲染清空,所以此处不必清空
            buffer.ClearRenderTarget(true, false, Color.clear);
            buffer.BeginSample(bufferName);
            ExecuteBuffer();
            int tiles    = ShadowDirectionalLightCount * shadowParams.settings.directional.cascadeCount;
            int split    = tiles <= 1 ? 1 : tiles <= 4 ? 2 : 4;//在x,y方向各切分了split个块
            int tileSize = atlasSize / split;

            for (int i = 0; i < ShadowDirectionalLightCount; ++i)
            {
                RenderDirectionalShadows(i, split, tileSize);
            }
            //(1-d/m)/f,d->深度depth,m->最大距离maxDistance,f->distanceFade
            float f = 1f - shadowParams.settings.directional.cascadeFade;

            buffer.SetGlobalVector(shadowDistanceFadeId, new Vector4(1f / shadowParams.settings.maxDistance, 1f / shadowParams.settings.distanceFade, 1f / (1f - f * f)));
            buffer.SetGlobalInt(cascadeCountId, shadowParams.settings.directional.cascadeCount);
            buffer.SetGlobalVectorArray(
                cascadeCullingSpheresId, cascadeCullingSpheres
                );
            buffer.SetGlobalMatrixArray(dirShadowMatricesId, dirShadowMatrices);
            buffer.EndSample(bufferName);
            ExecuteBuffer();
        }
コード例 #11
0
 void Setup()
 {
     context.SetupCameraProperties(camera);
     buffer.ClearRenderTarget(true, true, Color.clear);
     buffer.BeginSample(bufferName);
     ExecuteBuffer();
 }
コード例 #12
0
 void Setup(ScriptableRenderContext context, Camera camera)
 {
     buffer.ClearRenderTarget(true, true, Color.clear);
     buffer.BeginSample("Render");
     ExecuteBuffer(context, camera);
     context.SetupCameraProperties(camera);
 }
コード例 #13
0
    public void Render()
    {
        if (ShadowedDirectionalLightCount > 0)
        {
            RenderDirectionalShadows();
        }
        else
        {
            buffer.GetTemporaryRT(dirShadowAtlasId, 1, 1, 32, FilterMode.Bilinear, RenderTextureFormat.Shadowmap);
        }

        buffer.BeginSample(bufferName);
        SetKeywords(shadowMaskKeywords, useShadowMask ? QualitySettings.shadowmaskMode == ShadowmaskMode.Shadowmask ? 0 : 1 : -1);
        buffer.EndSample(bufferName);
        ExecuteBuffer();
    }
コード例 #14
0
        public void Initialization(Texture statisticsTexture, Color statisticsColor, int singleVertGridSize = 3, int sampleIgnoreNum = 4, int sampleIgnoreNumMask = 2)
        {
            mSingleVertGridSize = singleVertGridSize;
            mStatisticsTexture  = statisticsTexture;

            mMat = new Material(Shader.Find("Hidden/RealtimeImageStatisticsShader"));
            mMat.SetTexture("_Image", mStatisticsTexture);
            var loopImageSize = new Vector4(mStatisticsTexture.width / (float)mSingleVertGridSize, mStatisticsTexture.height / (float)mSingleVertGridSize);

            mMat.SetVector("_LoopImageSize", loopImageSize);
            mMat.SetColor("_Rec_Color", statisticsColor);
            mMat.SetVector("_SampleFilter", new Vector4(singleVertGridSize, singleVertGridSize, sampleIgnoreNum, sampleIgnoreNumMask));
            mMat.SetVector("_GainValue", new Vector4(mRecGainValue, 0, 0, 0));

            mTempRT = RenderTexture.GetTemporary(16, 16, 0);

            mCommandBuffer = new CommandBuffer();
            mCommandBuffer.BeginSample("---Rec Test---");
            mCommandBuffer.SetRenderTarget(mTempRT);
            mCommandBuffer.ClearRenderTarget(true, true, Color.clear);
            var pointsCount = Mathf.CeilToInt(loopImageSize.x * loopImageSize.y);

            mCommandBuffer.SetProjectionMatrix(Matrix4x4.Perspective(60f, 1f, 0.0001f, 1f));
            mCommandBuffer.DrawProcedural(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one), mMat, 0, MeshTopology.Points, pointsCount, 1);
            mCommandBuffer.EndSample("---Rec Test---");
        }
コード例 #15
0
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer cmd   = context.command;
            PropertySheet sheet = context.propertySheets.Get(shader);

            cmd.BeginSample(PROFILER_TAG);

            TimeX += (Time.deltaTime * settings.gridentSpeed);
            if (TimeX > 100)
            {
                TimeX = 0;
            }
            if (settings.FromGradientColor.value != null)
            {
                sheet.properties.SetColor(ShaderIDs.FromColor, settings.FromGradientColor.value.Evaluate(TimeX * 0.01f));
            }

            if (settings.ToGradientColor.value != null)
            {
                sheet.properties.SetColor(ShaderIDs.ToColor, settings.ToGradientColor.value.Evaluate(TimeX * 0.01f));
            }

            sheet.properties.SetFloat(ShaderIDs.Range, settings.Range);
            sheet.properties.SetFloat(ShaderIDs.Fuzziness, settings.Fuzziness);

            cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
            cmd.EndSample(PROFILER_TAG);
        }
コード例 #16
0
        internal void RenderMonitors(PostProcessRenderContext context)
        {
            bool flag  = false;
            bool flag2 = false;

            foreach (KeyValuePair <MonitorType, Monitor> monitor in m_Monitors)
            {
                bool flag3 = monitor.Value.IsRequestedAndSupported(context);
                flag  |= flag3;
                flag2 |= (flag3 && monitor.Value.NeedsHalfRes());
            }
            if (flag)
            {
                CommandBuffer command = context.command;
                command.BeginSample("Monitors");
                if (flag2)
                {
                    command.GetTemporaryRT(ShaderIDs.HalfResFinalCopy, context.width / 2, context.height / 2, 0, FilterMode.Bilinear, context.sourceFormat);
                    command.Blit(context.destination, ShaderIDs.HalfResFinalCopy);
                }
                foreach (KeyValuePair <MonitorType, Monitor> monitor2 in m_Monitors)
                {
                    Monitor value = monitor2.Value;
                    if (value.requested)
                    {
                        value.Render(context);
                    }
                }
                if (flag2)
                {
                    command.ReleaseTemporaryRT(ShaderIDs.HalfResFinalCopy);
                }
                command.EndSample("Monitors");
            }
        }
コード例 #17
0
    public void RenderMipmap(ScriptableRenderContext renderContext, Camera camera, VXGI vxgi)
    {
        var transform = Matrix4x4.TRS(vxgi.origin, Quaternion.identity, Vector3.one * vxgi.bound);

        _command.BeginSample(_command.name);

        if (vxgi.mipmapSampler == MipmapSampler.Point)
        {
            _command.EnableShaderKeyword("RADIANCE_POINT_SAMPLER");
        }
        else
        {
            _command.DisableShaderKeyword("RADIANCE_POINT_SAMPLER");
        }

        _command.SetGlobalFloat("MipmapLevel", Mathf.Min(vxgi.level, vxgi.radiances.Length));
        _command.SetGlobalFloat("TracingStep", vxgi.step);
        _command.DrawProcedural(transform, VisualizationShader.material, (int)VisualizationShader.Pass.Mipmap, MeshTopology.Quads, 24, 1);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();
    }
コード例 #18
0
    private void RenderFire()
    {
        // Graphics.DrawMeshInstanced(mesh, 0, material, matrices, meshCount, materialPropertyBlock,
        // ShadowCastingMode.On, true, 0, null, llpv ? LightProbeUsage.UseProxyVolume : LightProbeUsage.CustomProvided, llpv);
        List <Transform> fireList = new List <Transform>();

        for (int i = 0; i < fireRoot.childCount; ++i)
        {
            fireList.Add(fireRoot.GetChild(i));
        }

        Matrix4x4[] matrices = new Matrix4x4[fireList.Count];

        for (int i = 0; i < matrices.Length; ++i)
        {
            Transform fireAreaTransform = fireList[i];

            matrices[i] = Matrix4x4.TRS(fireAreaTransform.position,
                                        Quaternion.Euler(90, 0, 0),
                                        Vector3.one);
        }

        commandBuffer.BeginSample("Area");
        commandBuffer.GetTemporaryRT(areaPropertyID, 256, 256, 0, FilterMode.Bilinear, RenderTextureFormat.Default);
        commandBuffer.SetRenderTarget(areaPropertyID, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
        commandBuffer.DrawMeshInstanced(areaMesh, 0, fireAreaMaterial, 0, matrices);
        commandBuffer.EndSample("Area");
    }
コード例 #19
0
    private void InitCommandBuffer()
    {
        AudioSource ass;

        cb = new CommandBuffer {
            name = "AfterEverything"
        };
        cb.BeginSample("MyCommandBuffer");

        int id  = Shader.PropertyToID("CopyRT");
        int id1 = Shader.PropertyToID("CopyRT1");

        cb.GetTemporaryRT(id, Screen.width, Screen.height, 0, FilterMode.Bilinear);
        cb.GetTemporaryRT(id1, Screen.width, Screen.height, 0, FilterMode.Bilinear);

        //先把 CurrentActive 渲染出来 到id  不然是null 纯黑色
        cb.Blit(BuiltinRenderTextureType.CurrentActive, id);
        cb.Blit(id, id1, effectMaterial, 0);
        cb.Blit(id1, BuiltinRenderTextureType.CameraTarget, effectMaterial, 1);

        cb.ReleaseTemporaryRT(id);
        cb.ReleaseTemporaryRT(id1);

        cb.EndSample("MyCommandBuffer");
    }
コード例 #20
0
    void RenderShadows(ScriptableRenderContext context)
    {
        shadowBuffer.GetTemporaryRT(shadowMapId, 512, 512, 16, FilterMode.Bilinear, RenderTextureFormat.Depth);
        shadowMap            = RenderTexture.GetTemporary(512, 512, 16, RenderTextureFormat.Shadowmap);
        shadowMap.filterMode = FilterMode.Bilinear;
        shadowMap.wrapMode   = TextureWrapMode.Clamp;

        CoreUtils.SetRenderTarget(shadowBuffer, shadowMap, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Depth);
        shadowBuffer.BeginSample("Render Shadows");
        context.ExecuteCommandBuffer(shadowBuffer);
        shadowBuffer.Clear();

        Matrix4x4       viewMatrix, projectMatrix;
        ShadowSplitData splitData;

        cullingResults.ComputeSpotShadowMatricesAndCullingPrimitives(0, out viewMatrix, out projectMatrix, out splitData);
        shadowBuffer.SetViewProjectionMatrices(viewMatrix, projectMatrix);
        context.ExecuteCommandBuffer(shadowBuffer);

        // draw shadow
        var shadowSettings = new ShadowDrawingSettings(cullingResults, 0);

        context.DrawShadows(ref shadowSettings);

        shadowBuffer.EndSample("Render Shadows");
        context.ExecuteCommandBuffer(shadowBuffer);
        shadowBuffer.Clear();
    }
コード例 #21
0
ファイル: PostMLAA.cs プロジェクト: wingstone/SRP-Laboratory
    private void Render()
    {
        _CommandBuffer      = new CommandBuffer();
        _CommandBuffer.name = "AdvancedRTR";

        // get rt
        _CommandBuffer.GetTemporaryRT(ShaderConstants._SourceRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);
        _CommandBuffer.GetTemporaryRT(ShaderConstants._EdgeRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);
        _CommandBuffer.GetTemporaryRT(ShaderConstants._BlendWeightRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);

        // copy
        RuntimeUtilities.BuiltinBlit(_CommandBuffer, BuiltinRenderTextureType.CameraTarget, ShaderConstants._SourceRT);

        // MLAA
        _CommandBuffer.BeginSample("MLAA");

        // edge
        RuntimeUtilities.BlitFullscreenTriangle(_CommandBuffer, ShaderConstants._SourceRT, ShaderConstants._EdgeRT, _MLAAMat, 0);
        // weight
        RuntimeUtilities.BlitFullscreenTriangle(_CommandBuffer, ShaderConstants._EdgeRT, ShaderConstants._BlendWeightRT, _MLAAMat, 1);
        // blend
        _CommandBuffer.SetGlobalTexture("_BlendWeightTex", ShaderConstants._BlendWeightRT);
        RuntimeUtilities.BlitFullscreenTriangle(_CommandBuffer, ShaderConstants._SourceRT, BuiltinRenderTextureType.CameraTarget, _MLAAMat, 2);

        // release rt
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._SourceRT);
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._EdgeRT);
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._BlendWeightRT);

        _CommandBuffer.EndSample("MLAA");

        _Camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, _CommandBuffer);
    }
コード例 #22
0
ファイル: MixtureNode.cs プロジェクト: TrentSterling/Mixture
        void Process(CommandBuffer cmd)
        {
            var outputDimension = rtSettings.GetTextureDimension(graph);

            if (!supportedDimensions.Contains((OutputDimension)outputDimension))
            {
                // AddMessage($"Dimension {outputDimension} is not supported by this node", NodeMessageType.Error);
                return;
            }
            else
            {
                // TODO: simplify this with the node graph processor remove badges with matching words feature
                // RemoveMessage($"Dimension {TextureDimension.Tex2D} is not supported by this node");
                // RemoveMessage($"Dimension {TextureDimension.Tex3D} is not supported by this node");
                // RemoveMessage($"Dimension {TextureDimension.Cube} is not supported by this node");
            }

            beforeProcessSetup?.Invoke();

            // Avoid adding markers if it's CRT processing (CRT  already have one)
            // Or loops as it will bloat the debug markers
            bool loopNode = this is ILoopStart || this is ILoopEnd;

            if (this is IUseCustomRenderTextureProcessing || loopNode)
            {
                ProcessNode(cmd);
            }
            else
            {
                cmd.BeginSample(sampler);
                ProcessNode(cmd);
                cmd.EndSample(sampler);
            }
            afterProcessCleanup?.Invoke();
        }
コード例 #23
0
    void TriggerCameraEvent(ScriptableRenderContext renderContext, Camera camera, CameraEvent cameraEvent, VXGI vxgi)
    {
#if UNITY_EDITOR
        camera = camera.cameraType == CameraType.SceneView ? vxgi.Camera : camera;
#endif

        var commands = camera.GetCommandBuffers(cameraEvent);

        if (commands.Length == 0)
        {
            return;
        }

        _eventCommand.name = _sampleCameraEvent + cameraEvent.ToString();
        _eventCommand.BeginSample(_eventCommand.name);
        _eventCommand.SetRenderTarget(ShaderIDs.FrameBuffer);
        renderContext.ExecuteCommandBuffer(_eventCommand);
        _eventCommand.Clear();

        foreach (var command in commands)
        {
            renderContext.ExecuteCommandBuffer(command);
        }

        _eventCommand.EndSample(_eventCommand.name);
        renderContext.ExecuteCommandBuffer(_eventCommand);
        _eventCommand.Clear();
    }
コード例 #24
0
 public ProfilingSample(string _name, CommandBuffer _cmd)
 {
     cmd      = _cmd;
     disposed = false;
     name     = _name;
     cmd.BeginSample(name);
 }
コード例 #25
0
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer cmd   = context.command;
            PropertySheet sheet = context.propertySheets.Get(shader);

            cmd.BeginSample(PROFILER_TAG);


            float size = (1.01f - settings.pixelSize) * 300f;

            float ratio = settings.pixelRatio;

            if (settings.useAutoScreenRatio)
            {
                ratio = (float)(context.width / (float)context.height);
                if (ratio == 0)
                {
                    ratio = 1f;
                }
            }


            sheet.properties.SetVector(ShaderIDs.Params, new Vector4(size, ratio, settings.ledRadius));
            sheet.properties.SetColor(ShaderIDs.BackgroundColor, settings.BackgroundColor);

            cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
            cmd.EndSample(PROFILER_TAG);
        }
コード例 #26
0
        void FilterCubemapCommon(CommandBuffer cmd,
                                 Texture source, RenderTexture target, int mipCount,
                                 Matrix4x4[] worldToViewMatrices)
        {
            // Solid angle associated with a texel of the cubemap.
            float invOmegaP = (6.0f * source.width * source.width) / (4.0f * Mathf.PI);

            m_GgxConvolveMaterial.SetTexture("_MainTex", source);
            m_GgxConvolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData);
            m_GgxConvolveMaterial.SetFloat("_LastLevel", mipCount - 1);
            m_GgxConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP);

            for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip)
            {
                string sampleName = String.Format("Filter Cubemap Mip {0}", mip);
                cmd.BeginSample(sampleName);

                for (int face = 0; face < 6; ++face)
                {
                    Vector4   faceSize  = new Vector4(source.width >> mip, source.height >> mip, 1.0f / (source.width >> mip), 1.0f / (source.height >> mip));
                    Matrix4x4 transform = SkyManager.ComputePixelCoordToWorldSpaceViewDirectionMatrix(0.5f * Mathf.PI, faceSize, worldToViewMatrices[face], true);

                    MaterialPropertyBlock props = new MaterialPropertyBlock();
                    props.SetFloat("_Level", mip);
                    props.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, transform);

                    Utilities.SetRenderTarget(cmd, target, ClearFlag.ClearNone, mip, (CubemapFace)face);
                    Utilities.DrawFullScreen(cmd, m_GgxConvolveMaterial, props);
                }
                cmd.EndSample(sampleName);
            }
        }
コード例 #27
0
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer cmd   = context.command;
            PropertySheet sheet = context.propertySheets.Get(shader);

            cmd.BeginSample(PROFILER_TAG);

            if (settings.RTDownScaling > 1)
            {
                int RTWidth  = (int)(context.screenWidth / settings.RTDownScaling);
                int RTHeight = (int)(context.screenHeight / settings.RTDownScaling);
                cmd.GetTemporaryRT(ShaderIDs.BufferRT, RTWidth, RTHeight, 0, FilterMode.Bilinear);
                // downsample screen copy into smaller RT
                context.command.BlitFullscreenTriangle(context.source, ShaderIDs.BufferRT);
            }

            sheet.properties.SetVector(ShaderIDs.Params, new Vector2(settings.BlurRadius / context.height, settings.Iteration));

            if (settings.RTDownScaling > 1)
            {
                cmd.BlitFullscreenTriangle(ShaderIDs.BufferRT, context.destination, sheet, 0);
            }
            else
            {
                cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
            }

            cmd.ReleaseTemporaryRT(ShaderIDs.BufferRT);
            cmd.EndSample(PROFILER_TAG);
        }
コード例 #28
0
        public void Render(ref RenderingData context)
        {
            cmd.BeginSample("Shadow");
            cmd.Clear();

            ShadowDrawingSettings drawSetting = new ShadowDrawingSettings(context.cullResult, 0);

            Matrix4x4       view;
            Matrix4x4       proj;
            ShadowSplitData splitData;

            context.cullResult.ComputeDirectionalShadowMatricesAndCullingPrimitives(0, 0, 1, Vector3.zero, (int)context.asset.ShadowSetting.directional.altasSize, 0f, out view, out proj, out splitData);
            drawSetting.splitData = splitData;
            cmd.SetViewProjectionMatrices(view, proj);

            int texSize = (int)context.asset.ShadowSetting.directional.altasSize;

            var ren = new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget);

            cmd.GetTemporaryRT(dirShadowAtlasId, texSize, texSize, 24, FilterMode.Bilinear, RenderTextureFormat.Shadowmap);
            cmd.SetRenderTarget(dirShadowAtlasId, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
            cmd.ClearRenderTarget(true, false, Color.clear);
            context.context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            context.context.DrawShadows(ref drawSetting);

            // cmd.SetRenderTarget(ren);
            //  context.context.ExecuteCommandBuffer(cmd);

            cmd.EndSample("Shadow");
        }
コード例 #29
0
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer cmd   = context.command;
            PropertySheet sheet = context.propertySheets.Get(shader);

            cmd.BeginSample(PROFILER_TAG);


            int tw = (int)(context.screenWidth / settings.RTDownScaling);
            int th = (int)(context.screenHeight / settings.RTDownScaling);

            sheet.properties.SetFloat(ShaderIDs.BlurOffset, settings.BlurRadius);


            // Downsample
            RenderTargetIdentifier lastDown = context.source;

            for (int i = 0; i < settings.Iteration; i++)
            {
                int mipDown = m_Pyramid[i].down;
                int mipUp   = m_Pyramid[i].up;
                context.GetScreenSpaceTemporaryRT(cmd, mipDown, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, tw, th);
                context.GetScreenSpaceTemporaryRT(cmd, mipUp, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, tw, th);
                cmd.BlitFullscreenTriangle(lastDown, mipDown, sheet, 0);

                lastDown = mipDown;
                tw       = Mathf.Max(tw / 2, 1);
                th       = Mathf.Max(th / 2, 1);
            }

            // Upsample
            int lastUp = m_Pyramid[settings.Iteration - 1].down;

            for (int i = settings.Iteration - 2; i >= 0; i--)
            {
                int mipUp = m_Pyramid[i].up;

                cmd.BlitFullscreenTriangle(lastUp, mipUp, sheet, 1);
                lastUp = mipUp;
            }


            // Render blurred texture in blend pass
            cmd.BlitFullscreenTriangle(lastUp, context.destination, sheet, 1);

            // Cleanup
            for (int i = 0; i < settings.Iteration; i++)
            {
                if (m_Pyramid[i].down != lastUp)
                {
                    cmd.ReleaseTemporaryRT(m_Pyramid[i].down);
                }
                if (m_Pyramid[i].up != lastUp)
                {
                    cmd.ReleaseTemporaryRT(m_Pyramid[i].up);
                }
            }

            cmd.EndSample(PROFILER_TAG);
        }
コード例 #30
0
    private void Setup()
    {
        context.SetupCameraProperties(camera);
        var flags = camera.clearFlags;

        if (postFXStack.IsActive)
        {
            if (flags > CameraClearFlags.Color)
            {
                flags = CameraClearFlags.Color;
            }
            buffer.GetTemporaryRT(
                frameBufferId, camera.pixelWidth, camera.pixelHeight,
                32, FilterMode.Bilinear, RenderTextureFormat.Default
                );

            buffer.SetRenderTarget(
                frameBufferId,
                RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store
                );
        }

        buffer.ClearRenderTarget(
            flags != CameraClearFlags.Nothing,
            flags != CameraClearFlags.Nothing && flags != CameraClearFlags.Depth,
            camera.backgroundColor.linear);

        buffer.BeginSample(bufferName);
        ExecuteBuffer();
    }