当前位置: 首页>>代码示例>>C#>>正文


C# GraphicsDevice.SetRenderTargets方法代码示例

本文整理汇总了C#中GraphicsDevice.SetRenderTargets方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsDevice.SetRenderTargets方法的具体用法?C# GraphicsDevice.SetRenderTargets怎么用?C# GraphicsDevice.SetRenderTargets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphicsDevice的用法示例。


在下文中一共展示了GraphicsDevice.SetRenderTargets方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

 public override void Draw(GraphicsDevice device)
 {
     var oldTargets = device.GetRenderTargets();
     device.SetRenderTarget(Target);
     device.Clear(Color.Transparent);
     device.DepthStencilState = DepthStencilState.Default;
     Camera.ProjectionDirty();
     base.Draw(device);
     device.SetRenderTargets(oldTargets);
 }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:10,代码来源:3DTargetScene.cs

示例2: Draw

        public void Draw(GraphicsDevice device, GameTime gameTime, Vector4? clipPlane = null, float? alpha = null)
        {
            terrainWater.Time = (float)(gameTime.TotalGameTime.TotalMilliseconds) / 2000000.0f;

            RenderTargetBinding[] renderTargetBindings = device.GetRenderTargets();

            terrainWater.Board.UseLessVertices = true;

            DrawRefractionMap(device, gameTime);
            DrawReflectionMap(device, gameTime);

            terrainWater.Board.UseLessVertices = false;

            device.SetRenderTargets(renderTargetBindings);
            DrawWater(device);
        }
开发者ID:smarthaert,项目名称:icgame,代码行数:16,代码来源:TerrainWaterDrawer.cs

示例3: GenerateMaxMap

        private void GenerateMaxMap(RenderTarget2D texture, GraphicsDevice graphicsDevice)
        {
            // Save old render setup to restore later.
            SharpDX.Direct3D11.DepthStencilView depthStencilBefore;
            var renderTargetsBefore = graphicsDevice.GetRenderTargets(out depthStencilBefore);
            ViewportF oldViewport = graphicsDevice.GetViewport(0);

            numHeightmapMipLevels = 0;
            var currentWidth = texture.Width / 2;
            var currentHeight = texture.Height / 2;
            for (var mipLevel = 1; currentWidth > 0 && currentHeight > 0; ++mipLevel, currentWidth /= 2, currentHeight /= 2)
            {
                // Generate sampler on-the-fly.
                var samplerStateDesc = SharpDX.Direct3D11.SamplerStateDescription.Default();
                samplerStateDesc.AddressV = SharpDX.Direct3D11.TextureAddressMode.Clamp;
                samplerStateDesc.AddressU = SharpDX.Direct3D11.TextureAddressMode.Clamp;
                samplerStateDesc.Filter = SharpDX.Direct3D11.Filter.MinMagMipPoint;
                samplerStateDesc.MinimumLod = mipLevel-1;
                samplerStateDesc.MaximumLod = mipLevel-1;
                samplerStateDesc.MipLodBias = mipLevel-1;
                var mipLevelSamplerState = SamplerState.New(graphicsDevice, "MipLevelSampler_" + mipLevel, samplerStateDesc);

                // Draw.
                maxmapGenShader.Effect.Parameters["NearestSampler"].SetResource(mipLevelSamplerState);
                maxmapGenShader.Effect.Parameters["InputTexture"].SetResource(texture.ShaderResourceView[ViewType.Single, 0, mipLevel-1]);
                graphicsDevice.SetRenderTargets(texture.RenderTargetView[ViewType.Single, 0, mipLevel]);
                graphicsDevice.SetViewport(0, 0, currentWidth, currentHeight);
                maxmapGenShader.Effect.CurrentTechnique.Passes[0].Apply();
                graphicsDevice.Draw(PrimitiveType.PointList, 1);
                maxmapGenShader.Effect.CurrentTechnique.Passes[0].UnApply();

                ++numHeightmapMipLevels;
            }
            graphicsDevice.SetRenderTargets(depthStencilBefore, renderTargetsBefore);
            graphicsDevice.SetViewport(oldViewport);
        }
开发者ID:Wumpf,项目名称:mstbasedheightmapgen,代码行数:36,代码来源:TerrainRaymarcher.cs

