Skip to content

normal map attenuation properties #1461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: protocol_changes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion libraries/entities-renderer/src/RenderableZoneEntityItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <procedural/ProceduralSkybox.h>
#include <LightPayload.h>
#include <DeferredLightingEffect.h>
#include <ZoneRenderer.h>

#include "EntityTreeRenderer.h"

Expand Down Expand Up @@ -239,6 +240,13 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) {
} else if (_ambientOcclusionMode == COMPONENT_MODE_ENABLED) {
_ambientOcclusionStage->_currentFrame.pushElement(_ambientOcclusionIndex);
}

// Hack: CullTest::_containingZones is empty at the beginning of a frame, and our zones render in order,
// so we know we're in the first/smallest zone if CullTest::_containingZones.empty()
if (CullTest::_containingZones.empty() && ZoneRendererTask::_lightingModel) {
ZoneRendererTask::_lightingModel->setNormalMapAttenuation(_normalMapAttenuationProperties.getMin(),
_normalMapAttenuationProperties.getMax());
}
}

CullTest::_containingZones.insert(_entityID);
Expand Down Expand Up @@ -273,6 +281,7 @@ void ZoneEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointe
bool bloomChanged = entity->bloomPropertiesChanged();
bool tonemappingChanged = entity->tonemappingPropertiesChanged();
bool ambientOcclusionChanged = entity->ambientOcclusionPropertiesChanged();
bool normalMapAttenuationChanged = entity->normalMapAttenuationPropertiesChanged();
entity->resetRenderingPropertiesChanged();

if (transformChanged) {
Expand Down Expand Up @@ -322,6 +331,10 @@ void ZoneEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointe
updateAmbientOcclusionFromEntity(entity);
}

if (normalMapAttenuationChanged) {
_normalMapAttenuationProperties = entity->getNormalMapAttenuationProperties();
}

