Skip to main content
GameDev.net gamedev.net
🔒 Locked

Effect per-object?

Started by n3Xus Oct 4, 2008 at 9:18 AM 4 replies 550+ views
Original Post
n3Xus
n3Xus
Hello, I'm not sure how to handle effects for many game models-should I make, for example, one effect and share it among all in-game models (that would mean a lot of resource binding->different textures for every model while rendering,...) or should I use a totally separate effect for every model and use effect pools (the second one is better by my opinion but I'm not 100%)?
sirob
sirob
Are you using Direct3D 9 or Direct3D 10?
Sirob Yes.» - status: Work-O-Rama.
n3Xus
n3Xus
10
sirob
sirob
Direct3D10 introduced the concept of a constant buffer. These allow you to do two very useful things:

1) Have a constant buffer per object, and simply swap between them when changing between objects. This is useful if you have a lot of data per object, and the data doesn't change every frame.
2) Overwrite the entire buffer in a single operation (UpdateSubresource) allowing you to set all the constants to be applied to an object in one go. This is good when the whole data changes every frame.

Of course, you can apply two buffers in one drawing pass, and have one buffer use the first technique (change to a new buffer per object) and have the second one use the second (updates every frame).

This should allow you to get along entirely with a single effect instance for each type of effect you have, and there wouldn't be much point in keeping more than one instance around.
Sirob Yes.» - status: Work-O-Rama.
n3Xus
n3Xus
Thanks, I'll try using one constant buffer per object
ET3D
ET3D
Quote:
Original post by n3Xus
I'm not sure how to handle effects for many game models-should I make, for example, one effect and share it among all in-game models (that would mean a lot of resource binding->different textures for every model while rendering,...) or should I use a totally separate effect for every model and use effect pools (the second one is better by my opinion but I'm not 100%)?

The standard way is to bind textures as you use them. Otherwise you have a lot of textures bound to the pipeline that you don't use, which can be a problem for the card. Sorting by texture can reduce the number of textures set. Another solution applicable to D3D10 is to use texture arrays. I don't know what effect this can have on performance, but it may be worth testing.

Generally not all objects in a game would use the vertex shader and pixel shader, so you'd have several techniques. It'd be a good idea to be able to associate a technique with an object, not just go to one of the extremes (single technique or a separate technique for each object).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.