-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Billboard transparency #4886
Billboard transparency #4886
Changes from 10 commits
c9a486d
d53b383
2666f40
dd63d01
8347d70
3203985
31066db
9e4b576
c4fc142
a80bd3c
94adb32
f371ecc
5a4345f
19720fa
54b87ab
157b649
79e6800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,6 +170,7 @@ define([ | |
this._sp = undefined; | ||
this._rs = undefined; | ||
this._vaf = undefined; | ||
this._spTranslucent = undefined; | ||
this._spPick = undefined; | ||
|
||
this._billboards = []; | ||
|
@@ -1482,11 +1483,27 @@ define([ | |
vs.defines.push('DISTANCE_DISPLAY_CONDITION'); | ||
} | ||
|
||
fs = new ShaderSource({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and in the point cloud, shouldn't the render state be different for each pass? Opaque writes depth; translucent does not. |
||
defines : ['OPAQUE'], | ||
sources : [BillboardCollectionFS] | ||
}); | ||
this._sp = ShaderProgram.replaceCache({ | ||
context : context, | ||
shaderProgram : this._sp, | ||
vertexShaderSource : vs, | ||
fragmentShaderSource : BillboardCollectionFS, | ||
fragmentShaderSource : fs, | ||
attributeLocations : attributeLocations | ||
}); | ||
|
||
fs = new ShaderSource({ | ||
defines : ['TRANSLUCENT'], | ||
sources : [BillboardCollectionFS] | ||
}); | ||
this._spTranslucent = ShaderProgram.replaceCache({ | ||
context : context, | ||
shaderProgram : this._spTranslucent, | ||
vertexShaderSource : vs, | ||
fragmentShaderSource : fs, | ||
attributeLocations : attributeLocations | ||
}); | ||
|
||
|
@@ -1502,21 +1519,22 @@ define([ | |
vaLength = va.length; | ||
|
||
colorList.length = vaLength; | ||
for (j = 0; j < vaLength; ++j) { | ||
for (j = 0; j < vaLength * 2; ++j) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, but extract |
||
command = colorList[j]; | ||
if (!defined(command)) { | ||
command = colorList[j] = new DrawCommand({ | ||
pass : Pass.OPAQUE, | ||
owner : this | ||
}); | ||
command = colorList[j] = new DrawCommand(); | ||
} | ||
|
||
command.pass = (j % 2 === 0) ? Pass.OPAQUE : Pass.TRANSLUCENT; | ||
command.owner = this; | ||
|
||
var index = Math.floor(j / 2.0); | ||
command.boundingVolume = boundingVolume; | ||
command.modelMatrix = modelMatrix; | ||
command.count = va[j].indicesCount; | ||
command.shaderProgram = this._sp; | ||
command.count = va[index].indicesCount; | ||
command.shaderProgram = (j % 2 === 0) ? this._sp : this._spTranslucent; | ||
command.uniformMap = this._uniforms; | ||
command.vertexArray = va[j].va; | ||
command.vertexArray = va[index].va; | ||
command.renderState = this._rs; | ||
command.debugShowBoundingVolume = this.debugShowBoundingVolume; | ||
|
||
|
@@ -1658,6 +1676,7 @@ define([ | |
|
||
this._textureAtlas = this._destroyTextureAtlas && this._textureAtlas && this._textureAtlas.destroy(); | ||
this._sp = this._sp && this._sp.destroy(); | ||
this._spTranslucent = this._spTranslucent && this._spTranslucent.destroy(); | ||
this._spPick = this._spPick && this._spPick.destroy(); | ||
this._vaf = this._vaf && this._vaf.destroy(); | ||
destroyBillboards(this._billboards); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,7 @@ define([ | |
this._sp = undefined; | ||
this._rs = undefined; | ||
this._vaf = undefined; | ||
this._spTranslucent = undefined; | ||
this._spPick = undefined; | ||
|
||
this._pointPrimitives = []; | ||
|
@@ -875,11 +876,27 @@ define([ | |
vs.defines.push('DISTANCE_DISPLAY_CONDITION'); | ||
} | ||
|
||
fs = new ShaderSource({ | ||
defines : ['OPAQUE'], | ||
sources : [PointPrimitiveCollectionFS] | ||
}); | ||
this._sp = ShaderProgram.replaceCache({ | ||
context : context, | ||
shaderProgram : this._sp, | ||
vertexShaderSource : vs, | ||
fragmentShaderSource : PointPrimitiveCollectionFS, | ||
fragmentShaderSource : fs, | ||
attributeLocations : attributeLocations | ||
}); | ||
|
||
fs = new ShaderSource({ | ||
defines : ['TRANSLUCENT'], | ||
sources : [PointPrimitiveCollectionFS] | ||
}); | ||
this._spTranslucent = ShaderProgram.replaceCache({ | ||
context : context, | ||
shaderProgram : this._spTranslucent, | ||
vertexShaderSource : vs, | ||
fragmentShaderSource : fs, | ||
attributeLocations : attributeLocations | ||
}); | ||
|
||
|
@@ -892,21 +909,22 @@ define([ | |
vaLength = va.length; | ||
|
||
colorList.length = vaLength; | ||
for (j = 0; j < vaLength; ++j) { | ||
for (j = 0; j < vaLength * 2; ++j) { | ||
command = colorList[j]; | ||
if (!defined(command)) { | ||
command = colorList[j] = new DrawCommand({ | ||
primitiveType : PrimitiveType.POINTS, | ||
pass : Pass.OPAQUE, | ||
owner : this | ||
}); | ||
command = colorList[j] = new DrawCommand(); | ||
} | ||
|
||
command.primitiveType = PrimitiveType.POINTS; | ||
command.pass = (j % 2 === 0) ? Pass.OPAQUE : Pass.TRANSLUCENT; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make a public enum with the following properties:
Billboard, label, and point collections can expose this property (get/set ideally) and default to |
||
command.owner = this; | ||
|
||
var index = Math.floor(j / 2.0); | ||
command.boundingVolume = boundingVolume; | ||
command.modelMatrix = modelMatrix; | ||
command.shaderProgram = this._sp; | ||
command.shaderProgram = (j % 2 === 0) ? this._sp : this._spTranslucent; | ||
command.uniformMap = this._uniforms; | ||
command.vertexArray = va[j].va; | ||
command.vertexArray = va[index].va; | ||
command.renderState = this._rs; | ||
command.debugShowBoundingVolume = this.debugShowBoundingVolume; | ||
|
||
|
@@ -1015,6 +1033,7 @@ define([ | |
*/ | ||
PointPrimitiveCollection.prototype.destroy = function() { | ||
this._sp = this._sp && this._sp.destroy(); | ||
this._spTranslucent = this._spTranslucent && this._spTranslucent.destroy(); | ||
this._spPick = this._spPick && this._spPick.destroy(); | ||
this._vaf = this._vaf && this._vaf.destroy(); | ||
destroyPointPrimitives(this._pointPrimitives); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,28 @@ void main() | |
#else | ||
vec4 vertexColor = v_color; | ||
#endif | ||
|
||
vec4 color = texture2D(u_atlas, v_textureCoordinates) * vertexColor; | ||
if (color.a == 0.0) | ||
|
||
#ifdef RENDER_FOR_PICK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment here and to the point shader that explains this? For example: fully transparent parts are not pickable, and the billboard/point is rendered twice: the opaque pass discards translucent fragments, and the translucent pass discards opaque ones. |
||
if (color.a < 0.005) // matches 0/255 and 1/255 | ||
{ | ||
discard; | ||
} | ||
#else | ||
#ifdef OPAQUE | ||
if (color.a < 0.995) // matches < 254/255 | ||
{ | ||
discard; | ||
} | ||
|
||
#else | ||
if (color.a >= 0.995) // matches 254/255 and 255/255 | ||
{ | ||
discard; | ||
} | ||
#endif | ||
#endif | ||
|
||
#ifdef RENDER_FOR_PICK | ||
gl_FragColor = v_pickColor; | ||
#else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this.