bool visuallyReady = true;
uint32_t skyboxMode = entity->getSkyboxMode();
if (skyboxMode == COMPONENT_MODE_ENABLED && !_skyboxTextureURL.isEmpty()) {
Expand All @@ -344,7 +357,8 @@ bool ZoneEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoint
entity->bloomPropertiesChanged() ||
entity->skyboxPropertiesChanged() ||
entity->tonemappingPropertiesChanged() ||
entity->ambientOcclusionPropertiesChanged()) {
entity->ambientOcclusionPropertiesChanged() ||
entity->normalMapAttenuationPropertiesChanged()) {

return true;
}
Expand Down
1 change: 1 addition & 0 deletions libraries/entities-renderer/src/RenderableZoneEntityItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ZoneEntityRenderer : public TypedEntityRenderer<ZoneEntityItem> {
BloomPropertyGroup _bloomProperties;
TonemappingPropertyGroup _tonemappingProperties;
AmbientOcclusionPropertyGroup _ambientOcclusionProperties;
NormalMapAttenuationPropertyGroup _normalMapAttenuationProperties;

// More attributes used for rendering:
QString _ambientTextureURL;
Expand Down
3 changes: 3 additions & 0 deletions libraries/entities/src/EntityItemGroupProperties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ enum:AMBIENT_OCCLUSION_AO_OBSCURANCE_LEVEL prop:aoObscuranceLevel type:float def
enum:AMBIENT_OCCLUSION_AO_FALLOFF_ANGLE prop:aoFalloffAngle type:float default:0.25f min:0.0f max:1.0f,
enum:AMBIENT_OCCLUSION_AO_SAMPLING_AMOUNT prop:aoSamplingAmount type:float default:0.5f min:0.0f max:1.0f,
enum:AMBIENT_OCCLUSION_SSAO_NUM_SPIRAL_TURNS prop:ssaoNumSpiralTurns type:float default:7.0f min:0.0f max:10.0f,
normalMapAttenuation
enum:NORMAL_MAP_ATTENUATION_MIN prop:min type:float default:30.0f min:0.0f max:16000.0f,
enum:NORMAL_MAP_ATTENUATION_MAX prop:max type:float default:100.0f min:0.0f max:16000.0f,
ring type:RingGizmo
enum:START_ANGLE prop:startAngle type:float default:0.0f min:RingGizmoPropertyGroup::MIN_ANGLE max:RingGizmoPropertyGroup::MAX_ANGLE,
enum:END_ANGLE prop:endAngle type:float default:360.0f min:RingGizmoPropertyGroup::MIN_ANGLE max:RingGizmoPropertyGroup::MAX_ANGLE,
Expand Down
1 change: 1 addition & 0 deletions libraries/entities/src/EntityItemProperties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ group:bloom recordChange,
group:audio type:ZoneAudio,
group:tonemapping recordChange,
group:ambientOcclusion recordChange,
group:normalMapAttenuation recordChange,
enum:FLYING_ALLOWED prop:flyingAllowed type:bool default:ZoneEntityItem::DEFAULT_FLYING_ALLOWED basicProp,
enum:GHOSTING_ALLOWED prop:ghostingAllowed type:bool default:ZoneEntityItem::DEFAULT_GHOSTING_ALLOWED basicProp,
enum:FILTER_URL prop:filterURL type:QString default:ZoneEntityItem::DEFAULT_FILTER_URL urlPermission,
Expand Down
1 change: 1 addition & 0 deletions libraries/entities/src/EntityItemPropertiesDocs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@
*
* @property {Entities.ComponentMode} tonemappingMode="inherit" - Configures the tonemapping in the zone.
* @property {Entities.Tonemapping} tonemapping - The tonemapping properties of the zone.
* @property {Entities.NormalMapAttenuation} normalMapAttenuation - The normal map attenuation properties of the zone.
*
* @property {Entities.ComponentMode} ambientOcclusionMode="inherit" - Configures the ambient occlusion in the zone.
* @property {Entities.AmbientOcclusion} ambientOcclusion - The ambient occlusion properties of the zone.
Expand Down
2 changes: 2 additions & 0 deletions libraries/entities/src/EntityPropertyFlags.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ enum EntityPropertyList : uint16_t {
PROP_DERIVED_52,
PROP_DERIVED_53,
PROP_DERIVED_54,
PROP_DERIVED_55,
PROP_DERIVED_56,

PROP_AFTER_LAST_ITEM,

Expand Down
133 changes: 133 additions & 0 deletions libraries/entities/src/NormalMapAttenuationPropertyGroup.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// NormalMapAttenuationPropertyGroup.cpp
// libraries/entities/src
//
// Created by HifiExperiments on 10/18/24
// Copyright 2024 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// SPDX-License-Identifier: Apache-2.0
//

#include "NormalMapAttenuationPropertyGroup.h"

#include <OctreePacketData.h>

#include "EntityItemProperties.h"

void NormalMapAttenuationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties, ScriptEngine* engine,
bool skipDefaults, EntityItemProperties& defaultEntityProperties, bool returnNothingOnEmptyPropertyFlags, bool isMyOwnAvatarEntity) const {

@NormalMapAttenuation_GROUP_COPY_TO_SCRIPT@

}

void NormalMapAttenuationPropertyGroup::copyFromScriptValue(const ScriptValue& object, const QSet<QString> &namesSet, bool& _defaultSettings) {

@NormalMapAttenuation_GROUP_COPY_FROM_SCRIPT@

}

void NormalMapAttenuationPropertyGroup::merge(const NormalMapAttenuationPropertyGroup& other) {

@NormalMapAttenuation_GROUP_MERGE@

}

void NormalMapAttenuationPropertyGroup::debugDump() const {

@NormalMapAttenuation_GROUP_DEBUG_DUMP@

}

void NormalMapAttenuationPropertyGroup::listChangedProperties(QList<QString>& out) {

@NormalMapAttenuation_GROUP_LIST_CHANGED@

}

bool NormalMapAttenuationPropertyGroup::appendToEditPacket(OctreePacketData* packetData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const {

bool successPropertyFits = true;

@NormalMapAttenuation_GROUP_APPEND@

return successPropertyFits;
}

bool NormalMapAttenuationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt , int& processedBytes) {

int bytesRead = 0;
bool overwriteLocalData = true;
bool somethingChanged = false;

@NormalMapAttenuation_GROUP_READ@

@NormalMapAttenuation_GROUP_DECODE_CHANGED@

processedBytes += bytesRead;

return somethingChanged;
}

void NormalMapAttenuationPropertyGroup::markAllChanged() {

@NormalMapAttenuation_GROUP_MARK_CHANGED@

}

EntityPropertyFlags NormalMapAttenuationPropertyGroup::getChangedProperties() const {
EntityPropertyFlags changedProperties;

@NormalMapAttenuation_GROUP_CHANGED_PROPERTIES@

return changedProperties;
}

void NormalMapAttenuationPropertyGroup::getProperties(EntityItemProperties& properties) const {

@NormalMapAttenuation_GROUP_COPY_TO@

}

bool NormalMapAttenuationPropertyGroup::setProperties(const EntityItemProperties& properties) {
bool somethingChanged = false;

@NormalMapAttenuation_GROUP_SET_FROM@

return somethingChanged;
}

EntityPropertyFlags NormalMapAttenuationPropertyGroup::getEntityProperties(EncodeBitstreamParams& params) const {
EntityPropertyFlags requestedProperties;

@NormalMapAttenuation_REQUESTED_PROPS@

return requestedProperties;
}

int NormalMapAttenuationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
bool& somethingChanged) {

int bytesRead = 0;
const unsigned char* dataAt = data;

@NormalMapAttenuation_GROUP_READ@

return bytesRead;
}

