mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +02:00
Merge pull request #4596 from samcake/orange
On my quest for fixing the shadows i found a few syntax issues
This commit is contained in:
commit
b9310f67f8
6 changed files with 67 additions and 31 deletions
|
@ -2622,7 +2622,12 @@ glm::vec3 Application::getSunDirection() {
|
||||||
return skyStage->getSunLight()->getDirection();
|
return skyStage->getSunLight()->getDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME, preprocessor guard this check to occur only in DEBUG builds
|
||||||
|
static QThread * activeRenderingThread = nullptr;
|
||||||
|
|
||||||
void Application::updateShadowMap() {
|
void Application::updateShadowMap() {
|
||||||
|
activeRenderingThread = QThread::currentThread();
|
||||||
|
|
||||||
PerformanceTimer perfTimer("shadowMap");
|
PerformanceTimer perfTimer("shadowMap");
|
||||||
QOpenGLFramebufferObject* fbo = DependencyManager::get<TextureCache>()->getShadowFramebufferObject();
|
QOpenGLFramebufferObject* fbo = DependencyManager::get<TextureCache>()->getShadowFramebufferObject();
|
||||||
fbo->bind();
|
fbo->bind();
|
||||||
|
@ -2717,6 +2722,10 @@ void Application::updateShadowMap() {
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z);
|
glOrtho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z);
|
||||||
|
|
||||||
|
glm::mat4 projAgain;
|
||||||
|
glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)&projAgain);
|
||||||
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
@ -2772,6 +2781,7 @@ void Application::updateShadowMap() {
|
||||||
fbo->release();
|
fbo->release();
|
||||||
|
|
||||||
glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight());
|
glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight());
|
||||||
|
activeRenderingThread = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f };
|
const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f };
|
||||||
|
@ -2832,9 +2842,6 @@ QImage Application::renderAvatarBillboard() {
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME, preprocessor guard this check to occur only in DEBUG builds
|
|
||||||
static QThread * activeRenderingThread = nullptr;
|
|
||||||
|
|
||||||
ViewFrustum* Application::getViewFrustum() {
|
ViewFrustum* Application::getViewFrustum() {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (QThread::currentThread() == activeRenderingThread) {
|
if (QThread::currentThread() == activeRenderingThread) {
|
||||||
|
|
|
@ -337,8 +337,13 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool
|
||||||
|
|
||||||
// simple frustum check
|
// simple frustum check
|
||||||
float boundingRadius = getBillboardSize();
|
float boundingRadius = getBillboardSize();
|
||||||
ViewFrustum* frustum = (renderMode == Avatar::SHADOW_RENDER_MODE) ?
|
|
||||||
Application::getInstance()->getShadowViewFrustum() : Application::getInstance()->getDisplayViewFrustum();
|
ViewFrustum* frustum = nullptr;
|
||||||
|
if (renderMode == Avatar::SHADOW_RENDER_MODE) {
|
||||||
|
frustum = Application::getInstance()->getShadowViewFrustum();
|
||||||
|
} else {
|
||||||
|
frustum = Application::getInstance()->getDisplayViewFrustum();
|
||||||
|
}
|
||||||
if (frustum->sphereInFrustum(getPosition(), boundingRadius) == ViewFrustum::OUTSIDE) {
|
if (frustum->sphereInFrustum(getPosition(), boundingRadius) == ViewFrustum::OUTSIDE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1005,22 +1005,25 @@ void MyAvatar::renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, boo
|
||||||
Camera *camera = Application::getInstance()->getCamera();
|
Camera *camera = Application::getInstance()->getCamera();
|
||||||
const glm::vec3 cameraPos = camera->getPosition();
|
const glm::vec3 cameraPos = camera->getPosition();
|
||||||
|
|
||||||
// Set near clip distance according to skeleton model dimensions if first person and there is no separate head model.
|
// Only tweak the frustum near far if it's not shadow
|
||||||
if (shouldRenderHead(cameraPos, renderMode) || !getHead()->getFaceModel().getURL().isEmpty()) {
|
if (renderMode != SHADOW_RENDER_MODE) {
|
||||||
renderFrustum->setNearClip(DEFAULT_NEAR_CLIP);
|
// Set near clip distance according to skeleton model dimensions if first person and there is no separate head model.
|
||||||
} else {
|
if (shouldRenderHead(cameraPos, renderMode) || !getHead()->getFaceModel().getURL().isEmpty()) {
|
||||||
float clipDistance = _skeletonModel.getHeadClipDistance();
|
renderFrustum->setNearClip(DEFAULT_NEAR_CLIP);
|
||||||
if (OculusManager::isConnected()) {
|
} else {
|
||||||
// If avatar is horizontally in front of camera, increase clip distance by the amount it is in front.
|
float clipDistance = _skeletonModel.getHeadClipDistance();
|
||||||
glm::vec3 cameraToAvatar = _position - cameraPos;
|
if (OculusManager::isConnected()) {
|
||||||
cameraToAvatar.y = 0.0f;
|
// If avatar is horizontally in front of camera, increase clip distance by the amount it is in front.
|
||||||
glm::vec3 cameraLookAt = camera->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f);
|
glm::vec3 cameraToAvatar = _position - cameraPos;
|
||||||
float headOffset = glm::dot(cameraLookAt, cameraToAvatar);
|
cameraToAvatar.y = 0.0f;
|
||||||
if (headOffset > 0) {
|
glm::vec3 cameraLookAt = camera->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f);
|
||||||
clipDistance += headOffset;
|
float headOffset = glm::dot(cameraLookAt, cameraToAvatar);
|
||||||
|
if (headOffset > 0) {
|
||||||
|
clipDistance += headOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
renderFrustum->setNearClip(clipDistance);
|
||||||
}
|
}
|
||||||
renderFrustum->setNearClip(clipDistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the body's voxels and head
|
// Render the body's voxels and head
|
||||||
|
|
|
@ -104,7 +104,7 @@ void makeBindings(GLBackend::GLShader* shader) {
|
||||||
loc = glGetUniformBlockIndex(glprogram, "transformCameraBuffer");
|
loc = glGetUniformBlockIndex(glprogram, "transformCameraBuffer");
|
||||||
if (loc >= 0) {
|
if (loc >= 0) {
|
||||||
glUniformBlockBinding(glprogram, loc, gpu::TRANSFORM_CAMERA_SLOT);
|
glUniformBlockBinding(glprogram, loc, gpu::TRANSFORM_CAMERA_SLOT);
|
||||||
shader->_transformCameraSlot = gpu::TRANSFORM_OBJECT_SLOT;
|
shader->_transformCameraSlot = gpu::TRANSFORM_CAMERA_SLOT;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,18 +121,20 @@ Model::Locations Model::_normalMapLocations;
|
||||||
Model::Locations Model::_specularMapLocations;
|
Model::Locations Model::_specularMapLocations;
|
||||||
Model::Locations Model::_normalSpecularMapLocations;
|
Model::Locations Model::_normalSpecularMapLocations;
|
||||||
Model::Locations Model::_translucentLocations;
|
Model::Locations Model::_translucentLocations;
|
||||||
|
Model::Locations Model::_shadowLocations;
|
||||||
|
|
||||||
Model::Locations Model::_lightmapLocations;
|
Model::Locations Model::_lightmapLocations;
|
||||||
Model::Locations Model::_lightmapNormalMapLocations;
|
Model::Locations Model::_lightmapNormalMapLocations;
|
||||||
Model::Locations Model::_lightmapSpecularMapLocations;
|
Model::Locations Model::_lightmapSpecularMapLocations;
|
||||||
Model::Locations Model::_lightmapNormalSpecularMapLocations;
|
Model::Locations Model::_lightmapNormalSpecularMapLocations;
|
||||||
|
|
||||||
|
|
||||||
Model::SkinLocations Model::_skinLocations;
|
Model::SkinLocations Model::_skinLocations;
|
||||||
Model::SkinLocations Model::_skinNormalMapLocations;
|
Model::SkinLocations Model::_skinNormalMapLocations;
|
||||||
Model::SkinLocations Model::_skinSpecularMapLocations;
|
Model::SkinLocations Model::_skinSpecularMapLocations;
|
||||||
Model::SkinLocations Model::_skinNormalSpecularMapLocations;
|
Model::SkinLocations Model::_skinNormalSpecularMapLocations;
|
||||||
Model::SkinLocations Model::_skinShadowLocations;
|
|
||||||
Model::SkinLocations Model::_skinTranslucentLocations;
|
Model::SkinLocations Model::_skinTranslucentLocations;
|
||||||
|
Model::SkinLocations Model::_skinShadowLocations;
|
||||||
|
|
||||||
AbstractViewStateInterface* Model::_viewState = NULL;
|
AbstractViewStateInterface* Model::_viewState = NULL;
|
||||||
|
|
||||||
|
@ -284,8 +286,7 @@ void Model::init() {
|
||||||
|
|
||||||
_shadowProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelShadowVertex, modelShadowPixel));
|
_shadowProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelShadowVertex, modelShadowPixel));
|
||||||
makeResult = gpu::Shader::makeProgram(*_shadowProgram, slotBindings);
|
makeResult = gpu::Shader::makeProgram(*_shadowProgram, slotBindings);
|
||||||
Model::Locations tempShadowLoc;
|
initProgram(_shadowProgram, _shadowLocations);
|
||||||
initProgram(_shadowProgram, tempShadowLoc);
|
|
||||||
|
|
||||||
_lightmapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelLightmapVertex, modelLightmapPixel));
|
_lightmapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelLightmapVertex, modelLightmapPixel));
|
||||||
makeResult = gpu::Shader::makeProgram(*_lightmapProgram, slotBindings);
|
makeResult = gpu::Shader::makeProgram(*_lightmapProgram, slotBindings);
|
||||||
|
@ -656,7 +657,7 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) {
|
||||||
renderSetup(args);
|
renderSetup(args);
|
||||||
return renderCore(alpha, mode, args);
|
return renderCore(alpha, mode, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
||||||
PROFILE_RANGE(__FUNCTION__);
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
if (!_viewState) {
|
if (!_viewState) {
|
||||||
|
@ -670,7 +671,12 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
||||||
// Setup the projection matrix
|
// Setup the projection matrix
|
||||||
if (args && args->_viewFrustum) {
|
if (args && args->_viewFrustum) {
|
||||||
glm::mat4 proj;
|
glm::mat4 proj;
|
||||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
// If for easier debug depending on the pass
|
||||||
|
if (mode == RenderArgs::SHADOW_RENDER_MODE) {
|
||||||
|
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||||
|
} else {
|
||||||
|
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||||
|
}
|
||||||
batch.setProjectionTransform(proj);
|
batch.setProjectionTransform(proj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,7 +684,9 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
||||||
if (_transforms.empty()) {
|
if (_transforms.empty()) {
|
||||||
_transforms.push_back(Transform());
|
_transforms.push_back(Transform());
|
||||||
}
|
}
|
||||||
|
|
||||||
_transforms[0] = _viewState->getViewTransform();
|
_transforms[0] = _viewState->getViewTransform();
|
||||||
|
|
||||||
// apply entity translation offset to the viewTransform in one go (it's a preTranslate because viewTransform goes from world to eye space)
|
// 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);
|
_transforms[0].preTranslate(-_translation);
|
||||||
|
|
||||||
|
@ -699,7 +707,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
||||||
|
|
||||||
GLBATCH(glDisable)(GL_BLEND);
|
GLBATCH(glDisable)(GL_BLEND);
|
||||||
GLBATCH(glEnable)(GL_ALPHA_TEST);
|
GLBATCH(glEnable)(GL_ALPHA_TEST);
|
||||||
|
|
||||||
if (mode == SHADOW_RENDER_MODE) {
|
if (mode == SHADOW_RENDER_MODE) {
|
||||||
GLBATCH(glAlphaFunc)(GL_EQUAL, 0.0f);
|
GLBATCH(glAlphaFunc)(GL_EQUAL, 0.0f);
|
||||||
}
|
}
|
||||||
|
@ -1710,14 +1718,19 @@ void Model::startScene(RenderArgs::RenderSide renderSide) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::setupBatchTransform(gpu::Batch& batch) {
|
void Model::setupBatchTransform(gpu::Batch& batch, RenderArgs* args) {
|
||||||
|
|
||||||
// Capture the view matrix once for the rendering of this model
|
// Capture the view matrix once for the rendering of this model
|
||||||
if (_transforms.empty()) {
|
if (_transforms.empty()) {
|
||||||
_transforms.push_back(Transform());
|
_transforms.push_back(Transform());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We should be able to use the Frustum viewpoint onstead of the "viewTransform"
|
||||||
|
// but it s still buggy in some cases, so let's s wait and fix it...
|
||||||
_transforms[0] = _viewState->getViewTransform();
|
_transforms[0] = _viewState->getViewTransform();
|
||||||
|
|
||||||
_transforms[0].preTranslate(-_translation);
|
_transforms[0].preTranslate(-_translation);
|
||||||
|
|
||||||
batch.setViewTransform(_transforms[0]);
|
batch.setViewTransform(_transforms[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1738,7 +1751,12 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
glm::mat4 proj;
|
glm::mat4 proj;
|
||||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
// If for easier debug depending on the pass
|
||||||
|
if (mode == RenderArgs::SHADOW_RENDER_MODE) {
|
||||||
|
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||||
|
} else {
|
||||||
|
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||||
|
}
|
||||||
gpu::Batch batch;
|
gpu::Batch batch;
|
||||||
batch.setProjectionTransform(proj);
|
batch.setProjectionTransform(proj);
|
||||||
backend.render(batch);
|
backend.render(batch);
|
||||||
|
@ -2286,6 +2304,7 @@ void Model::pickPrograms(gpu::Batch& batch, RenderMode mode, bool translucent, f
|
||||||
skinLocations = &_skinLocations;
|
skinLocations = &_skinLocations;
|
||||||
if (mode == SHADOW_RENDER_MODE) {
|
if (mode == SHADOW_RENDER_MODE) {
|
||||||
program = _shadowProgram;
|
program = _shadowProgram;
|
||||||
|
locations = &_shadowLocations;
|
||||||
skinProgram = _skinShadowProgram;
|
skinProgram = _skinShadowProgram;
|
||||||
skinLocations = &_skinShadowLocations;
|
skinLocations = &_skinShadowLocations;
|
||||||
} else if (translucent && alphaThreshold == 0.0f) {
|
} else if (translucent && alphaThreshold == 0.0f) {
|
||||||
|
@ -2376,7 +2395,7 @@ int Model::renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool
|
||||||
pickPrograms(batch, mode, translucent, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, args, locations, skinLocations);
|
pickPrograms(batch, mode, translucent, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, args, locations, skinLocations);
|
||||||
pickProgramsNeeded = false;
|
pickProgramsNeeded = false;
|
||||||
}
|
}
|
||||||
model->setupBatchTransform(batch);
|
model->setupBatchTransform(batch, args);
|
||||||
meshPartsRendered += model->renderMeshesFromList(list, batch, mode, translucent, alphaThreshold, args, locations, skinLocations);
|
meshPartsRendered += model->renderMeshesFromList(list, batch, mode, translucent, alphaThreshold, args, locations, skinLocations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,6 +357,7 @@ private:
|
||||||
static Locations _specularMapLocations;
|
static Locations _specularMapLocations;
|
||||||
static Locations _normalSpecularMapLocations;
|
static Locations _normalSpecularMapLocations;
|
||||||
static Locations _translucentLocations;
|
static Locations _translucentLocations;
|
||||||
|
static Locations _shadowLocations;
|
||||||
|
|
||||||
static Locations _lightmapLocations;
|
static Locations _lightmapLocations;
|
||||||
static Locations _lightmapNormalMapLocations;
|
static Locations _lightmapNormalMapLocations;
|
||||||
|
@ -377,8 +378,9 @@ private:
|
||||||
static SkinLocations _skinNormalMapLocations;
|
static SkinLocations _skinNormalMapLocations;
|
||||||
static SkinLocations _skinSpecularMapLocations;
|
static SkinLocations _skinSpecularMapLocations;
|
||||||
static SkinLocations _skinNormalSpecularMapLocations;
|
static SkinLocations _skinNormalSpecularMapLocations;
|
||||||
static SkinLocations _skinShadowLocations;
|
|
||||||
static SkinLocations _skinTranslucentLocations;
|
static SkinLocations _skinTranslucentLocations;
|
||||||
|
static SkinLocations _skinShadowLocations;
|
||||||
|
|
||||||
|
|
||||||
static void initSkinProgram(ProgramObject& program, SkinLocations& locations);
|
static void initSkinProgram(ProgramObject& program, SkinLocations& locations);
|
||||||
static void initSkinProgram(gpu::ShaderPointer& program, SkinLocations& locations);
|
static void initSkinProgram(gpu::ShaderPointer& program, SkinLocations& locations);
|
||||||
|
@ -463,7 +465,7 @@ private:
|
||||||
bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args = NULL,
|
bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args = NULL,
|
||||||
bool forceRenderMeshes = false);
|
bool forceRenderMeshes = false);
|
||||||
|
|
||||||
void setupBatchTransform(gpu::Batch& batch);
|
void setupBatchTransform(gpu::Batch& batch, RenderArgs* args);
|
||||||
QVector<int>* pickMeshList(bool translucent, float alphaThreshold, bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned);
|
QVector<int>* pickMeshList(bool translucent, float alphaThreshold, bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned);
|
||||||
|
|
||||||
int renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold,
|
int renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold,
|
||||||
|
|
Loading…
Reference in a new issue