Giter Club home page Giter Club logo

Comments (23)

hadronized avatar hadronized commented on May 23, 2024 1

I must integrate the example of my latest blog entry about luminance. I’ll close this issue when it’s done.

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Yeah! Two demos I wrote! You can have a look at Céleri Rémoulade and Outline Invitation. I wrote an engine for that, spectra, which uses luminance.

On a general note, you’re right, I should provide more example. I’ll try to do that today and tomorrow. The main idea is:

  • create a context – you can use luminance-glfw or luminance-glutin (though the latest is not stable enough, I need to fix it)
  • create a pipeline with a framebuffer (use the default one with Framebuffer::default), a shader program and a tess object (it contains the vertices). You can alternatively use an attributeless render if you don’t want to allocate a buffer on the GPU
  • run the pipeline

You have a better example here.

I should definitely add those to the crate. How did you get into luminance by the way? :)

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

Sweet, I'll check those out! Got a little confused on how to render with the pipeline since the functionality changed from the old pipeline.run() to pipeline.enter() and how exactly to go about using the shader commands.

Discovered luminance on arewegameyet and found it much simpler than gfx. Playing around with some graphics stuff to try and write a game :P

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Well, the gate stuff is because I came to the realisation (with Céleri Rémoulade) that expecting a slice (&[ShadingCommand] for instance) was too constraining and caused some data structure to be impossible to render. For instance, I have a lot of shared resources (Rc<RefCell<_>>) that I need to borrow from. Once I’ve borrowed them, I need to keep the borrowed object around until the actual render is performed. This was not possible before introducing the gate concept. The idea is that when you do something like pipeline.enter(_), you pass in a continuation that accepts an object that will live until the pipeline dies. This enables the use of Iterator types and doesn’t require dynamic allocation in the rendering loop anymore.

I guess it’s a bit confusing and that I should write about it, indeed. Thanks for your feedback about arewegameyet, I didn’t even know my framework was listed there!

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

Another quick question. I've been looking through the sample code you provided and drew a triangle (yay!) but I am still unsure as to what the RawBuffer and RawTexture slices are for in the pipeline. What exactly should I pass to those?

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Yeah, this part is a bit unstable, I need to refactor it a bit.

Those two slices are there when you want to bind a uniform buffer or textures. If you don’t have any, just pass empty slices. Those are then “indexed“ via uniforms (respectively, Uniform<Binding> and Uniform<Unit>).

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

How would I map the uniforms/textures to the correct shader variable? When I pass a buffer filled with uniform data, it isn't being used 🙁

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

If you have a buffer, let’s say Buffer<Foo>, you can use a reference on it (it’ll be dereferenced to RawBuffer) and put that in your slice. Then you need to represent the buffer as a uniform to your shader with a Uniform<Binding> (0 in your case, since the buffer is at the index 0 in the slice).

This behavior is neat because it enables luminance to do aggressive optimization on the number of buffer bindings, but it’s not very intuitive and is prone to errors. As I said above, it might change in the future.

For instance, in my latest demo, I have a uniform representing a directional light (here). Then, look at how I create a slice for that buffer here and here.

So basically, you need:

  • your buffer, that will be used in the slice so that luminance passes its handle to the GPU (in the slice)
  • retain the index in that slice you put your buffer in
  • use a uniform with a buffer binding with that index
  • pass the uniform to the shader

I wish I had a better scheme to cope with that, but I haven’t found a way yet. For instance, glium uses a total type for that – you need to pass all the values at once, if you need several, you have to duplicate your pipeline. The model for luminance is streaming and partial traversal (the borrow stuff I talked earlier).

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

Can't seem to find a way to actually get a Uniform 😅. Uniform and UniformBuilder don't seem to have any constructors in the latest version. Also the ShadingGate method no longer takes an array of AlterUnis. That's what the binding buffer is for though right?

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Yeah I changed quite a bit of things. If you really use the latest version, the design is a bit cleaner to get uniforms. You have to use the UniformBuilder::ask function. It either gives you a uniform or a warning (inactive uniform, etc.).

This uniform builder lets you retrieve one uniform. You then have to fold down all the uniforms to a “uniforms” object. You can do that like this for instance. This project uses the last version of luminance – I should have linked that earlier. You should read the main.rs, it’s rather small – it’s a shader toy!

I should definitely update the documentation, you seem confused, it’s my fault and only mine. I’ll rework the documentation! Thank you very much for your precious feedback.

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Also, the unwrap_or_unbound method is used so that you accumulate warnings in a Vec if something is wrong with a single uniform. Because you still need a uniform for the folded type (here it’s ShaderToyUniforms), you have two options:

  • make the whole uniform interface fail, because you need all of its uniforms
  • use an unbound uniform, that is a special kind of uniform that will just do nothing when you try to update it

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

Ohhhhhh. I made the mistake of disregarding the second input from the shading gate 😬, my bad. I see where to get the uniforms now!

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

It works! That was a silly mistake on my part. Thanks for clearing that up!

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Well, it’s also due to my mistake not to update the doc and have something clean. I’ll do something about it!

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

Working on some texturing but I don't quite have it yet. From what I gathered, I need to assign the framebuffer a color slot, create a texture that matches that color slot, upload to the texture, bind a unit uniform to it and then pass the texture buffer to the render gate. Is there something I'm missing?

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

If you need to texturize an object, all you need is a simple texture. You just bind it as a uniform and pass the texture buffer. You have nothing to do with the framebuffer – if you really need color slot(s), luminance creates the texture(s) for you.

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

I'll leave that out then. Also which gate should the texture slice be passed to?

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Which one you want. The idea is to be able to texturize at every level in the tree. Bind as soon as you have it (the pipeline entry is a good point).

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

Still not showing up 🙁.
This would be a valid texture correct?

let tex = Texture::<Flat, Dim2, RGBA8UI>::new([1, 1], 0, &sampler).unwrap();  
tex.upload(false, &[(255, 0, 0, 255)]);

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

You’re using the upload function. It expects the texels’s size to match. If you want to clear the texture, use the clear function.

from luminance-rs.

svenknobloch avatar svenknobloch commented on May 23, 2024

That should make a 1x1 texture and then upload a single red pixel, no?

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Yeah, but I think 1x1 textures are forbidden by OpenGL. I should check that, actually, in luminance!

from luminance-rs.

hadronized avatar hadronized commented on May 23, 2024

Ok, I think there’s enough examples for now. I’m closing this. I’ll add more example when I think about them, but for now, I guess it’s quite okay.

from luminance-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.