Esempio n. 1
0
        //--------------------//

        #region Render
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            // Note: Doesn't call base methods
            PrepareRender();

            // Set floating view transformation
            Matrix transform = Matrix.Scaling(Scale) * Matrix.RotationQuaternion(Rotation);

            switch (Billboard)
            {
            case BillboardMode.Spherical:
                Engine.State.WorldTransform = transform * Matrix.Translation((Vector3)Position);
                break;

            case BillboardMode.Cylindrical:
                Engine.State.WorldTransform = transform * camera.CylindricalBillboard * camera.SimpleView * Matrix.Translation((Vector3)Position);
                break;

            default:
                Engine.State.WorldTransform = transform * camera.SimpleView * Matrix.Translation((Vector3)Position);
                break;
            }

            // Never light a floating model
            SurfaceEffect = SurfaceEffect.Plain;

            var effectiveLights = (SurfaceEffect == SurfaceEffect.Plain || getLights == null)
                ? new LightSource[0]
                : getLights(Position, BoundingSphere.HasValue ? BoundingSphere.Value.Radius : 0);

            for (int i = 0; i < NumberSubsets; i++)
            {
                RenderSubset(i, camera, effectiveLights);
            }
        }
Esempio n. 2
0
        //--------------------//

        #region Render
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            base.Render(camera, getLights);
            Engine.State.WorldTransform = WorldTransform;

            #region Draw
            // Activate the VertexBuffer
            Engine.State.SetVertexBuffer(_vb);

            // Prepare a render delegate
            Action render;
            if (_ib != null)
            {
                // Activate the IndexBuffer and render indexed primitives
                Engine.Device.Indices = _ib;
                render = (() => Engine.Device.DrawIndexedPrimitives(_primitiveType, 0, 0, _vertexCount, 0, _primitiveCount));
            }
            else
            {
                // Render non-indexed primitives
                render = (() => Engine.Device.DrawPrimitives(_primitiveType, 0, _primitiveCount));
            }

            // Handle lights for fixed-function or shader rendering
            var effectiveLights = (SurfaceEffect == SurfaceEffect.Plain || getLights == null)
                ? new LightSource[0]
                : getLights(Position, BoundingSphere.HasValue ? BoundingSphere.Value.Radius : 0);
            RenderHelper(render, _material, camera, effectiveLights);
            #endregion
        }
Esempio n. 3
0
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            #region Sanity checks
            if (getLights == null)
            {
                throw new ArgumentNullException(nameof(getLights));
            }
            #endregion

            // Rendering this without a shader isn't possible (non-standard FVF)
            if (SurfaceEffect < SurfaceEffect.Shader)
            {
                SurfaceEffect = SurfaceEffect.Shader;
            }

            // Note: Doesn't call base methods
            PrepareRender();
            Engine.State.WorldTransform = WorldTransform;

            // Update bounding bodies
            if (WorldTransformDirty)
            {
                RecalcWorldTransform();
            }

            for (int i = 0; i < NumberSubsets; i++)
            {
                RenderSubset(i, camera, getLights);
            }
        }
Esempio n. 4
0
        //--------------------//

        #region Render
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            base.Render(camera, getLights);

            Engine.State.SetVertexBuffer(_vb);
            Engine.Device.Indices = _ib;

            // Turn off texture wrapping at edges to prevent seams
            Engine.Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp);
            Engine.Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp);

            // Draw all sides of the cube
            for (int i = 0; i < 6; ++i)
            {
                // Skip any "empty" sides without errors
                if (Textures[i] == null)
                {
                    continue;
                }

                Engine.State.SetTexture(Textures[i]);
                Engine.Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, i * 4, 4, i * 6, 2);
            }

            // Restore normal texture handling
            Engine.Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Wrap);
            Engine.Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Wrap);
        }
Esempio n. 5
0
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            base.Render(camera, getLights);

            _lastCamera = camera;

            // Reload textures when they change
            if (Preset.TexturesDirty)
            {
                UpdateSpriteTextures();
            }

            // Never light a particle system
            SurfaceEffect = SurfaceEffect.Plain;

            if (camera.ClipPlane != default(DoublePlane))
            {
                // Rendering without shaders, so the clip plane is in world space
                Engine.State.UserClipPlane = camera.EffectiveClipPlane;
            }

            RenderParticles(camera);

            // Restore defaults
            Engine.State.UserClipPlane = default(Plane);
            Engine.State.ZBufferMode   = ZBufferMode.Normal;
        }
Esempio n. 6
0
        //--------------------//

        #region Render
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            base.Render(camera, getLights);
            Engine.State.WorldTransform = WorldTransform;

            // ToDo: Implement rendering
        }
Esempio n. 7
0
        //--------------------//

        #region Render
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            base.Render(camera, getLights);

            // ToDo: Implement
            throw new NotImplementedException();
        }
Esempio n. 8
0
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            base.Render(camera, getLights);

            // Scale by factor 3, which should be safe within a simple projection matrix (near=1 and far=10)
            Engine.State.WorldTransform = Matrix.Scaling(3, 3, 3);

            // Deactivate lighting
            Engine.State.FfpLighting = false;
        }