示例4: Draw

        /// <summary>
        /// Render the terrain
        /// </summary>
        /// <param name="device"></param>
        /// <param name="world"></param>
        public override void Draw(GraphicsDevice device, WorldState world)
        {
            if (VertexBuffer == null) return;
            PPXDepthEngine.RenderPPXDepth(Effect, true, (depthMode) =>
            {
                Effect.Parameters["LightGreen"].SetValue(LightGreen.ToVector4());
                Effect.Parameters["DarkGreen"].SetValue(DarkGreen.ToVector4());
                Effect.Parameters["DarkBrown"].SetValue(DarkBrown.ToVector4());
                Effect.Parameters["LightBrown"].SetValue(LightBrown.ToVector4());
                Effect.Parameters["ScreenSize"].SetValue(new Vector2(device.Viewport.Width, device.Viewport.Height));
                //Effect.Parameters["depthOutMode"].SetValue(DepthMode && (!FSOEnvironment.UseMRT));

                var offset = -world.WorldSpace.GetScreenOffset();

                world._3D.ApplyCamera(Effect);
                var worldmat = Matrix.Identity * Matrix.CreateTranslation(0, ((world.Zoom == WorldZoom.Far) ? -5 : ((world.Zoom == WorldZoom.Medium) ? -4 : -3)) * (20 / 522f), 0);
                Effect.Parameters["World"].SetValue(worldmat);

                Effect.Parameters["DiffuseColor"].SetValue(new Vector4(world.OutsideColor.R / 255f, world.OutsideColor.G / 255f, world.OutsideColor.B / 255f, 1.0f));

                device.SetVertexBuffer(VertexBuffer);
                device.Indices = IndexBuffer;

                Effect.CurrentTechnique = Effect.Techniques["DrawBase"];
                foreach (var pass in Effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, NumPrimitives);
                }

                int grassScale;
                float grassDensity;
                switch (world.Zoom)
                {
                    case WorldZoom.Far:
                        grassScale = 4;
                        grassDensity = 0.56f;
                        break;
                    case WorldZoom.Medium:
                        grassScale = 2;
                        grassDensity = 0.50f;
                        break;
                    default:
                        grassScale = 1;
                        grassDensity = 0.43f;
                        break;
                }

                grassDensity *= GrassDensityScale;

                if (BladePrimitives > 0)
                {
                    Effect.CurrentTechnique = Effect.Techniques["DrawBlades"];
                    int grassNum = (int)Math.Ceiling(GrassHeight / (float)grassScale);

                    //if (depthMode && (!FSOEnvironment.UseMRT)) return;
                    RenderTargetBinding[] rts = null;
                    if (FSOEnvironment.UseMRT)
                    {
                        rts = device.GetRenderTargets();
                        if (rts.Length > 1)
                        {
                            device.SetRenderTarget((RenderTarget2D)rts[0].RenderTarget);
                        }
                    }
                    device.Indices = BladeIndexBuffer;
                    for (int i = 0; i < grassNum; i++)
                    {
                        Effect.Parameters["World"].SetValue(Matrix.Identity * Matrix.CreateTranslation(0, i * (20 / 522f) * grassScale, 0));
                        Effect.Parameters["GrassProb"].SetValue(grassDensity * ((grassNum - (i / (2f * grassNum))) / (float)grassNum));
                        offset += new Vector2(0, 1);
                        Effect.Parameters["ScreenOffset"].SetValue(offset);

                        foreach (var pass in Effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, BladePrimitives);
                        }
                    }
                    if (FSOEnvironment.UseMRT)
                    {
                        device.SetRenderTargets(rts);
                    }
                }
            });
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:91,代码来源:TerrainComponent.cs

示例5: DrawPointLights

        /// <summary>
        /// Creates a Light texture.
        /// </summary>
        /// <param name="inGraphicsDevice">GraphicsDevice to use for rendering.</param>
        /// <param name="inView">View matrix.</param>
        /// <param name="inProjection">Projection matrix.</param>
        /// <param name="inCameraPosition">Camera position.</param>
        /// <param name="inLights">Collection of point lights.</param>
        protected virtual void DrawPointLights(GraphicsDevice inGraphicsDevice, Matrix inView, Matrix inProjection,
                                               Vector3 inCameraPosition, ICollection<PrePointLight> inLights)
        {
            // If there are no lights to draw, return.
            if (inLights.Count == 0) { return; }

            // Apply the depth and normal textures to our effect.
            mLightingEffect.Parameters["t_Depth"].SetValue(tDepth);
            mLightingEffect.Parameters["t_Normal"].SetValue(tNormal);

            // Rendering the lights requires the inverse ViewProjection matrix.
            mViewProjection = Matrix.Multiply(inView, inProjection);
            mInverseViewProjection = Matrix.Invert(mViewProjection);
            mLightingEffect.Parameters["matInverseViewProjection"].SetValue(mInverseViewProjection);

            // Prepare our light render-texture and clear it to black.
            inGraphicsDevice.SetRenderTarget(tLight);
            inGraphicsDevice.Clear(Color.Black);

            // Record render states here so they can be restored afterwards.
            mSavedBlendState = inGraphicsDevice.BlendState;
            mSavedDepthStencilState = inGraphicsDevice.DepthStencilState;
            inGraphicsDevice.BlendState = BlendState.Additive;
            inGraphicsDevice.DepthStencilState = DepthStencilState.None;

            foreach (PrePointLight pointLight in inLights)
            {
                // Apply the properties of each light to the lighting effect.
                pointLight.SetEffectParameters(mLightingEffect);

                // Calculate the WorldViewProjection matrix and apply it.
                mWorldViewProjection = (Matrix.CreateScale(pointLight.Attenuation) *
                                        Matrix.CreateTranslation(pointLight.Position)) *
                                        mViewProjection;
                mLightingEffect.Parameters["matWorldViewProjection"].SetValue(mWorldViewProjection);

                // If we're inside the mesh, we will only see the triangles drawn with the reverse winding-order,
                // meaning that normally they'd be culled. So swap cull-modes temporarily.
                float dist = Vector3.Distance(inCameraPosition, pointLight.Position);
                if (dist < pointLight.Attenuation) { inGraphicsDevice.RasterizerState = RasterizerState.CullClockwise; }

                // Draw the mesh and reset the RasterizerState to what it was previously.
                mPointLight.Meshes[0].Draw();
                inGraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            }

            inGraphicsDevice.BlendState = mSavedBlendState;
            inGraphicsDevice.DepthStencilState = mSavedDepthStencilState;
            inGraphicsDevice.SetRenderTargets(null);
        }
