コード例 #1
0
ファイル: ProjectorSystem.cs プロジェクト: third1020/MiniRTS
        public void RenderProjectors(PerspectiveCamera perspectiveCamera, GBuffer gBuffer)
        {
            this.Device.PostProcessState();

            for (var i = 0; i < this.Projectors.Count; i++)
            {
                var projector = this.Projectors[i];
                if (projector.ViewPoint.Frustum.Intersects(perspectiveCamera.Frustum))
                {
                    //G-Buffer input
                    this.Effect.DepthMap = gBuffer.DepthTarget;

                    // Projector properties
                    this.Effect.ProjectorMap            = projector.Texture;
                    this.Effect.Mask                    = projector.Mask;
                    this.Effect.ProjectorViewProjection = projector.ViewPoint.ViewProjection;
                    this.Effect.MaxDistance             = projector.MaxDistance;
                    this.Effect.ProjectorPosition       = projector.ViewPoint.Position;
                    this.Effect.ProjectorForward        = projector.ViewPoint.Forward;
                    this.Effect.Tint                    = projector.Tint;

                    // Camera properties
                    this.Effect.World                 = Matrix.Identity;
                    this.Effect.View                  = perspectiveCamera.View;
                    this.Effect.Projection            = ProjectionMath.ComputeProjectionMatrixThatFitsFrustum(perspectiveCamera, projector.ViewPoint.Frustum);
                    this.Effect.InverseViewProjection = perspectiveCamera.InverseViewProjection;

                    this.Effect.Apply(this.Technique);

                    this.FrustumDrawer.Render(projector.ViewPoint.Frustum);
                }
            }
        }
コード例 #2
0
        public void RenderLights(PerspectiveCamera perspectiveCamera, GBuffer gBuffer)
        {
            this.Device.ShadowCastingLightState();

            for (var i = 0; i < this.Lights.Count; i++)
            {
                var light = this.Lights[i];
                if (light.ViewPoint.Frustum.Intersects(perspectiveCamera.Frustum))
                {
                    // G-Buffer input
                    this.Effect.NormalMap = gBuffer.NormalTarget;
                    this.Effect.DepthMap  = gBuffer.DepthTarget;

                    // Light properties
                    this.Effect.LightDirection = light.ViewPoint.Forward;
                    this.Effect.LightPosition  = light.ViewPoint.Position;
                    this.Effect.Color          = light.Color;

                    // Camera properties for specular reflections
                    this.Effect.CameraPosition = perspectiveCamera.Position;
                    this.Effect.World          = Matrix.Identity;
                    this.Effect.View           = perspectiveCamera.View;

                    // Extend the far plane of the camera because otherwise the frustum might be clipped while the things its shadowing are still in view
                    this.Effect.Projection            = ProjectionMath.ComputeProjectionMatrixThatFitsFrustum(perspectiveCamera, light.ViewPoint.Frustum);
                    this.Effect.InverseViewProjection = perspectiveCamera.InverseViewProjection;

                    // Shadow properties
                    this.Effect.ShadowMap           = light.ShadowMap.DepthMap;
                    this.Effect.ColorMap            = light.ShadowMap.ColorMap;
                    this.Effect.LightViewProjection = light.ViewPoint.ViewProjection;

                    this.Effect.Apply();

                    this.FrustumDrawer.Render(light.ViewPoint.Frustum);
                }
            }
        }