Global graphics flag default to on.

Added cast shadows flag to zone/keylight.
Exit the RenderShadowMap job if current keylight doesn't cast shadows.
This commit is contained in:
NissimHadar 2018-02-08 15:52:20 -08:00
parent 179aca2bf9
commit 950a62f3f8
15 changed files with 94 additions and 20 deletions

View file

@ -330,6 +330,7 @@ void ZoneEntityRenderer::updateKeySunFromEntity(const TypedEntityPointer& entity
sunLight->setColor(ColorUtils::toVec3(_keyLightProperties.getColor()));
sunLight->setIntensity(_keyLightProperties.getIntensity());
sunLight->setDirection(_keyLightProperties.getDirection());
sunLight->setCastShadows(_keyLightProperties.getCastShadows());
}
void ZoneEntityRenderer::updateAmbientLightFromEntity(const TypedEntityPointer& entity) {

View file

@ -1128,6 +1128,8 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue
ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_COLOR, KeyLightColor, keyLightColor, xColor);
ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_INTENSITY, KeyLightIntensity, keyLightIntensity, float);
ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_DIRECTION, KeyLightDirection, keyLightDirection, glm::vec3);
ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_CAST_SHADOWS, KeyLightCastShadows, keyLightCastShadows, bool);
ADD_PROPERTY_TO_MAP(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3);
ADD_PROPERTY_TO_MAP(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray);
ADD_PROPERTY_TO_MAP(PROP_VOXEL_SURFACE_STYLE, VoxelSurfaceStyle, voxelSurfaceStyle, uint16_t);

View file

