示例#1
0
        public MainVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            renderState.Set(new ClearColorState(1, 1, 1, 1));
            renderState.Set(new DepthTest(true));
            renderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE));

            var envMap = contentLoader.Load <ITexture2D>("beach");

            envMap.WrapFunction = TextureWrapFunction.MirroredRepeat;
            envMap.Filter       = TextureFilterMode.Linear;
            var textureBinding = new TextureBinding[] { new TextureBinding(nameof(envMap), envMap) };

            var sphere = Meshes.CreateSphere(1f, 4);

            var skySphere        = sphere.Transform(Transformation.Scale(200f)).SwitchTriangleMeshWinding();
            var shaderBackground = contentLoader.Load <IShaderProgram>("background.*");

            visuals.Add(new MeshVisual(skySphere, shaderBackground, textureBinding));

#if SOLUTION
            var shaderEnvMap = contentLoader.Load <IShaderProgram>("envMapping.*");
            var visSphere    = new MeshVisual(sphere, shaderEnvMap, textureBinding);
            visSphere.SetUniform("reflective", 1f);
            visuals.Add(visSphere);
            var suzanne    = contentLoader.Load <DefaultMesh>("suzanne");
            var visSuzanne = new MeshVisual(suzanne.Transform(Transformation.Translation(0, -1.5f, 0)), shaderEnvMap, textureBinding);
            visSuzanne.SetUniform("reflective", 0.4f);
            visuals.Add(visSuzanne);
#endif
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonTexture3DInfo"/> class.
 /// </summary>
 /// <param name="name">[Optional] The name of the texture.</param>
 public GorgonTexture3DInfo(string name = null)
 {
     Name      = string.IsNullOrEmpty(name) ? GorgonGraphicsResource.GenerateName(GorgonTexture3D.NamePrefix) : name;
     Binding   = TextureBinding.ShaderResource;
     Usage     = ResourceUsage.Default;
     MipLevels = 1;
 }
示例#3
0
 public UIMaterial(ITagContainer diContainer, bool isFont) : base(diContainer.GetTag <GraphicsDevice>(), GetPipeline(diContainer, isFont))
 {
     Configure()
     .Add(Texture    = new TextureBinding(this))
     .Add(Sampler    = new SamplerBinding(this))
     .Add(ScreenSize = new UniformBinding <Vector2>(this))
     .NextBindingSet();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonTexture2DInfo"/> class.
 /// </summary>
 /// <param name="name">[Optional] The name of the texture.</param>
 public GorgonTexture2DInfo(string name = null)
 {
     Name            = string.IsNullOrEmpty(name) ? GorgonGraphicsResource.GenerateName(GorgonTexture2D.NamePrefix) : name;
     Binding         = TextureBinding.ShaderResource;
     Usage           = ResourceUsage.Default;
     MultisampleInfo = GorgonMultisampleInfo.NoMultiSampling;
     MipLevels       = 1;
     ArrayCount      = 1;
 }
示例#5
0
 public DebugIconMaterial(ITagContainer diContainer) : base(diContainer.GetTag <GraphicsDevice>(), GetPipeline(diContainer))
 {
     Configure()
     .Add(Texture    = new TextureBinding(this))
     .Add(Sampler    = new SamplerBinding(this))
     .Add(Projection = new UniformBinding <Matrix4x4>(this))
     .Add(View       = new UniformBinding <Matrix4x4>(this))
     .Add(World      = new UniformBinding <Matrix4x4>(this))
     .Add(Uniforms   = new UniformBinding <DebugIconUniforms>(this))
     .NextBindingSet();
 }
示例#6
0
 public ModelSkinnedMaterial(ITagContainer diContainer) : base(diContainer.GetTag <GraphicsDevice>(), GetPipeline(diContainer))
 {
     Configure()
     .Add(MainTexture = new TextureBinding(this))
     .Add(Sampler     = new SamplerBinding(this))
     .Add(Projection  = new UniformBinding <Matrix4x4>(this))
     .Add(View        = new UniformBinding <Matrix4x4>(this))
     .Add(World       = new UniformBinding <Matrix4x4>(this))
     .Add(Uniforms    = new UniformBinding <ModelStandardMaterialUniforms>(this))
     .Add(Pose        = new SkeletonPoseBinding(this))
     .NextBindingSet();
 }
示例#7
0
 /// <summary>
 /// Function to copy another information object to this object with a new name.
 /// </summary>
 /// <param name="name">The name of the object.</param>
 /// <param name="info">The destination for the copied data.</param>
 internal void Copy(string name, IGorgonTexture2DInfo info)
 {
     Name            = name;
     Format          = info.Format;
     ArrayCount      = info.ArrayCount;
     Binding         = info.Binding;
     Height          = info.Height;
     IsCubeMap       = info.IsCubeMap;
     MipLevels       = info.MipLevels;
     MultisampleInfo = info.MultisampleInfo;
     Usage           = info.Usage;
     Width           = info.Width;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonTexture1DInfo"/> class.
        /// </summary>
        /// <param name="info">A <see cref="IGorgonTexture1DInfo"/> to copy settings from.</param>
        /// <param name="newName">[Optional] The new name for the texture.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="info"/> parameter is <b>null</b>.</exception>
        public GorgonTexture1DInfo(IGorgonTexture1DInfo info, string newName = null)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            Name       = string.IsNullOrEmpty(newName) ? info.Name : newName;
            Format     = info.Format;
            ArrayCount = info.ArrayCount;
            Binding    = info.Binding;
            MipLevels  = info.MipLevels;
            Usage      = info.Usage;
            Width      = info.Width;
        }
示例#9
0
        public void BindTexture(TextureTarget target, int texture, int unit = -1)
        {
            if (unit < 0)
            {
                unit = _textureBindings.Length - 1;
            }

            TextureBinding binding = new TextureBinding(target, texture);

            UseTextureUnit(unit);

            if (_textureBindings[unit] != binding)
            {
                _textureBindings[unit] = binding;
                GL.BindTexture(target, texture);
            }
        }
示例#10
0
        public MainVisual(IRenderContext renderContext, IContentLoader contentLoader)
        {
            renderContext.RenderState.Set(new DepthTest(true));
            renderContext.RenderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE));

            var mesh = Meshes.CreatePlane(2, 2, 1024, 1024);

            var texHeightfield = contentLoader.Load <ITexture2D>("mountain_height");
            var bindings       = new TextureBinding[]
            {
                new TextureBinding("texHeightfield", texHeightfield),
                new TextureBinding("texColor", contentLoader.Load <ITexture2D>("mountain_color")),
                new TextureBinding("texStone", contentLoader.Load <ITexture2D>("stone")),
            };
            var shaderProgram = contentLoader.Load <IShaderProgram>("shader.*");

            mountain = new MeshVisual(mesh, shaderProgram, bindings);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonTexture2DInfo"/> class.
        /// </summary>
        /// <param name="info">A <see cref="IGorgonTexture2DInfo"/> to copy settings from.</param>
        /// <param name="newName">[Optional] The new name for the texture.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="info"/> parameter is <b>null</b>.</exception>
        public GorgonTexture2DInfo(IGorgonTexture2DInfo info, string newName = null)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            Name            = string.IsNullOrEmpty(newName) ? info.Name : newName;
            Format          = info.Format;
            ArrayCount      = info.ArrayCount;
            Binding         = info.Binding;
            Height          = info.Height;
            IsCubeMap       = info.IsCubeMap;
            MipLevels       = info.MipLevels;
            MultisampleInfo = info.MultisampleInfo;
            Usage           = info.Usage;
            Width           = info.Width;
        }
