Skip to content

Commit ab39980

Browse files
normal map attenuation properties
1 parent adacca8 commit ab39980

19 files changed

+253
-10
lines changed

libraries/entities-renderer/src/RenderableZoneEntityItem.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <procedural/ProceduralSkybox.h>
2323
#include <LightPayload.h>
2424
#include <DeferredLightingEffect.h>
25+
#include <ZoneRenderer.h>
2526

2627
#include "EntityTreeRenderer.h"
2728

@@ -239,6 +240,13 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) {
239240
} else if (_ambientOcclusionMode == COMPONENT_MODE_ENABLED) {
240241
_ambientOcclusionStage->_currentFrame.pushElement(_ambientOcclusionIndex);
241242
}
243+
244+
// Hack: CullTest::_containingZones is empty at the beginning of a frame, and our zones render in order,
245+
// so we know we're in the first/smallest zone if CullTest::_containingZones.empty()
246+
if (CullTest::_containingZones.empty() && ZoneRendererTask::_lightingModel) {
247+
ZoneRendererTask::_lightingModel->setNormalMapAttenuation(_normalMapAttenuationProperties.getMin(),
248+
_normalMapAttenuationProperties.getMax());
249+
}
242250
}
243251

244252
CullTest::_containingZones.insert(_entityID);
@@ -273,6 +281,7 @@ void ZoneEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointe
273281
bool bloomChanged = entity->bloomPropertiesChanged();
274282
bool tonemappingChanged = entity->tonemappingPropertiesChanged();
275283
bool ambientOcclusionChanged = entity->ambientOcclusionPropertiesChanged();
284+
bool normalMapAttenuationChanged = entity->normalMapAttenuationPropertiesChanged();
276285
entity->resetRenderingPropertiesChanged();
277286

278287
if (transformChanged) {
@@ -322,6 +331,10 @@ void ZoneEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointe
322331
updateAmbientOcclusionFromEntity(entity);
323332
}
324333

334+
if (normalMapAttenuationChanged) {
335+
_normalMapAttenuationProperties = entity->getNormalMapAttenuationProperties();
336+
}
337+
325338
bool visuallyReady = true;
326339
uint32_t skyboxMode = entity->getSkyboxMode();
327340
if (skyboxMode == COMPONENT_MODE_ENABLED && !_skyboxTextureURL.isEmpty()) {
@@ -344,7 +357,8 @@ bool ZoneEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoint
344357
entity->bloomPropertiesChanged() ||
345358
entity->skyboxPropertiesChanged() ||
346359
entity->tonemappingPropertiesChanged() ||
347-
entity->ambientOcclusionPropertiesChanged()) {
360+
entity->ambientOcclusionPropertiesChanged() ||
361+
entity->normalMapAttenuationPropertiesChanged()) {
348362

349363
return true;
350364
}

