本文整理汇总了C#中RenderHelper.SetViewPort方法的典型用法代码示例。如果您正苦于以下问题:C# RenderHelper.SetViewPort方法的具体用法?C# RenderHelper.SetViewPort怎么用?C# RenderHelper.SetViewPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RenderHelper
的用法示例。
在下文中一共展示了RenderHelper.SetViewPort方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderShadowMap
/// <summary>
/// Renders the shadow map using the orthographic camera created in
/// CalculateFrustum.
/// </summary>
/// <param name="gameTime">The game time.</param>
/// <param name="render">The render.</param>
/// <param name="splitIndex">Index of the split.</param>
/// <param name="world">The world.</param>
protected void RenderShadowMap(GameTime gameTime, RenderHelper render, int splitIndex, IWorld world)
{
// Set the viewport for the current split
Viewport splitViewport = new Viewport();
splitViewport.MinDepth = 0;
splitViewport.MaxDepth = 1;
splitViewport.Width = ShadowMapSize;
splitViewport.Height = ShadowMapSize;
splitViewport.X = splitIndex * ShadowMapSize;
splitViewport.Y = 0;
render.SetViewPort(splitViewport);
// Set up the effect
//shadowMapEffect.CurrentTechnique = shadowMapEffect.Techniques["GenerateShadowMap"];
//shadowMapEffect.Parameters["g_matViewProj"].SetValue(lightViewProjectionMatrices[splitIndex]);
// Draw the models
render.RenderSceneDepth(world, gameTime, ref lightViewMatrices[splitIndex], ref lightProjectionMatrices[splitIndex], true);
}
示例2: Render
/// <summary>
/// Renders a list of models to the shadow map, and returns a surface
/// containing the shadow occlusion factor
/// </summary>
/// <param name="gameTime">The game time.</param>
/// <param name="render">The render.</param>
/// <param name="ginfo">The ginfo.</param>
/// <param name="light">The light for which the shadow is being calculated</param>
/// <param name="mainCamera">The camera viewing the scene containing the light</param>
/// <param name="world">The world.</param>
/// <param name="deferredGBuffer">The deferred G buffer.</param>
/// <returns>
/// The shadow occlusion texture
/// </returns>
internal RenderTarget2D Render(GameTime gameTime, RenderHelper render,GraphicInfo ginfo, DirectionalLightPE light,
ICamera mainCamera, IWorld world, IDeferredGBuffer deferredGBuffer)
{
vp = render.GetViewPort();
// Set our targets
render.PushRenderTarget(shadowMap);
render.Clear(Color.White,ClearOptions.Target, 1.0f, 0);
render.Clear(Color.Black, ClearOptions.DepthBuffer, 1.0f, 0);
// Get corners of the main camera's bounding frustum
Matrix cameraTransform, viewMatrix;
viewMatrix = mainCamera.View;
cameraTransform = Matrix.Invert(viewMatrix);
mainCamera.BoundingFrustum.GetCorners(frustumCornersWS);
Vector3.Transform(frustumCornersWS, ref viewMatrix, frustumCornersVS);
for (int i = 0; i < 4; i++)
farFrustumCornersVS[i] = frustumCornersVS[i + 4];
// Calculate the cascade splits. We calculate these so that each successive
// split is larger than the previous, giving the closest split the most amount
// of shadow detail.
float N = NumSplits;
float near = mainCamera.NearPlane, far = mainCamera.FarPlane;
splitDepths[0] = near;
splitDepths[NumSplits] = far;
for (int i = 1; i < splitDepths.Length - 1; i++)
splitDepths[i] = splitConstant * near * (float)Math.Pow(far / near, i / N) + (1.0f - splitConstant) * ((near + (i / N)) * (far - near));
// Render our scene geometry to each split of the cascade
for (int i = 0; i < NumSplits; i++)
{
float minZ = splitDepths[i];
float maxZ = splitDepths[i + 1];
CalculateFrustum(light, mainCamera, minZ, maxZ, out lightProjectionMatrices[i], out lightViewMatrices[i],out lightViewProjectionMatrices[i]);
RenderShadowMap(gameTime,render, i,world);
}
render.PopRenderTargetAsSingleRenderTarget2D();
render.SetViewPort(ginfo.Viewport);
RenderShadowOcclusion(render,mainCamera,light,deferredGBuffer);
return shadowOcclusion;
}