mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 06:37:27 +02:00
Removing superfluous lighting and naked GL in mirror
This commit is contained in:
parent
5159452335
commit
d4e637c5b8
9 changed files with 40 additions and 104 deletions
|
@ -22,6 +22,11 @@ else ()
|
||||||
set(BUILD_SEQ "dev")
|
set(BUILD_SEQ "dev")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h
|
||||||
|
add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines
|
||||||
|
endif()
|
||||||
|
|
||||||
configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h")
|
configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h")
|
||||||
|
|
||||||
macro(GroupSources curdir)
|
macro(GroupSources curdir)
|
||||||
|
|
|
@ -993,11 +993,12 @@ void Application::paintGL() {
|
||||||
}
|
}
|
||||||
|
|
||||||
displaySide(&renderArgs, _myCamera);
|
displaySide(&renderArgs, _myCamera);
|
||||||
renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
|
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
|
if (_myCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
|
||||||
|
renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
|
||||||
renderRearViewMirror(&renderArgs, _mirrorViewRect);
|
renderRearViewMirror(&renderArgs, _mirrorViewRect);
|
||||||
|
renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
|
||||||
}
|
}
|
||||||
renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
@ -3113,19 +3114,7 @@ void Application::updateShadowMap(RenderArgs* renderArgs) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpu::Light defaultLight{
|
|
||||||
vec3( 0.525f, 0.525f, 0.6f), // ambient
|
|
||||||
vec3( 0.6f, 0.525f, 0.525f), // diffuse
|
|
||||||
vec4(0.08f, 0.08f, 0.08f, 1.0f), // specular
|
|
||||||
vec4( 0, 0, 0, 0 ), // position
|
|
||||||
96 // shininess
|
|
||||||
};
|
|
||||||
|
|
||||||
void Application::setupWorldLight(RenderArgs* renderArgs) {
|
void Application::setupWorldLight(RenderArgs* renderArgs) {
|
||||||
gpu::Batch batch;
|
|
||||||
defaultLight._position = vec4(getSunDirection(), 0);
|
|
||||||
batch.setLight(0, defaultLight);
|
|
||||||
renderArgs->_context->render(batch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) {
|
bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) {
|
||||||
|
@ -3624,9 +3613,8 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard) {
|
void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard) {
|
||||||
|
auto originalViewport = renderArgs->_viewport;
|
||||||
// Grab current viewport to reset it at the end
|
// Grab current viewport to reset it at the end
|
||||||
int viewport[4];
|
|
||||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
|
||||||
float aspect = (float)region.width() / region.height();
|
float aspect = (float)region.width() / region.height();
|
||||||
float fov = MIRROR_FIELD_OF_VIEW;
|
float fov = MIRROR_FIELD_OF_VIEW;
|
||||||
|
|
||||||
|
@ -3663,35 +3651,45 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi
|
||||||
_mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
|
_mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
|
||||||
_mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
|
_mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
|
||||||
|
|
||||||
|
|
||||||
// set the bounds of rear mirror view
|
// set the bounds of rear mirror view
|
||||||
|
gpu::Vec4i viewport;
|
||||||
if (billboard) {
|
if (billboard) {
|
||||||
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
|
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
|
||||||
glViewport(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
|
viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
|
||||||
glScissor(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
|
|
||||||
renderArgs->_viewport = glm::ivec4(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
|
|
||||||
} else {
|
} else {
|
||||||
// if not rendering the billboard, the region is in device independent coordinates; must convert to device
|
// if not rendering the billboard, the region is in device independent coordinates; must convert to device
|
||||||
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
|
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
|
||||||
float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
|
float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
|
||||||
int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
|
int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
|
||||||
glViewport(x, size.height() - y - height, width, height);
|
viewport = gpu::Vec4i(x, size.height() - y - height, width, height);
|
||||||
glScissor(x, size.height() - y - height, width, height);
|
|
||||||
|
|
||||||
renderArgs->_viewport = glm::ivec4(x, size.height() - y - height, width, height);
|
|
||||||
}
|
}
|
||||||
|
renderArgs->_viewport = viewport;
|
||||||
|
|
||||||
|
{
|
||||||
|
gpu::Batch batch;
|
||||||
|
batch.setViewportTransform(viewport);
|
||||||
|
batch.setStateScissorRect(viewport);
|
||||||
|
batch.clearFramebuffer(
|
||||||
|
gpu::Framebuffer::BUFFER_COLOR0 |
|
||||||
|
gpu::Framebuffer::BUFFER_COLOR1 |
|
||||||
|
gpu::Framebuffer::BUFFER_COLOR2 |
|
||||||
|
gpu::Framebuffer::BUFFER_DEPTH,
|
||||||
|
vec4(vec3(0), 1), 1.0, 0.0, true);
|
||||||
|
// Viewport is assigned to the size of the framebuffer
|
||||||
|
renderArgs->_context->render(batch);
|
||||||
|
}
|
||||||
|
|
||||||
bool updateViewFrustum = false;
|
bool updateViewFrustum = false;
|
||||||
updateProjectionMatrix(_mirrorCamera, updateViewFrustum);
|
updateProjectionMatrix(_mirrorCamera, updateViewFrustum);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
// render rear mirror view
|
// render rear mirror view
|
||||||
displaySide(renderArgs, _mirrorCamera, true, billboard);
|
displaySide(renderArgs, _mirrorCamera, true, billboard);
|
||||||
|
//{
|
||||||
// reset Viewport and projection matrix
|
// gpu::Batch batch;
|
||||||
renderArgs->_viewport = glm::ivec4(viewport[0], viewport[1], viewport[2], viewport[3]);
|
// renderArgs->_viewport = originalViewport;
|
||||||
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
// batch.setViewportTransform(originalViewport);
|
||||||
glDisable(GL_SCISSOR_TEST);
|
// renderArgs->_context->render(batch);
|
||||||
updateProjectionMatrix(_myCamera, updateViewFrustum);
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::resetSensors() {
|
void Application::resetSensors() {
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <GLMHelpers.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(NSIGHT_FOUND)
|
#if defined(NSIGHT_FOUND)
|
||||||
#include "nvToolsExt.h"
|
#include "nvToolsExt.h"
|
||||||
|
|
||||||
|
@ -301,13 +304,3 @@ void push_back(Batch::Params& params, const vec4& v) {
|
||||||
params.push_back(v.z);
|
params.push_back(v.z);
|
||||||
params.push_back(v.a);
|
params.push_back(v.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch::setLight(uint8_t index, const Light& light) {
|
|
||||||
ADD_COMMAND(setLight);
|
|
||||||
_params.push_back(index);
|
|
||||||
push_back(_params, light._ambientColor);
|
|
||||||
push_back(_params, light._diffuseColor);
|
|
||||||
push_back(_params, light._position);
|
|
||||||
push_back(_params, light._specularColor);
|
|
||||||
_params.push_back(light._shininess);
|
|
||||||
}
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Framebuffer.h"
|
#include "Framebuffer.h"
|
||||||
#include "Light.h"
|
|
||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
#include "Stream.h"
|
#include "Stream.h"
|
||||||
|
@ -77,8 +76,6 @@ public:
|
||||||
void setIndexBuffer(Type type, const BufferPointer& buffer, Offset offset);
|
void setIndexBuffer(Type type, const BufferPointer& buffer, Offset offset);
|
||||||
void setIndexBuffer(const BufferView& buffer); // not a command, just a shortcut from a BufferView
|
void setIndexBuffer(const BufferView& buffer); // not a command, just a shortcut from a BufferView
|
||||||
|
|
||||||
void setLight(uint8_t index, const Light& light);
|
|
||||||
|
|
||||||
// Transform Stage
|
// Transform Stage
|
||||||
// Vertex position is transformed by ModelTransform from object space to world space
|
// Vertex position is transformed by ModelTransform from object space to world space
|
||||||
// Then by the inverse of the ViewTransform from world space to eye space
|
// Then by the inverse of the ViewTransform from world space to eye space
|
||||||
|
@ -172,8 +169,6 @@ public:
|
||||||
COMMAND_setInputBuffer,
|
COMMAND_setInputBuffer,
|
||||||
COMMAND_setIndexBuffer,
|
COMMAND_setIndexBuffer,
|
||||||
|
|
||||||
COMMAND_setLight,
|
|
||||||
|
|
||||||
COMMAND_setModelTransform,
|
COMMAND_setModelTransform,
|
||||||
COMMAND_setViewTransform,
|
COMMAND_setViewTransform,
|
||||||
COMMAND_setProjectionTransform,
|
COMMAND_setProjectionTransform,
|
||||||
|
|
|
@ -26,8 +26,6 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
|
||||||
(&::gpu::GLBackend::do_setInputBuffer),
|
(&::gpu::GLBackend::do_setInputBuffer),
|
||||||
(&::gpu::GLBackend::do_setIndexBuffer),
|
(&::gpu::GLBackend::do_setIndexBuffer),
|
||||||
|
|
||||||
(&::gpu::GLBackend::do_setLight),
|
|
||||||
|
|
||||||
(&::gpu::GLBackend::do_setModelTransform),
|
(&::gpu::GLBackend::do_setModelTransform),
|
||||||
(&::gpu::GLBackend::do_setViewTransform),
|
(&::gpu::GLBackend::do_setViewTransform),
|
||||||
(&::gpu::GLBackend::do_setProjectionTransform),
|
(&::gpu::GLBackend::do_setProjectionTransform),
|
||||||
|
|
|
@ -253,8 +253,6 @@ protected:
|
||||||
void do_setInputBuffer(Batch& batch, uint32 paramOffset);
|
void do_setInputBuffer(Batch& batch, uint32 paramOffset);
|
||||||
void do_setIndexBuffer(Batch& batch, uint32 paramOffset);
|
void do_setIndexBuffer(Batch& batch, uint32 paramOffset);
|
||||||
|
|
||||||
void do_setLight(Batch& batch, uint32 paramOffset);
|
|
||||||
|
|
||||||
void initInput();
|
void initInput();
|
||||||
void killInput();
|
void killInput();
|
||||||
void syncInputStateCache();
|
void syncInputStateCache();
|
||||||
|
|
|
@ -305,24 +305,3 @@ void popParam(Batch::Params& params, uint32& paramOffset, V& v) {
|
||||||
v[i] = params[paramOffset++]._float;
|
v[i] = params[paramOffset++]._float;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::do_setLight(Batch& batch, uint32 paramOffset) {
|
|
||||||
int index = batch._params[paramOffset++]._uint;
|
|
||||||
gpu::Light light;
|
|
||||||
popParam(batch._params, paramOffset, light._ambientColor);
|
|
||||||
popParam(batch._params, paramOffset, light._diffuseColor);
|
|
||||||
popParam(batch._params, paramOffset, light._position);
|
|
||||||
popParam(batch._params, paramOffset, light._specularColor);
|
|
||||||
light._shininess = batch._params[paramOffset++]._int;
|
|
||||||
|
|
||||||
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
|
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
|
||||||
glLightfv(GL_LIGHT0 + index, GL_POSITION, &light._position.x);
|
|
||||||
glLightfv(GL_LIGHT0 + index, GL_AMBIENT, &light._ambientColor.r);
|
|
||||||
glLightfv(GL_LIGHT0 + index, GL_DIFFUSE, &light._diffuseColor.r);
|
|
||||||
glLightfv(GL_LIGHT0 + index, GL_SPECULAR, &light._specularColor.r);
|
|
||||||
glMaterialfv(GL_FRONT + index, GL_SPECULAR, &light._specularColor.r);
|
|
||||||
glMateriali(GL_FRONT + index, GL_SHININESS, light._shininess);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) {
|
||||||
|
|
||||||
void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) {
|
void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) {
|
||||||
memcpy(&_transform._viewport, batch.editData(batch._params[paramOffset]._uint), sizeof(Vec4i));
|
memcpy(&_transform._viewport, batch.editData(batch._params[paramOffset]._uint), sizeof(Vec4i));
|
||||||
|
glViewport(_transform._viewport.x, _transform._viewport.y, _transform._viewport.z, _transform._viewport.w);
|
||||||
_transform._invalidViewport = true;
|
_transform._invalidViewport = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Bradley Austin Davis 2015/07/18
|
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
#pragma once
|
|
||||||
#ifndef hifi_gpu_Light_h
|
|
||||||
#define hifi_gpu_Light_h
|
|
||||||
|
|
||||||
#include <GLMHelpers.h>
|
|
||||||
|
|
||||||
namespace gpu {
|
|
||||||
|
|
||||||
struct Light {
|
|
||||||
Light() {}
|
|
||||||
Light(const vec3& ambient, const vec3& diffuse, const vec4& position, const vec4& specular = vec4(), int shininess = 0) :
|
|
||||||
_ambientColor(ambient), _diffuseColor(diffuse), _position(position), _specularColor(specular), _shininess(shininess) {
|
|
||||||
|
|
||||||
}
|
|
||||||
vec3 _ambientColor;
|
|
||||||
vec3 _diffuseColor;
|
|
||||||
vec4 _position;
|
|
||||||
vec4 _specularColor;
|
|
||||||
int _shininess{0};
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in a new issue