public override void LoadContent(SharpDX.Direct3D11.DeviceContext context) { ImageLoadInformation imageLoadParam = new ImageLoadInformation() { BindFlags = BindFlags.ShaderResource, Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm, MipLevels = 1 }; _compassPanel = new CompassControl() { FrameName = "WindRose", Bounds = new UniRectangle(new UniScalar(1.0f, -160), 10, 150, 75), CompassTexture = ToDispose(new SpriteTexture(_engine.Device, ClientSettings.TexturePack + @"Gui\WindRose.png", Vector2I.Zero, imageLoadParam)), DayCircle = ToDispose(new SpriteTexture(_engine.Device, ClientSettings.TexturePack + @"Gui\DayCircle.png", Vector2I.Zero, imageLoadParam)), MaskArrow = ToDispose(new SpriteTexture(_engine.Device, ClientSettings.TexturePack + @"Gui\MaskArrow.png", Vector2I.Zero, imageLoadParam)), SoulStoneIcon = ToDispose(new SpriteTexture(_engine.Device, ClientSettings.TexturePack + @"Gui\SoulStoneIcon.png", Vector2I.Zero, imageLoadParam)), sampler = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVClamp_MinMagMipLinear), }; _dateTime = new LabelControl() { Color = Color.Tomato, Text = "", Bounds = new UniRectangle(-50, -5, new UniScalar(1.0f, 0.0f), 20.0f) }; _compassPanel.Children.Add(_dateTime); _compassPanel.LayoutFlags = S33M3CoreComponents.GUI.Nuclex.Controls.ControlLayoutFlags.Skip; _guiScreen.Desktop.Children.Add(_compassPanel); }
public override void LoadContent(DeviceContext context) { _milkShapeMeshfactory.LoadMesh(@"\Meshes\block.txt", out _cubeMeshBluePrint, 0); _cubeTextureView = _config.CubeTextureManager.CubeArrayTexture; //ArrayTexture.CreateTexture2DFromFiles(_d3DEngine.Device, _d3DEngine.ImmediateContext, ClientSettings.TexturePack + @"Terran/", @"ct*.png", FilterFlags.Point, "ArrayTexture_DefaultEntityRenderer", out _cubeTextureView); foreach (var cube in _config.WorldParameters.Configuration.GetAllCubesProfiles()) { CubePack pack; //Prapare to creation of a new mesh with the correct texture mapping ID var materialChangeMapping = new Dictionary <int, int>(); materialChangeMapping[0] = cube.Tex_Back.TextureArrayId; //Change the Back Texture Id materialChangeMapping[1] = cube.Tex_Front.TextureArrayId; //Change the Front Texture Id materialChangeMapping[2] = cube.Tex_Bottom.TextureArrayId; //Change the Bottom Texture Id materialChangeMapping[3] = cube.Tex_Top.TextureArrayId; //Change the Top Texture Id materialChangeMapping[4] = cube.Tex_Left.TextureArrayId; //Change the Left Texture Id materialChangeMapping[5] = cube.Tex_Right.TextureArrayId; //Change the Right Texture Id pack.Mesh = _cubeMeshBluePrint.Clone(materialChangeMapping); pack.Vb = ToDispose(new VertexBuffer <VertexMesh>(_d3DEngine.Device, _cubeMeshBluePrint.Vertices.Length, SharpDX.Direct3D.PrimitiveTopology.TriangleList, "Block VB")); pack.Ib = ToDispose(new IndexBuffer <ushort>(_d3DEngine.Device, _cubeMeshBluePrint.Indices.Length, "Block IB")); pack.Vb.SetData(_d3DEngine.ImmediateContext, pack.Mesh.Vertices); pack.Ib.SetData(_d3DEngine.ImmediateContext, pack.Mesh.Indices); _cache.Add(cube.Id, pack); } _cubeEffect = ToDispose(new HLSLCubeTool(_d3DEngine.Device, ClientSettings.EffectPack + @"Entities/CubeTool.hlsl", VertexMesh.VertexDeclaration)); _cubeEffect.DiffuseTexture.Value = _cubeTextureView; _cubeEffect.SamplerDiffuse.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVClamp_MinMagMipPoint); }
/// <summary> /// Creating a new D3DEngine with an associated window for rendering /// </summary> /// <param name="startingSize">Windows starting size</param> /// <param name="windowCaption">Window Caption</param> /// <param name="RenderResolution">if not passed or equal to 0;0 then the resolution will be the one from the Windows Size</param> public D3DEngine(Size startingSize, string windowCaption, SampleDescription samplingMode, Size renderResolution = default(Size)) { IsShuttingDownRequested = false; //Create the MainRendering Form _renderForm = new RenderForm() { Text = windowCaption, ClientSize = startingSize, StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen }; WindowHandle = _renderForm.Handle; _renderForm.KeyUp += new System.Windows.Forms.KeyEventHandler(_renderForm_KeyUp); this.RenderResolution = renderResolution; this.CurrentMSAASampling = samplingMode; string errorInit; isInitialized = false; if (Initialize(out errorInit) == false) { errorInit = "DirectX initialization error, cannot start the game : " + errorInit; System.Windows.Forms.MessageBox.Show(errorInit); logger.Error(errorInit); return; } isInitialized = true; //Init State repo RenderStatesRepo.Initialize(this); }
public override void Draw(SharpDX.Direct3D11.DeviceContext context, int index) { if (_activatedEffect == null) { if (_backBufferClouds.OffSreenRenderTarget != null) { _backBufferClouds.OffSreenRenderTarget = null; } return; } if (index == _postEffectStartingDrawId) { //Change RenderTarget to this offline texture //Clear renderTarger _engine.ImmediateContext.ClearRenderTargetView(_renderTargetView, __renderTargetViewDefaultColor); _engine.ImmediateContext.OutputMerger.SetTargets(_engine.DepthStencilTarget, _renderTargetView); _backBufferClouds.OffSreenRenderTarget = _renderTexture; _postEffectStartDrawDone = true; } else if (index == _postEffectEndingDrawId && _postEffectStartDrawDone) { //We have finished to draw into the offline texture, link back the screen backbuffer _engine.SetRenderTargets(context); //Start the Post effect code here RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthDisabled); _vBuffer.SetToDevice(context, 0); _iBuffer.SetToDevice(context, 0); _activatedEffect.Render(context); context.DrawIndexed(6, 0, 0); _postEffectStartDrawDone = false; } }
public override void Initialize() { //Initializate the Stars displayer _skyStars.Initialize(); //initialize Clouds displayer _clouds.Initialize(); //Generate manualy created models GenerateDome(); GenerateMoon(); BuffersToDevice(); //Create Buffers //Init effects _skyDomeEffect = new HLSLPlanetSkyDome(_d3dEngine.Device, ClientSettings.EffectPack + @"SkyDome\PlanetSkyDome.hlsl", VertexPosition.VertexDeclaration); _posiTextureEffect = new HLSLVertexPositionTexture(_d3dEngine.Device); //Init Textures _skyTex_View = ShaderResourceView.FromFile(_d3dEngine.Device, ClientSettings.TexturePack + @"SkyDome\skyText.png"); _moonTex_View = ShaderResourceView.FromFile(_d3dEngine.Device, ClientSettings.TexturePack + @"SkyDome\moon.png"); _glowTex_View = ShaderResourceView.FromFile(_d3dEngine.Device, ClientSettings.TexturePack + @"SkyDome\moonglow.png"); _skyDomeEffect.TerraTexture.Value = _skyTex_View; _skyDomeEffect.SamplerDiffuse.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UWrapVClamp_MinMagMipLinear); _posiTextureEffect.SamplerDiffuse.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVWrap_MinMagMipLinear); base.Initialize(); }
private static void CreateRasterStatesCollection(D3DEngine engine) { //Rasters.Default Rasters.Default = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.Back, FillMode = FillMode.Solid, IsMultisampleEnabled = engine.CurrentMSAASampling.Count == 1 ? false : true }); //Rasters.CullNone Rasters.CullNone = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.None, FillMode = FillMode.Solid, IsMultisampleEnabled = engine.CurrentMSAASampling.Count == 1 ? false : true }); //Rasters.CullFront Rasters.CullFront = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.Front, FillMode = FillMode.Solid, IsMultisampleEnabled = engine.CurrentMSAASampling.Count == 1 ? false : true }); //Rasters.Wired Rasters.Wired = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.Back, FillMode = FillMode.Wireframe, IsMultisampleEnabled = engine.CurrentMSAASampling.Count == 1 ? false : true }); //Rasters.Sprite Rasters.Sprite = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.Back, FillMode = FillMode.Wireframe, IsMultisampleEnabled = engine.CurrentMSAASampling.Count == 1 ? false : true }); }
private static void CreateRasterStatesCollection() { //Rasters.Default Rasters.Default = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.Back, FillMode = FillMode.Solid }); //Rasters.CullNone Rasters.CullNone = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.None, FillMode = FillMode.Solid }); //Rasters.CullFront Rasters.CullFront = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.Front, FillMode = FillMode.Solid }); //Rasters.Wired Rasters.Wired = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.Back, FillMode = FillMode.Wireframe }); //Rasters.Sprite Rasters.Sprite = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription() { CullMode = CullMode.Back, FillMode = FillMode.Wireframe }); }
public void Render(ModelControl control, IFlatGuiGraphics graphics) { var instance = control.ModelInstance; if (control.VoxelEffect == null && control.CubeRenderer == null) { return; } var needToRender = control.VoxelEffect != null && control.ModelInstance != null || control.CubeRenderer != null && control.SelectedCube != null; if (!needToRender) { return; } var bounds = control.GetAbsoluteBounds(); var voxelEffect = control.VoxelEffect; var context = graphics.Engine.ImmediateContext; float aspectRatio = bounds.Width / bounds.Height; Matrix projection; var fov = (float)Math.PI / 3.6f; Matrix.PerspectiveFovLH(fov, aspectRatio, 0.5f, 100f, out projection); Matrix view = Matrix.LookAtLH(new Vector3(0, 0, -1.9f), Vector3.Zero, Vector3.UnitY); //Set custom ViewPort graphics.Engine.SetCustomViewPort(new ViewportF(bounds.X, bounds.Y, bounds.Width, bounds.Height)); //Rendering the Tool RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadWriteEnabled); if (instance != null) { voxelEffect.Begin(context); voxelEffect.CBPerFrame.Values.LightDirection = Vector3.Zero; voxelEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(view * projection); voxelEffect.CBPerFrame.IsDirty = true; var state = instance.VoxelModel.GetMainState(); instance.SetState(state); var sphere = BoundingSphere.FromBox(state.BoundingBox); var rMax = 2f * Math.Sin(fov / 2); var size = state.BoundingBox.GetSize(); var offset = -size / 2 - state.BoundingBox.Minimum; var scale = (float)rMax / sphere.Radius; instance.World = Matrix.Translation(offset) * Matrix.Scaling(scale) * Matrix.RotationY(MathHelper.Pi + MathHelper.PiOver4) * control.AlterTransform * Matrix.RotationQuaternion(control.Rotation); control.VisualVoxelModel.Draw(context, control.VoxelEffect, instance); } else if (control.SelectedCube != null) { control.CubeRenderer.Render(context, control.AlterTransform * Matrix.RotationQuaternion(control.Rotation) * view, projection, new Color3(1, 1, 1)); } graphics.Engine.SetScreenViewPort(); }
public override void Draw(DeviceContext context, int index) { RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthDisabled); _cubeShader.Begin(context); _cubeShader.CBPerFrame.Values.View = Matrix.Transpose(_view); _cubeShader.CBPerFrame.Values.Projection = Matrix.Transpose(_engine.Projection2D); _cubeShader.CBPerFrame.IsDirty = true; _staticBlockVB.SetToDevice(context, 0); _staticBlockIB.SetToDevice(context, 0); foreach (RotationCube cube in _rotatingCubes) { //Draw Shadow Cube _cubeShader.CBPerDraw.Values.Color = cube.CubeShadowColor; _cubeShader.CBPerDraw.Values.World = Matrix.Transpose(cube.WorldShadow); _cubeShader.CBPerDraw.IsDirty = true; _cubeShader.Apply(context); context.DrawIndexed(_staticBlockIB.IndicesCount, 0, 0); //Draw Cube _cubeShader.CBPerDraw.Values.Color = cube.CubeColor; _cubeShader.CBPerDraw.Values.World = Matrix.Transpose(cube.World); _cubeShader.CBPerDraw.IsDirty = true; _cubeShader.Apply(context); context.DrawIndexed(_staticBlockIB.IndicesCount, 0, 0); } }
private static void CreateDepthStencilCollection() { List <DepthStencilStateDescription> statesCollection = new List <DepthStencilStateDescription>(); //DepthStencil.DepthEnabled DepthStencils.DepthReadWriteEnabled = RenderStatesRepo.AddDepthStencilStates(new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less, BackFace = new DepthStencilOperationDescription() { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep }, FrontFace = new DepthStencilOperationDescription() { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep } } ); //DepthStencil.DepthDisabled DepthStencils.DepthDisabled = RenderStatesRepo.AddDepthStencilStates(new DepthStencilStateDescription() { IsDepthEnabled = false, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less, BackFace = new DepthStencilOperationDescription() { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep }, FrontFace = new DepthStencilOperationDescription() { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep } } ); //DepthStencil.DepthDisabled DepthStencils.DepthReadEnabled = RenderStatesRepo.AddDepthStencilStates(new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.Zero, DepthComparison = Comparison.Less, BackFace = new DepthStencilOperationDescription() { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep }, FrontFace = new DepthStencilOperationDescription() { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep } } ); }
public static void CreateStates(D3DEngine engine) { //Init the Repository Objects RenderStatesRepo.Initialize(engine); CreateRasterStatesCollection(engine); CreateBlendStatesCollection(); CreateDepthStencilCollection(); CreateSamplerStatesCollection(); }
private void DrawingArm(DeviceContext context) { //Prepare DirectX rendering pipeline context.ClearDepthStencilView(_d3dEngine.DepthStencilTarget, DepthStencilClearFlags.Depth, 1.0f, 0); RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled); //Compute a "world matrix" for displaying the Arm var screenPosition = Matrix.RotationX(MathHelper.Pi * 1.3f) * Matrix.RotationY(MathHelper.Pi * 0.01f) * //Some rotations Matrix.Scaling(1.7f) * //Adjusting scale Matrix.Translation(0.1f, -1, 0) * //Translation Matrix.Invert(_camManager.ActiveCamera.View_focused) * //Keep the Arm On screen Matrix.Translation(_camManager.ActiveCamera.LookAt.ValueInterp * 2.5f); //Project the arm in the lookat Direction = Inside the screen //Prepare Effect _voxelModelEffect.Begin(context); _voxelModelEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_camManager.ActiveCamera.ViewProjection3D_focused); _voxelModelEffect.CBPerFrame.IsDirty = true; //Assign model variables values _voxelModelEffect.CBPerModel.Values.World = Matrix.Transpose(Matrix.Scaling(1f / 16) * screenPosition); _voxelModelEffect.CBPerModel.Values.LightColor = _lightColor.ValueInterp; _voxelModelEffect.CBPerModel.IsDirty = true; //Don't use the GetTransform of the Part because its linked to the entity body, here we have only the arm to display. _voxelModelEffect.CBPerPart.Values.Transform = Matrix.Transpose(Matrix.Identity); _voxelModelEffect.CBPerPart.IsDirty = true; //Assign color mappings var colorMapping = _player.ModelInstance.VoxelModel.Frames[_handState.ActiveFrame].ColorMapping; if (colorMapping != null) { _voxelModelEffect.CBPerModel.Values.ColorMapping = colorMapping.BlockColors; } else { _voxelModelEffect.CBPerModel.Values.ColorMapping = _player.ModelInstance.VoxelModel.ColorMapping.BlockColors; } _voxelModelEffect.CBPerModel.IsDirty = true; //Assign buffers var vb = _handVisualVoxelModel.VertexBuffer; var ib = _handVisualVoxelModel.IndexBuffer; vb.SetToDevice(context, 0); ib.SetToDevice(context, 0); //Push Effect _voxelModelEffect.Apply(context); //Draw ! context.DrawIndexed(ib.IndicesCount, 0, 0); }
public override void Draw(DeviceContext context, int index) { //Applying Correct Render States RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled); // draw hover selection if (PlayerEntityManager.PlayerCharacter.EntityState.IsBlockPicked || PlayerEntityManager.PlayerCharacter.EntityState.IsEntityPicked) { _pickedCube.Draw(context, _camManager.ActiveCamera); } }
private void DrawingMoon(DeviceContext context) { float alpha = (float)Math.Abs(Math.Sin((_clock.ClockTime.ClockTimeNormalized * MathHelper.TwoPi) + (float)Math.PI / 2.0f)); //Set States. RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled); Matrix World = Matrix.Scaling(2f, 2f, 2f) * Matrix.RotationX((_clock.ClockTime.ClockTimeNormalized * MathHelper.TwoPi) + (float)Math.PI / 2.0f) * Matrix.RotationY(-_fPhi + (float)Math.PI / 2.0f) * Matrix.Translation(LightDirection.X * 1900, LightDirection.Y * 1900, LightDirection.Z * 1900) * 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); _posiTextureEffect.Begin(context); _posiTextureEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_camManager.ActiveCamera.ViewProjection3D_focused); _posiTextureEffect.CBPerFrame.IsDirty = true; _posiTextureEffect.CBPerDraw.Values.World = Matrix.Transpose(World); if (LightDirection.Y > 0) { _posiTextureEffect.CBPerFrame.Values.Alpha = alpha; } else { _posiTextureEffect.CBPerFrame.Values.Alpha = 0; } _posiTextureEffect.CBPerDraw.IsDirty = true; _posiTextureEffect.DiffuseTexture.Value = _moonTex_View; _posiTextureEffect.DiffuseTexture.IsDirty = true; _posiTextureEffect.Apply(context); _moonIndexBuffer.SetToDevice(context, 0); _moonVertexBuffer.SetToDevice(context, 0); context.DrawIndexed(_moonIb.Length, 0, 0); //Draw moonLight World = Matrix.Scaling(6f, 6f, 6f) * Matrix.RotationX((_clock.ClockTime.ClockTimeNormalized * MathHelper.TwoPi) + (float)Math.PI / 2.0f) * Matrix.RotationY(-_fPhi + (float)Math.PI / 2.0f) * Matrix.Translation(LightDirection.X * 1700, LightDirection.Y * 1700, LightDirection.Z * 1700) * 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); _posiTextureEffect.CBPerDraw.Values.World = Matrix.Transpose(World); _posiTextureEffect.CBPerDraw.IsDirty = true; _posiTextureEffect.DiffuseTexture.Value = _glowTex_View; _posiTextureEffect.DiffuseTexture.IsDirty = true; _posiTextureEffect.Apply(context); context.DrawIndexed(_moonIb.Length, 0, 0); }
public override void Initialize() { _noise = new SimplexNoise(new Random()); _noise.SetParameters(0.075, SimplexNoise.InflectionMode.NoInflections, SimplexNoise.ResultScale.ZeroToOne); _effect = ToDispose(new HLSLClouds(_d3DEngine.Device, ClientSettings.EffectPack + @"Weather\Clouds.hlsl", VertexPosition2Cloud.VertexDeclaration, _sharedCB.CBPerFrame)); _effect.SamplerBackBuffer.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVWrap_MinMagMipPoint); _instancedBuffer = ToDispose(new InstancedVertexBuffer <VertexPosition3Color, VertexPosition2Cloud>(_d3DEngine.Device, SharpDX.Direct3D.PrimitiveTopology.TriangleList, "Clouds")); _indexBuffer = ToDispose(new IndexBuffer <ushort>(_d3DEngine.Device, 36, "_cloudIB", 10, ResourceUsage.Default)); _clouds = new List <VertexPosition2Cloud>(); _newCloudGenerated = false; }
public void LoadContent(DeviceContext context) { //Prepare Textured Block rendering when equiped ============================================================== _milkShapeMeshfactory.LoadMesh(@"\Meshes\block.txt", out _cubeMeshBluePrint, 0); _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); }
public override void Draw(DeviceContext context, int index) { RenderStatesRepo.ApplyStates(context, DXStates.Rasters.CullNone, DXStates.Blenders.Enabled); _vBuffer.SetToDevice(context, 0); _iBuffer.SetToDevice(context, 0); _effect.Begin(context); _effect.CBPerDraw.Values.Color = Color; _effect.CBPerDraw.IsDirty = true; _effect.Apply(context); context.DrawIndexed(6, 0, 0); }
public override void Initialize() { _rasterStateId = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription { IsAntialiasedLineEnabled = false, CullMode = CullMode.None, DepthBias = 0, DepthBiasClamp = 1f, IsDepthClipEnabled = true, FillMode = FillMode.Solid, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0, }); var blendDescr = new BlendStateDescription { IndependentBlendEnable = false, AlphaToCoverageEnable = false }; for (var i = 0; i < 8; i++) { blendDescr.RenderTarget[i].IsBlendEnabled = false; blendDescr.RenderTarget[i].BlendOperation = BlendOperation.Add; blendDescr.RenderTarget[i].AlphaBlendOperation = BlendOperation.Add; blendDescr.RenderTarget[i].DestinationBlend = BlendOption.InverseSourceAlpha; blendDescr.RenderTarget[i].DestinationAlphaBlend = BlendOption.One; blendDescr.RenderTarget[i].SourceBlend = BlendOption.One; blendDescr.RenderTarget[i].SourceAlphaBlend = BlendOption.One; blendDescr.RenderTarget[i].RenderTargetWriteMask = ColorWriteMaskFlags.All; } _blendStateId = RenderStatesRepo.AddBlendStates(blendDescr); _depthStateId = RenderStatesRepo.AddDepthStencilStates(new DepthStencilStateDescription { IsDepthEnabled = false, DepthComparison = Comparison.Less, DepthWriteMask = DepthWriteMask.All, IsStencilEnabled = false, BackFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep }, FrontFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep } }); }
private void DrawingTool(DeviceContext context) { if (_renderingType == ToolRenderingType.Voxel && (_toolVoxelInstance == null || _toolVoxelModel == null || !_toolVoxelModel.Initialized)) { return; } context.ClearDepthStencilView(_d3dEngine.DepthStencilTarget, DepthStencilClearFlags.Depth, 1.0f, 0); RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled); float scale; if (_renderingType == ToolRenderingType.Cube) { scale = 0.75f; } else { var voxelBB = _toolVoxelInstance.State.BoundingBox.GetSize(); scale = MathHelper.Min(1.0f, 16 / MathHelper.Max(MathHelper.Max(voxelBB.X, voxelBB.Y), voxelBB.Z)); scale *= 1.20f; } var screenPosition = Matrix.RotationQuaternion(_animationRotation) * Matrix.RotationX(MathHelper.Pi / 8) * Matrix.Scaling(scale) * Matrix.Translation(new Vector3(1.0f, -1, -0.2f) + _animationOffset) * Matrix.Invert(_camManager.ActiveCamera.View_focused) * Matrix.Translation(_camManager.ActiveCamera.LookAt.ValueInterp * 1.8f); if (_renderingType == ToolRenderingType.Cube) { _cubeRenderer.Render(context, Matrix.Translation(0.3f, 0.3f, 0.3f) * screenPosition, _camManager.ActiveCamera.ViewProjection3D_focused, _lightColor.ValueInterp ); } if (_renderingType == ToolRenderingType.Voxel && _toolVoxelModel != null) { _voxelModelEffect.Begin(context); _voxelModelEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_camManager.ActiveCamera.ViewProjection3D_focused); _voxelModelEffect.CBPerFrame.IsDirty = true; _toolVoxelInstance.World = Matrix.Scaling(1f / 16) * screenPosition; _toolVoxelInstance.LightColor = _lightColor.ValueInterp; _toolVoxelModel.Draw(context, _voxelModelEffect, _toolVoxelInstance); } }
public override void LoadContent(DeviceContext context) { ArrayTexture.CreateTexture2DFromFiles(_engine.Device, context, ClientSettings.TexturePack + @"Cracks/", @"ct*.png", TexturePackConfig.Current.Settings.enuSamplingFilter, "ArrayTexture_Cracks", out _cracksArray); ToDispose(_cracksArray); _cubeVb = ToDispose(new VertexBuffer <VertexMesh>(context.Device, _cubeMeshBluePrint.Vertices.Length, SharpDX.Direct3D.PrimitiveTopology.TriangleList, "Cracks Block VB")); _cubeIb = ToDispose(new IndexBuffer <ushort>(context.Device, _cubeMeshBluePrint.Indices.Length, "Cracks Block IB")); _cubeVb.SetData(context, _cubeMeshBluePrint.Vertices); _cubeIb.SetData(context, _cubeMeshBluePrint.Indices); _cubeEffect = ToDispose(new HLSLCracks(context.Device, ClientSettings.EffectPack + @"Terran/Cracks.hlsl", VertexMesh.VertexDeclaration)); _cubeEffect.DiffuseTexture.Value = _cracksArray; _cubeEffect.SamplerDiffuse.Value = RenderStatesRepo.GetSamplerState(DXStates.Samplers.UVClamp_MinMagMipPoint); base.LoadContent(context); }
public override void Draw(SharpDX.Direct3D11.DeviceContext context, int index) { if (Display && Transform.HasValue && _toolVoxelModel != null) { RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadEnabled); _voxelModelEffect.Begin(context); _voxelModelEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_cameraManager.ActiveCamera.ViewProjection3D); _voxelModelEffect.CBPerFrame.IsDirty = true; _toolVoxelInstance.World = Matrix.Scaling(1f / 16) * Transform.Value; _toolVoxelInstance.LightColor = new Color3(0.0f, 0.0f, 1f); _toolVoxelInstance.Alpha = _alpha; _toolVoxelModel.Draw(context, _voxelModelEffect, _toolVoxelInstance); } }
public override void Draw(DeviceContext context, int index) { RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadEnabled); foreach (var chunk in _worldChunks.GetChunks(WorldChunks.GetChunksFilter.VisibleWithinStaticObjectRange)) { if (chunk.DistanceFromPlayer > _worldChunks.StaticEntityViewRange) { break; //Limit the crack drawing to the same zone as the static entity visualization } foreach (var pair in chunk.BlockData.GetTags().Where(p => p.Value is DamageTag && _worldChunks.IsEntityVisible(p.Key))) { var tag = (DamageTag)pair.Value; var pos = BlockHelper.ConvertToGlobal(chunk.Position, pair.Key); var list = new List <Vector3I>(new[] { new Vector3I(1, 0, 0), new Vector3I(-1, 0, 0), new Vector3I(0, 1, 0), new Vector3I(0, -1, 0), new Vector3I(0, 0, 1), new Vector3I(0, 0, -1) }); var result = list.Select(v => v + pos).Select(v => _cubesHolder.GetCube(v).Cube.EmissiveColor.ToColor4()).Aggregate((s, c) => s + c); result.Red /= 6; result.Green /= 6; result.Blue /= 6; result.Alpha /= 6; result.Red = Math.Max(result.Red, result.Alpha * _skyDome.SunColor.Red); result.Green = Math.Max(result.Green, result.Alpha * _skyDome.SunColor.Green); result.Blue = Math.Max(result.Blue, result.Alpha * _skyDome.SunColor.Blue); _cubeEffect.Begin(context); _cubeEffect.CBPerDraw.Values.TextureIndex = 5 - 5 * tag.Strength / tag.TotalStrength; _cubeEffect.CBPerDraw.Values.World = Matrix.Transpose(Matrix.Scaling(1.01f) * Matrix.Translation(pos + new Vector3(0.5f))); _cubeEffect.CBPerDraw.Values.ViewProjection = Matrix.Transpose(_cameraManager.ActiveCamera.ViewProjection3D); _cubeEffect.CBPerDraw.Values.LightColor = new Color3(result.ToVector3()); // Color3.White; _cubeEffect.CBPerDraw.IsDirty = true; _cubeEffect.Apply(context); _cubeVb.SetToDevice(context, 0); _cubeIb.SetToDevice(context, 0); context.DrawIndexed(_cubeIb.IndicesCount, 0, 0); } } base.Draw(context, index); }
public override void Draw(SharpDX.Direct3D11.DeviceContext context, int index) { RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled); if (_bufferDirty) { _vb.SetData(context, _letreeVertexCollection.ToArray()); _ib.SetData(context, _letreeIndexCollection.ToArray()); _bufferDirty = false; } _shader.Begin(context); _shader.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_cameraManager.ActiveCamera.ViewProjection3D); _shader.CBPerFrame.IsDirty = true; _shader.CBPerDraw.Values.World = Matrix.Transpose(Matrix.RotationQuaternion(rotationQ.ValueInterp)); _shader.CBPerDraw.IsDirty = true; _shader.Apply(context); _vb.SetToDevice(context, 0); _ib.SetToDevice(context, 0); context.DrawIndexed(_ib.IndicesCount, 0, 0); //Draw text _spriteRenderer.Begin(false, context); Vector2 positionText = new Vector2(0, 0); ByteColor color = Color.White; string info = "[R] Toggle rotation; [T] New generation"; info += Environment.NewLine + "Blocks quantity : " + _letreeIndexCollection.Count / 36; info += Environment.NewLine + "Tree size : " + (MaxtreeSize.X - MintreeSize.X + 1).ToString("X : 00 ") + (MaxtreeSize.Y - MintreeSize.Y + 1).ToString("Y : 00 ") + (MaxtreeSize.Z - MintreeSize.Z + 1).ToString("Z : 00 "); if (_newTemplate != null) { info += Environment.NewLine + "Axiome : " + _newTemplate.Axiom; } _spriteRenderer.DrawText(_font, info, ref positionText, ref color, -1, -1, SpriteRenderer.TextFontPosition.RelativeToFontUp); _spriteRenderer.End(context); }
private void Render(DeviceContext context, VertexColumnChart[] dataPerInstance) { if (dataPerInstance.Length == 0) { return; } RenderStatesRepo.ApplyStates(_engine.ImmediateContext, _rasterStateId, _blendStateId, _depthStateId); _effect.Begin(context); _effect.CBPerDraw.Values.ViewportSize = new Vector2(_engine.ViewPort.Width, _engine.ViewPort.Height); _effect.CBPerDraw.IsDirty = true; _effect.Apply(context); _vBufferInstanced.SetInstancedData(context, dataPerInstance); _vBufferInstanced.SetToDevice(context, 0); context.DrawInstanced(2, dataPerInstance.Length, 0, 0); }
public override void Draw(DeviceContext context, int index) { if (index == SOLID_DRAW) { _chunkDrawByFrame = 0; RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled); DrawSolidFaces(context); #if DEBUG if (ShowDebugInfo) { DrawDebug(context); } #endif return; } if (index == TRANSPARENT_DRAW) { //Only 2 index registered, no need to test the value of the index here it is for transparent one ! if (!PlayerManager.IsHeadInsideWater) { //Head not inside Water => Draw water front Faces RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadWriteEnabled); } else { //Head inside Water block, draw back faces only RenderStatesRepo.ApplyStates(context, DXStates.Rasters.CullFront, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadWriteEnabled); } DefaultDrawLiquid(context); return; } if (index == ENTITIES_DRAW) { RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled); DrawStaticEntities(context); return; } }
public override void Draw(DeviceContext context, int index) { RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled); _effectStars.Begin(context); _effectStars.CBPerDraw.Values.ViewProjection = Matrix.Transpose(_camManager.ActiveCamera.ViewProjection3D_focused); //Compute Vibility ! if (_gameClock.ClockTime.ClockTimeNormalized < 0.25) { _visibility = 1; // Before 06:00 am } else if (_gameClock.ClockTime.ClockTimeNormalized >= 0.25 && _gameClock.ClockTime.ClockTimeNormalized < 0.30) { _visibility = MathHelper.FullLerp(1, 0, 0.25, 0.30, _gameClock.ClockTime.ClockTimeNormalized); //Between 04:00am and 06:00am } else if (_gameClock.ClockTime.ClockTimeNormalized >= 0.30 && _gameClock.ClockTime.ClockTimeNormalized < 0.75) { _visibility = 0; //Between 06:00am and 6:00pm } else if (_gameClock.ClockTime.ClockTimeNormalized >= 0.75 && _gameClock.ClockTime.ClockTimeNormalized < 0.85) { _visibility = MathHelper.FullLerp(0, 1, 0.75, 0.85, _gameClock.ClockTime.ClockTimeNormalized); //Between 06:00pm and 08:00pm } else { _visibility = 1; } _visibility = Math.Max(_visibility, Math.Min(Math.Max((float)_camManager.ActiveCamera.WorldPosition.ValueInterp.Y - 127, 0), 173) / 173.0f); _effectStars.CBPerDraw.Values.Visibility = _visibility; _effectStars.CBPerDraw.IsDirty = true; _effectStars.Apply(context); _skyStarVB.SetToDevice(context, 0); context.Draw(_skyStarVB.VertexCount, 0); }
public SpriteStaticEmitter( ParticuleEngine parentParticuleEngine, int textureSamplerId, ShaderResourceView textureParticules, int StateRasterId, int StateBlenderId, int StateDepthId, IWeather weather) { _particules = new List <SpriteParticule>(); _rnd = new FastRandom(); _textureParticules = textureParticules; _textureSampler = RenderStatesRepo.GetSamplerState(textureSamplerId); _stateRasterId = StateRasterId; _stateBlenderId = StateBlenderId; _stateDepthId = StateDepthId; _parentParticuleEngine = parentParticuleEngine; _weather = weather; }
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)); }
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); }
/// <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); }