Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more material param types (vec2,vec3,vec4) #5

Merged
merged 2 commits into from Feb 27, 2018

Conversation

jice-nospam
Copy link
Contributor

Shouldn't we use directly the tuples MaterialParam::VecN instead of going through a na::VectorN ? (to avoid creating temporary objects and be lighter on garbage collector for the web version)

@edwin0cheng
Copy link
Member

edwin0cheng commented Feb 27, 2018

  • I would prefer na::Vector to tuples, because normally material params are generated by some calculations (e.g. dynamic light direction etc) And it is quite inconvenient to convert them to tuple every single time.
  • The compiler should be able to handle it to not create an temp obj, even it create a temp object it should be created in stack. So it should not do any garbage collection both platforms (native or web). And the memory model of wasm do not support GC, that's why Rust is more powerful than other languages for developing wasm. ❤

However, wasm only support some primary types (u32, f32 etc), so passing other object type (struct, enum..) between Js and Wasm, some conventions has to be done.

Stdweb crate handled the conventions by serialize it to json and it is quite slow right now, So after some profiling, i did some optimization on implementation the uniform_matrix_4fv func in webgl crate. It is quite hacky and i don't know we should wait for the stdweb optimization or do it for all webgl functions.
So here are the options:

  1. Wait for the optimization of stdweb. (Js! macro performance in wasm32-unknown-unknown koute/stdweb#99)
  2. Do all hacky optimization by ourself, just like uniform_matrix_4fv.
  3. Keep it what it is, and do the optimization only on the hot path (of cos after profiling)

We do you think ?

@edwin0cheng edwin0cheng self-assigned this Feb 27, 2018
@jice-nospam
Copy link
Contributor Author

Ah indeed. I completely forgot rust kept us from the gc evil :) no problem, let's keep it the current way.

@jice-nospam
Copy link
Contributor Author

Is there a rust way we can simplify the creation of those params ? Right now, I do it like that :

params.insert("uvSize".to_string(),MaterialParam::Vec2(Vector2::new(1.0,1.0)));

@edwin0cheng
Copy link
Member

edwin0cheng commented Feb 27, 2018

No right now, but i would make the params as material functions, and im changing the mesh creation code too (For support multiple mesh buffer in single Mesh Component) for wave obj prefab loader.

@edwin0cheng
Copy link
Member

And all looks good for me, and i would merge it to master.

@edwin0cheng edwin0cheng merged commit 01b426f into unrust:master Feb 27, 2018
@edwin0cheng
Copy link
Member

The material api changed, please reference framebuffer/postprocessing api to use it, it should be much easier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants