Skip to content

Commit

Permalink
Model Renderer: Added built-in shader variable "uProjectionMatrix"
Browse files Browse the repository at this point in the history
Can be used like "uMapTime".
  • Loading branch information
skyjake committed Aug 26, 2017
1 parent 459124e commit e2b8d4d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 38 deletions.
1 change: 1 addition & 0 deletions doomsday/apps/client/include/render/rendersystem.h
Expand Up @@ -57,6 +57,7 @@ class RenderSystem : public de::System
de::GLShaderBank &shaders();
de::ImageBank &images();
de::GLUniform const &uMapTime() const;
de::GLUniform &uProjectionMatrix() const;
render::Environment &environment();
ModelRenderer &modelRenderer();
SkyDrawable &sky();
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/render/viewports.h
Expand Up @@ -238,4 +238,6 @@ void R_ViewWindowTicker(int consoleNum, timespan_t ticLength);
*/
de::Matrix4f const &Viewer_Matrix();

de::Matrix4f const &Viewer_ModelViewMatrix();

#endif // DENG_CLIENT_VIEWPORTS_H
69 changes: 38 additions & 31 deletions doomsday/apps/client/src/render/modelloader.cpp
Expand Up @@ -33,36 +33,37 @@ namespace render {

using namespace de;

String const ModelLoader::DEF_ANIMATION("animation");
String const ModelLoader::DEF_MATERIAL ("material");
String const ModelLoader::DEF_PASS ("pass");
String const ModelLoader::DEF_RENDER ("render");

static String const DEF_ALIGNMENT_PITCH("alignment.pitch");
static String const DEF_ALIGNMENT_YAW ("alignment.yaw");
static String const DEF_AUTOSCALE ("autoscale");
static String const DEF_BLENDFUNC ("blendFunc");
static String const DEF_BLENDOP ("blendOp");
static String const DEF_DEPTHFUNC ("depthFunc");
static String const DEF_DEPTHWRITE ("depthWrite");
static String const DEF_FRONT_VECTOR ("front");
static String const DEF_MESHES ("meshes");
static String const DEF_MIRROR ("mirror");
static String const DEF_OFFSET ("offset");
static String const DEF_SEQUENCE ("sequence");
static String const DEF_SHADER ("shader");
static String const DEF_STATE ("state");
static String const DEF_TEXTURE_MAPPING("textureMapping");
static String const DEF_TIMELINE ("timeline");
static String const DEF_UP_VECTOR ("up");
static String const DEF_VARIANT ("variant");

static String const SHADER_DEFAULT ("model.skeletal.generic");
static String const MATERIAL_DEFAULT ("default");

static String const VAR_U_MAP_TIME ("uMapTime");

static Atlas::Size const MAX_ATLAS_SIZE(8192, 8192);
String const ModelLoader::DEF_ANIMATION ("animation");
String const ModelLoader::DEF_MATERIAL ("material");
String const ModelLoader::DEF_PASS ("pass");
String const ModelLoader::DEF_RENDER ("render");

static String const DEF_ALIGNMENT_PITCH ("alignment.pitch");
static String const DEF_ALIGNMENT_YAW ("alignment.yaw");
static String const DEF_AUTOSCALE ("autoscale");
static String const DEF_BLENDFUNC ("blendFunc");
static String const DEF_BLENDOP ("blendOp");
static String const DEF_DEPTHFUNC ("depthFunc");
static String const DEF_DEPTHWRITE ("depthWrite");
static String const DEF_FRONT_VECTOR ("front");
static String const DEF_MESHES ("meshes");
static String const DEF_MIRROR ("mirror");
static String const DEF_OFFSET ("offset");
static String const DEF_SEQUENCE ("sequence");
static String const DEF_SHADER ("shader");
static String const DEF_STATE ("state");
static String const DEF_TEXTURE_MAPPING ("textureMapping");
static String const DEF_TIMELINE ("timeline");
static String const DEF_UP_VECTOR ("up");
static String const DEF_VARIANT ("variant");

static String const SHADER_DEFAULT ("model.skeletal.generic");
static String const MATERIAL_DEFAULT ("default");

static String const VAR_U_MAP_TIME ("uMapTime");
static String const VAR_U_PROJECTION_MATRIX ("uProjectionMatrix");

static Atlas::Size const MAX_ATLAS_SIZE (8192, 8192);

DENG2_PIMPL(ModelLoader)
, DENG2_OBSERVES(filesys::AssetObserver, Availability)
Expand Down Expand Up @@ -271,10 +272,16 @@ DENG2_PIMPL(ModelLoader)
i->newProgramCreated(*prog);
}

