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


C# Camera.GetFrustum方法代码示例

本文整理汇总了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();
        }
开发者ID:johang88,项目名称:triton,代码行数:97,代码来源:DeferredRenderer.cs

示例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);
            }
        }
开发者ID:johang88,项目名称:triton,代码行数:13,代码来源:DeferredRenderer.cs


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