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

Polygons on terrain #2865

Merged
merged 82 commits into from
Aug 21, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
c6c2d03
Ground primitive WIP.
bagnell Feb 21, 2015
11770c1
Clamp positions to near plane. Shadow volume sides that are entirely …
bagnell Feb 24, 2015
c1c9c65
Merge branch 'globe-depth' into ground-primitive
bagnell Mar 3, 2015
1b42df4
Merge branch 'globe-depth' into ground-primitive
bagnell Mar 11, 2015
ba6026a
Merge branch 'globe-depth' into ground-primitive
bagnell Mar 18, 2015
fe5fab1
Declare commands and properly release shaders.
bagnell Mar 18, 2015
5d408bf
Update CHANGES.md.
bagnell Mar 18, 2015
5496e4b
Merge branch 'globe-depth' into ground-primitive
bagnell Mar 24, 2015
4d72baf
Clip polygon to the near plane of the first frustum WIP. Added debug …
bagnell Mar 24, 2015
36b6772
More ground polygon WIP. Only extrude vertices in vertex shader. Vert…
bagnell Mar 24, 2015
0790da0
Fix blinking polygon by slightly offsetting intersection point from t…
bagnell Mar 24, 2015
f0c8e24
Fix multi-frustum artifact on ground polygons volume.
bagnell Mar 25, 2015
94e1336
Clean up intersection function to make it more clear and add comments.
bagnell Mar 25, 2015
3a96b61
Some shader clean up and fixing a volume artifact WIP.
bagnell Mar 27, 2015
60ab053
Remove ground polygon texture coordinates.
bagnell Apr 1, 2015
0230cb0
Merge branch 'globe-depth' into ground-primitive
bagnell Apr 1, 2015
f1d5831
Add ground polygon development Sandcastle example.
bagnell Apr 1, 2015
01d4d6a
Use the same normal for both extruded and non-extruded positions. Add…
bagnell Apr 8, 2015
d051c08
Fix artifact where more than one frustum was drawing at the far plane…
bagnell Apr 9, 2015
94552de
Merge branch 'master' into ground-primitive
bagnell Jul 1, 2015
063a0ac
Merge remote-tracking branch 'origin' into ground-primitive
bagnell Jul 8, 2015
9b54673
Fix looking up at terrain when inside the shadow volume.
bagnell Jul 9, 2015
239cd1c
Remove code for culled lines from the function to clip the line again…
bagnell Jul 9, 2015
a7eb9b6
Avoid computing eye coordinates multiple times.
bagnell Jul 9, 2015
f8877cd
Fix shadow volumes by using a different technique.
bagnell Jul 15, 2015
c344aa2
Move to more general ground primitive WIP.
bagnell Jul 15, 2015
e9affe0
Remove ground polygon for more general ground primitive.
bagnell Jul 15, 2015
fdd5e5b
Merge branch 'master' into ground-primitive
bagnell Jul 15, 2015
23f6700
Add Columbus view support and per instance attribute support.
bagnell Jul 15, 2015
ff0a67a
Add commands for z-pass algorithm.
bagnell Jul 16, 2015
50bf334
Add support for more geometry that can be clamped to the ground. Add …
bagnell Jul 17, 2015
face14c
Compute shadow volume height based on granularity. Overlap frustums w…
bagnell Jul 22, 2015
ea1fd7b
Merge branch 'master' into ground-primitive
bagnell Jul 22, 2015
68c49f8
Remove z-pass optimization to fix multi-frustum artifact.
bagnell Jul 23, 2015
d55ff80
Fix rectangle geometry surface volume.
bagnell Jul 23, 2015
2d1894c
Clean up primitive shadow volume creation.
bagnell Jul 23, 2015
3e10cf5
Add picking support to ground primitive and remove model matrix option.
bagnell Jul 23, 2015
6f546c6
Merge branch 'master' into ground-primitive
bagnell Jul 24, 2015
c99bd57
Reapply change from merge to reorganized code.
bagnell Jul 24, 2015
84ff66e
Merge branch 'globe-pick' into ground-primitive
bagnell Jul 24, 2015
3269056
Use a depth/stencil renderbuffer with the picking fbo.
bagnell Jul 24, 2015
6ab9532
Merge branch 'master' into ground-primitive
bagnell Jul 27, 2015
277930f
Merge branch 'depth-plane' into ground-primitive
bagnell Jul 27, 2015
164dbc8
Add doc and properties forwarded to the primitive.
bagnell Jul 28, 2015
9ef18a0
Clean up ground primitive example.
bagnell Jul 28, 2015
5c9e945
Rename _createShadowVolume by removing the underscore and making it p…
bagnell Jul 28, 2015
49d3769
Merge branch 'master' into ground-primitive
bagnell Jul 28, 2015
198f857
Remove #ifdefs from shader checking for GL_EXT_frag_depth. The shader…
bagnell Jul 28, 2015
282463f
Porting Primitive tests for GroundPrimitive WIP.
bagnell Jul 29, 2015
256c47b
Add remaining tests.
bagnell Jul 29, 2015
cd15a4e
Update doc.
bagnell Jul 29, 2015
ff9a863
Update CHANGES.md.
bagnell Jul 29, 2015
deaf939
Merge branch 'master' into ground-primitive
bagnell Jul 31, 2015
f503bd0
Refactor Primitive and GroundPrimitive updates.
bagnell Aug 17, 2015
1b7d5c2
Merge branch 'master' into ground-primitive
bagnell Aug 17, 2015
7a3417e
Add hooks to Primitive to override render state, shader, and command …
bagnell Aug 17, 2015
ea855bb
The GroundPrimitive creates more commands that Primitive. Properly sy…
bagnell Aug 17, 2015
71f0bc9
Add prototype versions of distanceSquaredTo and computePlaneDistances…
bagnell Aug 18, 2015
001fdf6
Add OrientedBoundingBox.distanceSquaredTo.
bagnell Aug 18, 2015
3043c44
Add OrientedBoundingBox.computePlaneDistances.
bagnell Aug 18, 2015
e4587c1
Add an isOccluded function to the prototypes of BoundingSphere and Or…
bagnell Aug 18, 2015
71193a8
Add support for both bounding spheres and boxes to Scene.
bagnell Aug 18, 2015
21d0118
Add hook to primitive for creating custom bounding volumes for geometry.
bagnell Aug 18, 2015
7c23324
Remove unnecessary vector multiplies and magnitudes when getting dist…
bagnell Aug 18, 2015
a4e8fa9
Use OBBs as bounding volumes for ground primitives.
bagnell Aug 18, 2015
6517e2d
Modify debugShowBoundingVolume to work with OBBs.
bagnell Aug 18, 2015
f10fecc
Merge branch 'master' into ground-primitive
bagnell Aug 19, 2015
3d9ced1
Fix ground primitive bounding volumes when not in 3D.
bagnell Aug 19, 2015
e301a3c
Change geometryInstances to geometryInstance since batching is not su…
bagnell Aug 19, 2015
e9caa53
Fix tests.
bagnell Aug 19, 2015
8155c35
Test optimization from review.
bagnell Aug 19, 2015
a18e6ab
Add tests for new BoundingSphere and OrientedBoundingBox functions.
bagnell Aug 19, 2015
b50d97a
Use scene instead of context for ground primitive rendering tests.
bagnell Aug 20, 2015
cc60873
Fix test.
bagnell Aug 20, 2015
3a6ee56
Enable picking ground primitives when depthTestAgainstTerrain is false.
bagnell Aug 20, 2015
2521859
Merge branch 'master' into ground-primitive
bagnell Aug 20, 2015
c320e39
Merge branch 'master' into ground-primitive
bagnell Aug 20, 2015
79aed81
Update CHANGES.ms.
bagnell Aug 21, 2015
870e68a
Merge branch 'master' into ground-primitive
bagnell Aug 21, 2015
d76b729
Fix after merge.
bagnell Aug 21, 2015
9f6664d
Fix IE tests.
bagnell Aug 21, 2015
b9856c0
Add GroundPrimitive.isSupported.
bagnell Aug 21, 2015
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
Prev Previous commit
Next Next commit
Fix shadow volumes by using a different technique.
  • Loading branch information
bagnell committed Jul 15, 2015
commit f8877cd41e3c01d24445bc5176ac76ef065c8f04
61 changes: 51 additions & 10 deletions Source/Scene/GroundPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ define([
'../Shaders/ShadowVolumeVS',
'./BlendingState',
'./CullFace',
'./DepthFunction',
'./Pass',
'./StencilFunction',
'./StencilOperation'
Expand All @@ -48,6 +49,7 @@ define([
ShadowVolumeVS,
BlendingState,
CullFace,
DepthFunction,
Pass,
StencilFunction,
StencilOperation) {
Expand Down Expand Up @@ -316,7 +318,49 @@ define([
}

if (!defined(this._stencilPassCommand)) {
var stencilPassRenderState = context.createRenderState({
var stencilPreloadRenderState = context.createRenderState({
colorMask : {
red : false,
green : false,
blue : false,
alpha : false
},
stencilTest : {
enabled : true,
frontFunction : StencilFunction.ALWAYS,
frontOperation : {
fail : StencilOperation.KEEP,
zFail : StencilOperation.DECREMENT_WRAP,
zPass : StencilOperation.DECREMENT_WRAP
},
backFunction : StencilFunction.ALWAYS,
backOperation : {
fail : StencilOperation.KEEP,
zFail : StencilOperation.INCREMENT_WRAP,
zPass : StencilOperation.INCREMENT_WRAP
},
reference : 0,
mask : ~0
},
depthTest : {
enabled : false
},
depthMask : false
});

this._stencilPreloadCommand = new DrawCommand({
primitiveType : PrimitiveType.TRIANGLES,
vertexArray : this._va,
renderState : stencilPreloadRenderState,
shaderProgram : this._sp,
uniformMap : this._uniformMap,
boundingVolume : this._boundingSphere,
owner : this,
modelMatrix : Matrix4.IDENTITY,
pass : Pass.GROUND
});

var stencilDepthRenderState = context.createRenderState({
colorMask : {
red : false,
green : false,
Expand All @@ -341,15 +385,16 @@ define([
mask : ~0
},
depthTest : {
enabled : true
enabled : true,
func : DepthFunction.LESS_OR_EQUAL
},
depthMask : false
});

this._stencilPassCommand = new DrawCommand({
this._stencilDepthCommand = new DrawCommand({
primitiveType : PrimitiveType.TRIANGLES,
vertexArray : this._va,
renderState : stencilPassRenderState,
renderState : stencilDepthRenderState,
shaderProgram : this._sp,
uniformMap : this._uniformMap,
boundingVolume : this._boundingSphere,
Expand All @@ -376,12 +421,8 @@ define([
reference : 0,
mask : ~0
},
cull : {
enabled : true,
face : CullFace.BACK
},
depthTest : {
enabled : true
enabled : false
},
depthMask : false,
blending : BlendingState.ALPHA_BLEND
Expand Down Expand Up @@ -433,7 +474,7 @@ define([
if (this.debugVolume) {
commandList.push(this._debugVolumeCommand);
} else {
commandList.push(this._stencilPassCommand, this._colorPassCommand);
commandList.push(this._stencilPreloadCommand, this._stencilDepthCommand, this._colorPassCommand);
}
}
};
Expand Down
23 changes: 7 additions & 16 deletions Source/Shaders/ShadowVolumeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,20 @@
#extension GL_EXT_frag_depth : enable
#endif

//varying vec3 v_pointEC;
#ifdef GL_EXT_frag_depth
// emulated noperspective
varying float v_WindowZ;
#endif

void czm_writeDepthClampedToFarPlane()
void writeDepthClampedToFarPlane()
{
/*
#ifdef GL_EXT_frag_depth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this #ifdef here and in the vertex shader? Should we even compile the shader if the extension is not supported?

vec4 pointCC = czm_projection * vec4(v_pointEC, 1.0);
float z = pointCC.z / pointCC.w;

float n = czm_depthRange.near;
float f = czm_depthRange.far;

float depth = (z * (f - n) + f + n) * 0.5;
depth = clamp(depth, n, f);
//gl_FragDepthEXT = depth;

//gl_FragDepthEXT = (z * (f - n) + f + n) * 0.5;
gl_FragDepthEXT = min(v_WindowZ * gl_FragCoord.w, 1.0);
#endif
*/
}

void main(void)
{
gl_FragColor = vec4(1.0, 1.0, 0.0, 0.5);
czm_writeDepthClampedToFarPlane();
writeDepthClampedToFarPlane();
}
62 changes: 13 additions & 49 deletions Source/Shaders/ShadowVolumeVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,18 @@ attribute float extrude;
uniform float centralBodyMinimumAltitude;
uniform float LODNegativeToleranceOverDistance;

vec4 clipPointToPlane(vec3 p0, vec3 p1, bool nearPlane)
#ifdef GL_EXT_frag_depth
// emulated noperspective
varying float v_WindowZ;
#endif

vec4 depthClampFarPlane(vec4 vertexInClipCoordinates)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure on this, but would this be useful as a czm_ function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave this for now until we know if its needed elsewhere.

{
const float offset = 1.0;
//const float denominatorEpsilon = czm_epsilon7;
const float denominatorEpsilon = 1e-15;

vec2 frustum = czm_currentFrustum;
float planeDistance = nearPlane ? frustum.x : frustum.y;

vec3 diff = p1 - p0;
float magnitude = length(diff);
vec3 direction = normalize(diff);
float denominator = -direction.z;
float pointDistance = -(planeDistance + p0.z);
bool behindPlane = nearPlane ? pointDistance < 0.0 : pointDistance > 0.0;

// point is behind the plane and not parallel
if (behindPlane && abs(denominator) > denominatorEpsilon)
{
// find intersection of ray and the plane
// t = (-dot(plane normal, point on plane) - dot(plane normal, ray origin)) / dot(plane normal, ray direction)
float t = (planeDistance + p0.z) / denominator;

// The intersection is on the segment
if (t >= 0.0 && t <= magnitude)
{
// compute intersection with plane slightly offset
// to prevent precision artifacts
t += offset;
p0 = p0 + t * direction;
}
}

return czm_projection * vec4(p0, 1.0);
#ifdef GL_EXT_frag_depth
v_WindowZ = (0.5 * (vertexInClipCoordinates.z / vertexInClipCoordinates.w) + 0.5) * vertexInClipCoordinates.w;
vertexInClipCoordinates.z = min(vertexInClipCoordinates.z, vertexInClipCoordinates.w);
#endif
return vertexInClipCoordinates;
}

void main()
Expand All @@ -48,20 +26,6 @@ void main()

float delta = 1.0; // TODO: moving the vertex is a function of the view

vec3 origPosition = position.xyz;
vec3 movedPosition = position.xyz + normal * delta;

vec3 origPositionEC = (czm_modelViewRelativeToEye * vec4(origPosition, 1.0)).xyz;
vec3 movedPositionEC = (czm_modelViewRelativeToEye * vec4(movedPosition, 1.0)).xyz;

vec3 diff = movedPositionEC - origPositionEC;

if (extrude == 0.0)
{
gl_Position = clipPointToPlane(origPositionEC, movedPositionEC, diff.z < 0.0);
}
else
{
gl_Position = clipPointToPlane(movedPositionEC, origPositionEC, diff.z >= 0.0);
}
position.xyz = position.xyz + extrude * normal * delta;
gl_Position = depthClampFarPlane(czm_modelViewProjectionRelativeToEye * position);
}