Shaders in an object orientated engine.

Started by
1 comment, last by EnlightenedOne 13 years, 5 months ago
Hi there I am wondering if anyone can give me a definitive answer to a question.

I have example code where Frank D Luna has had classes which are called with a draw function. The class handles its own shader and begins and ends it own effect data.

In my engine I have modelled the shader into the rendering thread and I currently have it calling classes to return their mesh and other unique data so they can be drawn in the perform render function. Why?

When you begin an effect and end an effect it is my understanding that all of the data you pass in between those points is passed in one batch to the shader so having every class of object begin and end effect represents a potential bottleneck. The issue with my method is that it is against the object orientated model and is different to the technique used by Frank D Luna. Should I be passing my classes of object my renderers data such as a reference to the cameras projection matricies the world and any other data it requires to draw itself?

Is it better to begin and end an effect and hold shaders inside of the render performing class and have this class begin and end shader effects passing the data to draw to objects so they can draw themselves based on their data? I feel redundancy is going to occur if I pull all the mesh's data out to draw it and I feel another degre of redundancy will occur if I do not!

What is the usual verdict on this? who does the drawing for an object? where should shaders begin and end for best performance? Is it true that data will be batched together within begin and end passes of a technique for a shader?

Thanks

Enlightened One
Advertisement
Generally you want to minimize state changes such as setshader calls as much as possible, and you want to batch all objects using the same shaders/assets to draw at the same time. Generally that means your renderer will be determining when to apply passes and your renderer will decide when an object is drawn. Your render may even pack the vertex data of many objects into one large vb. Drawing should be your renderer's job, not the job of a model.

This design also makes it easier to apply new algorithms such as shadow passes, depth passes and OQ passes.

The other organization is just for simplicity and allows you get stuff done faster from the start, but long term there are a lot of flaws with that method besides just performance and redundancy.
Thank you for the clarity on the issue I shall keep my data abstracted but continue to draw from the renderer and not a function of the class being drawn. I was worried adding in the multitude of shaders I am using might make the question unreadable :) I do use depth stencil project light shadows.

This topic is closed to new replies.

Advertisement