public static ResourceSet GenerateTextureResourceSetForNormalMapping <T>(ModelRuntimeDescriptor <T> modelRuntimeState, int meshIndex, DisposeCollectorResourceFactory factory, GraphicsDevice graphicsDevice) where T : struct, VertexLocateable { RealtimeMaterial material = modelRuntimeState.Model.GetMaterial(meshIndex); ImageSharpTexture diffuseTextureIS = new ImageSharpTexture(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, material.textureDiffuse)); Texture diffuseTexture = diffuseTextureIS.CreateDeviceTexture(graphicsDevice, factory); TextureView diffuseTextureView = factory.CreateTextureView(diffuseTexture); string normalTexPath = material.textureNormal.Length == 0 ? material.textureBump : material.textureNormal; ImageSharpTexture normalTextureIS = new ImageSharpTexture(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, normalTexPath)); Texture normalTexture = normalTextureIS.CreateDeviceTexture(graphicsDevice, factory); TextureView normalTextureView = factory.CreateTextureView(normalTexture); return(factory.CreateResourceSet(new ResourceSetDescription( modelRuntimeState.TextureResourceLayout, diffuseTextureView, modelRuntimeState.TextureSampler, normalTextureView, modelRuntimeState.TextureSampler ))); }
//TODO: Use new Veldrid Call! private static unsafe TextureView CreateCubeMapTextureViewFromImages( Image <Rgba32> front, Image <Rgba32> back, Image <Rgba32> left, Image <Rgba32> right, Image <Rgba32> top, Image <Rgba32> bottom, DisposeCollectorResourceFactory factory, GraphicsDevice graphicsDevice ) { Texture textureCube; TextureView textureView; fixed(Rgba32 *frontPin = &MemoryMarshal.GetReference(front.GetPixelSpan())) fixed(Rgba32 * backPin = &MemoryMarshal.GetReference(back.GetPixelSpan())) fixed(Rgba32 * leftPin = &MemoryMarshal.GetReference(left.GetPixelSpan())) fixed(Rgba32 * rightPin = &MemoryMarshal.GetReference(right.GetPixelSpan())) fixed(Rgba32 * topPin = &MemoryMarshal.GetReference(top.GetPixelSpan())) fixed(Rgba32 * bottomPin = &MemoryMarshal.GetReference(bottom.GetPixelSpan())) { uint width = (uint)front.Width; uint height = (uint)front.Height; textureCube = factory.CreateTexture(TextureDescription.Texture2D( width, height, 6, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled | TextureUsage.Cubemap)); uint faceSize = (uint)(front.Width * front.Height * Unsafe.SizeOf <Rgba32>()); graphicsDevice.UpdateTexture(textureCube, (IntPtr)rightPin, faceSize, 0, 0, 0, width, height, 1, 0, (uint)CubeMap.FaceIndices.Right); // +X graphicsDevice.UpdateTexture(textureCube, (IntPtr)leftPin, faceSize, 0, 0, 0, width, height, 1, 0, (uint)CubeMap.FaceIndices.Left); // -X graphicsDevice.UpdateTexture(textureCube, (IntPtr)topPin, faceSize, 0, 0, 0, width, height, 1, 0, (uint)CubeMap.FaceIndices.Top); // +Y graphicsDevice.UpdateTexture(textureCube, (IntPtr)bottomPin, faceSize, 0, 0, 0, width, height, 1, 0, (uint)CubeMap.FaceIndices.Bottom); // -Y graphicsDevice.UpdateTexture(textureCube, (IntPtr)backPin, faceSize, 0, 0, 0, width, height, 1, 0, (uint)CubeMap.FaceIndices.Back); // +Z graphicsDevice.UpdateTexture(textureCube, (IntPtr)frontPin, faceSize, 0, 0, 0, width, height, 1, 0, (uint)CubeMap.FaceIndices.Front); // -Z textureView = factory.CreateTextureView(new TextureViewDescription(textureCube)); } return(textureView); }