示例#12
0
        /// <summary>
        /// Function to create a new render target that is bindable to the GPU.
        /// </summary>
        /// <param name="graphics">The graphics interface to use when creating the target.</param>
        /// <param name="info">The information about the texture.</param>
        /// <returns>A new <see cref="GorgonRenderTarget3DView"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or <paramref name="info"/> parameter is <b>null</b>.</exception>
        /// <remarks>
        /// <para>
        /// This is a convenience method that will create a <see cref="GorgonTexture3D"/> and a <see cref="GorgonRenderTarget3DView"/> as a single object that users can use to apply a render target texture.
        /// This helps simplify creation of a render target by executing some prerequisite steps on behalf of the user.
        /// </para>
        /// <para>
        /// Since the <see cref="GorgonTexture3D"/> created by this method is linked to the <see cref="GorgonRenderTarget3DView"/> returned, disposal of either one will dispose of the other on your behalf.
        /// If the user created a <see cref="GorgonRenderTarget3DView"/> from the <see cref="GorgonTexture3D.GetRenderTargetView"/> method on the <see cref="GorgonTexture3D"/>, then it's assumed the user
        /// knows what they are doing and will handle the disposal of the texture and view on their own.
        /// </para>
        /// </remarks>
        /// <seealso cref="GorgonTexture3D"/>
        public static GorgonRenderTarget3DView CreateRenderTarget(GorgonGraphics graphics, IGorgonTexture3DInfo info)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            TextureBinding binding = TextureBinding.RenderTarget;

            if ((info.Binding & TextureBinding.ShaderResource) == TextureBinding.ShaderResource)
            {
                binding |= TextureBinding.ShaderResource;
            }

            if ((info.Binding & TextureBinding.ShaderResource) == TextureBinding.ReadWriteView)
            {
                binding |= TextureBinding.ReadWriteView;
            }

            var newInfo = new GorgonTexture3DInfo(info)
            {
                // Can't see a reason to use anything other than default for rtvs
                Usage   = ResourceUsage.Default,
                Binding = binding
            };

            var texture = new GorgonTexture3D(graphics, newInfo);
            GorgonRenderTarget3DView result = texture.GetRenderTargetView();

            result.OwnsResource = true;

            return(result);
        }
示例#13
0
        /// <summary>
        /// Function to create a new render target that is bindable to the GPU.
        /// </summary>
        /// <param name="graphics">The graphics interface to use when creating the target.</param>
        /// <param name="info">The information about the texture.</param>
        /// <param name="arrayIndex">[Optional] The index of a texture array to slice the view at.</param>
        /// <param name="arrayCount">[Optioanl] The number of array indices to view.</param>
        /// <returns>A new <see cref="GorgonRenderTarget2DView"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or <paramref name="info"/> parameter is <b>null</b>.</exception>
        /// <remarks>
        /// <para>
        /// This is a convenience method that will create a <see cref="GorgonTexture2D"/> and a <see cref="GorgonRenderTarget2DView"/> as a single object that users can use to apply a render target texture.
        /// This helps simplify creation of a render target by executing some prerequisite steps on behalf of the user.
        /// </para>
        /// <para>
        /// Since the <see cref="GorgonTexture2D"/> created by this method is linked to the <see cref="GorgonRenderTarget2DView"/> returned, disposal of either one will dispose of the other on your behalf.
        /// If the user created a <see cref="GorgonRenderTarget2DView"/> from the <see cref="GorgonTexture2D.GetRenderTargetView"/> method on the <see cref="GorgonTexture2D"/>, then it's assumed the user
        /// knows what they are doing and will handle the disposal of the texture and view on their own.
        /// </para>
        /// </remarks>
        /// <seealso cref="GorgonTexture2D"/>
        public static GorgonRenderTarget2DView CreateRenderTarget(GorgonGraphics graphics, IGorgonTexture2DInfo info, int arrayIndex = 0, int?arrayCount = null)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            TextureBinding binding = TextureBinding.RenderTarget;

            if ((info.Binding & TextureBinding.ShaderResource) == TextureBinding.ShaderResource)
            {
                binding |= TextureBinding.ShaderResource;
            }

            if ((info.Binding & TextureBinding.ShaderResource) == TextureBinding.ReadWriteView)
            {
                binding |= TextureBinding.ReadWriteView;
            }

            var newInfo = new GorgonTexture2DInfo(info)
            {
                Usage   = ResourceUsage.Default,
                Binding = binding
            };

            var texture = new GorgonTexture2D(graphics, newInfo);
            GorgonRenderTarget2DView result = texture.GetRenderTargetView(arrayIndex: arrayIndex, arrayCount: arrayCount ?? 1);

            result.OwnsResource = true;

            return(result);
        }
示例#14
0
        /// <summary>
        /// Function to create a new depth/stencil buffer that is bindable to the GPU.
        /// </summary>
        /// <param name="graphics">The graphics interface to use when creating the target.</param>
        /// <param name="info">The information about the depth/stencil texture.</param>
        /// <param name="viewFlags">[Optional] Flags used to determine if the depth buffer/stencil can be read by the GPU or not.</param>
        /// <returns>A new <see cref="GorgonDepthStencil2DView"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or <paramref name="info"/> parameter is <b>null</b>.</exception>
        /// <remarks>
        /// <para>
        /// This is a convenience method that will create a <see cref="GorgonTexture2D"/> and a <see cref="GorgonDepthStencil2DView"/> as a single object that users can use to apply a depth/stencil texture.
        /// This helps simplify creation of a render target by executing some prerequisite steps on behalf of the user.
        /// </para>
        /// <para>
        /// Since the <see cref="GorgonTexture2D"/> created by this method is linked to the <see cref="GorgonDepthStencil2DView"/> returned, disposal of either one will dispose of the other on your behalf.
        /// If the user created a <see cref="GorgonDepthStencil2DView"/> from the <see cref="GorgonTexture2D.GetRenderTargetView"/> method on the <see cref="GorgonTexture2D"/>, then it's assumed the user
        /// knows what they are doing and will handle the disposal of the texture and view on their own.
        /// </para>
        /// <para>
        /// To make the texture bindable on the GPU as a shader resource view, set the <see cref="IGorgonTexture2DInfo.Binding"/> to include the <see cref="TextureBinding.ShaderResource"/> flag in the value
        /// and set the <paramref name="viewFlags"/> to <see cref="DepthStencilViewFlags.ReadOnlyDepth"/>, <see cref="DepthStencilViewFlags.ReadOnlyStencil"/> or both.
        /// </para>
        /// </remarks>
        /// <seealso cref="GorgonTexture2D"/>
        public static GorgonDepthStencil2DView CreateDepthStencil(GorgonGraphics graphics, IGorgonTexture2DInfo info, DepthStencilViewFlags viewFlags = DepthStencilViewFlags.None)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            TextureBinding binding = TextureBinding.DepthStencil;

            if ((info.Binding & TextureBinding.ShaderResource) == TextureBinding.ShaderResource)
            {
                if (viewFlags != DepthStencilViewFlags.None)
                {
                    binding |= TextureBinding.ShaderResource;
                }
                else
                {
                    // Do this to notify the user that something is amiss.
                    graphics.Log.Print($"WARNING: Depth Stencil View {info.Name} - Depth/stencil texture has a binding of {TextureBinding.ShaderResource}, but has a view flags of {viewFlags}.  The view will not be bindable to the shader pipeline.",
                                       LoggingLevel.Simple);
                }
            }
            else if (viewFlags != DepthStencilViewFlags.None)
            {
                // Do this to notify the user that something is amiss.
                graphics.Log.Print($"WARNING: Depth Stencil View {info.Name} - Depth/stencil view flag(s) are set to {viewFlags}, but the texture lacks a {TextureBinding.ShaderResource} binding.",
                                   LoggingLevel.Simple);
            }

            var newInfo = new GorgonTexture2DInfo(info)
            {
                // Can't see a reason to use anything other than default for dsvs
                Usage   = ResourceUsage.Default,
                Binding = binding
            };

            BufferFormat depthStencilFormat = newInfo.Format;

            if (((binding & TextureBinding.ShaderResource) == TextureBinding.ShaderResource) &&
                (viewFlags != DepthStencilViewFlags.None))
            {
                switch (newInfo.Format)
                {
                case BufferFormat.R32G8X24_Typeless:
                    depthStencilFormat = BufferFormat.D32_Float_S8X24_UInt;
                    break;

                case BufferFormat.R24G8_Typeless:
                    depthStencilFormat = BufferFormat.D24_UNorm_S8_UInt;
                    break;

                case BufferFormat.R16_Typeless:
                    depthStencilFormat = BufferFormat.D16_UNorm;
                    break;

                case BufferFormat.R32_Typeless:
                    depthStencilFormat = BufferFormat.D32_Float;
                    break;
                }
            }

            var texture = new GorgonTexture2D(graphics, newInfo);
            GorgonDepthStencil2DView result = texture.GetDepthStencilView(depthStencilFormat, flags: viewFlags);

            result.OwnsResource = true;

            return(result);
        }
