Jump to content
  • Advertisement
Sign in to follow this  
Paul C Skertich

Should the mesh class render or the shader class render?

This topic is 1265 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

I have a Mesh Class that handles loading, rendering. Inside the Mesh Class I have a PointLight struct.  In Rastertek's tutorials he has the shader doing the rendering of the primatives. In most of the DirectX books I've bought the mesh loader does the rendering. This is what bothers me about tutorials some times because one site this is the way and the other site does this. 

 

But no one ever talks about multiple point lights or multple lights inside a level and how it is rendered. Does all the lights go into the constant buffer inside the  mesh loader class or is it completely seperate? Or should the multiple lights be inside the shader class that renders the models.

 

How does handling mutple light sources get managed inside  a game is the bottom question,

Share this post


Link to post
Share on other sites
Advertisement

Thanks L. Spiro the PointLight struct is seperate and the mesh class shares the point light struct. I haven't created the scene manager fully yet - partially. I was thinking the scene manager was the part that handles what objects get drawn based on culling and what lights get activated when the object is visible within the octree or frustum.

 

So I believe I was heading in the right direction just got confused. Let me clearify though:

//-- Pointlight.h

struct PointLight {
   float3 position;
   float padding;
   float3 direction;
   float Range;
   float3 att;
   float padding2;
   float4 diffuseColor;
   float4 ambientColor;
};

//-- Mesh.h

class Mesh {
private:
public:
   PointLight Light;
   CBPerObject cbPerObject; //-- this is constant buffer per object that has the PointLight for shader.

};

void Mesh::Render(...) {
     cbPerObject.pointLight = Light; //-- Hand off the Light to the cbPerObject for shader.
}

I'll get working on the scene manager today or this week and I'll have a clear picture. However, the sample code is what I have it set up to now. Is this what you're mentioning? I don't have the scene manager in yet because I'm revising the entire engine SDK.

Share this post


Link to post
Share on other sites
Here's what I do in my engine (high over):

- scene manager has one or more scene class objects
- scene manager has one shadermanager class object
- scene manager knows which scene is active
- scene class has x mesh instance class objects and y instance point light class objects
- mesh instance class has pointer to unique mesh
- mesh instance has x objects of renderable class
- renderable class objects have a int vector keeping track of which positional lighs currently affect the renderable (this is used by the scene manager/ during updating to set the shader constants/ parameters for the positional lights)
- renderable has its own orientation (matrix) related to it's parent (= mesh instance)
- renderable has an id of the scene material it uses

- scene manager class updates all shader constants/ parameters based on the current state of the scene (culling, lights visible, lights affecting objects etc,)

- renderqeue get it's data from the scene manager (pointing to the current scene)
- d3d renderer class takes the renderqueue data (basically indices and pointers)

So basically the renderer in my case takes renderqueue indices and a data source containing the actual vertex/ index data, materials etc.

Hope this helps.

Note; this is/ there's no right way to do it, I believe it's best to see other options and find the hybrid that suits best for your own needs

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!