Ejemplo n.º 1
0
 public void BindSourceImage(TextureArray2D texture, Sampler sampler, int id)
 {
     sampler.Bind(TextureBindingStart + id);
     texture.Bind(TextureBindingStart + id);
     // set srgb variable
     shader.Bind();
     GL.Uniform1(TextureSrgbStart + id, texture.IsSrgb?1:0);
 }
Ejemplo n.º 2
0
 public static Reaction <T> BindSamplers <T> (this Reaction <T> render,
                                              Func <T, IDictionary <Sampler, Texture> > getBindings)
 {
     return(input =>
     {
         var bindings = getBindings(input);
         Sampler.Bind(bindings);
         var result = render(input);
         Sampler.Unbind(bindings);
         return result;
     });
 }
Ejemplo n.º 3
0
        private void Render(Camera camera, CascadedShadowUniforms shadowSource)
        {
            lighting.UpdateDirectionalLight(camera);
            shadows.viewLightMatrices &= !shadowSource.viewLightMatrices;
            //shadows.lightSpaceMatrix &= !shadowSource.lightSpaceMatrix;

            foreach (var mesh in camera.NodesInView <Mesh <EntityVertex> > ())
            {
                Sampler.Bind(!samplers, mesh.Textures);
                transforms.UpdateModelViewAndNormalMatrices(camera.WorldToCamera * mesh.Transform);
                _entityShader.DrawElements(PrimitiveType.Triangles, mesh.VertexBuffer, mesh.IndexBuffer);
                Sampler.Unbind(!samplers, mesh.Textures);
            }
        }
Ejemplo n.º 4
0
        private void OnLoad(object sender, EventArgs e)
        {
            // load texture from file
            using (var bitmap = new Bitmap("Data/Textures/checker.jpg"))
            {
                BitmapTexture.CreateCompatible(bitmap, out _texture);
                _texture.LoadBitmap(bitmap);
            }
            _texture.GenerateMipMaps();

            // initialize sampler
            _sampler = new Sampler();
            _sampler.SetWrapMode(TextureWrapMode.Repeat);

            // create vertex data for a big plane
            const int a        = 10;
            const int b        = 10;
            var       vertices = new[]
            {
                new Vertex(-a, 0, -a, 0, 0),
                new Vertex(a, 0, -a, b, 0),
                new Vertex(-a, 0, a, 0, b),
                new Vertex(a, 0, a, b, b)
            };

            // create buffer object and upload vertex data
            _vbo = new Buffer <Vertex>();
            _vbo.Init(BufferTarget.ArrayBuffer, vertices);

            // initialize shader
            _program = ProgramFactory.Create <SimpleTextureProgram>();
            // activate shader program
            _program.Use();
            // bind sampler
            _sampler.Bind(TextureUnit.Texture0);
            // bind texture
            _program.Texture.BindTexture(TextureUnit.Texture0, _texture);
            // which is equivalent to
            //_program.Texture.Set(TextureUnit.Texture0);
            //_texture.Bind(TextureUnit.Texture0);

            // set up vertex array and attributes
            _vao = new VertexArray();
            _vao.Bind();
            // memory layout of our data is XYZUVXYZUV...
            // the buffer abstraction knows the total size of one "pack" of vertex data
            // and if a vertex attribute is bound without further arguments the first N elements are taken from each pack
            // where N is provided via the VertexAttribAttribute on the program property:
            _vao.BindAttribute(_program.InPosition, _vbo);
            // if data should not be taken from the start of each pack, the offset must be given in bytes
            // to reach the texture coordinates UV the XYZ coordinates must be skipped, that is 3 floats, i.e. an offset of 12 bytes is needed
            _vao.BindAttribute(_program.InTexCoord, _vbo, 12);
            // if needed all the available arguments can be specified manually, e.g.
            //_vao.BindAttribute(_program.InTexCoord, _vbo, 2, VertexAttribPointerType.Float, Marshal.SizeOf(typeof(Vertex)), 12, false);

            // set default camera
            Camera.DefaultState.Position = new Vector3(0, 0.5f, 3);
            Camera.ResetToDefault();

            // set a nice clear color
            GL.ClearColor(Color.MidnightBlue);
        }
Ejemplo n.º 5
0
 public void Render(Texture heightmap, Sampler heightmapSampler)
 {
     gb.Render(() =>
     {
         heightmapSampler.Bind(TextureUnit.Texture0);
     },
     (sp) =>
     {
         sp.SetUniform("heightmap", 0);
         sp.SetUniform("texsize", (float)heightmap.Width);
     });
 }