示例#1
0
        protected void SetParameters(DeviceContext deviceContext, Matrix view, Matrix proj, Matrix world,
                                     Vector4 lightPos, Vector4 lightCol, Vector4 eyePos, float lightIntensity,
                                     AbstractMaterial mat,
                                     ShaderResourceView texture, bool isTextureCube, bool isLighten)
        {
            MatrixRes = new MatrixBuf()
            {
                World = world,
                View  = view,
                Proj  = proj,
            };

            LightRes = new LightBuf()
            {
                Position  = lightPos,
                Color     = lightCol,
                EyePos    = eyePos,
                Intensity = lightIntensity
            };

            MaterialRes = new MaterialBuf()
            {
                Absorption = new Vector4(mat.Absorption, 0),
                Ambient    = new Vector4(mat.Ambient, 0),
                Diffuse    = new Vector4(mat.Diffuse, 0),
                Shiness    = mat.Shiness
            };

            FlagsRes = new FlagsBuf()
            {
                IsTextureCube = isTextureCube ? 1.0f : 0.0f,
                IsLighten     = isLighten ? 1.0f : 0.0f
            };

            deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer, InputTypeSize, 0));

            deviceContext.UpdateSubresource(ref MatrixRes, MatrixBuffer);
            deviceContext.VertexShader.SetConstantBuffer(0, MatrixBuffer);

            deviceContext.UpdateSubresource(ref LightRes, LightBuffer);
            deviceContext.PixelShader.SetConstantBuffer(1, LightBuffer);

            deviceContext.UpdateSubresource(ref MaterialRes, MaterialBuffer);
            deviceContext.PixelShader.SetConstantBuffer(2, MaterialBuffer);

            deviceContext.UpdateSubresource(ref FlagsRes, FlagsBuffer);
            deviceContext.PixelShader.SetConstantBuffer(4, FlagsBuffer);

            if (!isTextureCube)
            {
                deviceContext.PixelShader.SetShaderResource(0, texture);
            }
            else
            {
                deviceContext.PixelShader.SetShaderResource(2, texture);
            }
            deviceContext.PixelShader.SetSampler(0, Sampler);
            //ShadowBuf
        }
示例#2
0
        public void Render(DeviceContext deviceContext, RenderTargetView[] renderTargetViews, DepthStencilView depthStencilView,
                           Matrix view, Matrix proj, Matrix world,
                           Vector4 lightPos, Vector4 lightCol, Vector4 eyePos, float lightIntens,
                           AbstractMaterial mat,
                           ShaderResourceView texture, bool isTextureCube, bool isLighten,
                           PrimitiveTopology topology,
                           int vertexCount, bool withShadowMap = true)
        {
            SetParameters(deviceContext, view, proj, world, lightPos, lightCol, eyePos, lightIntens, mat, texture, isTextureCube, isLighten);

            if (withShadowMap)
            {
                SetShadowMapParameters(deviceContext, world);
            }

            RenderShader(deviceContext, renderTargetViews, depthStencilView, topology, vertexCount);
        }