Skip to content

Commit

Permalink
Renderer|Client: Rendering a cubemap screenshot (“cubeshot” command)
Browse files Browse the repository at this point in the history
IssueID #2208
  • Loading branch information
skyjake committed Mar 7, 2017
1 parent c2359e1 commit 2867bd4
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 67 deletions.
6 changes: 0 additions & 6 deletions doomsday/apps/client/include/gl/gl_main.h
Expand Up @@ -133,12 +133,6 @@ void GL_ProjectionMatrix();

de::Rangef GL_DepthClipRange();

/**
* Returns the projection matrix that is used for rendering the current frame's
* 3D portions.
*/
de::Matrix4f GL_GetProjectionMatrix();

/**
* The first selected unit is active after this call.
*/
Expand Down
9 changes: 9 additions & 0 deletions doomsday/apps/client/include/render/rend_main.h
Expand Up @@ -179,8 +179,17 @@ de::Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool inWorldSpace = true);

de::Vector3d Rend_EyeOrigin();

/**
* Returns the projection matrix that is used for rendering the current frame's
* 3D portions.
*/
de::Matrix4f Rend_GetProjectionMatrix();

#define Rend_PointDist2D(c) (fabs((vOrigin.z-(c)[VY])*viewsidex - (vOrigin.x-(c)[VX])*viewsidey))

void Rend_SetFixedView(int consoleNum, float yaw, float pitch, float fov, de::Vector2f viewportSize);
void Rend_UnsetFixedView();

/**
* The DOOM lighting model applies a light level delta to everything when
* e.g. the player shoots.
Expand Down
11 changes: 2 additions & 9 deletions doomsday/apps/client/include/ui/widgets/gamewidget.h
Expand Up @@ -32,22 +32,15 @@ class GameWidget : public de::GuiWidget
public:
GameWidget(de::String const &name = "game");

/*
* Convenience method for changing and immediately applying a new GL
* viewport. The viewport is automatically normalized in relation to the
* root view size.
*
* This is only intended to support old graphics code that doesn't use libgui.
*/
//void glApplyViewport(de::Rectanglei const &rect);

/**
* Pauses the game, if one is currently running and pausing is allowed.
*/
void pause();

void drawComposited();

void renderCubeMap(uint size, de::String const &outputImagePath);

// Events.
void viewResized() override;
void update() override;
Expand Down
12 changes: 1 addition & 11 deletions doomsday/apps/client/src/gl/gl_main.cpp
Expand Up @@ -390,16 +390,6 @@ Rangef GL_DepthClipRange()
return Rangef(glNearClip, glFarClip);
}

Matrix4f GL_GetProjectionMatrix()
{
dfloat const fov = Rend_FieldOfView();
//Vector2f const size(viewpw, viewph);
Vector2f const size = R_Console3DViewRect(displayPlayer).size();
yfov = vrCfg().verticalFieldOfView(fov, size);
return vrCfg().projectionMatrix(Rend_FieldOfView(), size, glNearClip, glFarClip) *
Matrix4f::scale(Vector3f(1, 1, -1));
}

void GL_ProjectionMatrix()
{
DENG_ASSERT_IN_MAIN_THREAD();
Expand All @@ -408,7 +398,7 @@ void GL_ProjectionMatrix()
// Actually shift the player viewpoint
// We'd like to have a left-handed coordinate system.
LIBGUI_GL.glMatrixMode(GL_PROJECTION);
LIBGUI_GL.glLoadMatrixf(GL_GetProjectionMatrix().values());
LIBGUI_GL.glLoadMatrixf(Rend_GetProjectionMatrix().values());
}

void GL_SetupFogFromMapInfo(Record const *mapInfo)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/fx/lensflares.cpp
Expand Up @@ -517,7 +517,7 @@ void LensFlares::draw()

d->uViewUnit = Vector2f(aspect, 1.f);
d->uPixelAsUv = Vector2f(1.f / window.pixelWidth(), 1.f / window.pixelHeight());
d->uMvpMatrix = Viewer_Matrix(); //GL_GetProjectionMatrix() * Rend_GetModelViewMatrix(console());
d->uMvpMatrix = Viewer_Matrix(); //Rend_GetProjectionMatrix() * Rend_GetModelViewMatrix(console());

DENG2_ASSERT(console() == displayPlayer);
//DENG2_ASSERT(viewPlayer - ddPlayers == displayPlayer);
Expand Down
77 changes: 72 additions & 5 deletions doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -157,6 +157,7 @@ D_CMD(OpenRendererAppearanceEditor);
D_CMD(LowRes);
D_CMD(MipMap);
D_CMD(TexReset);
D_CMD(CubeShot);

#if 0
dint useBias; ///< Shadow Bias enabled? cvar
Expand Down Expand Up @@ -229,6 +230,17 @@ Vector3d vOrigin;
dfloat vang, vpitch;
dfloat viewsidex, viewsidey;

// Helper for overriding the normal view matrices.
struct FixedView
{
Matrix4f projectionMatrix;
Matrix4f modelViewMatrix;
float yaw;
float pitch;
float horizontalFov;
};
static std::unique_ptr<FixedView> fixedView;

dbyte freezeRLs;
dint devNoCulling; ///< @c 1= disabled (cvar).
dint devRendSkyMode;
Expand Down Expand Up @@ -413,6 +425,11 @@ bool Rend_IsMTexDetails()

dfloat Rend_FieldOfView()
{
if (fixedView)
{
return fixedView->horizontalFov;
}

if (vrCfg().mode() == VRConfig::OculusRift)
{
// OVR tells us which FOV to use.
Expand Down Expand Up @@ -445,20 +462,53 @@ Vector3d Rend_EyeOrigin()
return vEyeOrigin;
}

Matrix4f Rend_GetModelViewMatrix(dint consoleNum, bool inWorldSpace)
void Rend_SetFixedView(int consoleNum, float yaw, float pitch, float fov, Vector2f viewportSize)
{
viewdata_t const *viewData = &DD_Player(consoleNum)->viewport();

dfloat bodyAngle = viewData->current.angleWithoutHeadTracking() / (dfloat) ANGLE_MAX * 360 - 90;
fixedView.reset(new FixedView);

fixedView->yaw = yaw;
fixedView->pitch = pitch;
fixedView->horizontalFov = fov;
fixedView->modelViewMatrix =
Matrix4f::rotate(pitch, Vector3f(1, 0, 0)) *
Matrix4f::rotate(yaw, Vector3f(0, 1, 0)) *
Matrix4f::scale(Vector3f(1.0f, 1.2f, 1.0f)) * // This is the aspect correction.
Matrix4f::translate(-viewData->current.origin.xzy());

Rangef const clip = GL_DepthClipRange();
fixedView->projectionMatrix = BaseGuiApp::app().vr()
.projectionMatrix(fov, viewportSize, clip.start, clip.end) *
Matrix4f::scale(Vector3f(1, 1, -1));
}

void Rend_UnsetFixedView()
{
fixedView.reset();
}

Matrix4f Rend_GetModelViewMatrix(dint consoleNum, bool inWorldSpace)
{
viewdata_t const *viewData = &DD_Player(consoleNum)->viewport();

/// @todo vOrigin et al. shouldn't be changed in a getter function. -jk

vOrigin = viewData->current.origin.xzy();
vang = viewData->current.angle() / (dfloat) ANGLE_MAX * 360 - 90; // head tracking included
vpitch = viewData->current.pitch * 85.0 / 110.0;

vEyeOrigin = vOrigin;

if (fixedView)
{
vang = fixedView->yaw;
vpitch = fixedView->pitch;
return fixedView->modelViewMatrix;
}

vang = viewData->current.angle() / (dfloat) ANGLE_MAX * 360 - 90; // head tracking included
vpitch = viewData->current.pitch * 85.0 / 110.0;

dfloat bodyAngle = viewData->current.angleWithoutHeadTracking() / (dfloat) ANGLE_MAX * 360 - 90;

OculusRift &ovr = vrCfg().oculusRift();
bool const applyHead = (vrCfg().mode() == VRConfig::OculusRift && ovr.isReady());

Expand Down Expand Up @@ -523,6 +573,22 @@ void Rend_ModelViewMatrix(bool inWorldSpace)
LIBGUI_GL.glLoadMatrixf(Rend_GetModelViewMatrix(DoomsdayApp::players().indexOf(viewPlayer), inWorldSpace).values());
}

Matrix4f Rend_GetProjectionMatrix()
{
if (fixedView)
{
return fixedView->projectionMatrix;
}

dfloat const fov = Rend_FieldOfView();
//Vector2f const size(viewpw, viewph);
Vector2f const size = R_Console3DViewRect(displayPlayer).size();
yfov = vrCfg().verticalFieldOfView(fov, size);
Rangef const clip = GL_DepthClipRange();
return vrCfg().projectionMatrix(Rend_FieldOfView(), size, clip.start, clip.end) *
Matrix4f::scale(Vector3f(1, 1, -1));
}

static inline ddouble viewFacingDot(Vector2d const &v1, Vector2d const &v2)
{
// The dot product.
Expand Down Expand Up @@ -6439,6 +6505,7 @@ void Rend_Register()

C_CMD("rendedit", "", OpenRendererAppearanceEditor);
C_CMD("modeledit", "", OpenModelAssetEditor);
C_CMD("cubeshot", "i", CubeShot);

C_CMD_FLAGS("lowres", "", LowRes, CMDF_NO_DEDICATED);
C_CMD_FLAGS("mipmap", "i", MipMap, CMDF_NO_DEDICATED);
Expand Down
40 changes: 5 additions & 35 deletions doomsday/apps/client/src/render/viewports.cpp
Expand Up @@ -675,7 +675,6 @@ void R_SetupFrame(player_t *player)
player->extraLight = player->targetExtraLight;
}

// Why?
validCount++;

extraLight = player->extraLight;
Expand Down Expand Up @@ -887,7 +886,7 @@ static Matrix4f frameViewMatrix;
static void setupViewMatrix()
{
// This will be the view matrix for the current frame.
frameViewMatrix = GL_GetProjectionMatrix() *
frameViewMatrix = Rend_GetProjectionMatrix() *
Rend_GetModelViewMatrix(DoomsdayApp::players().indexOf(viewPlayer));
}

Expand Down Expand Up @@ -1223,56 +1222,27 @@ void R_RenderViewPort(int playerNum)
RectRaw vdWindow(vd->window.topLeft.x, vd->window.topLeft.y,
vd->window.width(), vd->window.height());

//switch(layer)
//{
//case Player3DViewLayer:

R_UpdateViewer(vp->console);

//LensFx_BeginFrame(vp->console);

gx.DrawViewPort(localNum, &vpGeometry, &vdWindow, displayPlayer, /* layer: */ 0);

//LensFx_EndFrame();
//break;

LensFx_Draw(vp->console);

// Apply camera lens effects on the rendered view.


#if 0
case ViewBorderLayer:
R_RenderPlayerViewBorder();
break;

case HUDLayer:
gx.DrawViewPort(p, &vpGeometry, &vdWindow, displayPlayer, /* layer: */ 1);
break;
}
#endif
LensFx_Draw(vp->console);

