Stable version of the Transform and usage for Model rendering with soimilar performances and same accuracy level

This commit is contained in:
Sam Gateau 2014-11-12 00:26:44 -08:00
parent 7a9f45d34f
commit b716a512c6
9 changed files with 37 additions and 19 deletions

View file

@ -2805,6 +2805,8 @@ void Application::updateShadowMap() {
// store view matrix without translation, which we'll use for precision-sensitive objects // store view matrix without translation, which we'll use for precision-sensitive objects
updateUntranslatedViewMatrix(); updateUntranslatedViewMatrix();
// TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack
// setViewTransform(viewTransform);
glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt
@ -2883,6 +2885,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()");
// transform by eye offset // transform by eye offset
gpu::Transform viewTransform; gpu::Transform viewTransform;
// load the view frustum // load the view frustum
@ -2902,9 +2905,9 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
glm::quat eyeOffsetOrient = whichCamera.getEyeOffsetOrientation(); glm::quat eyeOffsetOrient = whichCamera.getEyeOffsetOrientation();
glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient); glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient);
glRotatef(-glm::degrees(glm::angle(eyeOffsetOrient)), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z); glRotatef(-glm::degrees(glm::angle(eyeOffsetOrient)), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z);
viewTransform.preRotate(glm::quat(-glm::angle(eyeOffsetOrient), glm::vec3(eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z))); viewTransform.postRotate(glm::conjugate(eyeOffsetOrient));
glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z); glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z);
viewTransform.preTranslate(glm::vec3(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z)); viewTransform.postTranslate(-eyeOffsetPos);
// transform view according to whichCamera // transform view according to whichCamera
// could be myCamera (if in normal mode) // could be myCamera (if in normal mode)
@ -2913,11 +2916,15 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
glm::quat rotation = whichCamera.getRotation(); glm::quat rotation = whichCamera.getRotation();
glm::vec3 axis = glm::axis(rotation); glm::vec3 axis = glm::axis(rotation);
glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
viewTransform.preRotate(glm::quat(-glm::angle(rotation), axis)); viewTransform.postRotate(glm::conjugate(rotation));
// store view matrix without translation, which we'll use for precision-sensitive objects // store view matrix without translation, which we'll use for precision-sensitive objects
updateUntranslatedViewMatrix(-whichCamera.getPosition()); updateUntranslatedViewMatrix(-whichCamera.getPosition());
viewTransform.preTranslate(-whichCamera.getPosition());
// Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation
// the viewTransofmr object is updated with the correct value and saved,
// this is what is used for rendering the ENtities and avatars
setViewTransform(viewTransform);
glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z); glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z);
@ -3120,8 +3127,10 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) { void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) {
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix); glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix);
_viewMatrixTranslation = viewMatrixTranslation; _viewMatrixTranslation = viewMatrixTranslation;
_viewTransform->evalFromRawMatrix(_untranslatedViewMatrix); }
_viewTransform->postTranslate(viewMatrixTranslation);
void Application::setViewTransform(const gpu::Transform& view) {
(*_viewTransform) = view;
} }
void Application::loadTranslatedViewMatrix(const glm::vec3& translation) { void Application::loadTranslatedViewMatrix(const glm::vec3& translation) {

View file

@ -234,6 +234,7 @@ public:
void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; } void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; }
const gpu::TransformPointer& getViewTransform() const { return _viewTransform; } const gpu::TransformPointer& getViewTransform() const { return _viewTransform; }
void setViewTransform(const gpu::Transform& view);
/// if you need to access the application settings, use lockSettings()/unlockSettings() /// if you need to access the application settings, use lockSettings()/unlockSettings()
QSettings* lockSettings() { _settingsMutex.lock(); return _settings; } QSettings* lockSettings() { _settingsMutex.lock(); return _settings; }

View file