Esempio n. 9
0
        //--------------------//

        #region Render
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            base.Render(camera, getLights);
            Engine.State.WorldTransform = WorldTransform;

            var effectiveLights = (SurfaceEffect == SurfaceEffect.Plain || getLights == null)
                ? new LightSource[0]
                : getLights(Position, BoundingSphere.HasValue ? BoundingSphere.Value.Radius : 0);

            for (int i = 0; i < NumberSubsets; i++)
            {
                RenderSubset(i, camera, effectiveLights);
            }
        }
Esempio n. 10
0
        //--------------------//

        #region Render
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            base.Render(camera, getLights);
            Engine.State.WorldTransform = WorldTransform;

            UpdateShader();

            // Disable ZBuffer writing so particles can flow into each other
            Engine.State.ZBufferMode = ZBufferMode.ReadOnly;

            RenderHelper(() => _particleMesh.DrawSubset(0), XMaterial.DefaultMaterial, camera);

            // Restore defaults
            Engine.State.ZBufferMode = ZBufferMode.Normal;
        }
        //--------------------//

        #region Render
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            #region Sanity checks
            if (IsDisposed)
            {
                throw new ObjectDisposedException(ToString());
            }
            if (camera == null)
            {
                throw new ArgumentNullException(nameof(camera));
            }
            #endregion

            // Auto-adapt the rotation for billboarding
            switch (Billboard)
            {
            case BillboardMode.Spherical:
                _internalRotation   = camera.SphericalBillboard;
                WorldTransformDirty = true;
                break;

            case BillboardMode.Cylindrical:
                _internalRotation   = camera.CylindricalBillboard;
                WorldTransformDirty = true;
                break;

            default:
                Matrix.Identity.To(ref _internalRotation, ref WorldTransformDirty);
                break;
            }

            // Only allow the visualization of bounding bodies in normal view
            if (SurfaceEffect < SurfaceEffect.Glow)
            {
                if (DrawBoundingSphere && WorldBoundingSphere.HasValue)
                {
                    Engine.DrawBoundingSphere(WorldBoundingSphere.Value);
                }
                if (DrawBoundingBox && WorldBoundingBox.HasValue)
                {
                    Engine.DrawBoundingBox(WorldBoundingBox.Value);
                }
            }

            base.Render(camera, getLights);
        }
Esempio n. 12
0
        private void RenderSubset(int i, Camera camera, GetLights lights)
        {
            // Frustum culling with the bouding box
            if (_subsetWorldBoundingBoxes != null && !camera.InFrustum(_subsetWorldBoundingBoxes[i]))
            {
                return;
            }

            using (new ProfilerEvent(() => "Subset " + i))
            {
                Action renderSubset = () => Mesh.DrawSubset(i);

                if (SurfaceEffect >= SurfaceEffect.Glow)
                {
                    // The terrain will always appear completely black on the glow/shadow map
                    using (new ProfilerEvent(() => "Apply black " + _subsetShaders[i]))
                        _subsetShaders[i].Apply(renderSubset, XMaterial.DefaultMaterial, camera);
                }
                else
                {
                    // Apply the normal terrain shader
                    if (_subsetShaders[i] != null)
                    {
                        SurfaceShader = _subsetShaders[i];
                    }
                    XMaterial currentMaterial = i < Materials.Length ? Materials[i] : Materials[0];

                    // Handle lights for fixed-function or shader rendering
                    Vector3 boxCenter = (_subsetBoundingBoxes == null ? new Vector3() : _subsetBoundingBoxes[i].Minimum + (_subsetBoundingBoxes[i].Maximum - _subsetBoundingBoxes[i].Minimum) * 0.5f);

                    var effectiveLights = (SurfaceEffect == SurfaceEffect.Plain)
                        ? new LightSource[0]
                        : lights(Position + boxCenter, _blockSize * StretchH * (float)(Math.Sqrt(2) / 2));
                    RenderHelper(renderSubset, currentMaterial, camera, effectiveLights);
                }
            }

            // Only allow the visualization of bounding bodies in normal view
            if (DrawBoundingBox && _subsetWorldBoundingBoxes != null && SurfaceEffect < SurfaceEffect.Glow)
            {
                Engine.DrawBoundingBox(_subsetWorldBoundingBoxes[i]);
            }
        }
Esempio n. 13
0
        /// <inheritdoc/>
        internal override void Render(Camera camera, GetLights getLights = null)
        {
            // Rendering this without a shader isn't possible (non-standard FVF)
            if (SurfaceEffect < SurfaceEffect.Shader)
            {
                SurfaceEffect = SurfaceEffect.Shader;
            }

            // Note: Doesn't call base methods
            PrepareRender();
            Engine.State.WorldTransform = WorldTransform;

            SelectShader();

            RenderHelper(() => Mesh.DrawSubset(0), Materials[0], camera);
            if (DrawBoundingBox && WorldBoundingBox.HasValue && SurfaceEffect < SurfaceEffect.Glow)
            {
                Engine.DrawBoundingBox(WorldBoundingBox.Value);
            }
        }
Esempio n. 14
0
 /// <summary>
 /// To be called when this object ist to be rendered.
 /// </summary>
 /// <param name="camera">Supplies information for the view transformation.</param>
 /// <param name="getLights">A delegate that will be called to get lighting information.</param>
 internal virtual void Render(Camera camera, GetLights getLights = null)
 {
     PrepareRender();
 }