示例#15
0
 public void AddTextureIndex(TextureBinding texture, int offset, int count)
 {
     _textureIndices.Add(new TextureIndex {
         Texture = texture, Offset = offset, Count = count
     });
 }
        //Deferred Renderer Rework - New GBuffer -
        //32:32:32 WorldPos, (16b:SPARE, 16b:materialIdx)
        //8:8:8 Norm, 8:SPARE
        //reproject z buffer and recompute chain for culling

        public DeferredRenderer(Framebuffer[] fbufs, LightManager man)
        {
            lMan = man;

            InfoBindings  = new TextureBinding[fbufs.Length];
            InfoBindings2 = new TextureBinding[fbufs.Length];
            DepthBindings = new TextureBinding[fbufs.Length];
            Framebuffers  = new Framebuffer[fbufs.Length];
            HiZMap        = new TextureView[fbufs.Length][];
            views         = new ViewData[fbufs.Length];
            HiZMapUBO     = new UniformBuffer(false);
            unsafe
            {
                int    off = 0;
                float *fp  = (float *)HiZMapUBO.Update();
                fp += 4;
                for (int i = 0; i < views.Length; i++)
                {
                    views[i] = new ViewData()
                    {
                        depthBuf = new Texture()
                        {
                            Width           = fbufs[i].Width,
                            Height          = fbufs[i].Height,
                            Depth           = 1,
                            Format          = PixelInternalFormat.DepthComponent32f,
                            GenerateMipmaps = false,
                            LayerCount      = 1,
                            LevelCount      = 1,
                            Target          = TextureTarget.Texture2D
                        }.Build(),
                        infoTex = new Texture()
                        {
                            Width           = fbufs[i].Width,
                            Height          = fbufs[i].Height,
                            Depth           = 1,
                            Format          = PixelInternalFormat.Rgba32f,
                            GenerateMipmaps = false,
                            LayerCount      = 1,
                            LevelCount      = 1,
                            Target          = TextureTarget.Texture2D
                        }.Build(),
                        infoTex2 = new Texture()
                        {
                            Width           = fbufs[i].Width,
                            Height          = fbufs[i].Height,
                            Depth           = 1,
                            Format          = PixelInternalFormat.Rgba8,
                            GenerateMipmaps = false,
                            LayerCount      = 1,
                            LevelCount      = 1,
                            Target          = TextureTarget.Texture2D
                        }.Build(),
                        hiZ = new Texture()
                        {
                            Width           = fbufs[i].Width,
                            Height          = fbufs[i].Height,
                            Depth           = 1,
                            Format          = PixelInternalFormat.Rg32f,
                            GenerateMipmaps = false,
                            LayerCount      = 1,
                            LevelCount      = (int)(MathHelper.Log2((ulong)Math.Max(fbufs[i].Width, fbufs[i].Height)) + 1),
                            Target          = TextureTarget.Texture2D
                        }.Build(),
                        gbuffer = new Framebuffer(fbufs[i].Width, fbufs[i].Height),
                    };

                    views[i].depthView = new TextureView()
                    {
                        BaseLayer  = 0,
                        BaseLevel  = 0,
                        Format     = PixelInternalFormat.DepthComponent32f,
                        LayerCount = 1,
                        LevelCount = 1,
                        Target     = TextureTarget.Texture2D
                    }.Build(views[i].depthBuf);

                    views[i].infoView = new TextureView()
                    {
                        BaseLayer  = 0,
                        BaseLevel  = 0,
                        Format     = PixelInternalFormat.Rgba32f,
                        LayerCount = 1,
                        LevelCount = 1,
                        Target     = TextureTarget.Texture2D
                    }.Build(views[i].infoTex);

                    views[i].infoView2 = new TextureView()
                    {
                        BaseLayer  = 0,
                        BaseLevel  = 0,
                        Format     = PixelInternalFormat.Rgba8,
                        LayerCount = 1,
                        LevelCount = 1,
                        Target     = TextureTarget.Texture2D
                    }.Build(views[i].infoTex2);

                    views[i].hiZView = new TextureView[views[i].hiZ.LevelCount];
                    for (int j = 0; j < views[i].hiZView.Length; j++)
                    {
                        views[i].hiZView[j] = new TextureView()
                        {
                            BaseLayer  = 0,
                            BaseLevel  = j,
                            Format     = PixelInternalFormat.Rg32f,
                            LayerCount = 1,
                            LevelCount = 1,
                            Target     = TextureTarget.Texture2D,
                        }.Build(views[i].hiZ);
                        var f_arr = (float[])views[i].hiZView[j].GetImageHandle().SetResidency(Residency.Resident, AccessMode.ReadWrite);
                        for (int q = 0; q < f_arr.Length; q++)
                        {
                            *(fp++) = f_arr[q];
                        }
                        fp += 2;
                    }
                    views[i].hiZTex = new TextureView()
                    {
                        BaseLayer  = 0,
                        BaseLevel  = 0,
                        Format     = PixelInternalFormat.Rg32f,
                        LayerCount = 1,
                        LevelCount = views[i].hiZView.Length,
                        Target     = TextureTarget.Texture2D
                    }.Build(views[i].hiZ);

                    var sampler = new TextureSampler();
                    sampler.SetEnableLinearFilter(false, true, false);
                    sampler.MinReadLevel = 0;
                    sampler.MaxReadLevel = views[i].hiZView.Length;
                    sampler.SetTileMode(TileMode.ClampToBorder, TileMode.ClampToBorder);

                    views[i].hiZBinding = new TextureBinding()
                    {
                        View    = views[i].hiZTex,
                        Sampler = sampler
                    };
                    var f_arr_ = (float[])views[i].hiZBinding.GetTextureHandle().SetResidency(Residency.Resident);
                    for (int q = 0; q < f_arr_.Length; q++)
                    {
                        *(fp++) = f_arr_[q];
                    }
                    fp += 2;

                    views[i].gbuffer[FramebufferAttachment.DepthAttachment]  = views[i].depthView;
                    views[i].gbuffer[FramebufferAttachment.ColorAttachment0] = views[i].infoView;
                    views[i].gbuffer[FramebufferAttachment.ColorAttachment1] = views[i].infoView2;
                    Framebuffers[i] = views[i].gbuffer;

                    views[i].program = new ShaderProgram(
                        ShaderSource.Load(ShaderType.VertexShader, "Shaders/RenderToTexture/FrameBufferTriangle/vertex.glsl"),
                        ShaderSource.Load(ShaderType.FragmentShader, "Shaders/RenderToTexture/FrameBufferTriangle/fragment.glsl")
                        );
                    views[i].copy = new ShaderProgram(
                        ShaderSource.Load(ShaderType.ComputeShader, "Shaders/HiZ/copy.glsl", $"#define MIP_COUNT {views[i].hiZView.Length}")
                        );
                    views[i].copyState = new RenderState(null, views[i].copy, null, new UniformBuffer[] { Engine.GlobalParameters, HiZMapUBO }, false, false, DepthFunc.Always, InverseDepth.Far, InverseDepth.Near, BlendFactor.SrcAlpha, BlendFactor.OneMinusSrcAlpha, Vector4.Zero, InverseDepth.ClearDepth, CullFaceMode.Back);
                    views[i].mipchain  = new ShaderProgram(
                        ShaderSource.Load(ShaderType.ComputeShader, "Shaders/HiZ/mipchain.glsl", $"#define MIP_COUNT {views[i].hiZView.Length}")
                        );
                    views[i].mipchainState = new RenderState(null, views[i].mipchain, null, new UniformBuffer[] { Engine.GlobalParameters, HiZMapUBO }, false, false, DepthFunc.Always, InverseDepth.Far, InverseDepth.Near, BlendFactor.SrcAlpha, BlendFactor.OneMinusSrcAlpha, Vector4.Zero, InverseDepth.ClearDepth, CullFaceMode.Back);

                    views[i].state = new RenderState(fbufs[i], views[i].program, null, new UniformBuffer[] { Engine.GlobalParameters }, false, true, DepthFunc.Always, InverseDepth.Far, InverseDepth.Near, BlendFactor.SrcAlpha, BlendFactor.OneMinusSrcAlpha, Vector4.Zero, InverseDepth.ClearDepth, CullFaceMode.None);

                    InfoBindings[i] = new TextureBinding()
                    {
                        View    = views[i].infoView,
                        Sampler = TextureSampler.Default
                    };
                    InfoBindings[i].GetTextureHandle().SetResidency(Residency.Resident);

                    InfoBindings2[i] = new TextureBinding()
                    {
                        View    = views[i].infoView2,
                        Sampler = TextureSampler.Default
                    };
                    InfoBindings2[i].GetTextureHandle().SetResidency(Residency.Resident);

                    DepthBindings[i] = new TextureBinding()
                    {
                        View    = views[i].depthView,
                        Sampler = TextureSampler.Default,
                    };
                    DepthBindings[i].GetTextureHandle().SetResidency(Residency.Resident);

                    HiZMap[i] = views[i].hiZView;

                    views[i].cBuffer = new CommandBuffer();
                    views[i].cBuffer.SetRenderState(views[i].state);
                    views[i].cBuffer.Draw(PrimitiveType.Triangles, 0, 3, 1, 0);
                }
                HiZMapUBO.UpdateDone();
            }
        }
示例#17
0
        List <StateGroupAsset> loadStateGroups()
        {
            var stateGroups = new List <StateGroupAsset>();

            if (!Directory.Exists(metadataPath + "StateGroups"))
            {
                Directory.CreateDirectory(metadataPath + "StateGroups");
            }

            foreach (var filename in Directory.EnumerateFiles(metadataPath + "StateGroups"))
            {
                var metadata = File.ReadAllLines(filename);

                var stateGroup = new StateGroupAsset();

                stateGroup.Name              = System.IO.Path.GetFileNameWithoutExtension(filename);
                stateGroup.Description       = metadata[0].Split('=')[1].Trim();
                stateGroup.LastUpdated       = parseLastUpdatedDate(metadata[1].Split('=')[1].Trim(), "stateGroup", stateGroup.Name);
                stateGroup.VertexShaderId    = metadata[2].Split('=')[1].Trim();
                stateGroup.GeometryShaderId  = metadata[3].Split('=')[1].Trim();
                stateGroup.PixelShaderId     = metadata[4].Split('=')[1].Trim();
                stateGroup.ShaderCombination = (ShaderCombination)Enum.Parse(typeof(ShaderCombination), metadata[5].Split('=')[1].Trim());
                stateGroup.ImportedFilename  = metadata[6].Split('=')[1].Trim();
                stateGroup.ImporterVersion   = int.Parse(metadata[7].Split('=')[1].Trim());

                var samplerLine    = metadata[8].Split('=')[1].Trim();
                var samplerConfigs = samplerLine.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var config in samplerConfigs)
                {
                    var data    = config.Split(',');
                    var sampler = new Sampler()
                    {
                        Name     = data[0].Trim(),
                        Filter   = (Filter)Enum.Parse(typeof(Filter), data[1].Trim()),
                        AddressU = (TextureAddressMode)Enum.Parse(typeof(TextureAddressMode), data[2].Trim()),
                        AddressV = (TextureAddressMode)Enum.Parse(typeof(TextureAddressMode), data[3].Trim()),
                        AddressW = (TextureAddressMode)Enum.Parse(typeof(TextureAddressMode), data[4].Trim())
                    };

                    stateGroup.Samplers.Add(sampler);
                }

                var textureLine    = metadata[9].Split('=')[1].Trim();
                var textureConfigs = textureLine.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var config in textureConfigs)
                {
                    var data    = config.Split(',');
                    var texture = new TextureBinding()
                    {
                        Slot    = Int32.Parse(data[0].Trim()),
                        Binding = data[1].Trim()
                    };

                    stateGroup.TextureBindings.Add(texture);
                }

                var blendStateLine = metadata[10].Split('=')[1].Trim();
                var blendConfigs   = blendStateLine.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var config in blendConfigs)
                {
                    var data = config.Split(',');

                    var renderTarget = new RenderTarget()
                    {
                        Index                 = int.Parse(data[0].Trim()),
                        BlendEnabled          = bool.Parse(data[1].Trim()),
                        BlendOperation        = (BlendOperation)Enum.Parse(typeof(BlendOperation), data[2].Trim()),
                        BlendOperationAlpha   = (BlendOperation)Enum.Parse(typeof(BlendOperation), data[3].Trim()),
                        SourceBlend           = (BlendOption)Enum.Parse(typeof(BlendOption), data[4].Trim()),
                        DestinationBlend      = (BlendOption)Enum.Parse(typeof(BlendOption), data[5].Trim()),
                        SourceBlendAlpha      = (BlendOption)Enum.Parse(typeof(BlendOption), data[6].Trim()),
                        DestinationBlendAlpha = (BlendOption)Enum.Parse(typeof(BlendOption), data[7].Trim()),
                        RenderTargetWriteMask = (WriteMask)Enum.Parse(typeof(WriteMask), data[8].Trim())
                    };

                    stateGroup.BlendState.RenderTargets.Add(renderTarget);
                }

                stateGroups.Add(stateGroup);
            }

            return(stateGroups);
        }
