Merge pull request #8340 from highfidelity/master

update discovery from master
This commit is contained in:
Howard Stearns 2016-08-01 13:08:10 -07:00 committed by GitHub
commit f8d3b7ce0b
8 changed files with 120 additions and 24 deletions

View file

@ -4685,7 +4685,8 @@ void Application::packetSent(quint64 length) {
void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine) {
scriptEngine->setEmitScriptUpdatesFunction([this]() {
return isPhysicsEnabled();
SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);
return !entityServerNode || isPhysicsEnabled();
});
// setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so

View file

@ -101,7 +101,7 @@ void Web3DOverlay::render(RenderArgs* args) {
batch.setModelTransform(transform);
auto geometryCache = DependencyManager::get<GeometryCache>();
geometryCache->bindSimpleProgram(batch, true, false, true, false);
geometryCache->bindSimpleSRGBTexturedUnlitNoTexAlphaProgram(batch);
geometryCache->renderQuad(batch, halfSize * -1.0f, halfSize, vec2(0), vec2(1), color);
batch.setResourceTexture(0, args->_whiteTexture); // restore default white color after me
}

View file

@ -203,14 +203,12 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
if (!success) {
return;
}
bool textured = false, culled = false, emissive = false;
if (_texture) {
batch._glActiveBindTexture(GL_TEXTURE0, GL_TEXTURE_2D, _texture);
textured = emissive = true;
}
DependencyManager::get<GeometryCache>()->bindSimpleProgram(batch, textured, culled, emissive);
DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f, 1.0f, 1.0f, 0.0f));
DependencyManager::get<GeometryCache>()->bindSimpleSRGBTexturedUnlitNoTexAlphaProgram(batch);
DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
}
void RenderableWebEntityItem::setSourceUrl(const QString& value) {

View file

@ -35,6 +35,7 @@
#include "simple_vert.h"
#include "simple_textured_frag.h"
#include "simple_textured_unlit_frag.h"
#include "simple_srgb_textured_unlit_no_tex_alpha_frag.h"
#include "glowLine_vert.h"
#include "glowLine_geom.h"
#include "glowLine_frag.h"
@ -1748,6 +1749,38 @@ inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) {
return a.getRaw() == b.getRaw();
}
void GeometryCache::bindSimpleSRGBTexturedUnlitNoTexAlphaProgram(gpu::Batch& batch) {
batch.setPipeline(getSimpleSRGBTexturedUnlitNoTexAlphaPipeline());
// Set a default normal map
batch.setResourceTexture(render::ShapePipeline::Slot::MAP::NORMAL_FITTING,
DependencyManager::get<TextureCache>()->getNormalFittingTexture());
}
gpu::PipelinePointer GeometryCache::getSimpleSRGBTexturedUnlitNoTexAlphaPipeline() {
// Compile the shaders, once
static std::once_flag once;
std::call_once(once, [&]() {
auto VS = gpu::Shader::createVertex(std::string(simple_vert));
auto PS = gpu::Shader::createPixel(std::string(simple_srgb_textured_unlit_no_tex_alpha_frag));
_simpleSRGBTexturedUnlitNoTexAlphaShader = gpu::Shader::createProgram(VS, PS);
gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::MAP::NORMAL_FITTING));
gpu::Shader::makeProgram(*_simpleSRGBTexturedUnlitNoTexAlphaShader, slotBindings);
auto state = std::make_shared<gpu::State>();
state->setCullMode(gpu::State::CULL_NONE);
state->setDepthTest(true, true, gpu::LESS_EQUAL);
state->setBlendFunction(false,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
_simpleSRGBTexturedUnlitNoTexAlphaPipeline = gpu::Pipeline::create(_simpleSRGBTexturedUnlitNoTexAlphaShader, state);
});
return _simpleSRGBTexturedUnlitNoTexAlphaPipeline;
}
void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool unlit, bool depthBiased) {
batch.setPipeline(getSimplePipeline(textured, culled, unlit, depthBiased));

View file

@ -157,6 +157,10 @@ public:
// Get the pipeline to render static geometry
gpu::PipelinePointer getSimplePipeline(bool textured = false, bool culled = true,
bool unlit = false, bool depthBias = false);
void bindSimpleSRGBTexturedUnlitNoTexAlphaProgram(gpu::Batch& batch);
gpu::PipelinePointer getSimpleSRGBTexturedUnlitNoTexAlphaPipeline();
render::ShapePipelinePointer getShapePipeline() { return GeometryCache::_simplePipeline; }
render::ShapePipelinePointer getWireShapePipeline() { return GeometryCache::_simpleWirePipeline; }
@ -416,6 +420,10 @@ private:
static render::ShapePipelinePointer _simpleWirePipeline;
gpu::PipelinePointer _glowLinePipeline;
QHash<SimpleProgramKey, gpu::PipelinePointer> _simplePrograms;
gpu::ShaderPointer _simpleSRGBTexturedUnlitNoTexAlphaShader;
gpu::PipelinePointer _simpleSRGBTexturedUnlitNoTexAlphaPipeline;
};
#endif // hifi_GeometryCache_h

View file

@ -0,0 +1,34 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// simple_srgb_texture_unlit_no_tex_alpha.frag
// fragment shader
//
// Created by Anthony Thibault on 7/25/16.
// Copyright 2016 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
//
<@include gpu/Color.slh@>
<@include DeferredBufferWrite.slh@>
// the albedo texture
uniform sampler2D originalTexture;
// the interpolated normal
in vec3 _normal;
in vec4 _color;
in vec2 _texCoord0;
void main(void) {
vec4 texel = texture(originalTexture, _texCoord0.st);
texel = colorToLinearRGBA(texel);
packDeferredFragmentUnlit(
normalize(_normal),
1.0,
_color.rgb * texel.rgb);
}

View file

@ -839,21 +839,24 @@ void ScriptEngine::run() {
// calculate a sleepUntil to be the time from our start time until the original target
// sleepUntil for this frame.
const std::chrono::microseconds FRAME_DURATION(USECS_PER_SECOND / SCRIPT_FPS + 1);
clock::time_point sleepUntil(startTime + thisFrame++ * FRAME_DURATION);
clock::time_point targetSleepUntil(startTime + thisFrame++ * FRAME_DURATION);
// However, if our sleepUntil is not at least our average update time into the future
// it means our script is taking too long in it's updates, and we want to punish the
// script a little bit. So we will force the sleepUntil to be at least our averageUpdate
// time into the future.
auto wouldSleep = (sleepUntil - clock::now());
auto avgerageUpdate = totalUpdates / thisFrame;
auto averageUpdate = totalUpdates / thisFrame;
auto sleepUntil = std::max(targetSleepUntil, beforeSleep + averageUpdate);
if (wouldSleep < avgerageUpdate) {
sleepUntil = beforeSleep + avgerageUpdate;
// We don't want to actually sleep for too long, because it causes our scripts to hang
// on shutdown and stop... so we want to loop and sleep until we've spent our time in
// purgatory, constantly checking to see if our script was asked to end
while (!_isFinished && clock::now() < sleepUntil) {
QCoreApplication::processEvents(); // before we sleep again, give events a chance to process
auto thisSleepUntil = std::min(sleepUntil, clock::now() + FRAME_DURATION);
std::this_thread::sleep_until(thisSleepUntil);
}
std::this_thread::sleep_until(sleepUntil);
#ifdef SCRIPT_DELAY_DEBUG
{
auto actuallySleptUntil = clock::now();
@ -865,7 +868,7 @@ void ScriptEngine::run() {
qCDebug(scriptengine) <<
"Frame:" << thisFrame <<
"Slept (us):" << std::chrono::duration_cast<std::chrono::microseconds>(actuallySleptUntil - beforeSleep).count() <<
"Avg Updates (us):" << avgerageUpdate.count() <<
"Avg Updates (us):" << averageUpdate.count() <<
"FPS:" << fps;
}
}

View file

@ -38,6 +38,15 @@ var BUMPER_ON_VALUE = 0.5;
var THUMB_ON_VALUE = 0.5;
var HAPTIC_PULSE_STRENGTH = 1.0;
var HAPTIC_PULSE_DURATION = 13.0;
var HAPTIC_TEXTURE_STRENGTH = 0.1;
var HAPTIC_TEXTURE_DURATION = 3.0;
var HAPTIC_TEXTURE_DISTANCE = 0.002;
var HAPTIC_DEQUIP_STRENGTH = 0.75;
var HAPTIC_DEQUIP_DURATION = 50.0;
var HAND_HEAD_MIX_RATIO = 0.0; // 0 = only use hands for search/move. 1 = only use head for search/move.
var PICK_WITH_HAND_RAY = true;
@ -934,7 +943,7 @@ function MyController(hand) {
entityPropertiesCache.addEntities(candidateEntities);
var potentialEquipHotspot = this.chooseBestEquipHotspot(candidateEntities);
if (!this.waitForTriggerRelease) {
this.updateEquipHaptics(potentialEquipHotspot);
this.updateEquipHaptics(potentialEquipHotspot, this.getHandPosition());
}
var nearEquipHotspots = this.chooseNearEquipHotspots(candidateEntities, EQUIP_HOTSPOT_RENDER_RADIUS);
@ -948,11 +957,15 @@ function MyController(hand) {
this.prevPotentialEquipHotspot = null;
};
this.updateEquipHaptics = function(potentialEquipHotspot) {
this.updateEquipHaptics = function(potentialEquipHotspot, currentLocation) {
if (potentialEquipHotspot && !this.prevPotentialEquipHotspot ||
!potentialEquipHotspot && this.prevPotentialEquipHotspot) {
Controller.triggerShortHapticPulse(0.5, this.hand);
}
Controller.triggerHapticPulse(HAPTIC_TEXTURE_STRENGTH, HAPTIC_TEXTURE_DURATION, this.hand);
this.lastHapticPulseLocation = currentLocation;
} else if (potentialEquipHotspot && Vec3.distance(this.lastHapticPulseLocation, currentLocation) > HAPTIC_TEXTURE_DISTANCE) {
Controller.triggerHapticPulse(HAPTIC_TEXTURE_STRENGTH, HAPTIC_TEXTURE_DURATION, this.hand);
this.lastHapticPulseLocation = currentLocation;
}
this.prevPotentialEquipHotspot = potentialEquipHotspot;
};
@ -1337,7 +1350,7 @@ function MyController(hand) {
}
}
this.updateEquipHaptics(potentialEquipHotspot);
this.updateEquipHaptics(potentialEquipHotspot, handPosition);
var nearEquipHotspots = this.chooseNearEquipHotspots(candidateEntities, EQUIP_HOTSPOT_RENDER_RADIUS);
equipHotspotBuddy.updateHotspots(nearEquipHotspots, timestamp);
@ -1422,13 +1435,16 @@ function MyController(hand) {
this.callEntityMethodOnGrabbed("startDistanceGrab");
}
Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
this.turnOffVisualizations();
this.previousRoomControllerPosition = roomControllerPosition;
};
this.distanceHolding = function(deltaTime, timestamp) {
if (this.triggerSmoothedReleased()) {
if (!this.triggerClicked) {
this.callEntityMethodOnGrabbed("releaseGrab");
this.setState(STATE_OFF, "trigger released");
return;
@ -1611,7 +1627,7 @@ function MyController(hand) {
if (handIsUpsideDown != this.prevHandIsUpsideDown) {
this.prevHandIsUpsideDown = handIsUpsideDown;
Controller.triggerShortHapticPulse(0.5, this.hand);
Controller.triggerHapticPulse(HAPTIC_DEQUIP_STRENGTH, HAPTIC_DEQUIP_DURATION, this.hand);
}
return handIsUpsideDown;
@ -1625,7 +1641,7 @@ function MyController(hand) {
this.dropGestureReset();
this.clearEquipHaptics();
Controller.triggerShortHapticPulse(1.0, this.hand);
Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
if (this.entityActivated) {
var saveGrabbedID = this.grabbedEntity;
@ -1746,7 +1762,7 @@ function MyController(hand) {
this.nearGrabbing = function(deltaTime, timestamp) {
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
if (this.state == STATE_NEAR_GRABBING && !this.triggerClicked) {
this.callEntityMethodOnGrabbed("releaseGrab");
this.setState(STATE_OFF, "trigger released");
return;
@ -1950,6 +1966,9 @@ function MyController(hand) {
var noVelocity = false;
if (this.grabbedEntity !== null) {
// Make a small release haptic pulse if we really were holding something
Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
// If this looks like the release after adjusting something still held in the other hand, print the position
// and rotation of the held thing to help content creators set the userData.
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {});