Beispiel #1
0
        private void AddTexturedMesh(string texPath, MeshData meshData, Vector3 position, Quaternion rotation, Vector3 scale)
        {
            ImageSharpMipmapChain texData = new ImageSharpMipmapChain(AssetHelper.GetPath(texPath));
            TexturedMesh          mesh    = new TexturedMesh(meshData, texData, CommonMaterials.Brick);

            mesh.Transform.Position = position;
            mesh.Transform.Rotation = rotation;
            mesh.Transform.Scale    = scale;
            mesh.CreateDeviceObjects(_rc);
            _scene.AddRenderable(mesh);
        }
Beispiel #2
0
        public BasicDemoApp(Sdl2Window window, RenderContext rc)
        {
            _window = window;
            _rc     = rc;

            _window.Closed  += () => _running = false;
            _window.Resized += () => _windowResized = true;

            ResourceFactory factory = _rc.ResourceFactory;

            _vb = factory.CreateVertexBuffer(s_cubeVertices, new VertexDescriptor(VertexPositionTexture.SizeInBytes, VertexPositionTexture.ElementCount), false);
            _ib = factory.CreateIndexBuffer(s_cubeIndices, false);

            Shader            vertexShader   = factory.CreateShader(ShaderStages.Vertex, factory.LoadProcessedShader(GetShaderBytecode(factory.BackendType, true)));
            Shader            fragmentShader = factory.CreateShader(ShaderStages.Fragment, factory.LoadProcessedShader(GetShaderBytecode(factory.BackendType, false)));
            VertexInputLayout inputLayout    = factory.CreateInputLayout(
                new VertexInputElement("vsin_position", VertexSemanticType.Position, VertexElementFormat.Float3),
                new VertexInputElement("vsin_texCoord", VertexSemanticType.TextureCoordinate, VertexElementFormat.Float2));

            _shaderSet        = factory.CreateShaderSet(inputLayout, vertexShader, fragmentShader);
            _resourceBindings = factory.CreateShaderResourceBindingSlots(
                _shaderSet,
                new ShaderResourceDescription("WorldViewProjectionBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("SurfaceTexture", ShaderResourceType.Texture, ShaderStages.Fragment),
                new ShaderResourceDescription("Sampler", ShaderResourceType.Sampler, ShaderStages.Fragment));
            _worldBuffer      = factory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);
            _viewBuffer       = factory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);
            _projectionBuffer = factory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);
            TextureData textureData = new ImageSharpMipmapChain(
                Path.Combine(AppContext.BaseDirectory, "Textures", "Sponza_Bricks.png"));

            _deviceTexture  = textureData.CreateDeviceTexture(factory);
            _textureBinding = factory.CreateShaderTextureBinding(_deviceTexture);

            _worldBuffer.SetData(Matrix4x4.Identity);
            _viewBuffer.SetData(Matrix4x4.CreateLookAt(new Vector3(0, 0, -5), Vector3.Zero, Vector3.UnitY));
        }