示例#18
0
        private List<TextureBinding> ReadNodeTextures(XmlElement nodeNode)
        {
            List<TextureBinding> texBindings = new List<TextureBinding>();
            List<int> texUnits = new List<int>();

            XmlNodeList xnl = nodeNode.GetElementsByTagName("texture");
            foreach(XmlNode texNode in xnl)
            {
                string pNameNode = ((XmlElement)texNode).GetAttribute("name");
                string pUnitName = ((XmlElement)texNode).GetAttribute("unit");
                string pSamplerName = ((XmlElement)texNode).GetAttribute("sampler");

                PARSE_THROW(pNameNode, "Textures on nodes must have a `name` attribute.");
                PARSE_THROW(pUnitName, "Textures on nodes must have a `unit` attribute.");
                PARSE_THROW(pSamplerName, "Textures on nodes must have a `sampler` attribute.");

                if(!m_textures.Keys.Contains(pNameNode))
                {
                    MessageBox.Show("The node texture named " + pNameNode + "  is a texture which does not exist.");
                }

                TextureBinding binding = new TextureBinding();

                binding.pTex = m_textures[pNameNode];
                binding.texUnit = int.Parse(pUnitName);
                binding.sampler = GetTypeFromName(pSamplerName);

                if(texUnits.Contains(binding.texUnit))
                {
                    MessageBox.Show("Multiply bound texture unit in node texture " + pNameNode);
                }
                texBindings.Add(binding);

                texUnits.Add(binding.texUnit);
            }

            return texBindings;
        }