void NormalMapAttenuationPropertyGroup::addPropertyMap(QHash<QString, EntityPropertyInfo>& _propertyInfos,
QHash<EntityPropertyList, QString>& _enumsToPropertyStrings) {

@NormalMapAttenuation_GROUP_ADD_TO_MAP@

}
43 changes: 43 additions & 0 deletions libraries/entities/src/NormalMapAttenuationPropertyGroup.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// NormalMapAttenuationPropertyGroup.h
// libraries/entities/src
//
// Created by HifiExperiments on 10/18/24
// Copyright 2024 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// SPDX-License-Identifier: Apache-2.0
//

#ifndef hifi_NormalMapAttenuationPropertyGroup_h
#define hifi_NormalMapAttenuationPropertyGroup_h

#include "PropertyGroup.h"
#include "EntityItemPropertiesMacros.h"

class EntityItemProperties;
class EncodeBitstreamParams;
class OctreePacketData;
class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
class ScriptEngine;
class ScriptValue;

/*@jsdoc
* NormalMapAttenuation is defined by the following properties:
* @typedef {object} Entities.NormalMapAttenuation
* @property {number} min=30.0 - The distance, in meters, at which the normal map starts to fade out.
* @property {number} max=100.0 - The distance, in meters, at which the normal map is fully faded out.
*/
class NormalMapAttenuationPropertyGroup : public PropertyGroup {
public:
ENTITY_PROPERTY_GROUP_METHODS(NormalMapAttenuationPropertyGroup)

protected:

@NormalMapAttenuation_GROUP_PROPS@

};

#endif // hifi_NormalMapAttenuationPropertyGroup_h
4 changes: 4 additions & 0 deletions libraries/entities/src/ZoneEntityItem.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ZoneAudioPropertyGroup.h"
#include "TonemappingPropertyGroup.h"
#include "AmbientOcclusionPropertyGroup.h"
#include "NormalMapAttenuationPropertyGroup.h"

