Skip to content
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
40 changes: 36 additions & 4 deletions libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,25 @@ void PolyLineEntityRenderer::updateModelTransformAndBound(const EntityItemPointe
}

bool PolyLineEntityRenderer::isTransparent() const {
return _glow || (_textureLoaded && _texture->getGPUTexture() && _texture->getGPUTexture()->getUsage().isAlpha());
// Glow always forces transparency
if (_glow) {
return true;
}

// Transparent if any per-point alpha is less than fully opaque
for (const auto& alpha : _alphas) {
if (alpha < 1.0f) {
return true;
}
}

// If there are fewer stroke alphas than points, the fallback alpha will apply
if (_alphas.size() < _points.size() && _alpha < 1.0f) {
return true;
}

// Transparent if the texture has an alpha channel (only if texture is loaded)
return (_textureLoaded && _texture->getGPUTexture() && _texture->getGPUTexture()->getUsage().isAlpha());
}

void PolyLineEntityRenderer::buildPipelines() {
Expand Down Expand Up @@ -123,7 +141,7 @@ ShapeKey PolyLineEntityRenderer::getShapeKey() {
}

bool PolyLineEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const {
if (entity->pointsChanged() || entity->widthsChanged() || entity->normalsChanged() || entity->texturesChanged() || entity->colorsChanged()) {
if (entity->pointsChanged() || entity->widthsChanged() || entity->normalsChanged() || entity->texturesChanged() || entity->colorsChanged() || entity->alphasChanged()) {
return true;
}

Expand All @@ -144,6 +162,7 @@ void PolyLineEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPo
auto widthsChanged = entity->widthsChanged();
auto normalsChanged = entity->normalsChanged();
auto colorsChanged = entity->colorsChanged();
auto alphasChanged = entity->alphasChanged();

bool isUVModeStretch = entity->getIsUVModeStretch();
bool glow = entity->getGlow();
Expand Down Expand Up @@ -197,13 +216,22 @@ void PolyLineEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPo
_colors = entity->getStrokeColors();
_color = toGlm(entity->getColor());
}
if (alphasChanged) {
_alphas = entity->getStrokeAlphas();
_alpha = entity->getAlpha();
}

bool uvModeStretchChanged = _isUVModeStretch != isUVModeStretch;
_isUVModeStretch = isUVModeStretch;

if (uvModeStretchChanged || pointsChanged || widthsChanged || normalsChanged || colorsChanged || textureChanged || faceCameraChanged) {
if (uvModeStretchChanged || pointsChanged || widthsChanged || normalsChanged || colorsChanged || alphasChanged || textureChanged || faceCameraChanged) {
updateGeometry();
}

auto sampler = entity->getSampler();
if (_sampler != sampler) {
_sampler = sampler;
}
}

void PolyLineEntityRenderer::updateGeometry() {
Expand Down Expand Up @@ -269,6 +297,7 @@ void PolyLineEntityRenderer::updateGeometry() {

// Color
glm::vec3 color = i < _colors.length() ? _colors[i] : _color;
float alpha = i < _alphas.length() ? _alphas[i] : _alpha;

// Normal
glm::vec3 normal = _normals[i];
Expand All @@ -291,7 +320,7 @@ void PolyLineEntityRenderer::updateGeometry() {
}
}

PolylineVertex vertex = { glm::vec4(point, uCoord), glm::vec4(color, 1.0f), glm::vec4(normal, 0.0f), glm::vec4(binormal, 0.5f * width) };
PolylineVertex vertex = { glm::vec4(point, uCoord), glm::vec4(color, alpha), glm::vec4(normal, 0.0f), glm::vec4(binormal, 0.5f * width) };
vertices.push_back(vertex);
}

Expand Down Expand Up @@ -336,6 +365,9 @@ void PolyLineEntityRenderer::doRender(RenderArgs* args) {
if (args->_renderMode == Args::RenderMode::DEFAULT_RENDER_MODE || args->_renderMode == Args::RenderMode::MIRROR_RENDER_MODE) {
_prevRenderTransform = transform;
}
if (_textureLoaded && texture) {
texture->setSampler(_sampler);
}
batch.setResourceTexture(0, texture);
batch.draw(gpu::TRIANGLE_STRIP, (gpu::uint32)(2 * _numVertices), 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class PolyLineEntityRenderer : public TypedEntityRenderer<PolyLineEntityItem> {
QVector<glm::vec3> _normals;
QVector<glm::vec3> _colors;
glm::vec3 _color;
QVector<float> _alphas;
float _alpha;
QVector<float> _widths;

NetworkTexturePointer _texture;
Expand All @@ -54,6 +56,7 @@ class PolyLineEntityRenderer : public TypedEntityRenderer<PolyLineEntityItem> {
bool _isUVModeStretch { false };
bool _faceCamera { false };
bool _glow { false };
Sampler _sampler;

size_t _numVertices { 0 };
gpu::BufferPointer _polylineDataBuffer;
Expand Down
3 changes: 3 additions & 0 deletions libraries/entities/src/EntityItemProperties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,17 @@ enum:COLOR prop:color type:u8vec3Color default:ENTITY_ITEM_DEFAULT_COLOR common
enum:LINE_POINTS prop:linePoints type:qVectorVec3 default:ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC common noGetterSetterProp,
PolyLine
enum:COLOR prop:color type:u8vec3Color default:ENTITY_ITEM_DEFAULT_COLOR common,
enum:ALPHA prop:alpha type:float default:ENTITY_ITEM_DEFAULT_ALPHA min:0.0f max:1.0f common,
enum:TEXTURES prop:textures type:QString default:"" common,
enum:LINE_POINTS prop:linePoints type:qVectorVec3 default:ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC common,
enum:STROKE_WIDTHS prop:strokeWidths type:qVectorFloat default:QVector<float>(),
enum:STROKE_NORMALS prop:normals type:qVectorVec3 default:ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC,
enum:STROKE_COLORS prop:strokeColors type:qVectorVec3 default:ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC,
enum:STROKE_ALPHAS prop:strokeAlphas type:qVectorFloat default:QVector<float>(),
enum:IS_UV_MODE_STRETCH prop:isUVModeStretch type:bool default:true renderProp,
enum:LINE_GLOW prop:glow type:bool default:false renderProp,
enum:LINE_FACE_CAMERA prop:faceCamera type:bool default:false renderProp,
enum:SAMPLER prop:sampler type:Sampler default:ENTITY_ITEM_DEFAULT_SAMPLER common renderProp,
Shape
enum:COLOR prop:color type:u8vec3Color default:ENTITY_ITEM_DEFAULT_COLOR common renderProp,
enum:ALPHA prop:alpha type:float default:ENTITY_ITEM_DEFAULT_ALPHA min:0.0f max:1.0f common renderProp,
Expand Down
6 changes: 6 additions & 0 deletions libraries/entities/src/EntityItemPropertiesDocs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@
* <p><strong>Warning:</strong> The ordinate values are in the range <code>0.0</code> &ndash; <code>1.0</code>.</p>
* @property {Color} color=255,255,255 - Used as the color for each point if <code>strokeColors</code> doesn't have a value for
* the point.
* @property {float[]} strokeAlphas=[]] - The base alphas of each point, with values in the range <code>0.0</code>
* &ndash; <code>1.0</code>. These alphas are multiplied with the alpha of the texture. If there are more line
* points than stroke alphas, the <code>alpha</code> property value is used for the remaining points.
* @property {float} alpha=1.0 - Used as the alpha for each point if <code>strokeAlphas</code> doesn't have a value for
* the point.
* @property {string} textures="" - The URL of a JPG or PNG texture to use for the lines. If you want transparency, use PNG
* format.
* @property {boolean} isUVModeStretch=true - <code>true</code> if the texture is stretched to fill the whole line,
Expand All @@ -574,6 +579,7 @@
* <code>false</code> if it doesn't.
* @property {boolean} faceCamera=false - <code>true</code> if each line segment rotates to face the camera, <code>false</code>
* if they don't.
* @property {Entities.Sampler} sampler - The texture sampler used to render the image.
* @example <caption>Draw a textured "V".</caption>
* var entity = Entities.addEntity({
* type: "PolyLine",
Expand Down
26 changes: 26 additions & 0 deletions libraries/entities/src/PolyLineEntityItem.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ void PolyLineEntityItem::setStrokeColors(const QVector<glm::vec3>& strokeColors)
});
}

void PolyLineEntityItem::setStrokeAlphas(const QVector<float>& strokeAlphas) {
withWriteLock([&] {
_strokeAlphas = strokeAlphas;
_alphasChanged = true;
});
}

void PolyLineEntityItem::computeAndUpdateDimensions() {
QVector<glm::vec3> points;
QVector<float> widths;
Expand Down Expand Up @@ -191,6 +198,12 @@ QVector<glm::vec3> PolyLineEntityItem::getStrokeColors() const {
});
}

QVector<float> PolyLineEntityItem::getStrokeAlphas() const {
return resultWithReadLock<QVector<float>>([&] {
return _strokeAlphas;
});
}

QVector<float> PolyLineEntityItem::getStrokeWidths() const {
return resultWithReadLock<QVector<float>>([&] {
return _strokeWidths;
Expand Down Expand Up @@ -224,3 +237,16 @@ glm::u8vec3 PolyLineEntityItem::getColor() const {
return _color;
});
}

void PolyLineEntityItem::setAlpha(const float value) {
withWriteLock([&] {
_alpha = value;
_alphasChanged = true;
});
}

float PolyLineEntityItem::getAlpha() const {
return resultWithReadLock<float>([&] {
return _alpha;
});
}
4 changes: 3 additions & 1 deletion libraries/entities/src/PolyLineEntityItem.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public:
bool pointsChanged() const { return _pointsChanged; }
bool normalsChanged() const { return _normalsChanged; }
bool colorsChanged() const { return _colorsChanged; }
bool alphasChanged() const { return _alphasChanged; }
bool widthsChanged() const { return _widthsChanged; }
bool texturesChanged() const { return _texturesChanged; }

void resetTexturesChanged() { _texturesChanged = false; }
void resetPolyLineChanged() { _colorsChanged = _widthsChanged = _normalsChanged = _pointsChanged = false; }
void resetPolyLineChanged() { _colorsChanged = _alphasChanged = _widthsChanged = _normalsChanged = _pointsChanged = false; }

void computeTightLocalBoundingBox(AABox& box) const;
private:
Expand All @@ -48,6 +49,7 @@ protected:
bool _pointsChanged { false };
bool _normalsChanged { false };
bool _colorsChanged { false };
bool _alphasChanged { false };
bool _widthsChanged { false };
bool _texturesChanged { false };
};
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 @@ -371,6 +371,7 @@ enum class EntityVersion : PacketVersion {
Fading,
Sampler,
CanvasEntity,
PolylineAlphaAndSampler,

// Add new versions above here
NUM_PACKET_TYPE,
Expand Down
Loading