本文整理汇总了C#中Camera.GetFrustum方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.GetFrustum方法的具体用法?C# Camera.GetFrustum怎么用?C# Camera.GetFrustum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera
的用法示例。
在下文中一共展示了Camera.GetFrustum方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderShadows
private void RenderShadows(RenderTarget renderTarget, Light light, Stage stage, Camera camera, int cascadeIndex, out Matrix4 viewProjection, out Vector2 clipPlane)
{
Backend.BeginPass(renderTarget, new Vector4(0, 0, 0, 1), true);
var modelViewProjection = Matrix4.Identity;
var orientation = Vector3.GetRotationTo(Vector3.UnitY, light.Direction);
clipPlane = new Vector2(light.ShadowNearClipDistance, light.Range * 2.0f);
Matrix4 view, projection;
if (light.Type == LighType.Directional)
{
var cameraFrustum = camera.GetFrustum();
var lightDir = -light.Direction;
lightDir.Normalize();
Matrix4 lightRotation = Matrix4.LookAt(Vector3.Zero, lightDir, Vector3.UnitY);
Vector3[] corners = cameraFrustum.GetCorners();
for (var i = 0; i < corners.Length; i++)
{
corners[i] = Vector3.Transform(corners[i], lightRotation);
}
var lightBox = BoundingBox.CreateFromPoints(corners);
var boxSize = lightBox.Max - lightBox.Min;
Vector3 halfBoxSize;
Vector3.Multiply(ref boxSize, 0.5f, out halfBoxSize);
var lightPosition = lightBox.Min + halfBoxSize;
lightPosition.Z = lightBox.Min.Z;
lightPosition = Vector3.Transform(lightPosition, Matrix4.Invert(lightRotation));
view = Matrix4.LookAt(lightPosition, lightPosition - lightDir, Vector3.UnitY);
projection = Matrix4.CreateOrthographic(boxSize.X, boxSize.Y, -boxSize.Z, boxSize.Z);
clipPlane.X = -boxSize.Z;
clipPlane.Y = boxSize.Z;
}
else
{
view = Matrix4.LookAt(light.Position, light.Position + light.Direction, Vector3.UnitY);
projection = Matrix4.CreatePerspectiveFieldOfView(light.OuterAngle, renderTarget.Width / (float)renderTarget.Height, clipPlane.X, clipPlane.Y);
}
viewProjection = view * projection;
ShadowRenderOperations.Reset();
stage.PrepareRenderOperations(view, ShadowRenderOperations, true, false);
RenderOperation[] operations;
int count;
ShadowRenderOperations.GetOperations(out operations, out count);
for (var i = 0; i < count; i++)
{
var world = operations[i].WorldMatrix;
modelViewProjection = world * view * projection;
Resources.ShaderProgram program;
RenderShadowsParams shadowParams;
if (operations[i].Skeleton != null)
{
program = RenderShadowsSkinnedShader;
shadowParams = RenderShadowsSkinnedParams;
}
else
{
program = RenderShadowsShader;
shadowParams = RenderShadowsParams;
}
Backend.BeginInstance(program.Handle, null, null, ShadowsRenderState);
Backend.BindShaderVariable(shadowParams.ModelViewProjection, ref modelViewProjection);
Backend.BindShaderVariable(shadowParams.ClipPlane, ref clipPlane);
if (light.Type == LighType.Directional)
{
float shadowBias = 0.05f * (cascadeIndex + 1);
Backend.BindShaderVariable(shadowParams.ShadowBias, shadowBias);
}
if (operations[i].Skeleton != null)
{
Backend.BindShaderVariable(shadowParams.Bones, ref operations[i].Skeleton.FinalBoneTransforms);
}
Backend.DrawMesh(operations[i].MeshHandle);
Backend.EndInstance();
}
Backend.EndPass();
}
示例2: RenderLights
private void RenderLights(Camera camera, ref Matrix4 view, ref Matrix4 projection, IReadOnlyCollection<Light> lights, Stage stage)
{
Matrix4 modelViewProjection = Matrix4.Identity;
var frustum = camera.GetFrustum();
foreach (var light in lights)
{
if (!light.Enabled)
continue;
RenderLight(camera, frustum, ref view, ref projection, stage, ref modelViewProjection, light);
}
}