libraries/entities-renderer/src/RenderableZoneEntityItem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class ZoneEntityRenderer : public TypedEntityRenderer<ZoneEntityItem> {
124124
BloomPropertyGroup _bloomProperties;
125125
TonemappingPropertyGroup _tonemappingProperties;
126126
AmbientOcclusionPropertyGroup _ambientOcclusionProperties;
127+
NormalMapAttenuationPropertyGroup _normalMapAttenuationProperties;
127128

128129
// More attributes used for rendering:
129130
QString _ambientTextureURL;

libraries/entities/src/EntityItemGroupProperties.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ enum:AMBIENT_OCCLUSION_AO_OBSCURANCE_LEVEL prop:aoObscuranceLevel type:float def
8080
enum:AMBIENT_OCCLUSION_AO_FALLOFF_ANGLE prop:aoFalloffAngle type:float default:0.25f min:0.0f max:1.0f,
8181
enum:AMBIENT_OCCLUSION_AO_SAMPLING_AMOUNT prop:aoSamplingAmount type:float default:0.5f min:0.0f max:1.0f,
8282
enum:AMBIENT_OCCLUSION_SSAO_NUM_SPIRAL_TURNS prop:ssaoNumSpiralTurns type:float default:7.0f min:0.0f max:10.0f,
83+
normalMapAttenuation
84+
enum:NORMAL_MAP_ATTENUATION_MIN prop:min type:float default:30.0f min:0.0f max:16000.0f,
85+
enum:NORMAL_MAP_ATTENUATION_MAX prop:max type:float default:100.0f min:0.0f max:16000.0f,
8386
ring type:RingGizmo
8487
enum:START_ANGLE prop:startAngle type:float default:0.0f min:RingGizmoPropertyGroup::MIN_ANGLE max:RingGizmoPropertyGroup::MAX_ANGLE,
8588
enum:END_ANGLE prop:endAngle type:float default:360.0f min:RingGizmoPropertyGroup::MIN_ANGLE max:RingGizmoPropertyGroup::MAX_ANGLE,

libraries/entities/src/EntityItemProperties.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ group:bloom recordChange,
173173
group:audio type:ZoneAudio,
174174
group:tonemapping recordChange,
175175
group:ambientOcclusion recordChange,
176+
group:normalMapAttenuation recordChange,
176177
enum:FLYING_ALLOWED prop:flyingAllowed type:bool default:ZoneEntityItem::DEFAULT_FLYING_ALLOWED basicProp,
177178
enum:GHOSTING_ALLOWED prop:ghostingAllowed type:bool default:ZoneEntityItem::DEFAULT_GHOSTING_ALLOWED basicProp,
178179
enum:FILTER_URL prop:filterURL type:QString default:ZoneEntityItem::DEFAULT_FILTER_URL urlPermission,

libraries/entities/src/EntityItemPropertiesDocs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@
894894
*
895895
* @property {Entities.ComponentMode} tonemappingMode="inherit" - Configures the tonemapping in the zone.
896896
* @property {Entities.Tonemapping} tonemapping - The tonemapping properties of the zone.
897+
* @property {Entities.NormalMapAttenuation} normalMapAttenuation - The normal map attenuation properties of the zone.
897898
*
898899
* @property {Entities.ComponentMode} ambientOcclusionMode="inherit" - Configures the ambient occlusion in the zone.
899900
* @property {Entities.AmbientOcclusion} ambientOcclusion - The ambient occlusion properties of the zone.

libraries/entities/src/EntityPropertyFlags.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ enum EntityPropertyList : uint16_t {
8282
PROP_DERIVED_52,
8383
PROP_DERIVED_53,
8484
PROP_DERIVED_54,
85+
PROP_DERIVED_55,
86+
PROP_DERIVED_56,
8587

8688
PROP_AFTER_LAST_ITEM,
8789

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//
2+
// NormalMapAttenuationPropertyGroup.cpp
3+
// libraries/entities/src
4+
//
5+
// Created by HifiExperiments on 10/18/24
6+
// Copyright 2024 Overte e.V.
7+
//
8+
// Distributed under the Apache License, Version 2.0.
9+
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10+
// SPDX-License-Identifier: Apache-2.0
11+
//
12+
13+
#include "NormalMapAttenuationPropertyGroup.h"
14+
15+
#include <OctreePacketData.h>
16+
17+
#include "EntityItemProperties.h"
18+
19+
void NormalMapAttenuationPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, ScriptValue& properties, ScriptEngine* engine,
20+
bool skipDefaults, EntityItemProperties& defaultEntityProperties, bool returnNothingOnEmptyPropertyFlags, bool isMyOwnAvatarEntity) const {
21+
22+
@NormalMapAttenuation_GROUP_COPY_TO_SCRIPT@
23+
24+
}
25+
26+
void NormalMapAttenuationPropertyGroup::copyFromScriptValue(const ScriptValue& object, const QSet<QString> &namesSet, bool& _defaultSettings) {
27+
28+
@NormalMapAttenuation_GROUP_COPY_FROM_SCRIPT@
29+
30+
}
31+
32+
void NormalMapAttenuationPropertyGroup::merge(const NormalMapAttenuationPropertyGroup& other) {
33+
34+
@NormalMapAttenuation_GROUP_MERGE@
35+
36+
}
37+
38+
void NormalMapAttenuationPropertyGroup::debugDump() const {
39+
40+
@NormalMapAttenuation_GROUP_DEBUG_DUMP@
41+
42+
}
43+
44+
void NormalMapAttenuationPropertyGroup::listChangedProperties(QList<QString>& out) {
45+
46+
@NormalMapAttenuation_GROUP_LIST_CHANGED@
47+
48+
}
49+
50+
bool NormalMapAttenuationPropertyGroup::appendToEditPacket(OctreePacketData* packetData,
51+
EntityPropertyFlags& requestedProperties,
52+
EntityPropertyFlags& propertyFlags,
53+
EntityPropertyFlags& propertiesDidntFit,
54+
int& propertyCount,
55+
OctreeElement::AppendState& appendState) const {
56+
57+
bool successPropertyFits = true;
58+
59+
@NormalMapAttenuation_GROUP_APPEND@
60+
61+
return successPropertyFits;
62+
}
63+
64+
bool NormalMapAttenuationPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt , int& processedBytes) {
65+
66+
int bytesRead = 0;
67+
bool overwriteLocalData = true;
68+
bool somethingChanged = false;
69+
70+
@NormalMapAttenuation_GROUP_READ@
71+
72+
@NormalMapAttenuation_GROUP_DECODE_CHANGED@
73+
74+
processedBytes += bytesRead;
75+
76+
return somethingChanged;
77+
}
78+
79+
void NormalMapAttenuationPropertyGroup::markAllChanged() {
80+
81+
@NormalMapAttenuation_GROUP_MARK_CHANGED@
82+
83+
}
84+
85+
EntityPropertyFlags NormalMapAttenuationPropertyGroup::getChangedProperties() const {
86+
EntityPropertyFlags changedProperties;
87+
88+
@NormalMapAttenuation_GROUP_CHANGED_PROPERTIES@
89+
90+
return changedProperties;
91+
}
92+
93+
void NormalMapAttenuationPropertyGroup::getProperties(EntityItemProperties& properties) const {
94+
95+
@NormalMapAttenuation_GROUP_COPY_TO@
96+
97+
}
98+
99+
bool NormalMapAttenuationPropertyGroup::setProperties(const EntityItemProperties& properties) {
100+
bool somethingChanged = false;
101+
102+
@NormalMapAttenuation_GROUP_SET_FROM@
103+
104+
return somethingChanged;
105+
}
106+
107+
EntityPropertyFlags NormalMapAttenuationPropertyGroup::getEntityProperties(EncodeBitstreamParams& params) const {
108+
EntityPropertyFlags requestedProperties;
109+
110+
@NormalMapAttenuation_REQUESTED_PROPS@
111+
112+
return requestedProperties;
113+
}
114+
115+
int NormalMapAttenuationPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
116+
ReadBitstreamToTreeParams& args,
117+
EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
118+
bool& somethingChanged) {
119+
120+
int bytesRead = 0;
121+
const unsigned char* dataAt = data;
122+
123+
@NormalMapAttenuation_GROUP_READ@
124+
125+
return bytesRead;
126+
}
127+
128+
void NormalMapAttenuationPropertyGroup::addPropertyMap(QHash<QString, EntityPropertyInfo>& _propertyInfos,
129+
QHash<EntityPropertyList, QString>& _enumsToPropertyStrings) {
130+
131+
@NormalMapAttenuation_GROUP_ADD_TO_MAP@
132+
133+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// NormalMapAttenuationPropertyGroup.h
3+
// libraries/entities/src
4+
//
5+
// Created by HifiExperiments on 10/18/24
6+
// Copyright 2024 Overte e.V.
7+
//
8+
// Distributed under the Apache License, Version 2.0.
9+
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10+
// SPDX-License-Identifier: Apache-2.0
11+
//
12+
13+
#ifndef hifi_NormalMapAttenuationPropertyGroup_h
14+
#define hifi_NormalMapAttenuationPropertyGroup_h
15+
16+
#include "PropertyGroup.h"
17+
#include "EntityItemPropertiesMacros.h"
18+
19+
class EntityItemProperties;
20+
class EncodeBitstreamParams;
21+
class OctreePacketData;
22+
class EntityTreeElementExtraEncodeData;
23+
class ReadBitstreamToTreeParams;
24+
class ScriptEngine;
25+
class ScriptValue;
26+
27+
/*@jsdoc
28+
* NormalMapAttenuation is defined by the following properties:
29+
* @typedef {object} Entities.NormalMapAttenuation
30+
* @property {number} min=30.0 - The distance, in meters, at which the normal map starts to fade out.
31+
* @property {number} max=100.0 - The distance, in meters, at which the normal map is fully faded out.
32+
*/
33+
class NormalMapAttenuationPropertyGroup : public PropertyGroup {
34+
public:
35+
ENTITY_PROPERTY_GROUP_METHODS(NormalMapAttenuationPropertyGroup)
36+
37+
protected:
38+
39+
@NormalMapAttenuation_GROUP_PROPS@
40+
41+
};
42+
43+
#endif // hifi_NormalMapAttenuationPropertyGroup_h

libraries/entities/src/ZoneEntityItem.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "ZoneAudioPropertyGroup.h"
2626
#include "TonemappingPropertyGroup.h"
2727
#include "AmbientOcclusionPropertyGroup.h"
28+
#include "NormalMapAttenuationPropertyGroup.h"
2829

2930
class ZoneEntityItem : public EntityItem {
3031
public:
@@ -56,6 +57,7 @@ public:
5657
const ZoneAudioPropertyGroup& getAudioProperties() const { return _audioProperties; }
5758
const TonemappingPropertyGroup& getTonemappingProperties() const { return _tonemappingProperties; }
5859
const AmbientOcclusionPropertyGroup& getAmbientOcclusionProperties() const { return _ambientOcclusionProperties; }
60+
const NormalMapAttenuationPropertyGroup& getNormalMapAttenuationProperties() const { return _normalMapAttenuationProperties; }
5961

6062
void setUserData(const QString& value) override;
6163

@@ -66,6 +68,7 @@ public:
6668
bool bloomPropertiesChanged() const { return _bloomPropertiesChanged; }
6769
bool tonemappingPropertiesChanged() const { return _tonemappingPropertiesChanged; }
6870
bool ambientOcclusionPropertiesChanged() const { return _ambientOcclusionPropertiesChanged; }
71+
bool normalMapAttenuationPropertiesChanged() const { return _normalMapAttenuationPropertiesChanged; }
6972

7073
void resetRenderingPropertiesChanged();
7174

@@ -99,6 +102,7 @@ protected:
99102
bool _bloomPropertiesChanged { false };
100103
bool _tonemappingPropertiesChanged { false };
101104
bool _ambientOcclusionPropertiesChanged { false };
105+
bool _normalMapAttenuationPropertiesChanged { false };
102106

103107
static bool _drawZoneBoundaries;
104108
static bool _zonesArePickable;

libraries/graphics/src/graphics/MaterialTextures.slh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz);
2424
vec3 normalizedBitangent = cross(normalizedNormal, normalizedTangent);
2525
// attenuate the normal map divergence from the mesh normal based on distance
26-
// The attenuation range [30,100] meters from the eye is arbitrary for now
27-
vec3 localNormal = mix(<$fetchedNormal$>, vec3(0.0, 1.0, 0.0), smoothstep(30.0, 100.0, (-<$fragPosES$>).z));
26+
vec2 normalMapAttenuation = getNormalMapAttenuation();
27+
vec3 localNormal = normalize(mix(<$fetchedNormal$>, vec3(0.0, 1.0, 0.0), smoothstep(normalMapAttenuation.x, normalMapAttenuation.y, (-<$fragPosES$>).z)));
2828
<$normal$> = vec3(normalizedBitangent * localNormal.x + normalizedNormal * localNormal.y + normalizedTangent * localNormal.z);
2929
}
3030
<@endfunc@>

0 commit comments

Comments
 (0)