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

rendering routine for shader

Started by shaquill Aug 5, 2006 at 3:17 AM 2 replies 650+ views
Original Post
shaquill
shaquill
I'm making a shader rendering routine. and I'm wondering what is the best way for performance. first, I did like this... shader for_each( BeginPass(i) ) DrawPrimitive(); EndPass(i); looks fine but I read that calling "BeginPass/EndPass" in a same shader is redundant and makes app's slow if pass has not been changed. So if rendering object such like mesh has more than two passes, I put the same entity as many as passes in rendering queue and render. So routine looks like below. for( pass ) rederqueue.push_back(entry);//push back same entry. ... shader if( CurrPass != PrevPass ) { // call beginPass() when technique pass is changed. // so it won't be called in same shader and same pass. BeginPass(CurrPass) } DrawPrimitive(); this is what I did until now. I'm not expert about shader thing and this is my first project using shader. so please give me advise. Anything will be fine.^^ thanks.
Hellow everyone
ET3D
ET3D
All I can say is: first make it work, then profile it and see where your real bottlenecks are. The change you're talking about is trivial enough that you could easily add it later if you find it makes a real difference (which I suspect it won't).
programmer_tom
programmer_tom

i just optimized my 2d stuff with a huge performance increase just due to begin/end pass.

before i had each class render() like this

beignpass()
render()
endpass()

but realized i could get away with

beginpass()
render_all_objects
endpass()

you just gotta remember that if you change techniques etc you have to call commitchanges().

so the answer is yes, it makes a big difference. write your system to use as few beginpass/endpass calls as you can. if you have multipass objects sandwiched in there, you can endpass() on the main pass, beingpass() and endpass() for the multipass, and beginpass() again to set the intial shared pass back up.

-programmer_tom
b3rs3rk
b3rs3rk
the best method would be to render togheter all the object that have the same material/shader in order to minimize state changes. So if you have more than 1 object that uses a shader, pack them togheter and render them all in one pass, then step to the next shader. Something like this:

for(every shader)
for( i=0 to shader.object_list.size )
shader.object_list.render()

hope it helps.

Topic Locked

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

Sign in to reply to this topic.