@ -205,6 +205,11 @@ enum EntityPropertyList {
PROP_HAZE_MODE,
PROP_KEYLIGHT_COLOR,
PROP_KEYLIGHT_INTENSITY,
PROP_KEYLIGHT_DIRECTION,
PROP_KEYLIGHT_CAST_SHADOWS,
PROP_HAZE_RANGE,
PROP_HAZE_COLOR,
PROP_HAZE_GLARE_COLOR,
@ -246,10 +251,6 @@ enum EntityPropertyList {
// Aliases/Piggyback properties for Zones. These properties intentionally reuse the enum values for
// other properties which will never overlap with each other. We do this so that we don't have to expand
// the size of the properties bitflags mask
PROP_KEYLIGHT_COLOR = PROP_COLOR,
PROP_KEYLIGHT_INTENSITY = PROP_INTENSITY,
PROP_KEYLIGHT_DIRECTION = PROP_EXPONENT,
PROP_SKYBOX_COLOR = PROP_ANIMATION_URL,
PROP_SKYBOX_URL = PROP_ANIMATION_FPS,

View file

@ -21,6 +21,7 @@ const xColor KeyLightPropertyGroup::DEFAULT_KEYLIGHT_COLOR = { 255, 255, 255 };
const float KeyLightPropertyGroup::DEFAULT_KEYLIGHT_INTENSITY = 1.0f;
const float KeyLightPropertyGroup::DEFAULT_KEYLIGHT_AMBIENT_INTENSITY = 0.5f;
const glm::vec3 KeyLightPropertyGroup::DEFAULT_KEYLIGHT_DIRECTION = { 0.0f, -1.0f, 0.0f };
const bool KeyLightPropertyGroup::DEFAULT_KEYLIGHT_CAST_SHADOWS { false };
void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, QScriptValue& properties,
QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
@ -28,23 +29,27 @@ void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desired
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_COLOR, KeyLight, keyLight, Color, color);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_INTENSITY, KeyLight, keyLight, Intensity, intensity);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_DIRECTION, KeyLight, keyLight, Direction, direction);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_CAST_SHADOWS, KeyLight, keyLight, CastShadows, castShadows);
}
void KeyLightPropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, color, xColor, setColor);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, intensity, float, setIntensity);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, direction, glmVec3, setDirection);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, castShadows, bool, setCastShadows);
// legacy property support
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightColor, xColor, setColor, getColor);
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightIntensity, float, setIntensity, getIntensity);
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightDirection, glmVec3, setDirection, getDirection);
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightCastShadows, bool, setCastShadows, getCastShadows);
}
void KeyLightPropertyGroup::merge(const KeyLightPropertyGroup& other) {
COPY_PROPERTY_IF_CHANGED(color);
COPY_PROPERTY_IF_CHANGED(intensity);
COPY_PROPERTY_IF_CHANGED(direction);
COPY_PROPERTY_IF_CHANGED(castShadows);
}
void KeyLightPropertyGroup::debugDump() const {
@ -52,6 +57,7 @@ void KeyLightPropertyGroup::debugDump() const {
qCDebug(entities) << " color:" << getColor(); // << "," << getColor()[1] << "," << getColor()[2];
qCDebug(entities) << " intensity:" << getIntensity();
qCDebug(entities) << " direction:" << getDirection();
qCDebug(entities) << " castShadows:" << getCastShadows();
}
void KeyLightPropertyGroup::listChangedProperties(QList<QString>& out) {
@ -64,6 +70,9 @@ void KeyLightPropertyGroup::listChangedProperties(QList<QString>& out) {
if (directionChanged()) {
out << "keyLight-direction";
}
if (castShadowsChanged()) {
out << "keyLight-castShadows";
}
}
bool KeyLightPropertyGroup::appendToEditPacket(OctreePacketData* packetData,
@ -71,19 +80,22 @@ bool KeyLightPropertyGroup::appendToEditPacket(OctreePacketData* packetData,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const {
OctreeElement::AppendState& appendState) const
{
bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, getColor());
APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, getIntensity());
APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, getDirection());
APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_CAST_SHADOWS, getCastShadows());
return true;
}
bool KeyLightPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt,
int& processedBytes) {
int& processedBytes)
{
int bytesRead = 0;
bool overwriteLocalData = true;
@ -92,11 +104,13 @@ bool KeyLightPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFl
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, xColor, setColor);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, float, setIntensity);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, glm::vec3, setDirection);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_CAST_SHADOWS, bool, setCastShadows);
DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_COLOR, Color);
DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_INTENSITY, Intensity);
DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_DIRECTION, Direction);
DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_CAST_SHADOWS, CastShadows);
processedBytes += bytesRead;
Q_UNUSED(somethingChanged);
@ -108,6 +122,7 @@ void KeyLightPropertyGroup::markAllChanged() {
_colorChanged = true;
_intensityChanged = true;
_directionChanged = true;
_castShadowsChanged = true;
}
EntityPropertyFlags KeyLightPropertyGroup::getChangedProperties() const {
@ -116,7 +131,8 @@ EntityPropertyFlags KeyLightPropertyGroup::getChangedProperties() const {
CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_COLOR, color);
CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_INTENSITY, intensity);
CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_DIRECTION, direction);
CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_CAST_SHADOWS, castShadows);
return changedProperties;
}
@ -124,6 +140,7 @@ void KeyLightPropertyGroup::getProperties(EntityItemProperties& properties) cons
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, Color, getColor);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, Intensity, getIntensity);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, Direction, getDirection);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, CastShadows, getCastShadows);
}
bool KeyLightPropertyGroup::setProperties(const EntityItemProperties& properties) {
@ -132,6 +149,7 @@ bool KeyLightPropertyGroup::setProperties(const EntityItemProperties& properties
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, Color, color, setColor);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, Intensity, intensity, setIntensity);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, Direction, direction, setDirection);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, CastShadows, castShadows, setCastShadows);
return somethingChanged;
}
@ -142,6 +160,7 @@ EntityPropertyFlags KeyLightPropertyGroup::getEntityProperties(EncodeBitstreamPa
requestedProperties += PROP_KEYLIGHT_COLOR;
requestedProperties += PROP_KEYLIGHT_INTENSITY;
requestedProperties += PROP_KEYLIGHT_DIRECTION;
requestedProperties += PROP_KEYLIGHT_CAST_SHADOWS;
return requestedProperties;
}
@ -159,6 +178,7 @@ void KeyLightPropertyGroup::appendSubclassData(OctreePacketData* packetData, Enc
APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, getColor());
APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, getIntensity());
APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, getDirection());
APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_CAST_SHADOWS, getCastShadows());
}
int KeyLightPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
@ -172,6 +192,7 @@ int KeyLightPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char*
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, xColor, setColor);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, float, setIntensity);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, glm::vec3, setDirection);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_CAST_SHADOWS, bool, setCastShadows);
return bytesRead;
}

