SoftPixel Forum

Official community of the SoftPixel Engine and the SoftPixel Sandbox (REGISTRATION only with consultation with the Admin)
It is currently Fri May 25, 2018 11:10 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Vertex in modelspace
PostPosted: Fri Apr 04, 2014 1:29 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
Hello.
Since I need to have the vertices multiplied with the modelmatrix, because I need it for shadow-mapping, I have some questions:
1. Can I let the vertexposition outputed already multiplied with the modelmatrix?
2. Can I set Scenenode-uniforms?
So I could do it like that:
Code:
Mesh->setConstant("modelmatrix", mesh->modelmatrix);


Or does a other way exist?


Top
 Profile  
 
 Post subject: Re: Vertex in modelspace
PostPosted: Fri Apr 04, 2014 2:11 pm 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
What you need is the "Object Callback" for a shader class.
Use video::ShaderClass::setObjectCallback to set your function, where you update your shader uniforms immediately before your mesh is rendered.

Code:
// This function must always have the same arguments!
void MyObjectCallback(ShaderClass* shaderClass, const scene::MaterialNode* renderableObject)
{
    // All single matrices (world-, view- and projection matrix):
    shaderClass->getVertexShader()->setConstant("worldMatrix", spRenderer->getWorldMatrix());
    shaderClass->getVertexShader()->setConstant("viewMatrix", spRenderer->getViewMatrix());
    shaderClass->getVertexShader()->setConstant("projectionMatrix", spRenderer->getProjectionMatrix());

    // Or use a composition world-view-projection matrix:
    dim::matrix4f wvpMatrix;
    wvpMatrix = spRenderer->getProjectionMatrix() * spRenderer->getViewMatrix() * spRenderer->getWorldMatrix();
    shaderClass->getVertexShader()->setConstant("wvpMatrix", wvpMatrix);
}

/* ... */

myShaderClass->setObjectCallback(MyObjectCallback);

Don't use a custom projection matrix. Only use "video::RenderSystem::getProjectionMatrix()" because
some hardware renderer need a left-handed and some need a right-handed coordinate system.
The SPE makes a work around for you, so you just need to upload the "getProjectionMatrix()" return value to your shader constant ;-)

Before your mesh is rendered, this callback will be called automatically.
"getWorldMatrix" etc. will have the matrices of the current render state, thus the correct object matrix you need ;-)

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
 Post subject: Re: Vertex in modelspace
PostPosted: Fri Apr 04, 2014 2:31 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
Thanks for the fast reply.
This helps me alot.

And wow, you really thought about all.
Even on objectcallbacks. Your engine is always a good surprise.


Top
 Profile  
 
 Post subject: Re: Vertex in modelspace
PostPosted: Fri Apr 04, 2014 3:05 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
Hmm..but I have a problem.
Im using Camera->turn and move.
I recognized now, that it affects the modelmatrix.
That lets the shadowmapping being false.
So I need to affect the viewmatrix.
Like:
Code:
Camera->getView()->turn(...);
Camera->getView()->move(...);


Top
 Profile  
 
 Post subject: Re: Vertex in modelspace
PostPosted: Fri Apr 04, 2014 3:18 pm 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
The view-matrix is always the inverse of the camera's object matrix.
Or in other words: the camera's object matrix is in "world-space" -> when you inverse this matrix, you have the view-matrix, which is in "view-space".

Maybe you turn the camera at the wrong point and the view matrix (accesed by RenderSystem::getViewMatrix()) will not be updated?!

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
 Post subject: Re: Vertex in modelspace
PostPosted: Fri Apr 04, 2014 3:29 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
Yes, nevermind.
I thought the modelmatrix was affected, but the depth-map-generation itself goes wrong, so it only seemed like it was.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group