mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-07 08:18:59 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into HMDLightingBug
This commit is contained in:
commit
3690d5a4c2
7 changed files with 190 additions and 156 deletions
|
@ -173,36 +173,46 @@ void AssetServer::sendStatsPacket() {
|
|||
auto endTimeMs = std::chrono::duration_cast<std::chrono::milliseconds>(stat.second.endTime);
|
||||
QDateTime date = QDateTime::fromMSecsSinceEpoch(endTimeMs.count());
|
||||
|
||||
static const float USEC_PER_SEC = 1000000.0f;
|
||||
static const float MEGABITS_PER_BYTE = 8.0f / 1000000.0f; // Bytes => Mbits
|
||||
float elapsed = (float)(stat.second.endTime - stat.second.startTime).count() / USEC_PER_SEC; // sec
|
||||
float megabitsPerSecPerByte = MEGABITS_PER_BYTE / elapsed; // Bytes => Mb/s
|
||||
|
||||
QJsonObject connectionStats;
|
||||
connectionStats["lastHeard"] = date.toString();
|
||||
connectionStats["estimatedBandwith"] = stat.second.estimatedBandwith;
|
||||
connectionStats["rtt"] = stat.second.rtt;
|
||||
connectionStats["congestionWindowSize"] = stat.second.congestionWindowSize;
|
||||
connectionStats["packetSendPeriod"] = stat.second.packetSendPeriod;
|
||||
nodeStats["connection"] = connectionStats;
|
||||
connectionStats["1. Last Heard"] = date.toString();
|
||||
connectionStats["2. Est. Max (P/s)"] = stat.second.estimatedBandwith;
|
||||
connectionStats["3. RTT (ms)"] = stat.second.rtt;
|
||||
connectionStats["4. CW (P)"] = stat.second.congestionWindowSize;
|
||||
connectionStats["5. Period (us)"] = stat.second.packetSendPeriod;
|
||||
connectionStats["6. Up (Mb/s)"] = stat.second.sentBytes * megabitsPerSecPerByte;
|
||||
connectionStats["7. Down (Mb/s)"] = stat.second.receivedBytes * megabitsPerSecPerByte;
|
||||
nodeStats["Connection Stats"] = connectionStats;
|
||||
|
||||
QJsonObject sendingStats;
|
||||
sendingStats["sendRate"] = stat.second.sendRate;
|
||||
sendingStats["sentPackets"] = stat.second.sentPackets;
|
||||
sendingStats["receivedACK"] = stat.second.events[udt::ConnectionStats::Stats::ReceivedACK];
|
||||
sendingStats["processedACK"] = stat.second.events[udt::ConnectionStats::Stats::ProcessedACK];
|
||||
sendingStats["receivedLightACK"] = stat.second.events[udt::ConnectionStats::Stats::ReceivedLightACK];
|
||||
sendingStats["receivedNAK"] = stat.second.events[udt::ConnectionStats::Stats::ReceivedNAK];
|
||||
sendingStats["receivedTimeoutNAK"] = stat.second.events[udt::ConnectionStats::Stats::ReceivedTimeoutNAK];
|
||||
sendingStats["sentACK2"] = stat.second.events[udt::ConnectionStats::Stats::SentACK2];
|
||||
sendingStats["retransmission"] = stat.second.events[udt::ConnectionStats::Stats::Retransmission];
|
||||
nodeStats["sending"] = sendingStats;
|
||||
using Events = udt::ConnectionStats::Stats::Event;
|
||||
const auto& events = stat.second.events;
|
||||
|
||||
QJsonObject receivingStats;
|
||||
receivingStats["receiveRate"] = stat.second.receiveRate;
|
||||
receivingStats["receivedPackets"] = stat.second.receivedPackets;
|
||||
receivingStats["SentACK"] = stat.second.events[udt::ConnectionStats::Stats::SentACK];
|
||||
receivingStats["SentLightACK"] = stat.second.events[udt::ConnectionStats::Stats::SentLightACK];
|
||||
receivingStats["SentNAK"] = stat.second.events[udt::ConnectionStats::Stats::SentNAK];
|
||||
receivingStats["SentTimeoutNAK"] = stat.second.events[udt::ConnectionStats::Stats::SentTimeoutNAK];
|
||||
receivingStats["ReceivedACK2"] = stat.second.events[udt::ConnectionStats::Stats::ReceivedACK2];
|
||||
receivingStats["Duplicate"] = stat.second.events[udt::ConnectionStats::Stats::Duplicate];
|
||||
nodeStats["receiving"] = receivingStats;
|
||||
QJsonObject upstreamStats;
|
||||
upstreamStats["1. Sent (P/s)"] = stat.second.sendRate;
|
||||
upstreamStats["2. Sent Packets"] = stat.second.sentPackets;
|
||||
upstreamStats["3. Recvd ACK"] = events[Events::ReceivedACK];
|
||||
upstreamStats["4. Procd ACK"] = events[Events::ProcessedACK];
|
||||
upstreamStats["5. Recvd LACK"] = events[Events::ReceivedLightACK];
|
||||
upstreamStats["6. Recvd NAK"] = events[Events::ReceivedNAK];
|
||||
upstreamStats["7. Recvd TNAK"] = events[Events::ReceivedTimeoutNAK];
|
||||
upstreamStats["8. Sent ACK2"] = events[Events::SentACK2];
|
||||
upstreamStats["9. Retransmitted"] = events[Events::Retransmission];
|
||||
nodeStats["Upstream Stats"] = upstreamStats;
|
||||
|
||||
QJsonObject downstreamStats;
|
||||
downstreamStats["1. Recvd (P/s)"] = stat.second.receiveRate;
|
||||
downstreamStats["2. Recvd Packets"] = stat.second.receivedPackets;
|
||||
downstreamStats["3. Sent ACK"] = events[Events::SentACK];
|
||||
downstreamStats["4. Sent LACK"] = events[Events::SentLightACK];
|
||||
downstreamStats["5. Sent NAK"] = events[Events::SentNAK];
|
||||
downstreamStats["6. Sent TNAK"] = events[Events::SentTimeoutNAK];
|
||||
downstreamStats["7. Recvd ACK2"] = events[Events::ReceivedACK2];
|
||||
downstreamStats["8. Duplicates"] = events[Events::Duplicate];
|
||||
nodeStats["Downstream Stats"] = downstreamStats;
|
||||
|
||||
QString uuid;
|
||||
auto nodelist = DependencyManager::get<NodeList>();
|
||||
|
|
|
@ -9,11 +9,10 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include "OctreeServer.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QTimer>
|
||||
#include <QUuid>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
@ -26,7 +25,6 @@
|
|||
|
||||
#include "../AssignmentClient.h"
|
||||
|
||||
#include "OctreeServer.h"
|
||||
#include "OctreeServerConsts.h"
|
||||
|
||||
OctreeServer* OctreeServer::_instance = NULL;
|
||||
|
@ -1293,80 +1291,72 @@ QString OctreeServer::getStatusLink() {
|
|||
|
||||
void OctreeServer::sendStatsPacket() {
|
||||
// Stats Array 1
|
||||
QJsonArray threadsStats;
|
||||
QJsonObject threadsStats;
|
||||
quint64 oneSecondAgo = usecTimestampNow() - USECS_PER_SECOND;
|
||||
threadsStats.push_back(QJsonObject({{"processing", (double)howManyThreadsDidProcess(oneSecondAgo)}}));
|
||||
threadsStats.push_back(QJsonObject({{"packetDistributor", (double)howManyThreadsDidPacketDistributor(oneSecondAgo)}}));
|
||||
threadsStats.push_back(QJsonObject({{"handlePacektSend", (double)howManyThreadsDidHandlePacketSend(oneSecondAgo)}}));
|
||||
threadsStats.push_back(QJsonObject({{"writeDatagram", (double)howManyThreadsDidCallWriteDatagram(oneSecondAgo)}}));
|
||||
threadsStats["1. processing"] = (double)howManyThreadsDidProcess(oneSecondAgo);
|
||||
threadsStats["2. packetDistributor"] = (double)howManyThreadsDidPacketDistributor(oneSecondAgo);
|
||||
threadsStats["3. handlePacektSend"] = (double)howManyThreadsDidHandlePacketSend(oneSecondAgo);
|
||||
threadsStats["4. writeDatagram"] = (double)howManyThreadsDidCallWriteDatagram(oneSecondAgo);
|
||||
|
||||
QJsonArray statsArray1;
|
||||
statsArray1.push_back(QJsonObject({{"configuration", getConfiguration()}}));
|
||||
statsArray1.push_back(QJsonObject({{"detailed_stats_url", getStatusLink()}}));
|
||||
statsArray1.push_back(QJsonObject({{"uptime", getUptime()}}));
|
||||
statsArray1.push_back(QJsonObject({{"persistFileLoadTime", getFileLoadTime()}}));
|
||||
statsArray1.push_back(QJsonObject({{"clients", getCurrentClientCount()}}));
|
||||
statsArray1.push_back(QJsonObject({{"threads", threadsStats}}));
|
||||
QJsonObject statsArray1;
|
||||
statsArray1["1. configuration"] = getConfiguration();
|
||||
statsArray1["2. detailed_stats_url"] = getStatusLink();
|
||||
statsArray1["3. uptime"] = getUptime();
|
||||
statsArray1["4. persistFileLoadTime"] = getFileLoadTime();
|
||||
statsArray1["5. clients"] = getCurrentClientCount();
|
||||
statsArray1["6. threads"] = threadsStats;
|
||||
|
||||
// Octree Stats
|
||||
QJsonArray octreeStats;
|
||||
octreeStats.push_back(QJsonObject({{"elementCount", (double)OctreeElement::getNodeCount()}}));
|
||||
octreeStats.push_back(QJsonObject({{"internalElementCount", (double)OctreeElement::getInternalNodeCount()}}));
|
||||
octreeStats.push_back(QJsonObject({{"leafElementCount", (double)OctreeElement::getLeafNodeCount()}}));
|
||||
QJsonObject octreeStats;
|
||||
octreeStats["1. elementCount"] = (double)OctreeElement::getNodeCount();
|
||||
octreeStats["2. internalElementCount"] = (double)OctreeElement::getInternalNodeCount();
|
||||
octreeStats["3. leafElementCount"] = (double)OctreeElement::getLeafNodeCount();
|
||||
|
||||
// Stats Object 2
|
||||
QJsonObject dataObject1;
|
||||
dataObject1["totalPackets"] = (double)OctreeSendThread::_totalPackets;
|
||||
dataObject1["totalBytes"] = (double)OctreeSendThread::_totalBytes;
|
||||
dataObject1["totalBytesWasted"] = (double)OctreeSendThread::_totalWastedBytes;
|
||||
dataObject1["totalBytesOctalCodes"] = (double)OctreePacketData::getTotalBytesOfOctalCodes();
|
||||
dataObject1["totalBytesBitMasks"] = (double)OctreePacketData::getTotalBytesOfBitMasks();
|
||||
dataObject1["totalBytesBitMasks"] = (double)OctreePacketData::getTotalBytesOfColor();
|
||||
dataObject1["1. totalPackets"] = (double)OctreeSendThread::_totalPackets;
|
||||
dataObject1["2. totalBytes"] = (double)OctreeSendThread::_totalBytes;
|
||||
dataObject1["3. totalBytesWasted"] = (double)OctreeSendThread::_totalWastedBytes;
|
||||
dataObject1["4. totalBytesOctalCodes"] = (double)OctreePacketData::getTotalBytesOfOctalCodes();
|
||||
dataObject1["5. totalBytesBitMasks"] = (double)OctreePacketData::getTotalBytesOfBitMasks();
|
||||
dataObject1["6. totalBytesBitMasks"] = (double)OctreePacketData::getTotalBytesOfColor();
|
||||
|
||||
QJsonArray timingArray1;
|
||||
timingArray1.push_back(QJsonObject({{"avgLoopTime", getAverageLoopTime()}}));
|
||||
timingArray1.push_back(QJsonObject({{"avgInsideTime", getAverageInsideTime()}}));
|
||||
timingArray1.push_back(QJsonObject({{"avgTreeLockTime", getAverageTreeWaitTime()}}));
|
||||
timingArray1.push_back(QJsonObject({{"avgEncodeTime", getAverageEncodeTime()}}));
|
||||
timingArray1.push_back(QJsonObject({{"avgCompressAndWriteTime", getAverageCompressAndWriteTime()}}));
|
||||
timingArray1.push_back(QJsonObject({{"avgSendTime", getAveragePacketSendingTime()}}));
|
||||
timingArray1.push_back(QJsonObject({{"nodeWaitTime", getAverageNodeWaitTime()}}));
|
||||
QJsonObject timingArray1;
|
||||
timingArray1["1. avgLoopTime"] = getAverageLoopTime();
|
||||
timingArray1["2. avgInsideTime"] = getAverageInsideTime();
|
||||
timingArray1["3. avgTreeLockTime"] = getAverageTreeWaitTime();
|
||||
timingArray1["4. avgEncodeTime"] = getAverageEncodeTime();
|
||||
timingArray1["5. avgCompressAndWriteTime"] = getAverageCompressAndWriteTime();
|
||||
timingArray1["6. avgSendTime"] = getAveragePacketSendingTime();
|
||||
timingArray1["7. nodeWaitTime"] = getAverageNodeWaitTime();
|
||||
|
||||
QJsonObject statsObject2;
|
||||
statsObject2["data"] = dataObject1;
|
||||
statsObject2["timing"] = timingArray1;
|
||||
|
||||
// Stats Object 3
|
||||
QJsonArray dataArray2;
|
||||
dataArray2.push_back(QJsonObject({{"packetQueue",
|
||||
(double)_octreeInboundPacketProcessor->packetsToProcessCount()}}));
|
||||
dataArray2.push_back(QJsonObject({{"totalPackets",
|
||||
(double)_octreeInboundPacketProcessor->getTotalPacketsProcessed()}}));
|
||||
dataArray2.push_back(QJsonObject({{"totalElements",
|
||||
(double)_octreeInboundPacketProcessor->getTotalElementsProcessed()}}));
|
||||
QJsonObject dataArray2;
|
||||
dataArray2["1. packetQueue"] = (double)_octreeInboundPacketProcessor->packetsToProcessCount();
|
||||
dataArray2["2. totalPackets"] = (double)_octreeInboundPacketProcessor->getTotalPacketsProcessed();
|
||||
dataArray2["3. totalElements"] = (double)_octreeInboundPacketProcessor->getTotalElementsProcessed();
|
||||
|
||||
QJsonArray timingArray2;
|
||||
timingArray2.push_back(QJsonObject({{"avgTransitTimePerPacket",
|
||||
(double)_octreeInboundPacketProcessor->getAverageTransitTimePerPacket()}}));
|
||||
timingArray2.push_back(QJsonObject({{"avgProcessTimePerPacket",
|
||||
(double)_octreeInboundPacketProcessor->getAverageProcessTimePerPacket()}}));
|
||||
timingArray2.push_back(QJsonObject({{"avgLockWaitTimePerPacket",
|
||||
(double)_octreeInboundPacketProcessor->getAverageLockWaitTimePerPacket()}}));
|
||||
timingArray2.push_back(QJsonObject({{"avgProcessTimePerElement",
|
||||
(double)_octreeInboundPacketProcessor->getAverageProcessTimePerElement()}}));
|
||||
timingArray2.push_back(QJsonObject({{"avgLockWaitTimePerElement",
|
||||
(double)_octreeInboundPacketProcessor->getAverageLockWaitTimePerElement()}}));
|
||||
QJsonObject timingArray2;
|
||||
timingArray2["1. avgTransitTimePerPacket"] = (double)_octreeInboundPacketProcessor->getAverageTransitTimePerPacket();
|
||||
timingArray2["2. avgProcessTimePerPacket"] = (double)_octreeInboundPacketProcessor->getAverageProcessTimePerPacket();
|
||||
timingArray2["3. avgLockWaitTimePerPacket"] = (double)_octreeInboundPacketProcessor->getAverageLockWaitTimePerPacket();
|
||||
timingArray2["4. avgProcessTimePerElement"] = (double)_octreeInboundPacketProcessor->getAverageProcessTimePerElement();
|
||||
timingArray2["5. avgLockWaitTimePerElement"] = (double)_octreeInboundPacketProcessor->getAverageLockWaitTimePerElement();
|
||||
|
||||
QJsonObject statsObject3;
|
||||
statsObject3["data"] = dataArray2;
|
||||
statsObject3["timing"] = timingArray2;
|
||||
|
||||
// Merge everything
|
||||
QJsonArray jsonArray;
|
||||
jsonArray.push_back(statsArray1);
|
||||
jsonArray.push_back(QJsonObject({{"octree", octreeStats}}));
|
||||
jsonArray.push_back(QJsonObject({{"outbound", statsObject2}}));
|
||||
jsonArray.push_back(QJsonObject({{"inbound", statsObject3}}));
|
||||
QJsonObject jsonArray;
|
||||
jsonArray["1. misc"] = statsArray1;
|
||||
jsonArray["2. octree"] = octreeStats;
|
||||
jsonArray["3. outbound"] = statsObject2;
|
||||
jsonArray["4. inbound"] = statsObject3;
|
||||
|
||||
QJsonObject statsObject;
|
||||
statsObject[QString(getMyServerName()) + "Server"] = jsonArray;
|
||||
|
|
|
@ -44,6 +44,10 @@ void Context::enableStereo(bool enable) {
|
|||
_backend->enableStereo(enable);
|
||||
}
|
||||
|
||||
bool Context::isStereo() {
|
||||
return _backend->isStereo();
|
||||
}
|
||||
|
||||
void Context::setStereoProjections(const mat4 eyeProjections[2]) {
|
||||
_backend->setStereoProjections(eyeProjections);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,10 @@ public:
|
|||
_stereo._enable = enable;
|
||||
}
|
||||
|
||||
virtual bool isStereo() {
|
||||
return _stereo._enable;
|
||||
}
|
||||
|
||||
void setStereoProjections(const mat4 eyeProjections[2]) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
_stereo._eyeProjections[i] = eyeProjections[i];
|
||||
|
@ -169,6 +173,7 @@ public:
|
|||
|
||||
void render(Batch& batch);
|
||||
void enableStereo(bool enable = true);
|
||||
bool isStereo();
|
||||
void setStereoProjections(const mat4 eyeProjections[2]);
|
||||
void setStereoViews(const mat4 eyeViews[2]);
|
||||
void syncCache();
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
<@if not DEFERRED_BUFFER_SLH@>
|
||||
<@def DEFERRED_BUFFER_SLH@>
|
||||
|
||||
uniform bool stereoMode = false;
|
||||
|
||||
// the diffuse texture
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
|
@ -55,6 +57,12 @@ DeferredFragment unpackDeferredFragment(vec2 texcoord) {
|
|||
frag.diffuseVal = texture(diffuseMap, texcoord);
|
||||
frag.specularVal = texture(specularMap, texcoord);
|
||||
|
||||
if (stereoMode) {
|
||||
if (texcoord.x > 0.5) {
|
||||
texcoord.x -= 0.5;
|
||||
}
|
||||
texcoord.x *= 2.0;
|
||||
}
|
||||
// compute the view space position using the depth
|
||||
float z = near / (frag.depthVal * depthScale - 1.0);
|
||||
frag.position = vec4((depthTexCoordOffset + texcoord * depthTexCoordScale) * z, z, 1.0);
|
||||
|
|
|
@ -50,6 +50,26 @@
|
|||
|
||||
static const std::string glowIntensityShaderHandle = "glowIntensity";
|
||||
|
||||
struct LightLocations {
|
||||
int shadowDistances;
|
||||
int shadowScale;
|
||||
int nearLocation;
|
||||
int depthScale;
|
||||
int depthTexCoordOffset;
|
||||
int depthTexCoordScale;
|
||||
int radius;
|
||||
int ambientSphere;
|
||||
int lightBufferUnit;
|
||||
int atmosphereBufferUnit;
|
||||
int invViewMat;
|
||||
int texcoordMat;
|
||||
int coneParam;
|
||||
int stereo;
|
||||
};
|
||||
|
||||
static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations);
|
||||
|
||||
|
||||
gpu::PipelinePointer DeferredLightingEffect::getPipeline(SimpleProgramKey config) {
|
||||
auto it = _simplePrograms.find(config);
|
||||
if (it != _simplePrograms.end()) {
|
||||
|
@ -91,6 +111,18 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
|||
gpu::Shader::makeProgram(*_emissiveShader, slotBindings);
|
||||
|
||||
_viewState = viewState;
|
||||
_directionalLightLocations = std::make_shared<LightLocations>();
|
||||
_directionalLightShadowMapLocations = std::make_shared<LightLocations>();
|
||||
_directionalLightCascadedShadowMapLocations = std::make_shared<LightLocations>();
|
||||
_directionalAmbientSphereLightLocations = std::make_shared<LightLocations>();
|
||||
_directionalAmbientSphereLightShadowMapLocations = std::make_shared<LightLocations>();
|
||||
_directionalAmbientSphereLightCascadedShadowMapLocations = std::make_shared<LightLocations>();
|
||||
_directionalSkyboxLightLocations = std::make_shared<LightLocations>();
|
||||
_directionalSkyboxLightShadowMapLocations = std::make_shared<LightLocations>();
|
||||
_directionalSkyboxLightCascadedShadowMapLocations = std::make_shared<LightLocations>();
|
||||
_pointLightLocations = std::make_shared<LightLocations>();
|
||||
_spotLightLocations = std::make_shared<LightLocations>();
|
||||
|
||||
loadLightProgram(deferred_light_vert, directional_light_frag, false, _directionalLight, _directionalLightLocations);
|
||||
loadLightProgram(deferred_light_vert, directional_light_shadow_map_frag, false, _directionalLightShadowMap,
|
||||
_directionalLightShadowMapLocations);
|
||||
|
@ -290,7 +322,7 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
invViewMat = args->_viewFrustum->getView();
|
||||
|
||||
auto& program = _directionalLight;
|
||||
const LightLocations* locations = &_directionalLightLocations;
|
||||
LightLocationsPtr locations = _directionalLightLocations;
|
||||
|
||||
// FIXME: Note: we've removed the menu items to enable shadows, so this will always be false for now.
|
||||
// When we add back shadow support, this old approach may likely be removed and completely replaced
|
||||
|
@ -302,16 +334,16 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
batch.setResourceTexture(4, framebufferCache->getShadowFramebuffer()->getDepthStencilBuffer());
|
||||
|
||||
program = _directionalLightShadowMap;
|
||||
locations = &_directionalLightShadowMapLocations;
|
||||
locations = _directionalLightShadowMapLocations;
|
||||
if (cascadeShadowsEnabled) {
|
||||
program = _directionalLightCascadedShadowMap;
|
||||
locations = &_directionalLightCascadedShadowMapLocations;
|
||||
locations = _directionalLightCascadedShadowMapLocations;
|
||||
if (useSkyboxCubemap) {
|
||||
program = _directionalSkyboxLightCascadedShadowMap;
|
||||
locations = &_directionalSkyboxLightCascadedShadowMapLocations;
|
||||
locations = _directionalSkyboxLightCascadedShadowMapLocations;
|
||||
} else if (_ambientLightMode > -1) {
|
||||
program = _directionalAmbientSphereLightCascadedShadowMap;
|
||||
locations = &_directionalAmbientSphereLightCascadedShadowMapLocations;
|
||||
locations = _directionalAmbientSphereLightCascadedShadowMapLocations;
|
||||
}
|
||||
batch.setPipeline(program);
|
||||
batch._glUniform3fv(locations->shadowDistances, 1, (const float*) &_viewState->getShadowDistances());
|
||||
|
@ -319,10 +351,10 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
} else {
|
||||
if (useSkyboxCubemap) {
|
||||
program = _directionalSkyboxLightShadowMap;
|
||||
locations = &_directionalSkyboxLightShadowMapLocations;
|
||||
locations = _directionalSkyboxLightShadowMapLocations;
|
||||
} else if (_ambientLightMode > -1) {
|
||||
program = _directionalAmbientSphereLightShadowMap;
|
||||
locations = &_directionalAmbientSphereLightShadowMapLocations;
|
||||
locations = _directionalAmbientSphereLightShadowMapLocations;
|
||||
}
|
||||
batch.setPipeline(program);
|
||||
}
|
||||
|
@ -331,10 +363,10 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
} else {
|
||||
if (useSkyboxCubemap) {
|
||||
program = _directionalSkyboxLight;
|
||||
locations = &_directionalSkyboxLightLocations;
|
||||
locations = _directionalSkyboxLightLocations;
|
||||
} else if (_ambientLightMode > -1) {
|
||||
program = _directionalAmbientSphereLight;
|
||||
locations = &_directionalAmbientSphereLightLocations;
|
||||
locations = _directionalAmbientSphereLightLocations;
|
||||
}
|
||||
batch.setPipeline(program);
|
||||
}
|
||||
|
@ -382,7 +414,9 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
float depthTexCoordOffsetT = bottom * nearScale - tMin * depthTexCoordScaleT;
|
||||
batch._glUniform2f(locations->depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
||||
batch._glUniform2f(locations->depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
||||
|
||||
bool stereo = args->_context->isStereo();
|
||||
batch._glUniform1f(locations->stereo, stereo ? 1 : 0);
|
||||
|
||||
{
|
||||
Transform model;
|
||||
model.setTranslation(glm::vec3(sMin, tMin, 0.0));
|
||||
|
@ -435,20 +469,20 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
|
||||
if (!_pointLights.empty()) {
|
||||
batch.setPipeline(_pointLight);
|
||||
batch._glUniform1f(_pointLightLocations.nearLocation, nearVal);
|
||||
batch._glUniform1f(_pointLightLocations.depthScale, depthScale);
|
||||
batch._glUniform2f(_pointLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
||||
batch._glUniform2f(_pointLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
||||
batch._glUniform1f(_pointLightLocations->nearLocation, nearVal);
|
||||
batch._glUniform1f(_pointLightLocations->depthScale, depthScale);
|
||||
batch._glUniform2f(_pointLightLocations->depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
||||
batch._glUniform2f(_pointLightLocations->depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
||||
|
||||
batch._glUniformMatrix4fv(_pointLightLocations.invViewMat, 1, false, reinterpret_cast< const float* >(&invViewMat));
|
||||
batch._glUniformMatrix4fv(_pointLightLocations->invViewMat, 1, false, reinterpret_cast< const float* >(&invViewMat));
|
||||
|
||||
batch._glUniformMatrix4fv(_pointLightLocations.texcoordMat, 1, false, reinterpret_cast< const float* >(&texcoordMat));
|
||||
batch._glUniformMatrix4fv(_pointLightLocations->texcoordMat, 1, false, reinterpret_cast< const float* >(&texcoordMat));
|
||||
|
||||
for (auto lightID : _pointLights) {
|
||||
auto& light = _allocatedLights[lightID];
|
||||
// IN DEBUG: light->setShowContour(true);
|
||||
if (_pointLightLocations.lightBufferUnit >= 0) {
|
||||
batch.setUniformBuffer(_pointLightLocations.lightBufferUnit, light->getSchemaBuffer());
|
||||
if (_pointLightLocations->lightBufferUnit >= 0) {
|
||||
batch.setUniformBuffer(_pointLightLocations->lightBufferUnit, light->getSchemaBuffer());
|
||||
}
|
||||
|
||||
float expandedRadius = light->getMaximumRadius() * (1.0f + SCALE_EXPANSION);
|
||||
|
@ -483,20 +517,20 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
|
||||
if (!_spotLights.empty()) {
|
||||
batch.setPipeline(_spotLight);
|
||||
batch._glUniform1f(_spotLightLocations.nearLocation, nearVal);
|
||||
batch._glUniform1f(_spotLightLocations.depthScale, depthScale);
|
||||
batch._glUniform2f(_spotLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
||||
batch._glUniform2f(_spotLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
||||
batch._glUniform1f(_spotLightLocations->nearLocation, nearVal);
|
||||
batch._glUniform1f(_spotLightLocations->depthScale, depthScale);
|
||||
batch._glUniform2f(_spotLightLocations->depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
||||
batch._glUniform2f(_spotLightLocations->depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
||||
|
||||
batch._glUniformMatrix4fv(_spotLightLocations.invViewMat, 1, false, reinterpret_cast< const float* >(&invViewMat));
|
||||
batch._glUniformMatrix4fv(_spotLightLocations->invViewMat, 1, false, reinterpret_cast< const float* >(&invViewMat));
|
||||
|
||||
batch._glUniformMatrix4fv(_spotLightLocations.texcoordMat, 1, false, reinterpret_cast< const float* >(&texcoordMat));
|
||||
batch._glUniformMatrix4fv(_spotLightLocations->texcoordMat, 1, false, reinterpret_cast< const float* >(&texcoordMat));
|
||||
|
||||
for (auto lightID : _spotLights) {
|
||||
auto light = _allocatedLights[lightID];
|
||||
// IN DEBUG: light->setShowContour(true);
|
||||
|
||||
batch.setUniformBuffer(_spotLightLocations.lightBufferUnit, light->getSchemaBuffer());
|
||||
batch.setUniformBuffer(_spotLightLocations->lightBufferUnit, light->getSchemaBuffer());
|
||||
|
||||
auto eyeLightPos = eyePoint - light->getPosition();
|
||||
auto eyeHalfPlaneDistance = glm::dot(eyeLightPos, light->getDirection());
|
||||
|
@ -510,7 +544,7 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
if ((eyeHalfPlaneDistance > -nearRadius) &&
|
||||
(glm::distance(eyePoint, glm::vec3(light->getPosition())) < expandedRadius + nearRadius)) {
|
||||
coneParam.w = 0.0f;
|
||||
batch._glUniform4fv(_spotLightLocations.coneParam, 1, reinterpret_cast< const float* >(&coneParam));
|
||||
batch._glUniform4fv(_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam));
|
||||
|
||||
Transform model;
|
||||
model.setTranslation(glm::vec3(0.0f, 0.0f, -1.0f));
|
||||
|
@ -530,7 +564,7 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
batch.setViewTransform(viewMat);
|
||||
} else {
|
||||
coneParam.w = 1.0f;
|
||||
batch._glUniform4fv(_spotLightLocations.coneParam, 1, reinterpret_cast< const float* >(&coneParam));
|
||||
batch._glUniform4fv(_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam));
|
||||
|
||||
Transform model;
|
||||
model.setTranslation(light->getPosition());
|
||||
|
@ -604,7 +638,7 @@ void DeferredLightingEffect::setupTransparent(RenderArgs* args, int lightBufferU
|
|||
args->_batch->setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer());
|
||||
}
|
||||
|
||||
void DeferredLightingEffect::loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocations& locations) {
|
||||
static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) {
|
||||
auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(vertSource)));
|
||||
auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(fragSource)));
|
||||
|
||||
|
@ -624,20 +658,21 @@ void DeferredLightingEffect::loadLightProgram(const char* vertSource, const char
|
|||
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
locations.shadowDistances = program->getUniforms().findLocation("shadowDistances");
|
||||
locations.shadowScale = program->getUniforms().findLocation("shadowScale");
|
||||
locations.nearLocation = program->getUniforms().findLocation("near");
|
||||
locations.depthScale = program->getUniforms().findLocation("depthScale");
|
||||
locations.depthTexCoordOffset = program->getUniforms().findLocation("depthTexCoordOffset");
|
||||
locations.depthTexCoordScale = program->getUniforms().findLocation("depthTexCoordScale");
|
||||
locations.radius = program->getUniforms().findLocation("radius");
|
||||
locations.ambientSphere = program->getUniforms().findLocation("ambientSphere.L00");
|
||||
locations.invViewMat = program->getUniforms().findLocation("invViewMat");
|
||||
locations.texcoordMat = program->getUniforms().findLocation("texcoordMat");
|
||||
locations.coneParam = program->getUniforms().findLocation("coneParam");
|
||||
locations->stereo = program->getUniforms().findLocation("stereoMode");
|
||||
locations->shadowDistances = program->getUniforms().findLocation("shadowDistances");
|
||||
locations->shadowScale = program->getUniforms().findLocation("shadowScale");
|
||||
locations->nearLocation = program->getUniforms().findLocation("near");
|
||||
locations->depthScale = program->getUniforms().findLocation("depthScale");
|
||||
locations->depthTexCoordOffset = program->getUniforms().findLocation("depthTexCoordOffset");
|
||||
locations->depthTexCoordScale = program->getUniforms().findLocation("depthTexCoordScale");
|
||||
locations->radius = program->getUniforms().findLocation("radius");
|
||||
locations->ambientSphere = program->getUniforms().findLocation("ambientSphere.L00");
|
||||
locations->invViewMat = program->getUniforms().findLocation("invViewMat");
|
||||
locations->texcoordMat = program->getUniforms().findLocation("texcoordMat");
|
||||
locations->coneParam = program->getUniforms().findLocation("coneParam");
|
||||
|
||||
locations.lightBufferUnit = program->getBuffers().findLocation("lightBuffer");
|
||||
locations.atmosphereBufferUnit = program->getBuffers().findLocation("atmosphereBufferUnit");
|
||||
locations->lightBufferUnit = program->getBuffers().findLocation("lightBuffer");
|
||||
locations->atmosphereBufferUnit = program->getBuffers().findLocation("atmosphereBufferUnit");
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
if (lightVolume) {
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
class AbstractViewStateInterface;
|
||||
class RenderArgs;
|
||||
class SimpleProgramKey;
|
||||
|
||||
struct LightLocations;
|
||||
using LightLocationsPtr = std::shared_ptr<LightLocations>;
|
||||
/// Handles deferred lighting for the bits that require it (voxels...)
|
||||
class DeferredLightingEffect : public Dependency {
|
||||
SINGLETON_DEPENDENCY
|
||||
|
@ -82,28 +83,9 @@ private:
|
|||
DeferredLightingEffect() {}
|
||||
virtual ~DeferredLightingEffect() { }
|
||||
|
||||
class LightLocations {
|
||||
public:
|
||||
int shadowDistances;
|
||||
int shadowScale;
|
||||
int nearLocation;
|
||||
int depthScale;
|
||||
int depthTexCoordOffset;
|
||||
int depthTexCoordScale;
|
||||
int radius;
|
||||
int ambientSphere;
|
||||
int lightBufferUnit;
|
||||
int atmosphereBufferUnit;
|
||||
int invViewMat;
|
||||
int texcoordMat;
|
||||
int coneParam;
|
||||
};
|
||||
|
||||
model::MeshPointer _spotLightMesh;
|
||||
model::MeshPointer getSpotLightMesh();
|
||||
|
||||
static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& program, LightLocations& locations);
|
||||
|
||||
gpu::PipelinePointer getPipeline(SimpleProgramKey config);
|
||||
|
||||
gpu::ShaderPointer _simpleShader;
|
||||
|
@ -113,30 +95,30 @@ private:
|
|||
gpu::PipelinePointer _blitLightBuffer;
|
||||
|
||||
gpu::PipelinePointer _directionalSkyboxLight;
|
||||
LightLocations _directionalSkyboxLightLocations;
|
||||
LightLocationsPtr _directionalSkyboxLightLocations;
|
||||
gpu::PipelinePointer _directionalSkyboxLightShadowMap;
|
||||
LightLocations _directionalSkyboxLightShadowMapLocations;
|
||||
LightLocationsPtr _directionalSkyboxLightShadowMapLocations;
|
||||
gpu::PipelinePointer _directionalSkyboxLightCascadedShadowMap;
|
||||
LightLocations _directionalSkyboxLightCascadedShadowMapLocations;
|
||||
LightLocationsPtr _directionalSkyboxLightCascadedShadowMapLocations;
|
||||
|
||||
gpu::PipelinePointer _directionalAmbientSphereLight;
|
||||
LightLocations _directionalAmbientSphereLightLocations;
|
||||
LightLocationsPtr _directionalAmbientSphereLightLocations;
|
||||
gpu::PipelinePointer _directionalAmbientSphereLightShadowMap;
|
||||
LightLocations _directionalAmbientSphereLightShadowMapLocations;
|
||||
LightLocationsPtr _directionalAmbientSphereLightShadowMapLocations;
|
||||
gpu::PipelinePointer _directionalAmbientSphereLightCascadedShadowMap;
|
||||
LightLocations _directionalAmbientSphereLightCascadedShadowMapLocations;
|
||||
LightLocationsPtr _directionalAmbientSphereLightCascadedShadowMapLocations;
|
||||
|
||||
gpu::PipelinePointer _directionalLight;
|
||||
LightLocations _directionalLightLocations;
|
||||
LightLocationsPtr _directionalLightLocations;
|
||||
gpu::PipelinePointer _directionalLightShadowMap;
|
||||
LightLocations _directionalLightShadowMapLocations;
|
||||
LightLocationsPtr _directionalLightShadowMapLocations;
|
||||
gpu::PipelinePointer _directionalLightCascadedShadowMap;
|
||||
LightLocations _directionalLightCascadedShadowMapLocations;
|
||||
LightLocationsPtr _directionalLightCascadedShadowMapLocations;
|
||||
|
||||
gpu::PipelinePointer _pointLight;
|
||||
LightLocations _pointLightLocations;
|
||||
LightLocationsPtr _pointLightLocations;
|
||||
gpu::PipelinePointer _spotLight;
|
||||
LightLocations _spotLightLocations;
|
||||
LightLocationsPtr _spotLightLocations;
|
||||
|
||||
class PointLight {
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue