示例#1
0
        /// <summary>
        /// Draws one model using its instance data
        /// </summary>
        /// <param name="context"></param>
        /// <param name="effect"></param>
        /// <param name="instance"></param>
        public void Draw(DeviceContext context, HLSLVoxelModel effect, VoxelModelInstance instance)
        {
            if (!_initialized)
            {
                return;
            }

            var state = instance.State;

            if (_model.ColorMapping != null)
            {
                effect.CBPerModel.Values.ColorMapping = _model.ColorMapping.BlockColors;
            }

            effect.CBPerModel.Values.World      = Matrix.Transpose(instance.World);
            effect.CBPerModel.Values.LightColor = instance.LightColor;
            effect.CBPerModel.Values.Alpha      = instance.Alpha;
            effect.CBPerModel.IsDirty           = true;

            // draw each part of the model
            for (int i = 0; i < state.PartsStates.Count; i++)
            {
                var voxelModelPartState = state.PartsStates[i];

                if (voxelModelPartState.ActiveFrame == byte.MaxValue)
                {
                    continue;
                }

                var vb = _visualFrames[voxelModelPartState.ActiveFrame].VertexBuffer;
                var ib = _visualFrames[voxelModelPartState.ActiveFrame].IndexBuffer;

                vb.SetToDevice(context, 0);
                ib.SetToDevice(context, 0);

                var frame = _model.Frames[voxelModelPartState.ActiveFrame];

                if (frame.ColorMapping != null)
                {
                    effect.CBPerModel.Values.ColorMapping = frame.ColorMapping.BlockColors;
                    effect.CBPerModel.IsDirty             = true;
                }

                if (_model.Parts[i].IsHead)
                {
                    var bb = _visualFrames[voxelModelPartState.ActiveFrame].BoundingBox;
                    RotateHead(voxelModelPartState, instance, bb, out effect.CBPerPart.Values.Transform);
                    effect.CBPerPart.Values.Transform = Matrix.Transpose(effect.CBPerPart.Values.Transform);
                }
                else
                {
                    effect.CBPerPart.Values.Transform = Matrix.Transpose(voxelModelPartState.GetTransformation() * Matrix.RotationQuaternion(instance.Rotation));
                }

                effect.CBPerPart.IsDirty = true;
                effect.Apply(context);

                context.DrawIndexed(ib.IndicesCount, 0, 0);
            }
        }
        public override void LoadContent(DeviceContext context)
        {
            _cubeRenderer.LoadContent(context);

            _voxelModelEffect = ToDispose(new HLSLVoxelModel(context.Device, ClientSettings.EffectPack + @"Entities\VoxelModel.hlsl", VertexVoxel.VertexDeclaration));

            Tool = _player.Equipment.RightTool;

            _playerModel = _voxelModelManager.GetModel(_player.ModelName);
            if (_playerModel != null)
            {
                if (!_playerModel.Initialized)
                {
                    _playerModel.BuildMesh();
                }

                if (_player.ModelInstance == null)
                {
                    _player.ModelInstance = _playerModel.VoxelModel.CreateInstance();

                    //Get Voxel Arm of the character.
                    var armPartIndex = _player.ModelInstance.VoxelModel.GetArmIndex();
                    _handVoxelModel       = _player.ModelInstance.VoxelModel.Parts[armPartIndex];
                    _handState            = _player.ModelInstance.VoxelModel.GetMainState().PartsStates[armPartIndex];
                    _handVisualVoxelModel = _playerModel.VisualVoxelFrames[armPartIndex];
                }
            }
        }
        public override void LoadContent(SharpDX.Direct3D11.DeviceContext context)
        {
            _voxelEffect = ToDispose(new HLSLVoxelModel(context.Device, ClientSettings.EffectPack + @"Entities\VoxelModel.hlsl", VertexVoxel.VertexDeclaration));

            SelectionWindow.VoxelEffect              = _voxelEffect;
            SelectionWindow.SelectionButton.Pressed += SelectionButtonOnPressed;

            base.LoadContent(context);
        }
        public override void LoadContent(DeviceContext context)
        {
            //ArrayTexture.CreateTexture2DFromFiles(context.Device, context, ClientSettings.TexturePack + @"Terran/", @"ct*.png", FilterFlags.Point, "ArrayTexture_DefaultEntityRenderer", out _cubeTextureView);
            //ToDispose(_cubeTextureView);
            _cubeTextureView = _visualWorldParameters.CubeTextureManager.CubeArrayTexture;


            //Create Vertex/Index Buffer to store the loaded cube mesh.
            _cubeVb = ToDispose(new VertexBuffer <VertexMesh>(context.Device, _cubeMeshBluePrint.Vertices.Length, SharpDX.Direct3D.PrimitiveTopology.TriangleList, "Block VB"));
            _cubeIb = ToDispose(new IndexBuffer <ushort>(context.Device, _cubeMeshBluePrint.Indices.Length, "Block IB"));

            _cubeToolEffect = ToDispose(new HLSLCubeTool(context.Device, ClientSettings.EffectPack + @"Entities/CubeTool.hlsl", VertexMesh.VertexDeclaration));
            _cubeToolEffect.DiffuseTexture.Value = _cubeTextureView;
            _cubeToolEffect.SamplerDiffuse.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVClamp_MinMagMipPoint);

            _voxelModelEffect      = ToDispose(new HLSLVoxelModelInstanced(context.Device, ClientSettings.EffectPack + @"Entities\VoxelModelInstanced.hlsl", VoxelInstanceData.VertexDeclaration));
            _voxelToolEffect       = ToDispose(new HLSLVoxelModel(context.Device, ClientSettings.EffectPack + @"Entities\VoxelModel.hlsl", VertexVoxel.VertexDeclaration));
            _materialChangeMapping = new Dictionary <int, int>();

            //Create the font to base use by the sprite3dText Processor
            _dynamicEntityNameFont = ToDispose(new SpriteFont());
            _dynamicEntityNameFont.Initialize("Lucida Console", 32f, System.Drawing.FontStyle.Regular, true, context.Device, false);

            //Create the processor that will be used by the Sprite3DRenderer
            Sprite3DTextProc textProcessor = ToDispose(new Sprite3DTextProc(_dynamicEntityNameFont, RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVWrap_Text), ToDispose(new UtopiaIncludeHandler()), _sharedFrameCB.CBPerFrame, ClientSettings.EffectPack + @"Sprites\PointSprite3DText.hlsl"));

            //Create a sprite3Drenderer that will use the previously created processor to accumulate text data for drawing.
            _dynamicEntityNameRenderer = ToDispose(new Sprite3DRenderer <Sprite3DTextProc>(textProcessor,
                                                                                           DXStates.Rasters.Default,
                                                                                           DXStates.Blenders.Enabled,
                                                                                           DXStates.DepthStencils.DepthReadWriteEnabled,
                                                                                           context));
            Sprite3DColorBillBoardProc energyBarProcessor = ToDispose(new Sprite3DColorBillBoardProc(ToDispose(new UtopiaIncludeHandler()), _sharedFrameCB.CBPerFrame, ClientSettings.EffectPack + @"Sprites\PointSpriteColor3DBillBoard.hlsl"));

            _dynamicEntityEnergyBarRenderer = ToDispose(new Sprite3DRenderer <Sprite3DColorBillBoardProc>(energyBarProcessor,
                                                                                                          DXStates.Rasters.Default,
                                                                                                          DXStates.Blenders.Enabled,
                                                                                                          DXStates.DepthStencils.DepthReadWriteEnabled,
                                                                                                          context));
        }
示例#5
0
        /// <summary>
        /// Allows to load world effects and textures or to reload textures
        /// </summary>
        /// <param name="context"></param>
        public void InitDrawComponents(DeviceContext context)
        {
            if (this.IsInitialized)
            {
                UnloadDrawComponents();
            }

            //Create Biomes Colors texture Array

            ArrayTexture.CreateTexture2DFromFiles(_d3dEngine.Device, context, ClientSettings.TexturePack + @"BiomesColors/", @"*.png", FilterFlags.Point, "BiomesColors_WorldChunk", out _biomesColors_View, SharpDX.DXGI.Format.BC1_UNorm);

            _terra_View = VisualWorldParameters.CubeTextureManager.CubeArrayTexture;
            //ArrayTexture.CreateTexture2DFromFiles(_d3dEngine.Device, context, ClientSettings.TexturePack + @"Terran/", @"ct*.png", TexturePackConfig.Current.Settings.enuSamplingFilter, "ArrayTexture_WorldChunk", out _terra_View);
            ArrayTexture.CreateTexture2DFromFiles(_d3dEngine.Device, context, ClientSettings.TexturePack + @"AnimatedTextures/", @"*.png", FilterFlags.Point, "ArrayTexture_AnimatedTextures", out _textureAnimation_View, SharpDX.DXGI.Format.BC4_UNorm);


            _terraEffect = new HLSLTerran(_d3dEngine.Device, ClientSettings.EffectPack + @"Terran/Terran.hlsl", VertexCubeSolid.VertexDeclaration, SharedFrameCb.CBPerFrame);
            _terraEffect.TerraTexture.Value      = _terra_View;
            _terraEffect.SamplerDiffuse.Value    = RenderStatesRepo.GetSamplerState(TexturePackConfig.Current.Settings.enuTexMipCreationFilteringId);
            _terraEffect.SamplerBackBuffer.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVClamp_MinMagMipPoint);
            _terraEffect.BiomesColors.Value      = _biomesColors_View;
            _terraEffect.SkyBackBuffer.Value     = _skyBackBuffer.RenderTextureView;

            _liquidEffect = new HLSLLiquid(_d3dEngine.Device, ClientSettings.EffectPack + @"Terran/Liquid.hlsl", VertexCubeLiquid.VertexDeclaration, SharedFrameCb.CBPerFrame);
            _liquidEffect.TerraTexture.Value      = _terra_View;
            _liquidEffect.SamplerDiffuse.Value    = RenderStatesRepo.GetSamplerState(TexturePackConfig.Current.Settings.enuTexMipCreationFilteringId);
            _liquidEffect.SamplerOverlay.Value    = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVWrap_MinMagMipLinear);
            _liquidEffect.SamplerBackBuffer.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVClamp_MinMagMipPoint);
            _liquidEffect.BiomesColors.Value      = _biomesColors_View;
            _liquidEffect.AnimatedTextures.Value  = _textureAnimation_View;
            _liquidEffect.SkyBackBuffer.Value     = _skyBackBuffer.RenderTextureView;

            _voxelModelEffect          = ToDispose(new HLSLVoxelModel(_d3dEngine.Device, ClientSettings.EffectPack + @"Entities\VoxelModel.hlsl", VertexVoxel.VertexDeclaration));
            _voxelModelInstancedEffect = ToDispose(new HLSLVoxelModelInstanced(_d3dEngine.Device, ClientSettings.EffectPack + @"Entities\VoxelModelInstanced.hlsl", VoxelInstanceData.VertexDeclaration));
            _voxelModelInstancedEffect.SamplerBackBuffer.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVClamp_MinMagMipPoint);
        }
示例#6
0
        public override void LoadContent(DeviceContext context)
        {
            _iBuffer          = ToDispose(new IndexBuffer <ushort>(context.Device, 6, "Blur_iBuffer"));
            _blurVertexBuffer = ToDispose(new VertexBuffer <VertexPosition2Texture>(context.Device, 4, PrimitiveTopology.TriangleList, "Blur_vBuffer", ResourceUsage.Immutable));

            //Create Vertices for Icon Plane.
            VertexPosition2Texture[] vertices =
            {
                new VertexPosition2Texture(new Vector2(-1.00f, -1.00f), new Vector2(0.00f, 1.00f)),
                new VertexPosition2Texture(new Vector2(1.00f,  -1.00f), new Vector2(1.00f, 1.00f)),
                new VertexPosition2Texture(new Vector2(1.00f,   1.00f), new Vector2(1.00f, 0.00f)),
                new VertexPosition2Texture(new Vector2(-1.00f,  1.00f), new Vector2(0.00f, 0.00f))
            };
            _blurVertexBuffer.SetData(context, vertices); //Send the vertices inside the VBuffer

            //Create the Indices for icon plane
            ushort[] indices = { 0, 3, 1, 1, 3, 2 };
            _iBuffer.SetData(context, indices); //Send the vertices inside the IBuffer

            //Create the various Effect for rendering the icons
            _blurHorisontalEffect = ToDispose(new HLSLBlur(_d3DEngine.Device, HLSLBlur.BlurPass.Horizontal, Path.Combine(ClientSettings.PathRoot, @"Effects\Sprites\Blur.hlsl")));
            _blurVerticalEffect   = ToDispose(new HLSLBlur(_d3DEngine.Device, HLSLBlur.BlurPass.Vertical, Path.Combine(ClientSettings.PathRoot, @"Effects\Sprites\Blur.hlsl")));
            _voxelEffect          = ToDispose(new HLSLVoxelModel(_d3DEngine.Device, Path.Combine(ClientSettings.EffectPack, @"Entities\VoxelModel.hlsl"), VertexVoxel.VertexDeclaration));
            _overlayEffect        = ToDispose(new HLSLColorOverlay(_d3DEngine.Device, Path.Combine(ClientSettings.PathRoot, @"Effects\Sprites\ColorOverlay.hlsl")));

            if (_visualWorldParameters.WorldParameters != null && _visualWorldParameters.WorldParameters.Configuration != null)
            {
                List <Texture2D> icons = new List <Texture2D>();

                ShaderResourceView cubeTextureView = _visualWorldParameters.CubeTextureManager.CubeArrayTexture;

                //ShaderResourceView cubeTextureView;
                //ArrayTexture.CreateTexture2DFromFiles(_d3DEngine.Device, context,
                //                                      Path.Combine(ClientSettings.TexturePack, @"Terran\"), @"ct*.png",
                //                                      FilterFlags.Point, "ArrayTexture_DefaultEntityRenderer",
                //                                      out cubeTextureView);

                icons = Create3DBlockIcons(context, cubeTextureView, IconSize);

                _nbrCubeIcon = icons.Count;
                if (_nbrCubeIcon == 0)
                {
                    return;
                }
                //Texture2D[] spriteTextures;
                //ArrayTexture.CreateTexture2DFromFiles(_d3DEngine.Device,
                //                                      Path.Combine(ClientSettings.TexturePack, @"Sprites\"), @"*.png",
                //                                      FilterFlags.Point, "ArrayTexture_WorldChunk", out spriteTextures,
                //                                      1);
                //icons.AddRange(spriteTextures);
                CreateTextureArray(context, icons);

                //Array created i can dispose the various icons
                foreach (var icon in icons)
                {
                    icon.Dispose();
                }
                //cubeTextureView.Dispose();
                //foreach (var tex in spriteTextures) tex.Dispose();


                CreateVoxelIcons(context);
            }
            else
            {
                logger.Warn("Could not create voxel models and blocks icons, no configuration is set");
            }
        }
 public override void LoadContent(SharpDX.Direct3D11.DeviceContext context)
 {
     _voxelModelEffect = ToDispose(new HLSLVoxelModel(context.Device, ClientSettings.EffectPack + @"Entities\VoxelModel.hlsl", VertexVoxel.VertexDeclaration));
 }