Exemple #1
0
 public static ResourceLayout GenerateTextureResourceLayoutForCubeMapping(DisposeCollectorResourceFactory factory)
 {
     return(factory.CreateResourceLayout(
                new ResourceLayoutDescription(
                    new ResourceLayoutElementDescription("CubeTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                    new ResourceLayoutElementDescription("CubeSampler", ResourceKind.Sampler, ShaderStages.Fragment)
                    )));
 }
Exemple #2
0
        public static ResourceLayout GenerateResourceLayout(DisposeCollectorResourceFactory factory, string name, ResourceKind resourceKind, ShaderStages shaderStages)
        {
            var resourceLayoutElementDescription = new ResourceLayoutElementDescription(name, resourceKind, shaderStages);

            ResourceLayoutElementDescription[] resourceLayoutElementDescriptions = { resourceLayoutElementDescription };
            var resourceLayoutDescription = new ResourceLayoutDescription(resourceLayoutElementDescriptions);

            return(factory.CreateResourceLayout(resourceLayoutDescription));
        }
Exemple #3
0
 public static Sampler GeneratePointSampler(DisposeCollectorResourceFactory factory)
 {
     return(factory.CreateSampler(new SamplerDescription
     {
         AddressModeU = SamplerAddressMode.Wrap,
         AddressModeV = SamplerAddressMode.Wrap,
         AddressModeW = SamplerAddressMode.Wrap,
         Filter = SamplerFilter.MinPoint_MagPoint_MipPoint,
         LodBias = 0,
         MinimumLod = 0,
         MaximumLod = uint.MaxValue,
         MaximumAnisotropy = 0,
     }));
 }
Exemple #4
0
 //TODO: UNIFY THIS!
 public static Sampler GenerateBiLinearSampler_Clamp(DisposeCollectorResourceFactory factory)
 {
     return(factory.CreateSampler(new SamplerDescription
     {
         AddressModeU = SamplerAddressMode.Clamp,
         AddressModeV = SamplerAddressMode.Clamp,
         AddressModeW = SamplerAddressMode.Clamp,
         Filter = SamplerFilter.MinLinear_MagLinear_MipPoint,
         LodBias = 0,
         MinimumLod = 0,
         MaximumLod = 0,
         MaximumAnisotropy = 0
     }));
 }
Exemple #5
0
        //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);
        }
Exemple #6
0
        public static ResourceSet GenrateResourceSet(DisposeCollectorResourceFactory factory, ResourceLayout resourceLayout, BindableResource[] bindableResources)
        {
            ResourceSetDescription resourceSetDescription = new ResourceSetDescription(resourceLayout, bindableResources);

            return(factory.CreateResourceSet(resourceSetDescription));
        }
Exemple #7
0
        public static ResourceSet GenerateTextureResourceSetForCubeMapping <T>(ModelRuntimeDescriptor <T> modelRuntimeState, int meshIndex, DisposeCollectorResourceFactory factory, GraphicsDevice graphicsDevice) where T : struct, VertexLocateable
        {
            RealtimeMaterial material = modelRuntimeState.Model.GetMaterial(meshIndex);

            Image <Rgba32> front  = Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, material.cubeMapFront));
            Image <Rgba32> back   = Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, material.cubeMapBack));
            Image <Rgba32> left   = Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, material.cubeMapLeft));
            Image <Rgba32> right  = Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, material.cubeMapRight));
            Image <Rgba32> top    = Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, material.cubeMapTop));
            Image <Rgba32> bottom = Image.Load <Rgba32>(Path.Combine(AppContext.BaseDirectory, modelRuntimeState.Model.BaseDir, material.cubeMapBottom));

            TextureView cubeMapTextureView = ResourceGenerator.CreateCubeMapTextureViewFromImages(front,
                                                                                                  back,
                                                                                                  left,
                                                                                                  right,
                                                                                                  top,
                                                                                                  bottom,
                                                                                                  factory,
                                                                                                  graphicsDevice);



            return(factory.CreateResourceSet(new ResourceSetDescription(
                                                 modelRuntimeState.TextureResourceLayout,
                                                 cubeMapTextureView,
                                                 modelRuntimeState.TextureSampler
                                                 )));
        }
Exemple #8
0
        public static ResourceSet GenerateTextureResourceSetForDiffuseMapping <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);

            return(factory.CreateResourceSet(new ResourceSetDescription(
                                                 modelRuntimeState.TextureResourceLayout,
                                                 diffuseTextureView,
                                                 modelRuntimeState.TextureSampler
                                                 )));
        }
Exemple #9
0
        public static ResourceSet GenerateResourceSetForShadowMapping(ResourceLayout textureLayout, TextureView shadowMapTexView, DisposeCollectorResourceFactory factory)
        {
            var sampler = ResourceGenerator.GenerateBiLinearSampler_Border(factory);

            return(factory.CreateResourceSet(new ResourceSetDescription(
                                                 textureLayout,
                                                 shadowMapTexView,
                                                 sampler
                                                 )));
        }