About Store Forum Documentation Contact



Post Reply 
Shader World Matrix
Author Message
fatcoder Offline
Member

Post: #1
Shader World Matrix
Quick question, is there an object world matrix in the shader constants, for converting to world space?

I see MatrixOC (in Constants.h), which is for converting straight to view space, but I can't find anything to convert from model/object space to world space.

MatrixObjWorldPos() is no good as it only gives the object's position in world space. I need the object's world matrix in order to convert other vectors to world space.

Surely this is being passed into a shader parameter by EE somewhere and I'm just missing it???
07-24-2012 01:36 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Shader World Matrix
transform by MatrixOC then transform the result by MatrixCam
or transform by MatrixOC * MatrixCam
07-24-2012 03:20 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #3
RE: Shader World Matrix
Thanks for the quick reply. I thought that might be the case.

However based on that logic, I should be able to do the following in the vertex shader (where input.pos is in model/object space passed into the VS).

Code:
Vec worldSpace = Transform(input.pos, MatrixOC0*MatrixCam);
Vec viewSpace  = Transform(worldSpace, -MatrixCam);

Vec projSpace  = Project(viewSpace);
return projSpace;

However this gives me a very different result from doing this.

Code:
Vec viewSpace  = TransformPos(input.pos);

Vec projSpace  = Project(viewSpace);
return projSpace;

In addition, this gives a completely different result again.

Code:
Vec worldSpace = Transform(input.pos, MatrixOC0);
    worldSpace = Transform(worldSpace, MatrixCam);
Vec viewSpace  = Transform(worldSpace, -MatrixCam);

Vec projSpace  = Project(viewSpace);
return projSpace;

Shouldn't all three of these give an identical result?


On a side note, are there any constants for the main directional light source, such as its direction vector? I found SkySunPos in Sky.h. Is that the direction of the sun light?

Is there a list of scene lights passed in somewhere?
07-25-2012 02:26 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Shader World Matrix
I don't think that -matrix in HLSL is its inverse.

The engine light parameters are not available from HLSL, if you want to use your own lighting, please use custom parameters.
07-29-2012 04:30 PM
Find all posts by this user Quote this message in a reply
Post Reply