示例#1
0
        public void SetTexture(string shaderName, CShaderResourceView rsv)
        {
            var txBind = new CTextureBindInfo();

            Effect.ShaderProgram.FindTextureBindInfo(Material, "txDiffuse", ref txBind);
            Textures[txBind.PSBindPoint] = rsv;
        }
示例#2
0
        public void BindScreenTexture2Mesh(Graphics.Mesh.CGfxMesh mesh, UInt32 atom, string shaderVar)
        {
            if (atom >= mesh.MtlMeshArray.Length)
            {
                return;
            }
            CTextureBindInfo txInfo = new CTextureBindInfo();

            for (int i = 0; i < mesh.MtlMeshArray[atom].PrebuildPassArray.Length; i++)
            {
                var pass = mesh.MtlMeshArray[atom].PrebuildPassArray[i];
                if (pass == null || pass.GpuProgram == null)
                {
                    continue;
                }
                var TexBinder     = pass.ShaderResources;
                var SamplerBinder = pass.ShaderSamplerBinder;
                var Shader        = pass.GpuProgram;

                if (Shader.FindTextureBindInfo(pass.MtlInst, shaderVar, ref txInfo))
                {
                    TexBinder.PSBindTexture(txInfo.PSBindPoint, OffScreenTexture);
                    TexBinder.SetUserControlTexture(txInfo.PSBindPoint, true);
                }
            }
        }
示例#3
0
        public void DrawScene(CRenderContext rc, CCommandList cmd, Graphics.CGfxCamera Camera, Graphics.View.CGfxSceneView view)
        {
            if (EnableDraw == false)
            {
                return;
            }
            if (mNeedUpdateGpuBuffer)
            {
                mNeedUpdateGpuBuffer = false;
                UpdateGpuBuffer(rc, cmd, Camera);
            }

            var program = mPass.Effect.ShaderProgram;

            if (UseComputeShader == false)
            {
                UpdateIndexBufferCPU(cmd, Camera);
            }
            else
            {
                ComputeDispatch(rc, cmd, Camera);
            }

            if (UseVTF)
            {
                CTextureBindInfo tbInfo = new CTextureBindInfo();
                if (program.FindTextureBindInfo(null, "gVertexTexture", ref tbInfo))
                {
                    mPass.ShaderResources.VSBindTexture(tbInfo.VSBindPoint, mVertexTextureView);
                }
                if (program.FindTextureBindInfo(null, "gInstanceDataTexture", ref tbInfo))
                {
                    mPass.ShaderResources.VSBindTexture(tbInfo.VSBindPoint, mInstanceDataTextureView);
                }
                var spInfo = new CSamplerBindInfo();
                if (program.FindSamplerBindInfo(null, "Samp_gVertexTexture", ref spInfo))
                {
                    mPass.ShaderSamplerBinder.VSBindSampler(spInfo.VSBindPoint, mSamplerState);
                }
                if (program.FindSamplerBindInfo(null, "Samp_gInstanceDataTexture", ref spInfo))
                {
                    mPass.ShaderSamplerBinder.VSBindSampler(spInfo.VSBindPoint, mSamplerState);
                }
            }
            else
            {
                //CTextureBindInfo tbInfo = new CTextureBindInfo();
                //if(program.FindTextureBindInfo(null, "AllVertexArray", ref tbInfo))
                //{
                //    mPass.ShaderResources.VSBindTexture(tbInfo.VSBindPoint, mAllVertexSRV);
                //}
                //if (program.FindTextureBindInfo(null, "MeshInstanceArray", ref tbInfo))
                //{
                //    mPass.ShaderResources.VSBindTexture(tbInfo.VSBindPoint, mMeshInstanceSRV);
                //}
                mPass.ShaderResources.VSBindTexture(14, mAllVertexSRV);
                mPass.ShaderResources.VSBindTexture(13, mMeshInstanceSRV);
            }

            CConstantBufferDesc cbInfo = new CConstantBufferDesc();

            if (mCBMeshBatch != null && program.GetCBufferDesc(program.FindCBuffer("cbMeshBatch"), ref cbInfo))
            {
                mPass.BindCBufferVS(cbInfo.VSBindPoint, mCBMeshBatch);
            }
            mPass.ViewPort = Camera.SceneView.Viewport;

            mPass.BindCBuffer(mPass.Effect.ShaderProgram, mPass.Effect.CacheData.CBID_Camera, Camera.CBuffer);
            if (view != null)
            {
                mPass.BindCBuffer(mPass.Effect.ShaderProgram, mPass.Effect.CacheData.CBID_View, view.SceneViewCB);
            }

            //mPass.ViewPort = view.Viewport;

            if (UseComputeShader == false)
            {
                mPass.AttachIndexBuffer = mCpuDrawIndexBuffer;

                var dpDesc = new CDrawPrimitiveDesc();
                dpDesc.SetDefault();
                dpDesc.NumPrimitives = mDrawArgs.IndexCountPerInstance / 3;
                mPass.GeometryMesh.SetAtom(0, 0, ref dpDesc);
            }
            else
            {
                mPass.AttachIndexBuffer = mDrawIndexBuffer;
                mPass.SetIndirectDraw(bufferIndirectDrawArgs, 0);
            }

            cmd.PushPass(mPass);
        }
