public RenderToTextureScene(IEye eye, DisplayMode desctopDisplayMode) : base(eye, desctopDisplayMode) { var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText)); var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText)); shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader); var meshFactory = new MeshFactory(Device, Handedness.Right, Winding.Clockwise); cubeMesh = meshFactory.CreateCube(2.0f); vertexLayout = Device.Create.VertexLayout(vertexShader, new[] { new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0), new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12), new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 24) }); transformBuffer = Device.Create.Buffer( new BufferDescription { SizeInBytes = Transform.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic }); cameraVertexBuffer = Device.Create.Buffer( new BufferDescription { SizeInBytes = CameraVertex.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic }); lightBuffer = Device.Create.Buffer( new BufferDescription { SizeInBytes = Light.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic }); var renderTargetFormats = Eye.Adapters[0] .GetSupportedFormats(FormatSupport.Texture2D | FormatSupport.RenderTarget | FormatSupport.MipAutogen) .Where(fi => fi.ColorBits <= 24); if (!renderTargetFormats.Any()) throw new NotSupportedException("Render target textures are not supported."); var renderTargetFormatInfo = renderTargetFormats .OrderByDescending(fi => fi.ColorBits) .ThenBy(fi => fi.TotalBits) .First(); var renderTargetTexture = Device.Create.Texture2D(new Texture2DDescription { Width = TargetSize, Height = TargetSize, MipLevels = TextureHelper.MipLevels(TargetSize, TargetSize, 1), ArraySize = 1, FormatID = renderTargetFormatInfo.ID, Sampling = Sampling.NoMultisampling, Usage = Usage.Default, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, MiscFlags = MiscFlags.GenerateMips, ExtraFlags = ExtraFlags.None }); targetRtv = renderTargetTexture.ViewAsRenderTarget(renderTargetFormatInfo.ID, 0); targetSrv = renderTargetTexture.ViewAsShaderResource(renderTargetFormatInfo.ID, 0, renderTargetTexture.MipLevels); var dsFormats = Eye.Adapters[0].GetSupportedFormats(FormatSupport.Texture2D | FormatSupport.DepthStencil); var dsFormatInfo = dsFormats .OrderBy(fi => (fi.ColorBits == 24 && fi.AlphaBits == 8) ? 0 : 1) .ThenByDescending(fi => fi.ColorBits) .ThenBy(fi => fi.TotalBits) .First(); var depthStencilTexture = Device.Create.Texture2D(new Texture2DDescription { Width = TargetSize, Height = TargetSize, MipLevels = 1, ArraySize = 1, FormatID = dsFormatInfo.ID, Sampling = Sampling.NoMultisampling, Usage = Usage.Default, BindFlags = BindFlags.DepthStencil, MiscFlags = MiscFlags.None, ExtraFlags = ExtraFlags.None }); targetDsv = depthStencilTexture.ViewAsDepthStencil(dsFormatInfo.ID, DepthStencilViewFlags.None, 0); var textureLoader = new TextureLoader(Device); var diffuseTexture = textureLoader.Load("../Textures/DiffuseTest.png"); diffuseView = diffuseTexture.ViewAsShaderResource(diffuseTexture.FormatID, 0, diffuseTexture.MipLevels); samplerState = Device.Create.SamplerState(SamplerDescription.Anisotropic); depthStencilState = Device.Create.DepthStencilState(DepthStencilDescription.Enabled); }
public TriangleScene(IEye eye, DisplayMode desctopDisplayMode) : base(eye, desctopDisplayMode) { var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText)); var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText)); shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader); var vertexData = new[] { new Vertex(-0.7f, -0.7f, Color4.Red), new Vertex(0.0f, 0.7f, Color4.Yellow), new Vertex(0.7f, -0.7f, Color4.Green) }; vertexBuffer = Device.Create.Buffer(new BufferDescription { SizeInBytes = vertexData.Length * Vertex.SizeInBytes, Usage = Usage.Immutable, BindFlags = BindFlags.VertexBuffer }, new SubresourceData(vertexData)); vertexLayout = Device.Create.VertexLayout(vertexShader, new[] { new VertexLayoutElement(ExplicitFormat.R32G32B32A32_FLOAT, 0, 0), new VertexLayoutElement(ExplicitFormat.R32G32B32A32_FLOAT, 0, 16) }); }
public Stars(IDevice device, int starCount) { this.starCount = starCount; shaders = CreateShaders(device); timeUbuffer = CreateTimeUbuffer(device); vertexLayout = CreateVertexLayout(device, shaders.VertexShader); vertexBuffer = CreateVertexBuffer(device, starCount); indexBuffer = CreateIndexBuffer(device, starCount); rasterizerState = CreateRasterizerState(device); depthStencilState = CreateDepthStencilState(device); blendState = CreateBlendState(device); }
public ColorfulSpaceScene(IEye eye, DisplayMode desctopDisplayMode) : base(eye, desctopDisplayMode) { var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText)); var geometryShader = Device.Create.GeometryShader(ShaderParser.Parse(GeometryShaderText)); var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText)); shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, geometryShader, pixelShader); var vertexData = new Vertex[ParticleCount]; for (int i = 0; i < vertexData.Length; i++) vertexData[i] = new Vertex((float)i / ParticleCount); vertexBuffer = Device.Create.Buffer(new BufferDescription { Usage = Usage.Immutable, SizeInBytes = ParticleCount * Vertex.SizeInBytes, BindFlags = BindFlags.VertexBuffer, ExtraFlags = ExtraFlags.Points }, new SubresourceData(vertexData)); vertexLayout = Device.Create.VertexLayout(vertexShader, new[] { new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0), new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12) }); timeBuffer = Device.Create.Buffer(new BufferDescription { Usage = Usage.Dynamic, SizeInBytes = Time.SizeInBytes, BindFlags = BindFlags.UniformBuffer }); cameraBuffer = Device.Create.Buffer(new BufferDescription { Usage = Usage.Dynamic, SizeInBytes = Camera.SizeInBytes, BindFlags = BindFlags.UniformBuffer }); blendState = Device.Create.BlendState(BlendDescription.Additive); }
public CurveTesselationScene(IEye eye, DisplayMode desctopDisplayMode) : base(eye, desctopDisplayMode) { var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText)); var hullShader = Device.Create.HullShader(ShaderParser.Parse(HullShaderText)); var domainShader = Device.Create.DomainShader(ShaderParser.Parse(DomainShaderTet)); var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText)); shaderCombination = Device.Create.ShaderCombination(vertexShader, hullShader, domainShader, null, pixelShader); vertexBuffer = Device.Create.Buffer(new BufferDescription { SizeInBytes = 12 * Vertex.SizeInBytes, Usage = Usage.Immutable, BindFlags = BindFlags.VertexBuffer, }, new SubresourceData(new[] { new Vertex(-1f, 1/3f), new Vertex(4f, 1f), new Vertex(-4f, 1f), new Vertex(1f, 1/3f), new Vertex(-1f, -1/3f), new Vertex(4f, 1/3f), new Vertex(-4f, 1/3f), new Vertex(1f, -1/3f), new Vertex(-1f, -1f), new Vertex(4f, -1/3f), new Vertex(-4f, -1/3f), new Vertex(1f, -1f) })); vertexLayout = Device.Create.VertexLayout(vertexShader, new[] { new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 0) }); tessFactorBuffer = Device.Create.Buffer(new BufferDescription { SizeInBytes = TessFactor.SizeInBytes, Usage = Usage.Dynamic, BindFlags = BindFlags.UniformBuffer }); }
public FullscreenQuadScene(IEye eye, DisplayMode desctopDisplayMode) : base(eye, desctopDisplayMode) { var vs = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText)); var ps = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText)); shaders = Device.Create.ShaderCombination(vs, null, null, null, ps); vertexLayout = Device.Create.VertexLayout(vs, new[] { new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 0), new VertexLayoutElement(ExplicitFormat.R32G32B32A32_FLOAT, 0, 8) }); vertexBuffer = Device.Create.Buffer(new BufferDescription { BindFlags = BindFlags.VertexBuffer, Usage = Usage.Immutable, SizeInBytes = 4 * Vertex.SizeInBytes }, new SubresourceData(new[] { new Vertex(-1, -1, -1, -1, 1, 1), new Vertex( 1, -1, 1, -1, 1, 1), new Vertex( 1, 1, 1, 1, 0, 0), new Vertex(-1, 1, -1, 1, 0, 0) })); indexBuffer = Device.Create.Buffer(new BufferDescription { BindFlags = BindFlags.IndexBuffer, Usage = Usage.Immutable, ExtraFlags = ExtraFlags.SixteenBitIndices, SizeInBytes = 6 * sizeof(ushort) }, new SubresourceData(new ushort[] { 0, 1, 2, 0, 2, 3 })); }
public CubeScene(IEye eye, DisplayMode desctopDisplayMode) : base(eye, desctopDisplayMode) { var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText)); var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText)); shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader); var meshFactory = new MeshFactory(Device, Handedness.Right, Winding.Clockwise); cubeMesh = meshFactory.CreateCube(2.0f); vertexLayout = Device.Create.VertexLayout(vertexShader, new[] { new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0), new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12), new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 24) }); transformBuffer = Device.Create.Buffer( new BufferDescription { SizeInBytes = Transform.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic }); cameraVertexBuffer = Device.Create.Buffer( new BufferDescription { SizeInBytes = CameraVertex.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic }); cameraPixelBuffer = Device.Create.Buffer( new BufferDescription { SizeInBytes = CameraPixel.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic }); lightBuffer = Device.Create.Buffer( new BufferDescription { SizeInBytes = Light.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic }); var textureLoader = new TextureLoader(Device); var diffuseTexture = textureLoader.Load("../Textures/DiffuseTest.png"); diffuseView = diffuseTexture.ViewAsShaderResource(diffuseTexture.FormatID, 0, diffuseTexture.MipLevels); var specularTexture = textureLoader.Load("../Textures/SpecularTest.png"); specualrView = specularTexture.ViewAsShaderResource(specularTexture.FormatID, 0, specularTexture.MipLevels); samplerState = Device.Create.SamplerState(SamplerDescription.Default); depthStencilState = Device.Create.DepthStencilState(DepthStencilDescription.Enabled); }