@ -21,7 +21,11 @@ Batch::Batch() :
_commandOffsets(), _commandOffsets(),
_params(), _params(),
_resources(), _resources(),
_data(){ _data(),
_buffers(),
_streamFormats(),
_transforms()
{
} }
Batch::~Batch() { Batch::~Batch() {
@ -32,8 +36,10 @@ void Batch::clear() {
_commandOffsets.clear(); _commandOffsets.clear();
_params.clear(); _params.clear();
_resources.clear(); _resources.clear();
_buffers.clear();
_data.clear(); _data.clear();
_buffers.clear();
_streamFormats.clear();
_transforms.clear();
} }
uint32 Batch::cacheResource(Resource* res) { uint32 Batch::cacheResource(Resource* res) {

View file

@ -316,13 +316,12 @@ public:
CommandOffsets _commandOffsets; CommandOffsets _commandOffsets;
Params _params; Params _params;
Resources _resources; Resources _resources;
Bytes _data;
BufferCaches _buffers; BufferCaches _buffers;
StreamFormatCaches _streamFormats; StreamFormatCaches _streamFormats;
TransformCaches _transforms; TransformCaches _transforms;
Bytes _data;
protected: protected:
}; };

View file

@ -458,6 +458,7 @@ void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) {
void GLBackend::updateTransform() { void GLBackend::updateTransform() {
if (_transform._invalidProj) { if (_transform._invalidProj) {
// TODO: implement the projection matrix assignment to gl state
/* if (_transform._lastMode != GL_PROJECTION) { /* if (_transform._lastMode != GL_PROJECTION) {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
_transform._lastMode = GL_PROJECTION; _transform._lastMode = GL_PROJECTION;

View file

@ -560,7 +560,8 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) {
_transforms.push_back(gpu::TransformPointer(new gpu::Transform())); _transforms.push_back(gpu::TransformPointer(new gpu::Transform()));
} }
(*_transforms[0]) = gpu::Transform((*Application::getInstance()->getViewTransform())); (*_transforms[0]) = gpu::Transform((*Application::getInstance()->getViewTransform()));
_transforms[0]->postTranslate(_translation); // apply entity translation + camera position offset to the viewTransform in one go
_transforms[0]->postTranslate(Application::getInstance()->getViewMatrixTranslation() + _translation);
batch.setViewTransform(_transforms[0]); batch.setViewTransform(_transforms[0]);

View file

@ -919,7 +919,9 @@ void SetSpannerTool::applyEdit(const AttributePointer& attribute, const SharedOb
Application::getInstance()->setupWorldLight(); Application::getInstance()->setupWorldLight();
Application::getInstance()->updateUntranslatedViewMatrix(); Application::getInstance()->updateUntranslatedViewMatrix();
// TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack
// setViewTransform(viewTransform);
const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f); const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f);
spannerData->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DIFFUSE_MODE, glm::vec3(), 0.0f); spannerData->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DIFFUSE_MODE, glm::vec3(), 0.0f);

View file

@ -25,14 +25,12 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat
Mat3 rotationMat = rotationScaleMatrix; Mat3 rotationMat = rotationScaleMatrix;
do { do {
Mat3 nextRotation; Mat3 nextRotation;
Mat3 currInvTranspose = Mat3 currInvTranspose = glm::inverse(glm::transpose(rotationMat));
glm::inverse(glm::transpose(rotationMat));
// Go through every component in the matrices and find the next matrix // Go through every component in the matrices and find the next matrix
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
for (int j = 0; j <3; j++) { for (int j = 0; j <3; j++) {
nextRotation[j][i] = 0.5f * nextRotation[j][i] = 0.5f * (rotationMat[j][i] + currInvTranspose[j][i]);
(rotationMat[j][i] + currInvTranspose[j][i]);
} }
} }
@ -73,7 +71,8 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat
// Beware: even though the matRot is supposed to be normalized at that point, // Beware: even though the matRot is supposed to be normalized at that point,
// glm::quat_cast doesn't always return a normalized quaternion... // glm::quat_cast doesn't always return a normalized quaternion...
rotation = glm::normalize(glm::quat_cast(matRot)); // rotation = glm::normalize(glm::quat_cast(matRot));
rotation = (glm::quat_cast(matRot));
} }

View file

@ -296,7 +296,7 @@ inline Transform& Transform::evalInverse(Transform& inverse) const {
} }
} }
if (isRotating()) { if (isRotating()) {
inverse.postRotate(-_rotation); inverse.postRotate(glm::conjugate(_rotation));
} }
if (isTranslating()) { if (isTranslating()) {
inverse.postTranslate(-_translation); inverse.postTranslate(-_translation);