EmbarkStudios/rust-gpu

need to assign the result of texture fetches to an explicitly Vec4 variable, before actually using it as something smaller

oisyn opened this issue · 1 comments

oisyn commented

Currently, this doesn't work:

let pixel = image.fetch(coords);

Because fetch needs to infer the return type. So you have to write this:

let pixel: Vec4 = image.fetch(coords);

This also implies you cannot do something like:

let result = calculate(image.fetch(coords).xy + somevec);

Although it's nice to be able to use your own vector library with rust-gpu, this inconvenience makes writing shaders a bit of a pain in the rear end.

But there is a solution. As fetch and similar functions require some input, we can combine the different vector types into a single "vector type library" type that's referenced by all vector types. So by having a certain implementation of Vertor<T,N>, we can look up another Vector<T2,N2> from the same implementing library.

This way, in above example, fetch can simply return a concrete Vector<f32,4> type based on the concrete type of coords, which is likely coming from the same vector library.

oisyn commented

The above idea proved to be more troublesome than initially thought, and it was ultimately decided to do away with the whole support for generic vector libraries and go with glam only (and possibly support other popular vector libraries manually if needed). Done in #990.