示例#4
0
        public async System.Threading.Tasks.Task InitPass(CRenderContext rc, Graphics.CGfxMaterialInstance MtlInst = null, bool isSM3 = false)
        {
            if (rc == null)
            {
                rc = CEngine.Instance.RenderContext;
            }

            if (CRenderContext.ShaderModel >= 4)
            {
                UseComputeShader = true;
                Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"GpuDriven: SM = {CRenderContext.ShaderModel},Use ComputeShader");
            }
            else
            {
                UseComputeShader = false;
                Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"GpuDriven: SM = {CRenderContext.ShaderModel},CPU Culling");
            }

            if (rc.ContextCaps.MaxVertexShaderStorageBlocks == 0)
            {
                UseVTF = true;
                Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"GpuDriven: No SSBO in VertexShader,Use VTF");
            }
            else
            {
                UseVTF = false;
                Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"GpuDriven: Use SSBO in VertexShader");
            }
            if (mMergeInstanceSE == null)
            {
                mMergeInstanceSE = mMergeInstanceSE = EngineNS.CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMergeInstanceSE>();
                if (UseVTF)
                {
                    mMergeInstanceSE.SetMacroDefineValue("ENV_USEVTF", "1");
                }
                else
                {
                    mMergeInstanceSE.SetMacroDefineValue("ENV_USEVTF", "0");
                }
            }
            if (MtlInst == null)
            {
                MtlInst = await CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, RName.GetRName("Material/defaultmaterial.instmtl"));
            }
            if (mPass == null)
            {
                var pass = rc.CreatePass();

                var meshpri = CEngine.Instance.MeshPrimitivesManager.CreateMeshPrimitives(rc, 1);
                EngineNS.Graphics.Mesh.CGfxMeshCooker.MakeRect3D(rc, meshpri);
                //var meshpri = CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(rc, CEngineDesc.ScreenAlignedTriangleName, true);
                var ViewportMesh = CEngine.Instance.MeshManager.CreateMesh(rc, meshpri);
                ViewportMesh.SetMaterialInstance(rc, 0, MtlInst,
                                                 CEngine.Instance.PrebuildPassData.DefaultShadingEnvs);

                var affectLights = new List <GamePlay.SceneGraph.GSceneGraph.AffectLight>();
                ViewportMesh.mMeshVars.SetPointLights(affectLights);

                await pass.InitPassForViewportView(rc, mMergeInstanceSE, MtlInst, ViewportMesh);

                mPass = pass;

                var vsDesc = mPass.Effect.ShaderProgram.VertexShader.Desc;

                var tbInfo = new CTextureBindInfo();
                if (vsDesc.GetSRVDesc(vsDesc.FindSRVDesc("AllVertexArray"), ref tbInfo))
                {
                }
                if (vsDesc.GetSRVDesc(vsDesc.FindSRVDesc("MeshInstanceArray"), ref tbInfo))
                {
                }
            }

            //const string CSVersion = "cs_5_0";
            var macros     = new CShaderDefinitions();
            var shaderFile = RName.GetRName("Shaders/Compute/GpuDriven/Cluster.compute", RName.enRNameType.Engine);

            mCS_MeshBatchDesc = rc.CreateShaderDesc(shaderFile, "CSMain_MeshBatch", EShaderType.EST_ComputeShader, macros, CIPlatform.Instance.PlatformType);
            mCS_MeshBatch     = rc.CreateComputeShader(mCS_MeshBatchDesc);

            mCS_ClearBatchArgsDesc = rc.CreateShaderDesc(shaderFile, "CSMain_ClearBatchArgs", EShaderType.EST_ComputeShader, macros, CIPlatform.Instance.PlatformType);
            mCS_ClearBatchArgs     = rc.CreateComputeShader(mCS_ClearBatchArgsDesc);

            var cbIndex = mCS_MeshBatchDesc.FindCBufferDesc("cbMeshBatch");

            if (cbIndex != uint.MaxValue)
            {
                mCBMeshBatch = rc.CreateConstantBuffer(mCS_MeshBatchDesc, cbIndex);
            }
        }