restoreDefaultGLState();

LIBGUI_GL.glMatrixMode(GL_PROJECTION);
LIBGUI_GL.glPopMatrix();
//}

//if(layer == Player3DViewLayer)
//{
// Increment the internal frame count. This does not
// affect the window's FPS counter.
frameCount++;

// Keep reseting until a new sharp world has arrived.
if(resetNextViewer > 1) resetNextViewer = 0;
//}

// Restore things back to normal.
displayPlayer = oldDisplay;

//R_UseViewPort(nullptr);
//currentViewport = nullptr;
}

#if 0
Expand Down Expand Up @@ -1539,9 +1509,9 @@ void R_ViewerClipLumobj(Lumobj *lum)
/// @todo Determine the exact centerpoint of the light in addLuminous!
Vector3d const origin(lum->x(), lum->y(), lum->z() + lum->zOffset());

if(!(devNoCulling || P_IsInVoid(DD_Player(displayPlayer))))
if (!P_IsInVoid(DD_Player(displayPlayer)) && !devNoCulling)
{
if(!ClientApp::renderSystem().angleClipper().isPointVisible(origin))
if (!ClientApp::renderSystem().angleClipper().isPointVisible(origin))
{
markLumobjClipped(*lum); // Won't have a halo.
}
Expand All @@ -1551,7 +1521,7 @@ void R_ViewerClipLumobj(Lumobj *lum)
markLumobjClipped(*lum);

Vector3d const eye = Rend_EyeOrigin().xzy();
if(LineSightTest(eye, origin, -1, 1, LS_PASSLEFT | LS_PASSOVER | LS_PASSUNDER)
if (LineSightTest(eye, origin, -1, 1, LS_PASSLEFT | LS_PASSOVER | LS_PASSUNDER)
.trace(lum->map().bspTree()))
{
markLumobjClipped(*lum, false); // Will have a halo.
Expand Down

0 comments on commit 2867bd4

Please sign in to comment.