From 5f881e765093d62d9ecc0031b3883ff31acb5505 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 3 Dec 2015 13:46:29 -0800 Subject: [PATCH] polylines now take color as a uniform --- examples/flowArts/lightTrails.js | 7 ++++--- examples/painting/closePaint.js | 5 ++++- .../painting/whiteboard/whiteboardEntityScript.js | 3 +++ .../src/RenderablePolyLineEntityItem.cpp | 13 +++---------- .../src/RenderablePolyLineEntityItem.h | 1 - libraries/entities-renderer/src/paintStroke.slf | 6 ++---- libraries/entities-renderer/src/paintStroke.slv | 3 --- libraries/entities/src/PolyLineEntityItem.h | 2 +- 8 files changed, 17 insertions(+), 23 deletions(-) diff --git a/examples/flowArts/lightTrails.js b/examples/flowArts/lightTrails.js index 4a7f9de277..e063897eb8 100644 --- a/examples/flowArts/lightTrails.js +++ b/examples/flowArts/lightTrails.js @@ -22,7 +22,7 @@ var RIGHT = 1; var MAX_POINTS_PER_LINE = 50; var LIFETIME = 6000; -var DRAWING_DEPTH = 0.6; +var DRAWING_DEPTH = 0.8; var LINE_DIMENSIONS = 20; var lightZone = Entities.addEntity({ @@ -65,7 +65,7 @@ var colorPalette = [{ blue: 129 }]; -var STROKE_WIDTH = 0.03; +var STROKE_WIDTH = 0.04; function controller(side, triggerAction) { this.triggerHeld = false; @@ -83,7 +83,7 @@ function controller(side, triggerAction) { z: 20 }, color: colorPalette[randInt(0, colorPalette.length)], - intensity: 20 + intensity: 5 }); this.trail = Entities.addEntity({ @@ -93,6 +93,7 @@ function controller(side, triggerAction) { y: LINE_DIMENSIONS, z: LINE_DIMENSIONS }, + color: {red: 255, green: 255, blue: 255}, textures: texture, lifetime: LIFETIME }); diff --git a/examples/painting/closePaint.js b/examples/painting/closePaint.js index 60b4ac2e25..bea4d9c9aa 100644 --- a/examples/painting/closePaint.js +++ b/examples/painting/closePaint.js @@ -43,6 +43,8 @@ var MAX_STROKE_WIDTH = 0.04; var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(Camera.getOrientation()))); +var textureURL = "https://s3.amazonaws.com/hifi-public/eric/textures/paintStrokes/paintStroke.png"; + function MyController(hand, triggerAction) { @@ -148,7 +150,8 @@ function MyController(hand, triggerAction) { y: 50, z: 50 }, - lifetime: 200 + lifetime: 200, + textures: textureURL }); this.strokePoints = []; this.strokeNormals = []; diff --git a/examples/painting/whiteboard/whiteboardEntityScript.js b/examples/painting/whiteboard/whiteboardEntityScript.js index 61d7291e11..374ec8b873 100644 --- a/examples/painting/whiteboard/whiteboardEntityScript.js +++ b/examples/painting/whiteboard/whiteboardEntityScript.js @@ -29,6 +29,8 @@ var MIN_STROKE_WIDTH = 0.0005; var MAX_STROKE_WIDTH = 0.03; + var textureURL = "https://s3.amazonaws.com/hifi-public/eric/textures/paintStrokes/paintStroke.png"; + var TRIGGER_CONTROLS = [ Controller.Standard.LT, Controller.Standard.RT, @@ -168,6 +170,7 @@ type: "PolyLine", name: "paintStroke", color: this.strokeColor, + textures: "https://s3.amazonaws.com/hifi-public/eric/textures/paintStrokes/paintStroke.png", dimensions: { x: 50, y: 50, diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index bfb27a93b9..d38da0d3f7 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -25,7 +25,7 @@ struct PolyLineUniforms { - float time; + glm::vec3 color; }; EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { @@ -34,7 +34,6 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& enti RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : PolyLineEntityItem(entityItemID, properties), -_counter(0.0f), _numVertices(0) { _vertices = QVector(0.0f); @@ -49,13 +48,11 @@ int32_t RenderablePolyLineEntityItem::PAINTSTROKE_GPU_SLOT; void RenderablePolyLineEntityItem::createPipeline() { static const int NORMAL_OFFSET = 12; - static const int COLOR_OFFSET = 24; - static const int TEXTURE_OFFSET = 28; + static const int TEXTURE_OFFSET = 24; _format.reset(new gpu::Stream::Format()); _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); _format->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), NORMAL_OFFSET); - _format->setAttribute(gpu::Stream::COLOR, 0, gpu::Element::COLOR_RGBA_32, COLOR_OFFSET); _format->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), TEXTURE_OFFSET); auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(paintStroke_vert))); @@ -91,14 +88,12 @@ void RenderablePolyLineEntityItem::updateGeometry() { _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); - _verticesBuffer->append(sizeof(int), (gpu::Byte*)&_color); _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); vertexIndex++; uv.y = 1.0f; _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex)); _verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i)); - _verticesBuffer->append(sizeof(int), (gpu::Byte*)_color); _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); vertexIndex++; @@ -154,10 +149,8 @@ void RenderablePolyLineEntityItem::updateVertices() { void RenderablePolyLineEntityItem::update(const quint64& now) { PolyLineUniforms uniforms; - _counter += 0.01; - uniforms.time = _counter; + uniforms.color = toGlm(getXColor()); memcpy(&_uniformBuffer.edit(), &uniforms, sizeof(PolyLineUniforms)); - if (_pointsChanged || _strokeWidthsChanged || _normalsChanged) { updateVertices(); updateGeometry(); diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.h b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.h index 658614e72e..411b856d91 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.h @@ -47,7 +47,6 @@ protected: gpu::BufferView _uniformBuffer; unsigned int _numVertices; QVector _vertices; - float _counter; }; diff --git a/libraries/entities-renderer/src/paintStroke.slf b/libraries/entities-renderer/src/paintStroke.slf index 6c51b4c979..1a87f84bfd 100644 --- a/libraries/entities-renderer/src/paintStroke.slf +++ b/libraries/entities-renderer/src/paintStroke.slf @@ -21,12 +21,11 @@ uniform sampler2D originalTexture; // the interpolated normal in vec3 interpolatedNormal; in vec2 varTexcoord; -in vec4 varColor; flat in int varVertexId; struct PolyLineUniforms { - float time; + vec3 color; }; uniform polyLineBuffer { @@ -38,11 +37,10 @@ void main(void) { vec4 texel = texture(originalTexture, varTexcoord); int frontCondition = 1 -int(gl_FrontFacing) * 2; - vec3 color = varColor.rgb; packDeferredFragmentTranslucent( interpolatedNormal * frontCondition, texel.a, - texel.rgb, + polyline.color * texel.rgb, vec3(0.01, 0.01, 0.01), 10.0); } diff --git a/libraries/entities-renderer/src/paintStroke.slv b/libraries/entities-renderer/src/paintStroke.slv index 25f046456a..5c368f9c0f 100644 --- a/libraries/entities-renderer/src/paintStroke.slv +++ b/libraries/entities-renderer/src/paintStroke.slv @@ -23,15 +23,12 @@ out vec3 interpolatedNormal; //the diffuse texture out vec2 varTexcoord; -out vec4 varColor; flat out int varVertexId; void main(void) { varTexcoord = inTexCoord0.st; - // pass along the diffuse color - varColor = inColor; varVertexId = gl_VertexID; // standard transform diff --git a/libraries/entities/src/PolyLineEntityItem.h b/libraries/entities/src/PolyLineEntityItem.h index 1610bf87b5..20549d1bbd 100644 --- a/libraries/entities/src/PolyLineEntityItem.h +++ b/libraries/entities/src/PolyLineEntityItem.h @@ -49,7 +49,7 @@ class PolyLineEntityItem : public EntityItem { memcpy(_color, value, sizeof(_color)); } void setColor(const xColor& value) { - + _color[RED_INDEX] = value.red; _color[GREEN_INDEX] = value.green; _color[BLUE_INDEX] = value.blue;