示例#1
0
        public void SetPassData(CRenderContext rc, CGfxMesh mesh, UInt32 index, CGfxSceneView vp, CPass pass)
        {
            //OnEffectRefresh(rc);
            if (pass.RenderPipeline == null)
            {
                var rplDesc = new CRenderPipelineDesc();
                pass.RenderPipeline = rc.CreateRenderPipeline(rplDesc);
            }
            pass.RenderPipeline.ShaderProgram     = mEffect.ShaderProgram;
            pass.RenderPipeline.RasterizerState   = mMaterial.RasterizerState;
            pass.RenderPipeline.DepthStencilState = mMaterial.DepthStencilState;
            pass.RenderPipeline.BlendState        = mMaterial.BlendState;

            pass.GeometryMesh = mesh.MeshPrimitives.GeometryMesh;

            pass.BindCBuffer(mEffect.ShaderProgram, mEffect.PerInstanceId, CBuffer);
            pass.BindCBuffer(mEffect.ShaderProgram, mEffect.PerFrameId, CEngine.Instance.PerFrameCBuffer);

            if (vp != null)
            {
                pass.ViewPort = vp.Viewport;
            }

            var textures = new CShaderResources();

            {
                Material.BindTextures(textures, mEffect.ShaderProgram);
                foreach (var i in Textures)
                {
                    textures.PSBindTexture(i.Key, i.Value);
                }
                mesh.ShadingEnv.BindResources(mesh, CBuffer, textures, mEffect.ShaderProgram);
            }
            pass.ShaderResources = textures;

            CShaderSamplers samplers = new CShaderSamplers();

            {
                CSamplerStateDesc sampDesc = new CSamplerStateDesc();
                sampDesc.SetDefault();
                sampDesc.Filter = ESamplerFilter.SPF_MIN_MAG_MIP_POINT;
                CSamplerState samp = CEngine.Instance.SamplerStateManager.GetSamplerState(rc, sampDesc);
                for (UInt32 i = 0; i < mEffect.ShaderProgram.SamplerNumber; i++)
                {
                    CSamplerBindInfo info = new CSamplerBindInfo();
                    mEffect.ShaderProgram.GetSamplerBindInfo(i, ref info);
                    samplers.PSBindSampler(info.PSBindPoint, samp);
                }
            }
            pass.ShaderSamplers = samplers;

            foreach (var i in mesh.MdfQueue.Modifiers)
            {
                i.OnSetPassData(pass);
            }

            CDrawPrimitiveDesc dpDesc = new CDrawPrimitiveDesc();

            mesh.MeshPrimitives.GetAtom(index, 0, ref dpDesc);
            pass.BindDrawPrimitive(ref dpDesc);
        }