Skip to content

Commit

Permalink
Added pixelSize property
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Nov 14, 2015
1 parent ae4a19d commit c9d6cf8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
23 changes: 21 additions & 2 deletions Source/Scene/PointAppearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ define([
* @param {String} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.
* @param {RenderState} [options.renderState] Optional render state to override the default render state.
* @param {Object} [options.uniforms] Additional uniforms that are used by the vertex and fragment shaders.
* @param {Number} [options.pointSize] Point size in pixels.
* @param {Color} [options.highlightColor] Color multiplier in the fragment shader. The alpha channel is used for alpha blending when translucency is enabled.
*
* @example
* var primitive = new Cesium.Primitive({
Expand All @@ -58,6 +60,8 @@ define([
this._vertexShaderSource = defaultValue(options.vertexShaderSource, PointAppearanceVS);
this._fragmentShaderSource = defaultValue(options.fragmentShaderSource, PointAppearanceFS);
this._renderState = Appearance.getDefaultRenderState(false, false, options.renderState);
this._pointSize = defaultValue(options.pointSize, 2.0);
this._highlightColor = defined(options.highlightColor) ? options.highlightColor : new Color();

/**
* This property is part of the {@link Appearance} interface, but is not
Expand All @@ -82,8 +86,8 @@ define([
* @private
*/
this.uniforms = {
highlightColor : new Color(),
pointSize : 2.0
highlightColor : this._highlightColor,
pointSize : this._pointSize
};

// Combine default uniforms and additional uniforms
Expand Down Expand Up @@ -168,6 +172,21 @@ define([
get : function() {
return PointAppearance.VERTEX_FORMAT;
}
},

/**
* The size in pixels used when rendering the primitive. This helps calculate an accurate
* bounding volume for point rendering and other appearances that are defined in pixel sizes.
*
* @memberof PointAppearance.prototype
*
* @type {Number}
* @readonly
*/
pixelSize : {
get : function() {
return this._pointSize;
}
}
});

Expand Down
14 changes: 7 additions & 7 deletions Source/Scene/Primitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -1227,17 +1227,17 @@ define([
}

function updateBoundingVolumes(primitive, frameState) {
// Update bounding volume when using PointAppearance and PointGeometry.
// The point size in meters will vary per frame, so update bounding volume accordingly.
var uniforms = primitive.appearance.uniforms;
if (defined(uniforms) && defined(uniforms.pointSize)) {
// Update bounding volumes for primitives that are sized in pixels.
// The pixel size in meters varies per based on the distance from the camera.
var pixelSize = primitive.appearance.pixelSize;
if (defined(pixelSize)) {
var length = primitive._boundingSpheres.length;
for (var i = 0; i < length; ++i) {
var boundingSphere = primitive._boundingSpheres[i];
var boundingSphereWC = primitive._boundingSphereWC[i];
var pixelSize = frameState.camera.getPixelSize(boundingSphere, frameState.context.drawingBufferWidth, frameState.context.drawingBufferHeight);
var size = pixelSize * uniforms.pointSize;
boundingSphereWC.radius = boundingSphere.radius + size;
var pixelSizeInMeters = frameState.camera.getPixelSize(boundingSphere, frameState.context.drawingBufferWidth, frameState.context.drawingBufferHeight);
var sizeInMeters = pixelSizeInMeters * pixelSize;
boundingSphereWC.radius = boundingSphere.radius + sizeInMeters;
}
}
}
Expand Down

0 comments on commit c9d6cf8

Please sign in to comment.