Comments (23)
I must integrate the example of my latest blog entry about luminance. I’ll close this issue when it’s done.
from luminance-rs.
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
orluminance-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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
It works! That was a silly mistake on my part. Thanks for clearing that up!
from luminance-rs.
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.
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.
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.
I'll leave that out then. Also which gate should the texture slice be passed to?
from luminance-rs.
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.
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.
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.
That should make a 1x1 texture and then upload a single red pixel, no?
from luminance-rs.
Yeah, but I think 1x1 textures are forbidden by OpenGL. I should check that, actually, in luminance!
from luminance-rs.
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)
- What's the replacement for new_texture_no_texels? HOT 5
- Texture swizzling HOT 1
- Decouple vertex semantics from representation HOT 4
- Intermixing of Tess's with different structures HOT 1
- `Vertex` derive macro obstructs use of the inherent method name `new`
- Placeholder `#repr_ty_name` in derived attribute wrapper type documentation HOT 2
- Incorrect(?) warning when a shader uses a subset of attributes declared in semantics HOT 1
- [luminance-glutin] How to make use of glutin:WindowedContext HOT 3
- luminance-glutin doesn't resize correctly under Wayland
- Depth-only framebuffer causes generated binding code to error?
- Web examples instructions incomplete HOT 1
- Instanced rendering using instance attributes? HOT 1
- Learn luminance book is very out of date HOT 2
- Why GL_ARB_separate_shader_objects? HOT 1
- Pure OpenGL ES renderer? HOT 1
- luminance 0.46.1 needs unpublished luminance-derive HOT 1
- Luminance 0.47 isn't on crates.io HOT 1
- Clearing textures
- Segmentation fault when dropping shader program struct HOT 3
- Fields of Vertex struct being reordered on new rust version results in incorrect render HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luminance-rs.