Jump to content
  • Advertisement
Sign in to follow this  
SiliconMunky

Engine Design - Where to create my vertex shader constants

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

Hello, I'm having a problem trying to figure out how to come up with the worldViewProj matrix constant to set in my vertex shader. I know most people just calculate it like worldViewProj = matWorld * matView * matProjection but the part where I'm having difficulty is getting the view and projection matrix. My engine has an instance of a Map class, and the Map class doesn't know anything about the view or projection matricies, it only knows how to create the world transformation matrix. What I'm wondering is how should the Map class calculate the worldViewProj? Should the Map class ask the Engine for (matView * matProjection) and then mutiply it's world matrix and pass it to the vertex shader constant? This seems like it would be a pretty common problem and I was wondering how others have gotten around it without coupling the camera and map classes. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
err this matrix is always changing the view matrix represents the camara which is something that is always changing, and shouldn't be attributed to any particular object. most people have a seperate camara class to take care of it. so it's definitly not a constant, unless your program draws a view of a fixed scene(boring). in any event, I'm not quite sure I'm getting your question? what exactly is the map class? whatever it is, it certianlly sounds like it shouldn't be responsible for calculating the camara. the camara is seperate from all the scene elements and cam*projection can be calculated by the camara if you like. the projection matrix is basically constant, but it's still bad practice to treat it as such. perhaps you want to change the filed of view or the aspect ratio? for this you'd need to modify the projection matrix

Tim

Share this post


Link to post
Share on other sites
I know it's not going to be constant, it's going to change every frame that the camera moves, but I was referring to using the shader constant table to put the matrix data into the worldViewProj matrix that is in the HLSL shader.

I guess the simplest question would be, do I have to and how do I apply the world, view, and projection matricies in a vertex shader?

Thanks.

Edit: The map class simply takes case of loading and rendering the terrain. The Engine passes the D3Ddevice to it, and it takes care of the rest.

Edit#2: Yeah, I've got a seperate camera class that takes care of creating the view and projection matricies. The engine has an instance of this camera class. The map class obviously shouldn't know anything about the camera class, so what I was wondering is how should the map class get the view and projection matrix?

[Edited by - SiliconMunky on September 8, 2005 8:26:32 PM]

Share this post


Link to post
Share on other sites
You can get the Projection and View matrices from your D3DDevice, by doing something like this:


D3DXMATRIX matProj, matView;
m_pd3dDevice->GetTransform( D3DTS_PROJECTION, &matProj );
m_pd3dDevice->GetTransform( D3DTS_VIEW, &matView );

Share this post


Link to post
Share on other sites
hmmm interesting, do you think it'd be better for the Engine to put the matricies into the device and have the Map class get the matricies it needs from the device, rather than having the Map ask the Engine for the matricies?

Got another question now :)
The matricies set by IDirect3DDevice9::SetTransform are only used in the fixed function pipeline, is that correct?

Share this post


Link to post
Share on other sites


Generally an object being rendered (having its draw function called) knows about what camera, or at least view frustrum it is currently being rendered too. Another option is to have a current "scene" structure or interface thats passed into each draw call which contains all the information about the scene (view, projection, fog parameters, lights etc). In the fixed function pipe, the device would store a lot of this information for you, though not necassarily in the best format.

If your really worried about coupling, setup and interface class thats used (such as the scene). Then use this interface to query the current scene setup. I don't think its too much to ask for an object to know what its drawing with/into.

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!