auto &render = ClientApp::renderSystem();

// Built-in special uniforms.
if (prog->def->hasMember(VAR_U_MAP_TIME))
{
*prog << ClientApp::renderSystem().uMapTime();
*prog << render.uMapTime();
}
if (prog->def->hasMember(VAR_U_PROJECTION_MATRIX))
{
*prog << render.uProjectionMatrix();
}

programs[name] = prog.get();
Expand Down
5 changes: 5 additions & 0 deletions doomsday/apps/client/src/render/modelrenderer.cpp
Expand Up @@ -149,6 +149,8 @@ DENG2_PIMPL(ModelRenderer)
Vector3f const aspectCorrect(1.0f, 1.0f/1.2f, 1.0f);
Vector3d origin = modelWorldOrigin + modelOffset * aspectCorrect;

// "local" == world space but with origin at model origin

Matrix4f modelToLocal =
Matrix4f::rotate(-90 + yawAngle, Vector3f(0, 1, 0) /* vertical axis for yaw */) *
Matrix4f::rotate(pitchAngle, Vector3f(1, 0, 0));
Expand All @@ -175,6 +177,9 @@ DENG2_PIMPL(ModelRenderer)
/**
* Sets up the transformation matrices.
*
* "Local space" is the same as world space but relative to the object's origin.
* That is, (0,0,0) being the object's origin.
*
* @param relativeEyePos Position of the eye in relation to object (in world space).
* @param modelToLocal Transformation from model space to the object's local space
* (object's local frame in world space).
Expand Down
8 changes: 7 additions & 1 deletion doomsday/apps/client/src/render/rendersystem.cpp
Expand Up @@ -68,7 +68,8 @@ DENG2_PIMPL(RenderSystem)
Store buffer;
DrawLists drawLists;

GLUniform uMapTime { "uMapTime", GLUniform::Float };
GLUniform uMapTime { "uMapTime", GLUniform::Float };
GLUniform uProjectionMatrix { "uProjectionMatrix", GLUniform::Mat4 };

// Texture => world surface projection lists.
struct ProjectionLists
Expand Down Expand Up @@ -422,6 +423,11 @@ GLUniform const &RenderSystem::uMapTime() const
return d->uMapTime;
}

GLUniform &RenderSystem::uProjectionMatrix() const
{
return d->uProjectionMatrix;
}

render::Environment &RenderSystem::environment()
{
return d->environment;
Expand Down
21 changes: 15 additions & 6 deletions doomsday/apps/client/src/render/viewports.cpp
Expand Up @@ -881,18 +881,27 @@ static void setupPlayerSprites()
}
}

static Matrix4f frameViewMatrix;
static Matrix4f frameModelViewMatrix;
static Matrix4f frameViewerMatrix;

static void setupViewMatrix()
{
// This will be the view matrix for the current frame.
frameViewMatrix = Rend_GetProjectionMatrix() *
Rend_GetModelViewMatrix(DoomsdayApp::players().indexOf(viewPlayer));
auto &rend = ClientApp::renderSystem();

// These will be the matrices for the current frame.
rend.uProjectionMatrix() = Rend_GetProjectionMatrix();
frameModelViewMatrix = Rend_GetModelViewMatrix(DoomsdayApp::players().indexOf(viewPlayer));
frameViewerMatrix = rend.uProjectionMatrix().toMatrix4f() * frameModelViewMatrix;
}

Matrix4f const &Viewer_Matrix()
{
return frameViewMatrix;
return frameViewerMatrix;
}

Matrix4f const &Viewer_ModelViewMatrix()
{
return frameModelViewMatrix;
}

enum ViewState { Default2D, PlayerView3D, PlayerSprite2D };
Expand Down Expand Up @@ -1547,7 +1556,7 @@ D_CMD(ViewGrid)
void Viewports_Register()
{
C_VAR_INT ("con-show-during-setup", &loadInStartupMode, 0, 0, 1);

C_VAR_INT ("rend-camera-smooth", &rendCameraSmooth, CVF_HIDE, 0, 1);

C_VAR_BYTE("rend-info-deltas-angles", &showViewAngleDeltas, 0, 0, 1);
Expand Down

0 comments on commit e2b8d4d

Please sign in to comment.