View file

@ -78,10 +78,12 @@ public:
static const float DEFAULT_KEYLIGHT_INTENSITY;
static const float DEFAULT_KEYLIGHT_AMBIENT_INTENSITY;
static const glm::vec3 DEFAULT_KEYLIGHT_DIRECTION;
static const bool DEFAULT_KEYLIGHT_CAST_SHADOWS;
DEFINE_PROPERTY_REF(PROP_KEYLIGHT_COLOR, Color, color, xColor, DEFAULT_KEYLIGHT_COLOR);
DEFINE_PROPERTY(PROP_KEYLIGHT_INTENSITY, Intensity, intensity, float, DEFAULT_KEYLIGHT_INTENSITY);
DEFINE_PROPERTY_REF(PROP_KEYLIGHT_DIRECTION, Direction, direction, glm::vec3, DEFAULT_KEYLIGHT_DIRECTION);
DEFINE_PROPERTY(PROP_KEYLIGHT_CAST_SHADOWS, CastShadows, castShadows, bool, DEFAULT_KEYLIGHT_CAST_SHADOWS);
};
#endif // hifi_KeyLightPropertyGroup_h

View file

@ -65,6 +65,14 @@ const Vec3& Light::getDirection() const {
return _lightSchemaBuffer->volume.direction;
}
void Light::setCastShadows(const bool castShadows) {
_castShadows = castShadows;
}
const bool Light::getCastShadows() const {
return _castShadows;
}
void Light::setColor(const Color& color) {
_lightSchemaBuffer.edit().irradiance.color = color;
updateLightRadius();
@ -132,7 +140,6 @@ void Light::setSpotExponent(float exponent) {
_lightSchemaBuffer.edit().irradiance.falloffSpot = exponent;
}
void Light::setAmbientIntensity(float intensity) {
_ambientSchemaBuffer.edit().intensity = intensity;
}

View file

@ -103,6 +103,9 @@ public:
void setDirection(const Vec3& direction);
const Vec3& getDirection() const;
void setCastShadows(const bool castShadows);
const bool getCastShadows() const;
void setOrientation(const Quat& orientation);
const glm::quat& getOrientation() const { return _transform.getRotation(); }
@ -187,6 +190,8 @@ protected:
void updateLightRadius();
bool _castShadows{ false };
};
typedef std::shared_ptr< Light > LightPointer;

View file

@ -30,7 +30,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
case PacketType::EntityEdit:
case PacketType::EntityData:
case PacketType::EntityPhysics:
return static_cast<PacketVersion>(EntityVersion::SoftEntities);
return static_cast<PacketVersion>(EntityVersion::ShadowControl);
case PacketType::EntityQuery:
return static_cast<PacketVersion>(EntityQueryPacketVersion::RemovedJurisdictions);

View file

