public SkyboxRenderer(GraphicsDevice device, Framebuffer target, Image <Rgba32> positiveXImage, Image <Rgba32> negativeXImage, Image <Rgba32> positiveYImage, Image <Rgba32> negativeYImage, Image <Rgba32> positiveZImage, Image <Rgba32> negativeZImage) { _skyboxTexture = new ImageSharpCubemapTexture(positiveXImage, negativeXImage, positiveYImage, negativeYImage, positiveZImage, negativeZImage); var factory = device.ResourceFactory; var deviceTexture = _skyboxTexture.CreateDeviceTexture(device, factory); _skyboxTexture = null; TextureView textureView = factory.CreateTextureView(new TextureViewDescription(deviceTexture)); _vb = factory.CreateBuffer(new BufferDescription(VertexPosition.SizeInBytes * (uint)s_vertices.Length, BufferUsage.VertexBuffer)); device.UpdateBuffer(_vb, 0, s_vertices); _ib = factory.CreateBuffer(new BufferDescription(sizeof(ushort) * (uint)s_indices.Length, BufferUsage.IndexBuffer)); device.UpdateBuffer(_ib, 0, s_indices); VertexLayoutDescription[] vertexLayouts = new VertexLayoutDescription[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float3)) }; _layout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Projection", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("View", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("CubeTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("CubeSampler", ResourceKind.Sampler, ShaderStages.Fragment))); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, //device.IsDepthRangeZeroToOne ? DepthStencilStateDescription.DepthOnlyGreaterEqual : DepthStencilStateDescription.DepthOnlyLessEqual, new DepthStencilStateDescription(false, false, ComparisonKind.LessEqual), new RasterizerStateDescription(FaceCullMode.Back, PolygonFillMode.Solid, FrontFace.Clockwise, true, true), PrimitiveTopology.TriangleList, new ShaderSetDescription( vertexLayouts, factory.CreateFromSpirv( new ShaderDescription(ShaderStages.Vertex, Encoding.UTF8.GetBytes(SkyboxShader.VertexCode), "main"), new ShaderDescription(ShaderStages.Fragment, Encoding.UTF8.GetBytes(SkyboxShader.FragmentCode), "main"))), new ResourceLayout[] { _layout }, target.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); ProjectionMatrixBuffer = factory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); ViewMatrixBuffer = factory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); _resourceSet = factory.CreateResourceSet(new ResourceSetDescription( _layout, ProjectionMatrixBuffer, ViewMatrixBuffer, textureView, device.Aniso4xSampler)); }
public override void CreateDeviceObjects(GraphicsDevice gd, CommandList cl, SceneContext sc) { ResourceFactory factory = gd.ResourceFactory; _vb = factory.CreateBuffer(new BufferDescription(s_vertices.SizeInBytes(), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, s_vertices); _ib = factory.CreateBuffer(new BufferDescription(s_indices.SizeInBytes(), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, s_indices); ImageSharpCubemapTexture imageSharpCubemapTexture = new ImageSharpCubemapTexture(_right, _left, _top, _bottom, _back, _front, false); Texture textureCube = imageSharpCubemapTexture.CreateDeviceTexture(gd, factory); TextureView textureView = factory.CreateTextureView(new TextureViewDescription(textureCube)); VertexLayoutDescription[] vertexLayouts = new VertexLayoutDescription[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float3)) }; (Shader vs, Shader fs) = StaticResourceCache.GetShaders(gd, gd.ResourceFactory, "Skybox"); _layout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Projection", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("View", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("CubeTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("CubeSampler", ResourceKind.Sampler, ShaderStages.Fragment))); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, gd.IsDepthRangeZeroToOne ? DepthStencilStateDescription.DepthOnlyGreaterEqual : DepthStencilStateDescription.DepthOnlyLessEqual, new RasterizerStateDescription(FaceCullMode.None, PolygonFillMode.Solid, FrontFace.Clockwise, true, true), PrimitiveTopology.TriangleList, new ShaderSetDescription(vertexLayouts, new[] { vs, fs }, ShaderHelper.GetSpecializations(gd)), new ResourceLayout[] { _layout }, sc.MainSceneFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); pd.Outputs = sc.ReflectionFramebuffer.OutputDescription; _reflectionPipeline = factory.CreateGraphicsPipeline(ref pd); _resourceSet = factory.CreateResourceSet(new ResourceSetDescription( _layout, sc.ProjectionMatrixBuffer, sc.ViewMatrixBuffer, textureView, gd.PointSampler)); _disposeCollector.Add(_vb, _ib, textureCube, textureView, _layout, _pipeline, _reflectionPipeline, _resourceSet, vs, fs); }
public void CreateDeviceObjects(GraphicsDevice gd, OutputDescription outputs) { ResourceFactory factory = gd.ResourceFactory; _vb = factory.CreateBuffer(new BufferDescription((uint)(s_vertices.Length * 12), BufferUsage.VertexBuffer)); gd.UpdateBuffer(_vb, 0, s_vertices); _ib = factory.CreateBuffer(new BufferDescription((uint)(s_indices.Length * 2), BufferUsage.IndexBuffer)); gd.UpdateBuffer(_ib, 0, s_indices); ImageSharpCubemapTexture imageSharpCubemapTexture = new ImageSharpCubemapTexture(_front, _back, _top, _bottom, _right, _left, true); Texture textureCube = imageSharpCubemapTexture.CreateDeviceTexture(gd, factory); TextureView textureView = factory.CreateTextureView(new TextureViewDescription(textureCube)); VertexLayoutDescription[] vertexLayouts = new VertexLayoutDescription[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float3)) }; Shader[] shaders = factory.CreateFromSpirv( new ShaderDescription(ShaderStages.Vertex, Encoding.ASCII.GetBytes(VertexShader), "main"), new ShaderDescription(ShaderStages.Fragment, Encoding.ASCII.GetBytes(FragmentShader), "main")); _disposables.Add(shaders[0]); _disposables.Add(shaders[1]); _layout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("UBO", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("CubeTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("CubeSampler", ResourceKind.Sampler, ShaderStages.Fragment))); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, DepthStencilStateDescription.DepthOnlyLessEqual, new RasterizerStateDescription(FaceCullMode.None, PolygonFillMode.Solid, FrontFace.Clockwise, true, true), PrimitiveTopology.TriangleList, new ShaderSetDescription(vertexLayouts, shaders), new ResourceLayout[] { _layout }, outputs); _pipeline = factory.CreateGraphicsPipeline(ref pd); _ubo = factory.CreateBuffer(new BufferDescription(64 * 3, BufferUsage.UniformBuffer | BufferUsage.Dynamic)); _resourceSet = factory.CreateResourceSet(new ResourceSetDescription( _layout, _ubo, textureView, gd.PointSampler)); }
public override void CreateDeviceObjects(GraphicsDevice gd, CommandList cl, SceneContext sc) { ResourceFactory factory = gd.ResourceFactory; _vb = factory.CreateBuffer(new BufferDescription(s_vertices.SizeInBytes(), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, s_vertices); _ib = factory.CreateBuffer(new BufferDescription(s_indices.SizeInBytes(), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, s_indices); ImageSharpCubemapTexture cubemap = PreloadTexture(sc); Texture textureCube = cubemap.CreateDeviceTexture(gd, factory); TextureLoaded?.Invoke(sc, cubemap); _pendingCubemap = null; VertexLayoutDescription[] vertexLayouts = new VertexLayoutDescription[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float3)) }; (Shader vs, Shader fs, SpecializationConstant[] specs) = StaticResourceCache.GetShaders(gd, gd.ResourceFactory, "Skybox"); _layout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("CameraInfo", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("CubeTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("CubeSampler", ResourceKind.Sampler, ShaderStages.Fragment))); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, gd.IsDepthRangeZeroToOne ? DepthStencilStateDescription.DepthOnlyGreaterEqual : DepthStencilStateDescription.DepthOnlyLessEqual, new RasterizerStateDescription(FaceCullMode.None, PolygonFillMode.Solid, FrontFace.Clockwise, true, true), PrimitiveTopology.TriangleList, new ShaderSetDescription(vertexLayouts, new[] { vs, fs }, specs), new ResourceLayout[] { _layout }, sc.MainSceneFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); _resourceSet = factory.CreateResourceSet(new ResourceSetDescription( _layout, sc.CameraInfoBuffer, textureCube, gd.PointSampler)); _disposeCollector.Add(_vb, _ib, textureCube, _layout, _pipeline, _resourceSet, vs, fs); }
public Skybox(Image <Rgba32> positiveXImage, Image <Rgba32> negativeXImage, Image <Rgba32> positiveYImage, Image <Rgba32> negativeYImage, Image <Rgba32> positiveZImage, Image <Rgba32> negativeZImage) { _skyboxTexture = new ImageSharpCubemapTexture(positiveXImage, negativeXImage, positiveYImage, negativeYImage, positiveZImage, negativeZImage); }