Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MickeyMouse

Advices on shader code design needed

This topic is 5685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone! First short description of what I have implemented so far: I have shaders, each with its buffer for meshes. I have models that have method Render() which iterates through all meshes of that model calling method Push() of shader certain mesh belongs to (something like Mesh->Shader->Push(Mesh) ). When I'm done with iterating, all meshes (in fact pointers to them) are placed in different shaders' buffers. Now to perform final rendering to screen I iterate through all shaders calling Flush() method for each one which renders all meshes in its buffer and then frees buffer. Hope it's clear so far. This method is very nice and allows for nearly optimal state sorting which is one of the keys of fast rendering. The only problem appears with skeletal models which require their meshes to be transformed by some hierarchy matrices. If I simply push all meshes to shaders' buffers and then flush those buffers I'll "loose" those transformations. If I transform each vertex of each mesh before pushing it to buffers it will be damn slow (imagine multiplication 4d matrix by 4d vector for each vertex). I'd like some opinions on how is it done in more or less "proffesional" engines or scene graphs or whatever that allows for rendering skeletal models and state sorting. Thanks in advance for any help. [edited by - MickeyMouse on January 21, 2003 9:26:05 AM]

Share this post


Link to post
Share on other sites
Advertisement
What I do in my engine, is to add state parameters to each mesh, when it gets sorted into the individual shader buffers. Those state parameters can also be matrices. When you render each shader mesh buffer, you simply apply the transformations as given by the state params of that mesh.

It gets a little more complex, if you have different shaders on a single hierarchical model. In that case, you can either go down the hierarchy multiple times, once for each shader, and minimize shader changes. Or you traverse the hierarchy once, changing the shader state multiple times.

Another possibility is to pretransform the hierarchy on the CPU (compute the exact matrices for each subpart of the hierarchy). This does not need vertex level manipulation, only a matrix concatenation for each bone, which is pretty fast. Then you apply each pretransformed matrix as state parameter to your meshes, and sort them into their respective buffers.

Share this post


Link to post
Share on other sites
Thanks.
That's what I'm planning to do, I think I'll attach to each buffered mesh info on global transformation and morphing animation (from, to, scale).
Loading matrix for each mesh costs a bit, but changing texture for each mesh costs even more,..also I can sort buffered meshes by matrices they reqiure to be applied.

[edited by - MickeyMouse on January 22, 2003 6:13:06 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!