@ -206,7 +206,8 @@ enum class EntityVersion : PacketVersion {
OwnershipChallengeFix,
ZoneLightInheritModes = 82,
ZoneStageRemoved,
SoftEntities
SoftEntities,
ShadowControl
};
enum class EntityScriptCallMethodVersion : PacketVersion {

View file

@ -541,15 +541,23 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext,
auto keyLight = lightAndShadow.first;
graphics::LightPointer keyAmbientLight;
graphics::LightPointer ambientLight;
if (lightStage && lightStage->_currentFrame._ambientLights.size()) {
keyAmbientLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front());
ambientLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front());
}
bool hasAmbientMap = (keyAmbientLight != nullptr);
bool hasAmbientMap = (ambientLight != nullptr);
// Setup the global directional pass pipeline
{
if (deferredLightingEffect->_shadowMapEnabled) {
// Check if keylight casts shadows
bool keyLightCastShadows { false };
if (lightStage && lightStage->_currentFrame._sunLights.size()) {
graphics::LightPointer keyLight = lightStage->getLight(lightStage->_currentFrame._sunLights.front());
keyLightCastShadows = keyLight->getCastShadows();
}
if (deferredLightingEffect->_shadowMapEnabled && keyLightCastShadows) {
// If the keylight has an ambient Map then use the Skybox version of the pass
// otherwise use the ambient sphere version

View file

@ -61,7 +61,7 @@ public:
private:
DeferredLightingEffect() = default;
bool _shadowMapEnabled{ false };
bool _shadowMapEnabled{ true }; // note that this value is overwritten in the ::configure method
bool _ambientOcclusionEnabled{ false };
graphics::MeshPointer _pointLightMesh;

View file

@ -120,6 +120,12 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, con
auto lightStage = renderContext->_scene->getStage<LightStage>();
assert(lightStage);
// Exit if current keylight does not cast shadows
bool castShadows = lightStage->getCurrentKeyLight()->getCastShadows();
if (!castShadows) {
return;
}
auto shadow = lightStage->getCurrentKeyShadow();
if (!shadow || _cascadeIndex >= shadow->getCascadeCount()) {
return;
@ -378,6 +384,15 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, O
void RenderShadowCascadeSetup::run(const render::RenderContextPointer& renderContext, Outputs& output) {
auto lightStage = renderContext->_scene->getStage<LightStage>();
assert(lightStage);
// Exit if current keylight does not cast shadows
bool castShadows = lightStage->getCurrentKeyLight()->getCastShadows();
if (!castShadows) {
output.edit0() = ItemFilter::Builder::nothing();
output.edit1() = ViewFrustumPointer();
return;
}
// Cache old render args
RenderArgs* args = renderContext->args;

View file

@ -38,7 +38,7 @@ class RenderShadowTaskConfig : public render::Task::Config::Persistent {
Q_OBJECT
Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty)
public:
RenderShadowTaskConfig() : render::Task::Config::Persistent(QStringList() << "Render" << "Engine" << "Shadows", false) {}
RenderShadowTaskConfig() : render::Task::Config::Persistent(QStringList() << "Render" << "Engine" << "Shadows", true) {}
signals:
void dirty();

View file

@ -532,6 +532,10 @@
<div></div>
</div>
</div>
<div class="zone-group zone-section keylight-section property checkbox">
<input type="checkbox" id="property-zone-key-light-cast-shadows">
<label for="property-zone-key-light-cast-shadows">Cast Shadows</label>
</div>
<fieldset class="minor">
<legend class="sub-section-header zone-group zone-section background-section">
Skybox

View file

@ -652,6 +652,8 @@ function loaded() {
var elZoneKeyLightDirectionX = document.getElementById("property-zone-key-light-direction-x");
var elZoneKeyLightDirectionY = document.getElementById("property-zone-key-light-direction-y");
var elZoneKeyLightCastShadows = document.getElementById("property-zone-key-light-cast-shadows");
// Skybox
var elZoneSkyboxModeInherit = document.getElementById("property-zone-skybox-mode-inherit");
var elZoneSkyboxModeDisabled = document.getElementById("property-zone-skybox-mode-disabled");
@ -1026,6 +1028,8 @@ function loaded() {
elZoneKeyLightDirectionX.value = properties.keyLight.direction.x.toFixed(2);
elZoneKeyLightDirectionY.value = properties.keyLight.direction.y.toFixed(2);
elZoneKeyLightCastShadows.checked = properties.keyLight.castShadows;
// Skybox
elZoneSkyboxModeInherit.checked = (properties.skyboxMode === 'inherit');
elZoneSkyboxModeDisabled.checked = (properties.skyboxMode === 'disabled');
@ -1463,6 +1467,9 @@ function loaded() {
elZoneKeyLightDirectionX.addEventListener('change', zoneKeyLightDirectionChangeFunction);
elZoneKeyLightDirectionY.addEventListener('change', zoneKeyLightDirectionChangeFunction);
elZoneKeyLightCastShadows.addEventListener('change',
createEmitGroupCheckedPropertyUpdateFunction('keyLight', 'castShadows'));
// Skybox
var skyboxModeChanged = createZoneComponentModeChangedFunction('skyboxMode',
elZoneSkyboxModeInherit, elZoneSkyboxModeDisabled, elZoneSkyboxModeEnabled);