PDA

View Full Version : how to render from ortho viewports?


humangous
03-24-2008, 10:59 AM
Hi!
I'm developing a render plugin for 3DMax.
Now it is very similar to cjrender.
It accurately does transformations for perspective viewport (camera, vierport, view fom light etc.), but renders from Front, Left, Top viewports are wrong! Something is wrong transformations.
What I do:

void GetViewParams(INode* vnode, ViewParams& vp, TimeValue t)
{
...
const ObjectState& os = vnode->EvalWorldState(t);
switch(os.obj->SuperClassID()){
case CAMERA_CLASS_ID:{
...
if(cs.isOrtho){
vp.projType = PROJ_PARALLEL;
}else{
vp.projType = PROJ_PERSPECTIVE;
}
vp.fov = cs.fov;
...
}


and


void ComputeViewParams(const ViewParams &vp)
{
worldToCam = vp.affineTM;
camToWorld = Inverse(worldToCam);

xc = devWidth / 2.0f;
yc = devHeight / 2.0f;

projType = vp.projType;

if(projType == PROJ_PERSPECTIVE){
float fac = -(float)(1.0/tan(0.5*(double)vp.fov));
xscale = fac*xc;
yscale = -devAspect*xscale;
}
else{
xscale = (float)devWidth / (VIEW_DEFAULT_WIDTH * vp.zoom);
yscale = -devAspect*xscale;
}
}




Point2 MyRenderParams::MapToScreen(Point3 p)
{
Point2 s;

if(projType == PROJ_PERSPECTIVE){
s.x = xc + xscale*p.x/p.z;
s.y = yc + yscale*p.y/p.z;
}else{
s.x = xc + xscale*p.x;
s.y = yc + yscale*p.y;
}
return s;
}

,in Render() i do:


int Render(TimeValue t, Bitmap* tobm, FrameRendParams &frp, HWND hwnd, RendProgressCallback* prog, ViewParams* viewPar)
{
...
if(viewPar)
view = *viewPar;
if(pViewNode)
GetViewParams(pViewNode, view, t);
rendParams.ComputeViewParams(view);

for(i = 0; i < instTab.Count(); i++){
instTab[i]->mtl->Update(t, FOREVER);
instTab[i]->Update(t, theView, this);
}

for(i = 0; i < instTab.Count(); i++){
instTab[i]->UpdateViewTM(view.affineTM);
instTab[i]->mesh->buildRenderNormals();
instTab[i]->TransformGeometry(instTab[i]->objToCam, instTab[i]->normalObjToCam);
}

RenderImage(...);
...
}



I think, if we are in ortho viewport, then calculations for PROJ_PARALLEL is used.
What I am doing wrong?
How to do correct renders from ORTHO viewports? (and, also, ORTHO cameras too).
What I have to do for correct ORTHO rendering?

Thanks.

CGTalk Moderation
03-24-2008, 10:59 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.