Skip to content
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

Extend GroundPrimitive shadow volume based on screen space error #4751

Merged
merged 20 commits into from
Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from 9 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
10 changes: 7 additions & 3 deletions Source/Core/CircleGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ define([
extrudedHeight : options.extrudedHeight,
granularity : options.granularity,
vertexFormat : options.vertexFormat,
stRotation : options.stRotation
stRotation : options.stRotation,
shadowVolume: options.shadowVolume
};
this._ellipseGeometry = new EllipseGeometry(ellipseGeometryOptions);
this._workerName = 'createCircleGeometry';
Expand Down Expand Up @@ -113,7 +114,8 @@ define([
vertexFormat : new VertexFormat(),
stRotation : undefined,
semiMajorAxis : undefined,
semiMinorAxis : undefined
semiMinorAxis : undefined,
shadowVolume: undefined
};

/**
Expand All @@ -133,6 +135,7 @@ define([
scratchOptions.granularity = ellipseGeometry._granularity;
scratchOptions.vertexFormat = VertexFormat.clone(ellipseGeometry._vertexFormat, scratchOptions.vertexFormat);
scratchOptions.stRotation = ellipseGeometry._stRotation;
scratchOptions.shadowVolume = ellipseGeometry._shadowVolume;

if (!defined(result)) {
scratchOptions.radius = ellipseGeometry._semiMajorAxis;
Expand Down Expand Up @@ -173,7 +176,8 @@ define([
granularity : granularity,
extrudedHeight : minHeight,
height : maxHeight,
vertexFormat : VertexFormat.POSITION_ONLY
vertexFormat : VertexFormat.POSITION_ONLY,
shadowVolume: true
});
};

Expand Down
64 changes: 47 additions & 17 deletions Source/Core/CorridorGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ define([

function computePositionsExtruded(params, vertexFormat) {
var topVertexFormat = new VertexFormat({
position : vertexFormat.positon,
normal : (vertexFormat.normal || vertexFormat.binormal),
position : vertexFormat.position,
normal : (vertexFormat.normal || vertexFormat.binormal || params.shadowVolume),
tangent : vertexFormat.tangent,
binormal : (vertexFormat.normal || vertexFormat.binormal),
st : vertexFormat.st
Expand Down Expand Up @@ -590,28 +590,50 @@ define([
newPositions.set(wallPositions, length * 2);
attributes.position.values = newPositions;

length /= 3;
attributes = extrudedAttributes(attributes, vertexFormat);
var size = length / 3;
if (params.shadowVolume) {
var topNormals = attributes.normal.values;
length = topNormals.length;

var extrudeNormals = new Float32Array(length * 6);
for (i = 0; i < length; i ++) {
topNormals[i] = -topNormals[i];
}
//only get normals for bottom layer that's going to be pushed down
extrudeNormals.set(topNormals, length); //bottom face
extrudeNormals.set(topNormals, length * 4); //bottom wall positions
extrudeNormals.set(topNormals, length * 5); //duplicate bottom wall positions
attributes.extrudeDirection = new GeometryAttribute({
componentDatatype : ComponentDatatype.FLOAT,
componentsPerAttribute : 3,
values : extrudeNormals
});
if (!vertexFormat.normal) {
attributes.normal = undefined;
}
}

var i;
var iLength = indices.length;
var twoLength = length + length;
var newIndices = IndexDatatype.createTypedArray(newPositions.length / 3, iLength * 2 + twoLength * 3);
var twoSize = size + size;
var newIndices = IndexDatatype.createTypedArray(newPositions.length / 3, iLength * 2 + twoSize * 3);
newIndices.set(indices);
var index = iLength;
for (i = 0; i < iLength; i += 3) { // bottom indices
var v0 = indices[i];
var v1 = indices[i + 1];
var v2 = indices[i + 2];
newIndices[index++] = v2 + length;
newIndices[index++] = v1 + length;
newIndices[index++] = v0 + length;
newIndices[index++] = v2 + size;
newIndices[index++] = v1 + size;
newIndices[index++] = v0 + size;
}

attributes = extrudedAttributes(attributes, vertexFormat);
var UL, LL, UR, LR;

for (i = 0; i < twoLength; i += 2) { //wall indices
UL = i + twoLength;
LL = UL + twoLength;
for (i = 0; i < twoSize; i += 2) { //wall indices
UL = i + twoSize;
LL = UL + twoSize;
UR = UL + 1;
LR = LL + 1;
newIndices[index++] = UL;
Expand Down Expand Up @@ -793,14 +815,15 @@ define([
this._extrudedHeight = defaultValue(options.extrudedHeight, this._height);
this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED);
this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
this._shadowVolume = defaultValue(options.shadowVolume, false);
this._workerName = 'createCorridorGeometry';
this._rectangle = computeRectangle(positions, this._ellipsoid, width, this._cornerType);

/**
* The number of elements used to pack the object into an array.
* @type {Number}
*/
this.packedLength = 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 5;
this.packedLength = 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 6;
}

/**
Expand Down Expand Up @@ -845,7 +868,8 @@ define([
array[startingIndex++] = value._height;
array[startingIndex++] = value._extrudedHeight;
array[startingIndex++] = value._cornerType;
array[startingIndex] = value._granularity;
array[startingIndex++] = value._granularity;
array[startingIndex] = value._shadowVolume ? 1.0 : 0.0;

return array;
};
Expand All @@ -861,7 +885,8 @@ define([
height : undefined,
extrudedHeight : undefined,
cornerType : undefined,
granularity : undefined
granularity : undefined,
shadowVolume: undefined
};

/**
Expand Down Expand Up @@ -901,7 +926,8 @@ define([
var height = array[startingIndex++];
var extrudedHeight = array[startingIndex++];
var cornerType = array[startingIndex++];
var granularity = array[startingIndex];
var granularity = array[startingIndex++];
var shadowVolume = array[startingIndex] === 1.0;

if (!defined(result)) {
scratchOptions.positions = positions;
Expand All @@ -910,6 +936,7 @@ define([
scratchOptions.extrudedHeight = extrudedHeight;
scratchOptions.cornerType = cornerType;
scratchOptions.granularity = granularity;
scratchOptions.shadowVolume = shadowVolume;
return new CorridorGeometry(scratchOptions);
}

Expand All @@ -922,6 +949,7 @@ define([
result._cornerType = cornerType;
result._granularity = granularity;
result._rectangle = Rectangle.clone(rectangle);
result._shadowVolume = shadowVolume;

return result;
};
Expand Down Expand Up @@ -962,6 +990,7 @@ define([
height = h;
params.height = height;
params.extrudedHeight = extrudedHeight;
params.shadowVolume = corridorGeometry._shadowVolume;
attr = computePositionsExtruded(params, vertexFormat);
} else {
var computedPositions = CorridorGeometryLibrary.computePositions(params);
Expand Down Expand Up @@ -1000,7 +1029,8 @@ define([
granularity : granularity,
extrudedHeight : minHeight,
height : maxHeight,
vertexFormat : VertexFormat.POSITION_ONLY
vertexFormat : VertexFormat.POSITION_ONLY,
shadowVolume: true
});
};

Expand Down
Loading