Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


multiple shaders per model


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 miggs   Members   -  Reputation: 260

Like
0Likes
Like

Posted 22 March 2012 - 02:58 PM

hi
(i'm using opengl 4.0 but this question is rather theroetical so thats not important)

currently i have a structure, like this (simplified)
model{ // object on screen with a world matrix
  modelpart{ // a part of the model with a material, e.g. arm, leg, or pants, or window (if model is a house..)
	 mesh { vertBuffer, iBUffer... etc.. }
  }
}

when i render, i activate the models shader, a normal shader for example ( sometimes in renderlists a shader is even activated along multiple models)

my question is, what if i would like to have different shaders on each modelpart, how do you guys go on about that?
if for example the naked arm has a different shader than some fancy blink metal armor on the chest, or a part has normalmapping, and a part is parallax?

because at the moment the Model->Render() method sets a ModelViewMatrix for the active shader, and now each ModelPart would need a reference to the parent Model's ModelViewMatrix, and activate it's own shader and set the modelviewmatrix


is this situation even realistic or does a shader per model suffice in most cases? Or is it that extreme that instead of rendering Models, you have renderlists of modelparts with the same shader?

would it help to chang my model structure somehow?


thanks in advance

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 32049

Like
2Likes
Like

Posted 22 March 2012 - 04:55 PM

Different meshes can share the same vertex/index buffers -- the model can own these buffers, and then the meshes can contain offsets into the buffers.
Likewise, different meshes can share the same constant buffers (aka uniform buffers in GL) -- you can write the common parameters (e.g. modelViewMatrix) into one cbuffer, which is then used by every shader on that model.

Or is it that extreme that instead of rendering Models, you have renderlists of modelparts with the same shader?

Yes, kind of. When you "render" a model, I wouldn't actually have it render anything, I would have the model insert it's meshes into an array. After all models to be drawn have been inserted into the array, I would then sort it and then actually render the sorted meshes.

#3 miggs   Members   -  Reputation: 260

Like
0Likes
Like

Posted 22 March 2012 - 05:25 PM

ah very interesting. i had also thought about seperating meshes from models once but i took the convenient (and slow) route and set the buffer pointers on each mesh draw call. but with your way i can bind a buffer for a model of a kind once and then render it on different positions with different parameters.

this brings me to another question:

when you have your meshes sorted in a list, if we say for example 3 meshes share the same buffers and are drawn one after the other, but for some reason one of those wants to use a different shader. what would you prioritise?

- would you rather group meshes with the same buffer first, and then with those meshes sort those with the same shaders and change shaders more often
- or group shaders, and then within shaders group meshes which share buffers?



thanks is advance, your answer was very very helpful

#4 tanzanite7   Members   -  Reputation: 1379

Like
1Likes
Like

Posted 25 March 2012 - 10:41 AM

what would you prioritise?

Shader. However, nearly all my meshes come from one buffer (over 128MB buf in my current project) - so, there essentially are no buffer changes anyway. And there are only a few vertex formats (two, currently) sourcing from that buffer.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS