Exemplo n.º 1
0
        public override void Draw(DeviceContext context, int index)
        {
            if (index == _smDrawID)
            {
                //Draw the DephtBuffer texture

                _shadowMap.DrawDepthBuffer(context, ref depthBufferDrawSize);
            }
            else
            {
                CreateLightViewProjectionMatrix(out LightViewProjection);

                var m = Matrix.Translation(_camManager.ActiveCamera.WorldPosition.ValueInterp.AsVector3());
                m.Invert();

                _shadowMap.Begin();

                // draw players
                DynamicEntityManager.VoxelDraw(context, m * LightViewProjection);

                // draw chunks
                Matrix worldFocus = Matrix.Identity;
                foreach (var chunk in WorldChunks.Chunks.Where(x => x.Graphics.IsExistingMesh4Drawing))
                {
                    _worldFocusManager.CenterTranslationMatrixOnFocus(ref chunk.World, ref worldFocus);
                    _landScapeShadowMapEffect.Begin(context);
                    _landScapeShadowMapEffect.CBPerDraw.Values.LightWVP = Matrix.Transpose(worldFocus * LightViewProjection);
                    _landScapeShadowMapEffect.CBPerDraw.IsDirty         = true;
                    _landScapeShadowMapEffect.Apply(context);

                    chunk.Graphics.DrawSolidFaces(context);
                }

                //WorldChunks.PrepareVoxelDraw(context, m * LightViewProjection);
                _entitiesShadowMapEffect.Begin(context);
                _entitiesShadowMapEffect.CBPerDraw.Values.LightWVP = Matrix.Transpose(m * LightViewProjection);
                _entitiesShadowMapEffect.CBPerDraw.IsDirty         = true;
                _entitiesShadowMapEffect.Apply(context);
                foreach (var chunk in WorldChunks.Chunks.Where(x => x.Graphics.IsExistingMesh4Drawing && x.DistanceFromPlayer <= WorldChunks.StaticEntityViewRange))
                {
                    WorldChunks.DrawStaticEntitiesShadow(context, chunk);
                }

                _shadowMap.End();

                _d3dEngine.SetRenderTargetsAndViewPort(context);

#if DEBUG
                if (!_debugSMTextureNeedToBeSaved)
                {
                    //Texture2D.ToFile(context, _shadowMap.DepthMap.Resource, ImageFileFormat.Dds, @"E:\1.dds");
                    _debugSMTextureNeedToBeSaved = true;
                }
#endif
            }
        }
Exemplo n.º 2
0
        private void DrawingDome(DeviceContext context)
        {
            Matrix World = Matrix.Translation((float)_camManager.ActiveCamera.WorldPosition.ValueInterp.X, -(float)_camManager.ActiveCamera.WorldPosition.ValueInterp.Y, (float)_camManager.ActiveCamera.WorldPosition.ValueInterp.Z);

            _worldFocusManager.CenterTranslationMatrixOnFocus(ref World, ref World);

            //Set States.
            RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadWriteEnabled);

            _skyDomeEffect.Begin(context);
            _skyDomeEffect.CBPerDraw.Values.ViewProj            = Matrix.Transpose(_camManager.ActiveCamera.ViewProjection3D_focused);
            _skyDomeEffect.CBPerDraw.Values.CameraWorldPosition = _camManager.ActiveCamera.WorldPosition.ValueInterp.AsVector3();
            _skyDomeEffect.CBPerDraw.Values.time           = _clock.ClockTime.ClockTimeNormalized;
            _skyDomeEffect.CBPerDraw.Values.World          = Matrix.Transpose(World);
            _skyDomeEffect.CBPerDraw.Values.LightDirection = LightDirection;
            _skyDomeEffect.CBPerDraw.Values.HeadUnderWater = PlayerManager.IsHeadInsideWater ? 1.0f : 0.0f;
            _skyDomeEffect.CBPerDraw.IsDirty = true;
            _skyDomeEffect.Apply(context);

            _domeVertexBuffer.SetToDevice(context, 0);
            _domeIndexBuffer.SetToDevice(context, 0);

            context.DrawIndexed(_domeIb.Length, 0, 0);
        }
Exemplo n.º 3
0
        public override void Draw(DeviceContext context, int index)
        {
            RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled);
            _effect.Begin(_d3DEngine.ImmediateContext);


            var world = Matrix.Identity * Matrix.Translation(-(CloudGridSize / 2 * CloudBlockSize) + _smallOffset.X + (float)_cameraManager.ActiveCamera.WorldPosition.ValueInterp.X, 140, -(CloudGridSize / 2 * CloudBlockSize) + _smallOffset.Y + (float)_cameraManager.ActiveCamera.WorldPosition.ValueInterp.Z);

            _worldFocusManager.CenterTranslationMatrixOnFocus(ref world, ref world);

            _effect.CBPerDraw.Values.World      = Matrix.Transpose(world);
            _effect.CBPerDraw.Values.Brightness = _brightness;
            _effect.CBPerDraw.IsDirty           = true;

            _effect.Apply(_d3DEngine.ImmediateContext);

            //Set the buffers to the graphical card
            _instancedBuffer.SetToDevice(_d3DEngine.Device.ImmediateContext, 0);
            _indexBuffer.SetToDevice(_d3DEngine.Device.ImmediateContext, 0);

            _d3DEngine.ImmediateContext.DrawIndexedInstanced(36, _cloudBlocksCount, 0, 0, 0);
        }