Public Group

# Effects and matricies (XNA)

This topic is 4136 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm having a few problems understanding the relationship between effects and matrices. It probably doesn't help that I don't know much about effects! Basically I have a model that I am drawing in a 3D world, when it's draw method is called it updates an effect on every mesh - what is this 'effect' and why does it need to know the world matrix, view matrix and projection matrix? I also would like to know more about the world, view and projection matricies. I understand that the world matrix is sort of like a mesh's position in the 3d world but am I right in thinking that only the camera should be updating the view and projection matricies? Thanks, James

##### Share on other sites
I'll try it step-by-step. Let's forget about effects for a moment to understand how models and matrices are related:

- A matrix is a pure math thing. Its most common use is to store the location and orientation of an object in 3D space.
- You need to be able to draw a model at different locations in your world. So when you tell your graphics card to draw it, you also hand over a matrix which specifies where the model is located and which direction it is facing.

Now on to the effects:

- Back in the past, the graphics card just rotated and moved the model's polygons according to the matrix it was given all by its own.
- With the introduction of vertex shaders, programmers now have to write small programs ("shaders") running on the graphics card that rotate and move the model's polygons. So instead of handing over a matrix with the model's location and orientation to the graphics card, you instead have to hand it over to your vertex shader.
- An effect finally, amongst other things, contains the vertex shader, which, as explained above, needs to know about the model's location and orientation to draw it at the correct location.

I think that's as simple as one can put it :)

-Markus-

##### Share on other sites
Thanks, makes a bit more sense now! I also found these resources, which helped me understand this a little better (just in case anyone else comes across this post again looking for a similar answer):

http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Chase-Camera-Sample.aspx - This helps with the world / view / projection matricies.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=802167&SiteID=1 - Should point anyone in the right direction for help with effects / shaders.

Cheers,

James

##### Share on other sites
Quote:

okay I can understand that a model may need to know where it is so it can be rendered appropriately, but why do you have to set it up for each and every part of the model? within one call to Draw(), the camera isn't going to move is it? all of the models will be rendered based on the camera's position at that exact moment, so why would you have to set up the camera for each and every object? I'm still seeing it the way the op does, where the camera would be initialized to a certain position and projection, and then the models would just be rendered relative to their own coordinates, regardless of where the camera is or is looking...

so can you go over it again? I'm just not getting it :(

-SelArom

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009713
• ### Who's Online (See full list)

There are no registered users currently online

×