class ZoneEntityItem : public EntityItem {
public:
Expand Down Expand Up @@ -56,6 +57,7 @@ public:
const ZoneAudioPropertyGroup& getAudioProperties() const { return _audioProperties; }
const TonemappingPropertyGroup& getTonemappingProperties() const { return _tonemappingProperties; }
const AmbientOcclusionPropertyGroup& getAmbientOcclusionProperties() const { return _ambientOcclusionProperties; }
const NormalMapAttenuationPropertyGroup& getNormalMapAttenuationProperties() const { return _normalMapAttenuationProperties; }

void setUserData(const QString& value) override;

Expand All @@ -66,6 +68,7 @@ public:
bool bloomPropertiesChanged() const { return _bloomPropertiesChanged; }
bool tonemappingPropertiesChanged() const { return _tonemappingPropertiesChanged; }
bool ambientOcclusionPropertiesChanged() const { return _ambientOcclusionPropertiesChanged; }
bool normalMapAttenuationPropertiesChanged() const { return _normalMapAttenuationPropertiesChanged; }

void resetRenderingPropertiesChanged();

Expand Down Expand Up @@ -99,6 +102,7 @@ protected:
bool _bloomPropertiesChanged { false };
bool _tonemappingPropertiesChanged { false };
bool _ambientOcclusionPropertiesChanged { false };
bool _normalMapAttenuationPropertiesChanged { false };

static bool _drawZoneBoundaries;
static bool _zonesArePickable;
Expand Down
4 changes: 2 additions & 2 deletions libraries/graphics/src/graphics/MaterialTextures.slh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz);
vec3 normalizedBitangent = cross(normalizedNormal, normalizedTangent);
// attenuate the normal map divergence from the mesh normal based on distance
// The attenuation range [30,100] meters from the eye is arbitrary for now
vec3 localNormal = mix(<$fetchedNormal$>, vec3(0.0, 1.0, 0.0), smoothstep(30.0, 100.0, (-<$fragPosES$>).z));
vec2 normalMapAttenuation = getNormalMapAttenuation();
vec3 localNormal = normalize(mix(<$fetchedNormal$>, vec3(0.0, 1.0, 0.0), smoothstep(normalMapAttenuation.x, normalMapAttenuation.y, (-<$fragPosES$>).z)));
<$normal$> = vec3(normalizedBitangent * localNormal.x + normalizedNormal * localNormal.y + normalizedTangent * localNormal.z);
}
<@endfunc@>
Expand Down
1 change: 1 addition & 0 deletions libraries/networking/src/udt/PacketHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ enum class EntityVersion : PacketVersion {
TextVerticalAlignment,
RemoveScreenshare,
TorusInnerRadius,
NormalMapAttenuation,

// Add new versions above here
NUM_PACKET_TYPE,
Expand Down
10 changes: 9 additions & 1 deletion libraries/render-utils/src/LightingModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "LightingModel.h"
#include "RandomAndNoise.h"
#include "BRDF.h"
#include "ZoneRenderer.h"

#include "render-utils/ShaderConstants.h"

Expand Down Expand Up @@ -283,6 +284,12 @@ bool LightingModel::isShadowEnabled() const {
return (bool)_parametersBuffer.get<Parameters>().enableShadow;
}

void LightingModel::setNormalMapAttenuation(float min, float max) {
Parameters& parameters = _parametersBuffer.edit<Parameters>();
parameters.normalMapAttenuationMin = std::min(min, max);
parameters.normalMapAttenuationMax = max;
}

MakeLightingModel::MakeLightingModel() {
_lightingModel = std::make_shared<LightingModel>();
}
Expand Down Expand Up @@ -322,9 +329,10 @@ void MakeLightingModel::configure(const Config& config) {
void MakeLightingModel::run(const render::RenderContextPointer& renderContext, LightingModelPointer& lightingModel) {

lightingModel = _lightingModel;
ZoneRendererTask::_lightingModel = _lightingModel;

// make sure the enableTexturing flag of the render ARgs is in sync
renderContext->args->_enableTexturing = _lightingModel->isMaterialTexturingEnabled();
renderContext->args->_enableBlendshape = _lightingModel->isBlendshapeEnabled();
renderContext->args->_enableSkinning = _lightingModel->isSkinningEnabled();
}
}
6 changes: 4 additions & 2 deletions libraries/render-utils/src/LightingModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class LightingModel {
void setShadow(bool enable);
bool isShadowEnabled() const;

void setNormalMapAttenuation(float min, float max);

UniformBufferView getParametersBuffer() const { return _parametersBuffer; }
gpu::TexturePointer getAmbientFresnelLUT() const { return _ambientFresnelLUT; }

Expand Down Expand Up @@ -118,8 +120,8 @@ class LightingModel {

float enableAmbientOcclusion { 1.0f };
float enableShadow { 1.0f };
float spare1 { 1.0f };
float spare2 { 1.0f };
float normalMapAttenuationMin { 1.0f };
float normalMapAttenuationMax { 1.0f };

Parameters() {}
};
Expand Down
5 changes: 5 additions & 0 deletions libraries/render-utils/src/LightingModel.slh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct LightingModel {
vec4 _AmbientDirectionalPointSpot;
vec4 _ShowContourObscuranceWireframe;
vec4 _HazeBloomSkinningBlendshape;
vec4 _AmbientOcclusionShadowsNormalMapAttenuationMinMax;
};

// See DeferredShader_BufferSlot in DeferredLightingEffect.cpp
Expand Down Expand Up @@ -90,6 +91,10 @@ float isBlendshapeEnabled() {
return lightingModel._HazeBloomSkinningBlendshape.w;
}

vec2 getNormalMapAttenuation() {
return vec2(lightingModel._AmbientOcclusionShadowsNormalMapAttenuationMinMax.z, lightingModel._AmbientOcclusionShadowsNormalMapAttenuationMinMax.w);
}

<@endfunc@>
<$declareLightingModel()$>

Expand Down
Loading