开发者ID:BaronVonTeapot,项目名称:Basic,代码行数:58,代码来源:PrePassRenderer.cs

示例6: DrawDepthNormal

        /// <summary>
        /// Creates the Depth and Normal textures.
        /// </summary>
        /// <param name="inGraphicsDevice">GraphicsDevice to use for rendering.</param>
        /// <param name="inView">View matrix.</param>
        /// <param name="inProjection">Projection matrix.</param>
        /// <param name="inCameraPosition">Camera position vector.</param>
        /// <param name="inModels">Collection of models to create depth and normal maps for.</param>
        protected virtual void DrawDepthNormal(GraphicsDevice inGraphicsDevice, Matrix inView, Matrix inProjection,
                                               Vector3 inCameraPosition, ICollection<ModelInstance> inModels)
        {
            // Prepare the render-textures for drawing and clear to white (infinite depth).
            inGraphicsDevice.SetRenderTargets(tNormal, tDepth);
            inGraphicsDevice.Clear(Color.White);

            // Draw each model instance using the DepthNormal shader technique. This is rather slow
            // because each model has to cache its effects and change them. I'd rather switch to a
            // different technique, forcing each ModelInstance to cache the name of its current
            // technique. A string is easier to store than a whole file.
            foreach (ModelInstance modelInstance in inModels)
            {
                modelInstance.CacheEffects();
                modelInstance.SetModelEffect(mDepthNormalEffect, false);
                modelInstance.DrawBasic(inGraphicsDevice, inView,
                                        inProjection, inCameraPosition);
                modelInstance.RestoreCached();
            }

            // Resolve the render-textures.
            inGraphicsDevice.SetRenderTargets(null);
        }
开发者ID:BaronVonTeapot,项目名称:Basic,代码行数:31,代码来源:PrePassRenderer.cs

示例7: UpdateNormalMapTexture

		private void UpdateNormalMapTexture(GraphicsDevice pGraphicsDevice)
		{
			RenderTargetBinding[] pSavedSurfaces = pGraphicsDevice.GetRenderTargets();

			pGraphicsDevice.SetRenderTarget(m_pNormalMapTexture);

			pGraphicsDevice.Clear(Color.Black);

			Matrix tWorld = Matrix.Identity;
			Matrix tView = Matrix.Identity;
			Matrix tProjection = Matrix.CreateOrthographicOffCenter(0, Settings.NORMAL_MAP_TEXTURE_SIZE,
				Settings.NORMAL_MAP_TEXTURE_SIZE, 0, 0.0f, 1.0f);

			m_pNormalMapUpdateEffect.SetValue("WorldViewProjection", Matrix.Transpose(tProjection));

			// render to texture here
			m_pNormalMapUpdateEffect.SetValue("ElevationTexture", m_pElevationTexture);
			m_pNormalMapUpdateEffect.SetValue("ElevationTextureSizeInverse", Settings.ELEVATION_TEXTURE_SIZE_INVERSE);
			m_pNormalMapUpdateEffect.SetValue("NormalScaleFactor", new Vector2(0.5f / (float)m_nGridSpacing));
			m_pNormalMapUpdateEffect.Render(new RenderCallback(RenderNormalMapTexture));

			pGraphicsDevice.SetRenderTargets(pSavedSurfaces);

			//m_pNormalMapTexture.GetTexture().Save("NormalMap " + m_nGridSpacing + ".dds", ImageFileFormat.Dds);
		}
开发者ID:modulexcite,项目名称:torq2,代码行数:25,代码来源:Level.cs

示例8: UpdateElevationTexture

		private void UpdateElevationTexture(GraphicsDevice pGraphicsDevice)
		{
			// TODO: currently we just update the whole texture. we need to do this toroidally
			RenderTargetBinding[] pSavedSurfaces = pGraphicsDevice.GetRenderTargets();

			pGraphicsDevice.SetRenderTarget(m_pElevationTexture);

			Matrix tWorld = Matrix.Identity;
			Matrix tView = Matrix.Identity;
			Matrix tProjection = Matrix.CreateOrthographicOffCenter(0, Settings.ELEVATION_TEXTURE_SIZE,
				Settings.ELEVATION_TEXTURE_SIZE, 0, 0.0f, 1.0f);

			m_pElevationUpdateEffect.SetValue("WorldViewProjection", Matrix.Transpose(tProjection));

			// render to texture here
			m_pElevationUpdateEffect.SetValue("HeightMapTexture", m_pParentTerrain.HeightMapTexture);
			m_pElevationUpdateEffect.SetValue("HeightMapSizeInverse", 1.0f / (float) m_pParentTerrain.HeightMapTexture.Width);
			m_pElevationUpdateEffect.SetValue("GridSpacing", (float) m_nGridSpacing);
			m_pElevationUpdateEffect.SetValue("WorldPosMin", (Vector2) m_tPositionMin);
			m_pElevationUpdateEffect.SetValue("ToroidalOrigin", m_tToroidalOrigin);
			m_pElevationUpdateEffect.SetValue("ElevationTextureSize", Settings.ELEVATION_TEXTURE_SIZE);
			m_pElevationUpdateEffect.Render(RenderElevationTexture);

			pGraphicsDevice.SetRenderTargets(pSavedSurfaces);

			/*using (Stream pFileStream = File.OpenWrite("Level " + m_nGridSpacing + ".png"))
			{
				m_pElevationTexture.SaveAsPng(pFileStream,
					Settings.ELEVATION_TEXTURE_SIZE,
					Settings.ELEVATION_TEXTURE_SIZE);
			}*/
		}
开发者ID:modulexcite,项目名称:torq2,代码行数:32,代码来源:Level.cs

示例9: RenderTargetSwitchContext

 public RenderTargetSwitchContext(GraphicsDevice graphicsDevice, RenderTarget2D target) {
    this.graphicsDevice = graphicsDevice;
    this.target = target;
    oldRenderTargets = graphicsDevice.GetRenderTargets(out oldDepthStencil);
    graphicsDevice.SetRenderTargets(target);
 }
开发者ID:ItzWarty,项目名称:AdventuresInShade,代码行数:6,代码来源:Canvas.cs

示例10: Draw

        public void Draw(GraphicsDevice device)
        {
            PostProcessor postprocessor = PostProcessor.GetInstance(device);

            device.SetRenderTargets(postprocessor.color_rt, postprocessor.depth_rt);
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil, Application.CLEAR_COLOR, 1.0f, 0);
            device.BlendState = BlendState.Opaque;
            device.DepthStencilState = DepthStencilState.Default;

            level.Draw3dEntities(device, camera);

            postprocessor.DepthOfField(postprocessor.color_rt, postprocessor.result_rt, postprocessor.depth_rt, camera, DepthOfFieldType.DiscBlur, player.position.Z, 5, total_time);

            device.SetRenderTarget(postprocessor.color_rt);
            device.Clear(ClearOptions.Target, Application.CLEAR_COLOR, 1, 0);
            device.BlendState = BlendState.AlphaBlend;

            level.Draw2dEntities(device, camera);
            device.DepthStencilState = DepthStencilState.DepthRead;
            particlemanager.Draw(device, camera);
            device.DepthStencilState = DepthStencilState.Default;
            level.DrawBubbleReflections(device, camera);

            device.SetRenderTargets(postprocessor.result_rt);

            SpriteRenderer spriterenderer = SpriteRenderer.GetInstance(device);
            spriterenderer.Begin(null);
            spriterenderer.Add(new TextureRegion(postprocessor.color_rt, 0, 0, postprocessor.color_rt.Width, postprocessor.color_rt.Height), Color.White, 0, 0, postprocessor.color_rt.Width, postprocessor.color_rt.Height, 0);
            spriterenderer.End();
        }
开发者ID:zfedoran,项目名称:bubblebound,代码行数:30,代码来源:game.cs


注:本文中的GraphicsDevice.SetRenderTargets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。