diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index cd4f4d7d2c..ddbc76fce6 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -156,7 +156,7 @@ void Batch::setViewTransform(const Transform& view) { void Batch::setProjectionTransform(const Mat4& proj) { ADD_COMMAND(setProjectionTransform); - _params.push_back(cacheData(sizeof(Mat4), &proj); + _params.push_back(cacheData(sizeof(Mat4), &proj)); } void Batch::setUniformBuffer(uint32 slot, const BufferPointer& buffer, Offset offset, Offset size) { diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 7cc3958497..4473b00341 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -80,21 +80,25 @@ GLBackend::~GLBackend() { } -void GLBackend::renderBatch(Batch& batch) { +void GLBackend::render(Batch& batch) { + uint32 numCommands = batch.getCommands().size(); const Batch::Commands::value_type* command = batch.getCommands().data(); const Batch::CommandOffsets::value_type* offset = batch.getCommandOffsets().data(); - GLBackend backend; - for (unsigned int i = 0; i < numCommands; i++) { CommandCall call = _commandCalls[(*command)]; - (backend.*(call))(batch, *offset); + (this->*(call))(batch, *offset); command++; offset++; } } +void GLBackend::renderBatch(Batch& batch) { + GLBackend backend; + backend.render(batch); +} + void GLBackend::checkGLError() { GLenum error = glGetError(); if (!error) { @@ -416,9 +420,9 @@ void GLBackend::killTransform() { #else #endif } - +#define LEGACY_TRANSFORM_PIPELINE 1 void GLBackend::updateTransform() { -#define LEGACY_TRANSFORM_PIPELINE + #ifdef LEGACY_TRANSFORM_PIPELINE if (_transform._invalidProj) { // TODO: implement the projection matrix assignment to gl state diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index 1c5906525b..249a2fb8f9 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -27,10 +27,13 @@ public: GLBackend(); ~GLBackend(); + void render(Batch& batch); + static void renderBatch(Batch& batch); static void checkGLError(); + class GLBuffer { public: @@ -138,7 +141,7 @@ protected: _projection(), _invalidModel(true), _invalidView(true), - _invalidProj(true), + _invalidProj(false), _lastMode(GL_TEXTURE) {} } _transform; diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index 8181a1098b..61324861e8 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -870,7 +870,11 @@ void ViewFrustum::evalProjectionMatrix(glm::mat4& proj) const { if (isOrthographic()) { proj = glm::ortho(getWidth() * -0.5, getWidth() * +0.5, getHeight() * -0.5, getHeight() * 0.5); } else { - proj = glm::perspective(getFieldOfView(), getAspectRatio(), getNearClip(), getFarClip()); + float left, right, bottom, top, near, far; + glm::vec4 clip0, clip1; + computeOffAxisFrustum(left, right, bottom, top, near, far, clip0, clip1); + proj = glm::perspective(glm::radians(getFieldOfView()), getAspectRatio(), getNearClip(), getFarClip()); + // proj = glm::perspective(getFieldOfView() * 0.5f, getAspectRatio(), getNearClip(), getFarClip()); } } diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 5aa42cf3aa..6657100e6f 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -95,7 +95,10 @@ vec3 evalAmbienSphereGlobalColor(float shadowAttenuation, vec3 position, vec3 no vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) { Light light = getLight(); - float diffuseDot = dot(normal, getLightDirection(light)); + + vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0)); + + float diffuseDot = dot(fragNormal, getLightDirection(light)); // need to catch normals perpendicular to the projection plane hence the magic number for the threshold // it should be just 0, but we have innacurracy so we need to overshoot diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index edbce6b814..05ae810f6c 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -687,6 +687,12 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { _renderBatch.clear(); gpu::Batch& batch = _renderBatch; + if (args) { + glm::mat4 proj; + args->_viewFrustum->evalProjectionMatrix(proj); + batch.setProjectionTransform(proj); + } + // Capture the view matrix once for the rendering of this model if (_transforms.empty()) { _transforms.push_back(Transform()); @@ -1659,26 +1665,26 @@ void Model::setupBatchTransform(gpu::Batch& batch) { void Model::endScene(RenderMode mode, RenderArgs* args) { PROFILE_RANGE(__FUNCTION__); - + #if defined(ANDROID) + #else + glPushMatrix(); + #endif + RenderArgs::RenderSide renderSide = RenderArgs::MONO; if (args) { renderSide = args->_renderSide; } + gpu::GLBackend backend; + if (args) { glm::mat4 proj; args->_viewFrustum->evalProjectionMatrix(proj); gpu::Batch batch; batch.setProjectionTransform(proj); - ::gpu::GLBackend::renderBatch(batch); - + backend.render(batch); } - _viewState->getViewTransform(); - // apply entity translation offset to the viewTransform in one go (it's a preTranslate because viewTransform goes from world to eye space) - _transforms[0].preTranslate(-_translation); - - // Do the rendering batch creation for mono or left eye, not for right eye if (renderSide != RenderArgs::STEREO_RIGHT) { // Let's introduce a gpu::Batch to capture all the calls to the graphics api @@ -1833,19 +1839,15 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { // Render! { PROFILE_RANGE("render Batch"); - #if defined(ANDROID) - #else - glPushMatrix(); - #endif - - ::gpu::GLBackend::renderBatch(_sceneRenderBatch); - - #if defined(ANDROID) - #else - glPopMatrix(); - #endif + backend.render(_sceneRenderBatch); } + + #if defined(ANDROID) + #else + glPopMatrix(); + #endif + // restore all the default material settings _viewState->setupWorldLight(); diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv index 1da88a3876..f3f52ad990 100755 --- a/libraries/render-utils/src/model.slv +++ b/libraries/render-utils/src/model.slv @@ -11,19 +11,14 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/Transform.slh@> +//include gpu/Transform.slh const int MAX_TEXCOORDS = 2; -<$inputPosition(vin_position)$> -<$inputNormal(vin_normal)$> -<$inputTexcoord(vin_texcoord)$> -<$inputColor(vin_color)$> - uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; // the interpolated normal varying vec4 normal; - +/* void main(void) { // transform and store the normal for interpolation normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0)); @@ -37,10 +32,9 @@ void main(void) { // use standard pipeline transform gl_Position = gl_ModelViewProjectionMatrix * vec4(vin_position, 1.0); } +*/ - -/* void main(void) { // transform and store the normal for interpolation normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0)); @@ -54,4 +48,3 @@ void main(void) { // use standard pipeline transform gl_Position = ftransform(); } -*/