public override bool Init() { if (!base.Init()) { return(false); } _waves = new Waves(); _waves.Init(160, 160, 1.0f, 0.03f, 5.0f, 0.3f); Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _grassMapSRV = ShaderResourceView.FromFile(Device, "Textures/grass.dds"); _wavesMapSRV = ShaderResourceView.FromFile(Device, "Textures/water2.dds"); _boxMapSRV = ShaderResourceView.FromFile(Device, "Textures/WireFence.dds"); var filenames = new [] { "Textures/tree0.dds", "Textures/tree1.dds", "Textures/tree2.dds", "Textures/tree3.dds" }; _treeTextureMapArraySRV = Util.CreateTexture2DArraySRV(Device, ImmediateContext, filenames, Format.R8G8B8A8_UNorm); BuildLandGeometryBuffers(); BuildWaveGeometryBuffers(); BuildCrateGeometryBuffers(); BuildTreeSpritesBuffers(); Window.KeyDown += SwitchRenderState; return(true); }
public void OnParticleSystemChanged() { _particles = new List <Particle>(_particleSystem.MaxParticles); for (int i = 0; i < _particleSystem.MaxParticles; i++) { _particles.Add(new Particle()); } _bufferSize = _particleSystem.MaxParticles; if (_particleSystem.PlayOnAwake) { _playing = true; } //Load texture _textureResourceView = ShaderResourceView.FromFile(_context.Device, _particleSystem.ImagePath); //Recreate buffer CreateBuffer(); Reset(); DebugLog.Log("Changed particle system", "Particle Emitter"); }
protected override void CreateDeviceDependentResources() { RemoveAndDispose(ref vertexBuffer); RemoveAndDispose(ref indexBuffer); // Retrieve our SharpDX.Direct3D11.Device1 instance var device = this.DeviceManager.Direct3DDevice; // Load texture (a DDS cube map) textureView = ShaderResourceView.FromFile(device, "CubeMap.dds"); // Create our sampler state samplerState = new SamplerState(device, new SamplerStateDescription() { AddressU = TextureAddressMode.Clamp, AddressV = TextureAddressMode.Clamp, AddressW = TextureAddressMode.Clamp, BorderColor = new Color4(0, 0, 0, 0), ComparisonFunction = Comparison.Never, Filter = Filter.MinMagMipLinear, MaximumLod = 9, // Our cube map has 10 mip map levels (0-9) MinimumLod = 0, MipLodBias = 0.0f }); Vertex[] vertices; int[] indices; GeometricPrimitives.GenerateSphere(out vertices, out indices, Color.Gray); vertexBuffer = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, vertices)); vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <Vertex>(), 0); indexBuffer = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, indices)); totalVertexCount = indices.Length; }
public void AddTexture(string file) { m_TextureConstantBufferDesc.HasTexture = true; textures_.Add(ShaderResourceView.FromFile(ApplicationDX11.Instance.Device, file)); m_TextureConstantBuffer.UpdateStruct(m_TextureConstantBufferDesc); }
public override bool Init() { if (!base.Init()) { return(false); } _waves = new Waves(); _waves.Init(160, 160, 1.0f, 0.03f, 5.0f, 0.3f); Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _grassMapSRV = ShaderResourceView.FromFile(Device, "Textures/grass.dds"); _wavesMapSRV = ShaderResourceView.FromFile(Device, "Textures/water2.dds"); _boxMapSRV = ShaderResourceView.FromFile(Device, "Textures/WireFence.dds"); BuildLandGeometryBuffers(); BuildWaveGeometryBuffers(); BuildCrateGeometryBuffers(); Window.KeyDown += SwitchRenderState; return(true); }
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(); }
public Sky(Device device, string filename, float skySphereRadius) { CubeMapSRV = ShaderResourceView.FromFile(device, filename); using (var r = CubeMapSRV.Resource) { r.DebugName = "sky cubemap"; } var sphere = GeometryGenerator.CreateSphere(skySphereRadius, 30, 30); var vertices = sphere.Vertices.Select(v => v.Position).ToArray(); var vbd = new BufferDescription( Marshal.SizeOf(typeof(Vector3)) * vertices.Length, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0 ); _vb = new Buffer(device, new DataStream(vertices, false, false), vbd); _indexCount = sphere.Indices.Count; var ibd = new BufferDescription( _indexCount * sizeof(int), ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0 ); _ib = new Buffer(device, new DataStream(sphere.Indices.ToArray(), false, false), ibd); }
public override bool Init() { if (!base.Init()) { return(false); } Effects.InitAll(Device); InputLayouts.InitAll(Device); _sky = new Sky(Device, "Textures/sunsetcube1024.dds", 5000.0f); _floorTexSRV = ShaderResourceView.FromFile(Device, "Textures/floor.dds"); _stoneTexSRV = ShaderResourceView.FromFile(Device, "Textures/stone.dds"); _brickTexSRV = ShaderResourceView.FromFile(Device, "Textures/bricks.dds"); BuildDynamicCubeMapViews(); BuildShapeGeometryBuffers(); BuildSkullGeometryBuffers(); Window.KeyDown += SwitchLights; return(true); }
protected override void CreateDeviceDependentResources() { base.CreateDeviceDependentResources(); // Dispose before creating RemoveAndDispose(ref buffer_); RemoveAndDispose(ref vertexBinding_); RemoveAndDispose(ref texture_); // Load texture var test = File.Exists(Path.Combine(TEXTUREFOLDER, TextureName)); if (!string.IsNullOrWhiteSpace(TextureName) && File.Exists(Path.Combine(TEXTUREFOLDER, TextureName))) { texture_ = ToDispose(ShaderResourceView.FromFile(DeviceManager.Direct3DDevice, Path.Combine(TEXTUREFOLDER, TextureName))); // Create sampler state samplerState = ToDispose(new SamplerState(DeviceManager.Direct3DDevice, new SamplerStateDescription { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, Filter = Filter.MinMagMipLinear })); } // Create buffer and binding CreateVertexBinding(); }
public void Init(Device device, DeviceContext dc, Terrain terrain) { _device = device; NumPatchVertRows = ((terrain.Info.HeightMapHeight - 1) / Terrain.CellsPerPatch) + 1; NumPatchVertCols = ((terrain.Info.HeightMapWidth - 1) / Terrain.CellsPerPatch) + 1; _numPatchVertices = NumPatchVertRows * NumPatchVertCols; _numPatchQuadFaces = (NumPatchVertRows - 1) * (NumPatchVertCols - 1); if (device.FeatureLevel == FeatureLevel.Level_11_0) { _useTessellation = true; } if (terrain.Info.Material.HasValue) { _material = terrain.Info.Material.Value; } D3DApp.GD3DApp.ProgressUpdate.Draw(0.60f, "Building terrain patches"); if (_useTessellation) { CalcAllPatchBoundsY(); BuildQuadPatchVB(device); BuildQuadPatchIB(device); } else { BuildPatches(device); } D3DApp.GD3DApp.ProgressUpdate.Draw(0.65f, "Loading textures"); _heightMapSRV = terrain.HeightMap.BuildHeightmapSRV(device); var layerFilenames = new List <string> { terrain.Info.LayerMapFilename0 ?? "textures/null.bmp", terrain.Info.LayerMapFilename1 ?? "textures/null.bmp", terrain.Info.LayerMapFilename2 ?? "textures/null.bmp", terrain.Info.LayerMapFilename3 ?? "textures/null.bmp", terrain.Info.LayerMapFilename4 ?? "textures/null.bmp" }; _layerMapArraySRV = Util.CreateTexture2DArraySRV(device, dc, layerFilenames.ToArray(), Format.R8G8B8A8_UNorm); if (!string.IsNullOrEmpty(terrain.Info.BlendMapFilename)) { D3DApp.GD3DApp.ProgressUpdate.Draw(0.70f, "Loading blendmap from file"); _blendMapSRV = ShaderResourceView.FromFile(device, terrain.Info.BlendMapFilename); _blendMapSRV.Resource.DebugName = terrain.Info.BlendMapFilename; } else { _blendMapSRV = CreateBlendMap(terrain.HeightMap, device, terrain); } if (DebugQuadTree) { D3DApp.GD3DApp.ProgressUpdate.Draw(0.95f, "Building quadtree debug vertex buffers"); BuildQuadTreeDebugBuffers(device); } D3DApp.GD3DApp.ProgressUpdate.Draw(1.0f, "Terrain initialized"); _walkMap = new WalkMap(this); }
public override bool Init() { if (!base.Init()) { return(false); } Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); Patch.InitPatchData(Terrain.CellsPerPatch, Device); _sky = new Sky(Device, "Textures/grasscube1024.dds", 5000.0f); var tii = new InitInfo { HeightMapFilename = null, LayerMapFilename0 = "textures/grass.dds", LayerMapFilename1 = "textures/darkdirt.dds", LayerMapFilename2 = "textures/stone.dds", LayerMapFilename3 = "Textures/lightdirt.dds", LayerMapFilename4 = "textures/snow.dds", BlendMapFilename = null, HeightScale = 50.0f, HeightMapWidth = 2049, HeightMapHeight = 2049, CellSpacing = 0.5f, Seed = 0, NoiseSize1 = 3.0f, Persistence1 = 0.7f, Octaves1 = 7, NoiseSize2 = 2.5f, Persistence2 = 0.8f, Octaves2 = 3, }; _terrain = new Terrain(); _terrain.Init(Device, ImmediateContext, tii); _camera.Height = _terrain.Height; AddUIElements(); _camera.SetLens(0.25f * MathF.PI, AspectRatio, 1.0f, 1000.0f); _ssao = new Ssao(Device, ImmediateContext, ClientWidth, ClientHeight, _camera.FovY, _camera.FarZ); _whiteTex = ShaderResourceView.FromFile(Device, "Textures/white.dds"); _sMap = new ShadowMap(Device, SMapSize, SMapSize); _sceneBounds = new BoundingSphere(new Vector3(), MathF.Sqrt(_terrain.Width * _terrain.Width + _terrain.Depth * _terrain.Depth) / 2); _minimap = new Minimap(Device, ImmediateContext, MinimapSize, MinimapSize, _terrain, _camera); return(true); }
/// <summary> /// Create any device dependent resources here. /// This method will be called when the device is first /// initialized or recreated after being removed or reset. /// </summary> protected override void CreateDeviceDependentResources() { // Ensure that if already set the device resources // are correctly disposed of before recreating RemoveAndDispose(ref axisLinesVertices); // Retrieve our SharpDX.Direct3D11.Device1 instance var device = this.DeviceManager.Direct3DDevice; // Load texture textureView = ToDispose(ShaderResourceView.FromFile(device, "Texture.png")); // Create our sampler state samplerState = ToDispose(new SamplerState(device, new SamplerStateDescription() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = new Color4(0, 0, 0, 0), ComparisonFunction = Comparison.Never, Filter = Filter.MinMagMipLinear, MaximumAnisotropy = 16, MaximumLod = float.MaxValue, MinimumLod = 0, MipLodBias = 0.0f })); // Create xyz-axis arrows // X is Red, Y is Green, Z is Blue // The arrows point along the + for each axis axisLinesVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[] { /* Vertex Position Texture UV */ // ~45x10 -1f, 0f, 0f, 1f, 0.1757f, 0.039f, // - x-axis 1f, 0f, 0f, 1f, 0.1757f, 0.039f, // + x-axis 0.9f, -0.05f, 0f, 1f, 0.1757f, 0.039f, // arrow head start 1f, 0f, 0f, 1f, 0.1757f, 0.039f, 0.9f, 0.05f, 0f, 1f, 0.1757f, 0.039f, 1f, 0f, 0f, 1f, 0.1757f, 0.039f, // arrow head end // ~135x35 0f, -1f, 0f, 1f, 0.5273f, 0.136f, // - y-axis 0f, 1f, 0f, 1f, 0.5273f, 0.136f, // + y-axis -0.05f, 0.9f, 0f, 1f, 0.5273f, 0.136f, // arrow head start 0f, 1f, 0f, 1f, 0.5273f, 0.136f, 0.05f, 0.9f, 0f, 1f, 0.5273f, 0.136f, 0f, 1f, 0f, 1f, 0.5273f, 0.136f, // arrow head end // ~220x250 0f, 0f, -1f, 1f, 0.859f, 0.976f, // - z-axis 0f, 0f, 1f, 1f, 0.859f, 0.976f, // + z-axis 0f, -0.05f, 0.9f, 1f, 0.859f, 0.976f, // arrow head start 0f, 0f, 1f, 1f, 0.859f, 0.976f, 0f, 0.05f, 0.9f, 1f, 0.859f, 0.976f, 0f, 0f, 1f, 1f, 0.859f, 0.976f, // arrow head end })); axisLinesBinding = new VertexBufferBinding(axisLinesVertices, Utilities.SizeOf <float>() * 6, 0); }
/// <summary> /// Create any device dependent resources here. /// This method will be called when the device is first /// initialized or recreated after being removed or reset. /// </summary> protected override void CreateDeviceDependentResources() { // Ensure that if already set the device resources // are correctly disposed of before recreating RemoveAndDispose(ref quadVertices); RemoveAndDispose(ref quadIndices); RemoveAndDispose(ref textureView); RemoveAndDispose(ref samplerState); // Retrieve our SharpDX.Direct3D11.Device1 instance var device = this.DeviceManager.Direct3DDevice; // Create a quad (two triangles) quadVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[] { /* Vertex Position Vertex Color */ //new Vertex(0.25f, 0.5f, -0.5f, Color.Lime), // Top-left //new Vertex(0.75f, 0.5f, -0.5f, Color.Yellow), // Top-right //new Vertex(0.75f, 0.0f, -0.5f, Color.Red), // Base-right //new Vertex(0.25f, 0.0f, -0.5f, Color.Blue), // Base-left new Vertex(0f, 1.5f, -0.001f, 0, 0, -1, 0.0f, 0.0f, Color.Black), // Top-left new Vertex(1.5f, 1.5f, -0.001f, 0, 0, -1, 2.0f, 0.0f, Color.Black), // Top-right new Vertex(1.5f, 0f, -0.001f, 0, 0, -1, 2.0f, 2.0f, Color.Black), // Base-right new Vertex(0f, 0f, -0.001f, 0, 0, -1, 0.0f, 2.0f, Color.Black), // Base-left })); quadBinding = new VertexBufferBinding(quadVertices, Utilities.SizeOf <Vertex>(), 0); // v0 v1 // |-----| // | \ A | // | B \ | // |-----| // v3 v2 // Indices not required //quadIndices = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, new ushort[] { // 0, 1, 2, // A // 2, 3, 0 // B //})); // Load texture textureView = ToDispose(ShaderResourceView.FromFile(device, "Texture2.png")); // Create our sampler state samplerState = ToDispose(new SamplerState(device, new SamplerStateDescription() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = new Color4(0, 0, 0, 0), ComparisonFunction = Comparison.Never, Filter = Filter.MinMagMipLinear, MaximumAnisotropy = 16, MaximumLod = float.MaxValue, MinimumLod = 0, MipLodBias = 0.0f })); }
public ShaderResourceView GetResource(Device Device, string path) { if (!ResourceViews.ContainsKey(path)) { ResourceViews.Add(path, ShaderResourceView.FromFile(Device, path)); } return(ResourceViews[path]); }
private void InitRenderTargets() { try { D3D11Device = Core.D3DDevice.Device; var colorDesc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = RenderConfig.Width, Height = RenderConfig.Height, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; var depthdesc = new Texture2DDescription { BindFlags = BindFlags.DepthStencil, Format = Format.D32_Float_S8X24_UInt, Width = RenderConfig.Width, Height = RenderConfig.Height, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; _sharedTexture = new Texture2D(D3D11Device, colorDesc); colorDesc.OptionFlags = ResourceOptionFlags.None; colorDesc.Format = Format.R16G16B16A16_UNorm; _sceneRenderTargetTexture = new Texture2D(D3D11Device, colorDesc); _depthTexture = new Texture2D(D3D11Device, depthdesc); _renderDepth = new Texture2D(D3D11Device, depthdesc); _sharedTextureRenderView = new RenderTargetView(D3D11Device, SharedTexture); _sceneRenderTargetTextureRenderView = new RenderTargetView(D3D11Device, SceneRenderTargetTexture); _renderTargetDepthView = new DepthStencilView(D3D11Device, _renderDepth); _texture = ShaderResourceView.FromFile(D3D11Device, "./assets-common/image/white.png"); _screenQuadMesh = Mesh.CreateScreenQuadMesh(); _gpuSyncer = new BlockingGpuSyncer(D3D11Device); } catch (Exception e) { Logger.Error(e.Message); } D3D11Device.ImmediateContext.Flush(); }
public model CreateMesh(Device device, aiMesh aiMesh, aiMaterialVector mMaterials, String directory) { var numFaces = (int)aiMesh.mNumFaces; var numVertices = (int)aiMesh.mNumVertices; var aiPositions = aiMesh.mVertices; var aiNormals = aiMesh.mNormals; var aiTextureCoordsAll = aiMesh.mTextureCoords; var aiTextureCoords = (aiTextureCoordsAll != null) ? aiTextureCoordsAll[0] : null; VertexPostitionTexture[] VertexPostitionTextures = new VertexPostitionTexture[aiMesh.mNumVertices]; for (int j = 0; j < aiMesh.mNumVertices; j++) { VertexPostitionTextures[j].position = new Vector3(aiMesh.mVertices[j].x, aiMesh.mVertices[j].y, aiMesh.mVertices[j].z); VertexPostitionTextures[j].textcoord = new Vector2(aiMesh.mTextureCoords[0][j].x, aiMesh.mTextureCoords[0][j].y); } ///being brute =P int SizeInBytes = Marshal.SizeOf(typeof(VertexPostitionTexture)); BufferDescription bd = new BufferDescription(SizeInBytes * (int)aiMesh.mNumVertices, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, SizeInBytes); var vertices = Buffer.Create <VertexPostitionTexture>(device, VertexPostitionTextures, bd); var aiFaces = aiMesh.mFaces; var dxIndices = new uint[numFaces * 3]; for (int i = 0; i < numFaces; ++i) { var aiFace = aiFaces[i]; var aiIndices = aiFace.mIndices; for (int j = 0; j < 3; ++j) { dxIndices[i * 3 + j] = (uint)aiIndices[j]; } } BufferDescription bi = new BufferDescription(sizeof(uint) * numFaces * 3, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, sizeof(uint)); var indices = Buffer.Create <uint>(device, dxIndices, bd); model modelteste = new model(); modelteste.indices = indices; modelteste.numberIndices = numFaces * 3; modelteste.vertex = vertices; modelteste.numberVertices = numVertices; aiString difuse = new aiString(); mMaterials[(int)aiMesh.mMaterialIndex].GetTextureDiffuse0(difuse); modelteste.difuseTextureName = difuse.Data; String fullPath = String.IsNullOrEmpty(directory) ? modelteste.difuseTextureName : Path.Combine(directory, modelteste.difuseTextureName); modelteste.ShaderResourceView = ShaderResourceView.FromFile(device, fullPath); return(modelteste); }
public WalkMap(TerrainRenderer terrainRenderer) { _terrainRenderer = terrainRenderer; UnwalkableSRV = ShaderResourceView.FromFile(terrainRenderer._device, "textures/unwalkable.png"); CreateWalkableTexture( terrainRenderer._terrain.Tiles, terrainRenderer._terrain.WidthInTiles, terrainRenderer._terrain.HeightInTiles ); }
public void SetNormalTexture(string filePath) { if (_mesh != null) { if (_mesh.NormalTexture != null) { _mesh.NormalTexture.Dispose(); } _mesh.NormalTexture = ShaderResourceView.FromFile(_context.Device, filePath); } }
public static ShaderResourceView Load(Device device, string textureFileName) { try { return(ShaderResourceView.FromFile(device, textureFileName)); } catch (Exception ex) { throw new Exception("textureLoad: " + ex); } }
static void LoadTexture() { ImageLoadInformation imageLoadInfo = new ImageLoadInformation { Format = SlimDX.DXGI.Format.R16_UNorm, BindFlags = BindFlags.ShaderResource, }; _TextureRV1 = ShaderResourceView.FromFile(_Device, "haha.dds", imageLoadInfo); _TextureRV2 = ShaderResourceView.FromFile(_Device, "C:\\users\\paul\\desktop\\15000x6000.tif", imageLoadInfo); }
/// <summary> /// テクスチャをロード /// </summary> public static ShaderResourceView FromFileTexture(string path) { try { return(ShaderResourceView.FromFile(Device, path)); } catch (System.Exception e) { System.Console.WriteLine(path + " / " + e.Message); return(null); } }
/// <summary> /// Create a mesh from wavefront obj file format using Tangent and Binormal vertex format /// </summary> /// <param name="device">Device</param> /// <param name="filename">Filename</param> /// <returns>Mesh</returns> public static SharpMesh CreateNormalMappedFromObj(SharpDevice device, string filename) { SharpMesh mesh = new SharpMesh(device); WaveFrontModel[] modelParts = WaveFrontModel.CreateFromObj(filename); mesh.Device = device; mesh.SubSets = new List <SharpSubSet>(); List <TangentVertex> vertices = new List <TangentVertex>(); List <int> indices = new List <int>(); int vcount = 0; int icount = 0; foreach (WaveFrontModel model in modelParts) { vertices.AddRange(model.TangentData); indices.AddRange(model.IndexData.Select(i => i + vcount)); var mate = model.MeshMaterial.First(); ShaderResourceView tex = null; ShaderResourceView ntex = null; if (!string.IsNullOrEmpty(mate.DiffuseMap)) { string textureFile = Path.GetDirectoryName(filename) + "\\" + Path.GetFileName(mate.DiffuseMap); tex = ShaderResourceView.FromFile(device.Device, textureFile); string normalMap = Path.GetDirectoryName(textureFile) + "\\" + Path.GetFileNameWithoutExtension(textureFile) + "N" + Path.GetExtension(textureFile); ntex = ShaderResourceView.FromFile(device.Device, normalMap); } mesh.SubSets.Add(new SharpSubSet() { IndexCount = model.IndexData.Count, StartIndex = icount, DiffuseMap = tex, NormalMap = ntex }); vcount += model.VertexData.Count; icount += model.IndexData.Count; } mesh.VertexBuffer = Buffer11.Create <TangentVertex>(device.Device, BindFlags.VertexBuffer, vertices.ToArray()); mesh.IndexBuffer = Buffer11.Create(device.Device, BindFlags.IndexBuffer, indices.ToArray()); mesh.VertexSize = SharpDX.Utilities.SizeOf <TangentVertex>(); return(mesh); }
public bool Initialize(Device device, string fileName) { try { // Load the texture file. TextureResource = ShaderResourceView.FromFile(device, fileName); return(true); } catch (Exception) { return(false); } }
private ShaderResourceView LoadSafe(Device device, string filename) { if (device == null) { return(null); } try { return(ShaderResourceView.FromFile(device, filename)); } catch (Exception e) { AcToolsLogging.Write($"Texture {Name} damaged: {e}"); return(null); } }
public static ShaderResourceView Get(string key) { if (s_ressources.ContainsKey(key)) { return(s_ressources[key]); } else { var rsc = ShaderResourceView.FromFile(Scene.GetGraphicsDevice(), key); s_ressources.Add(key, rsc); return(rsc); } }
private ShaderResourceView LoadTexture(string filename) { if (_cache.TryGetValue(filename, out var cacheEntry)) { if (cacheEntry == null) { return(null); } cacheEntry.UsedId = ++_usedId; return(cacheEntry.Value); } if (!File.Exists(filename)) { _cache[filename] = null; return(null); } if (_totalSize > OptionMaxCacheSize) { // AcToolsLogging.Write($"Limit exceeded: {_totalSize.ToReadableSize()} out of {OptionMaxCacheSize.ToReadableSize()} (cached: {_cache.Count})"); var e = _cache.Values.NonNull().Where(x => x.Key != filename).MinEntryOrDefault(x => x.UsedId); if (e != null) { _totalSize -= e.Size; _cache.Remove(e.Key); e.Dispose(); GCHelper.CleanUp(); } } ShaderResourceView view; try { view = ShaderResourceView.FromFile(Device, filename); } catch (Exception e) { AcToolsLogging.Write(e); _cache[filename] = null; return(null); } cacheEntry = new CacheEntry(filename, view); _totalSize += cacheEntry.Size; _cache[filename] = cacheEntry; cacheEntry.UsedId = ++_usedId; return(cacheEntry.Value); }
// Load an image public void LoadSourceImage(string sourceImage) { sourceImageFile = sourceImage; if (this.DeviceManager != null) { var device = this.DeviceManager.Direct3DDevice; sourceTextureSRV = ShaderResourceView.FromFile(device, sourceImageFile); //using (var tmpTex = sourceTextureSRV.ResourceAs<Texture2D>()) //{ // if (tmpTex.Description.Format != Format.R8G8B8A8_UNorm) // throw new Exception("Expected an RGBA texture with 8 bits per channel"); //} } }
/// <summary> /// Create a texture resource using the complete filepath to the texture file /// </summary> /// <param name="fileName"> filepath to the texture file </param> /// <returns></returns> protected ShaderResourceView CreateTexture(String fileName) { if (!diffuseTextureSRV.ContainsKey(fileName)) { if (File.Exists(fileName)) { diffuseTextureSRV[fileName] = ShaderResourceView.FromFile(GraphicsRenderer.Device, fileName); } else { return(null); } } return(diffuseTextureSRV[fileName]); }
/// <summary> /// Create any device dependent resources here. /// This method will be called when the device is first /// initialized or recreated after being removed or reset. /// </summary> protected override void CreateDeviceDependentResources() { base.CreateDeviceDependentResources(); // Ensure that if already set the device resources // are correctly disposed of before recreating RemoveAndDispose(ref triangleVertices); RemoveAndDispose(ref textureView); RemoveAndDispose(ref samplerState); // Retrieve our SharpDX.Direct3D11.Device1 instance var device = this.DeviceManager.Direct3DDevice; var context = this.DeviceManager.Direct3DContext; // Load texture textureView = ToDispose(ShaderResourceView.FromFile(device, "Texture2.png")); // Create our sampler state samplerState = ToDispose(new SamplerState(device, new SamplerStateDescription() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = new Color4(0, 0, 0, 0), ComparisonFunction = Comparison.Never, Filter = Filter.MinMagMipLinear, MaximumAnisotropy = 16, MaximumLod = float.MaxValue, MinimumLod = 0, MipLodBias = 0.0f })); // Create a triangle triangleVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[] { /* Vertex Position Vertex UV */ //0.0f, 0.0f, 0.5f, 1.0f, 1.0f, 1.0f, // Base-right //-0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, // Base-left //-0.25f, 0.5f, 0.25f, 1.0f, 0.5f, 0.0f, // Apex 0.75f, -0.75f, -0.001f, 1.0f, 1.0f, 1.0f, // Base-right -0.75f, -0.75f, -0.001f, 1.0f, 0.0f, 1.0f, // Base-left 0.0f, 0.75f, -0.001f, 1.0f, 0.5f, 0.0f, // Apex })); triangleBinding = new VertexBufferBinding(triangleVertices, Utilities.SizeOf <float>() * 6, 0); //0.5f, -1.5f, 0.0f, 1.0f, 1.0f, 1.0f, // Base-right //-0.5f, -1.5f, 0.0f, 1.0f, 0.0f, 1.0f, // Base-left //0.0f, -0.5f, 0.0f, 1.0f, 0.5f, 0.0f, // Apex }
public override bool Init() { if (!base.Init()) { return(false); } Effects.InitAll(Device); _fx = Effects.BasicFX; InputLayouts.InitAll(Device); _diffuseMapSRV = ShaderResourceView.FromFile(Device, "Textures/WoodCrate01.dds"); BuildGeometryBuffers(); return(true); }