Skip to content

Commit 5585535

Browse files
authored
Merge pull request #6801 from likangning93/edl2.0
Remove dependence on WEBGL_color_buffer_float for EDL
2 parents 9d89fb2 + 3ca8958 commit 5585535

File tree

3 files changed

+50
-62
lines changed

3 files changed

+50
-62
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Change Log
1919
* Fixed a bug where 3D Tilesets using the `region` bounding volume don't get transformed when the tileset's `modelMatrix` changes. [6755](https://github.com/AnalyticalGraphicsInc/cesium/pull/6755)
2020
* Fixed `PolygonGeometry` and `EllipseGeometry` tangent and bitangent attributes when a texture rotation is used [#6788](https://github.com/AnalyticalGraphicsInc/cesium/pull/6788)
2121
* Fixed an issue where tiles were missing in VR mode. [#6612](https://github.com/AnalyticalGraphicsInc/cesium/issues/6612)
22+
* Fixed a bug that caused eye dome lighting for point clouds to fail in Safari on macOS and Edge on Windows by removing the dependency on floating point color textures. [#6792](https://github.com/AnalyticalGraphicsInc/cesium/issues/6792)
2223

2324
### 1.47 - 2018-07-02
2425

Source/Scene/PointCloudEyeDomeLighting.js

+27-43
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ define([
4646

4747
/**
4848
* Eye dome lighting. Does not support points with per-point translucency, but does allow translucent styling against the globe.
49-
* Requires support for EXT_frag_depth, OES_texture_float, and WEBGL_draw_buffers extensions in WebGL 1.0.
49+
* Requires support for EXT_frag_depth and WEBGL_draw_buffers extensions in WebGL 1.0.
5050
*
5151
* @private
5252
*/
5353
function PointCloudEyeDomeLighting() {
5454
this._framebuffer = undefined;
55-
this._colorTexture = undefined; // color gbuffer
56-
this._ecAndLogDepthTexture = undefined; // depth gbuffer
55+
this._colorGBuffer = undefined; // color gbuffer
56+
this._depthGBuffer = undefined; // depth gbuffer
5757
this._depthTexture = undefined; // needed to write depth so camera based on depth works
5858
this._drawCommand = undefined;
5959
this._clearCommand = undefined;
@@ -77,14 +77,14 @@ define([
7777
return;
7878
}
7979

80-
processor._colorTexture.destroy();
81-
processor._ecAndLogDepthTexture.destroy();
80+
processor._colorGBuffer.destroy();
81+
processor._depthGBuffer.destroy();
8282
processor._depthTexture.destroy();
8383
framebuffer.destroy();
8484

8585
processor._framebuffer = undefined;
86-
processor._colorTexture = undefined;
87-
processor._ecAndLogDepthTexture = undefined;
86+
processor._colorGBuffer = undefined;
87+
processor._depthGBuffer = undefined;
8888
processor._depthTexture = undefined;
8989
processor._drawCommand = undefined;
9090
processor._clearCommand = undefined;
@@ -94,22 +94,21 @@ define([
9494
var screenWidth = context.drawingBufferWidth;
9595
var screenHeight = context.drawingBufferHeight;
9696

97-
var colorTexture = new Texture({
97+
var colorGBuffer = new Texture({
9898
context : context,
9999
width : screenWidth,
100100
height : screenHeight,
101101
pixelFormat : PixelFormat.RGBA,
102-
// Firefox as of 57.02 throws FRAMEBUFFER_UNSUPPORTED 0x8CDD if this doesn't match what's in ecTexture
103-
pixelDatatype : FeatureDetection.isFirefox() ? PixelDatatype.FLOAT : PixelDatatype.UNSIGNED_BYTE,
102+
pixelDatatype : PixelDatatype.UNSIGNED_BYTE,
104103
sampler : createSampler()
105104
});
106105

107-
var ecTexture = new Texture({
106+
var depthGBuffer = new Texture({
108107
context : context,
109108
width : screenWidth,
110109
height : screenHeight,
111110
pixelFormat : PixelFormat.RGBA,
112-
pixelDatatype : PixelDatatype.FLOAT,
111+
pixelDatatype : PixelDatatype.UNSIGNED_BYTE,
113112
sampler : createSampler()
114113
});
115114

@@ -125,14 +124,14 @@ define([
125124
processor._framebuffer = new Framebuffer({
126125
context : context,
127126
colorTextures : [
128-
colorTexture,
129-
ecTexture
127+
colorGBuffer,
128+
depthGBuffer
130129
],
131130
depthTexture : depthTexture,
132131
destroyAttachments : false
133132
});
134-
processor._colorTexture = colorTexture;
135-
processor._ecAndLogDepthTexture = ecTexture;
133+
processor._colorGBuffer = colorGBuffer;
134+
processor._depthGBuffer = depthGBuffer;
136135
processor._depthTexture = depthTexture;
137136
}
138137

@@ -142,11 +141,11 @@ define([
142141
var blendFS = PointCloudEyeDomeLightingShader;
143142

144143
var blendUniformMap = {
145-
u_pointCloud_colorTexture : function() {
146-
return processor._colorTexture;
144+
u_pointCloud_colorGBuffer : function() {
145+
return processor._colorGBuffer;
147146
},
148-
u_pointCloud_ecAndLogDepthTexture : function() {
149-
return processor._ecAndLogDepthTexture;
147+
u_pointCloud_depthGBuffer : function() {
148+
return processor._depthGBuffer;
150149
},
151150
u_distancesAndEdlStrength : function() {
152151
distancesAndEdlStrengthScratch.x = processor._radius / context.drawingBufferWidth;
@@ -184,13 +183,13 @@ define([
184183
function createResources(processor, context) {
185184
var screenWidth = context.drawingBufferWidth;
186185
var screenHeight = context.drawingBufferHeight;
187-
var colorTexture = processor._colorTexture;
186+
var colorGBuffer = processor._colorGBuffer;
188187
var nowDirty = false;
189-
var resized = defined(colorTexture) &&
190-
((colorTexture.width !== screenWidth) ||
191-
(colorTexture.height !== screenHeight));
188+
var resized = defined(colorGBuffer) &&
189+
((colorGBuffer.width !== screenWidth) ||
190+
(colorGBuffer.height !== screenHeight));
192191

193-
if (!defined(colorTexture) || resized) {
192+
if (!defined(colorGBuffer) || resized) {
194193
destroyFramebuffer(processor);
195194
createFramebuffer(processor, context);
196195
createCommands(processor, context);
@@ -200,7 +199,7 @@ define([
200199
}
201200

202201
function isSupported(context) {
203-
return context.floatingPointTexture && context.drawBuffers && context.fragmentDepth;
202+
return context.drawBuffers && context.fragmentDepth;
204203
}
205204

206205
PointCloudEyeDomeLighting.isSupported = isSupported;
@@ -210,39 +209,24 @@ define([
210209
if (!defined(shader)) {
211210
var attributeLocations = shaderProgram._attributeLocations;
212211

213-
var vs = shaderProgram.vertexShaderSource.clone();
214212
var fs = shaderProgram.fragmentShaderSource.clone();
215213

216-
vs.sources = vs.sources.map(function(source) {
217-
source = ShaderSource.replaceMain(source, 'czm_point_cloud_post_process_main');
218-
return source;
219-
});
220-
221214
fs.sources = fs.sources.map(function(source) {
222215
source = ShaderSource.replaceMain(source, 'czm_point_cloud_post_process_main');
223216
source = source.replace(/gl_FragColor/g, 'gl_FragData[0]');
224217
return source;
225218
});
226219

227-
vs.sources.push(
228-
'varying vec3 v_positionEC; \n' +
229-
'void main() \n' +
230-
'{ \n' +
231-
' czm_point_cloud_post_process_main(); \n' +
232-
' v_positionEC = (czm_inverseProjection * gl_Position).xyz; \n' +
233-
'}');
234220
fs.sources.unshift('#extension GL_EXT_draw_buffers : enable \n');
235221
fs.sources.push(
236-
'varying vec3 v_positionEC; \n' +
237222
'void main() \n' +
238223
'{ \n' +
239224
' czm_point_cloud_post_process_main(); \n' +
240-
// Write log base 2 depth to alpha for EDL
241-
' gl_FragData[1] = vec4(v_positionEC, log2(-v_positionEC.z)); \n' +
225+
' gl_FragData[1] = czm_packDepth(gl_FragCoord.z); \n' +
242226
'}');
243227

244228
shader = context.shaderCache.createDerivedShaderProgram(shaderProgram, 'EC', {
245-
vertexShaderSource : vs,
229+
vertexShaderSource : shaderProgram.vertexShaderSource,
246230
fragmentShaderSource : fs,
247231
attributeLocations : attributeLocations
248232
});
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
11
#extension GL_EXT_frag_depth : enable
22

3-
uniform sampler2D u_pointCloud_colorTexture;
4-
uniform sampler2D u_pointCloud_ecAndLogDepthTexture;
3+
uniform sampler2D u_pointCloud_colorGBuffer;
4+
uniform sampler2D u_pointCloud_depthGBuffer;
55
uniform vec3 u_distancesAndEdlStrength;
66
varying vec2 v_textureCoordinates;
77

88
vec2 neighborContribution(float log2Depth, vec2 padding)
99
{
10-
vec2 depthAndLog2Depth = texture2D(u_pointCloud_ecAndLogDepthTexture, v_textureCoordinates + padding).zw;
11-
if (depthAndLog2Depth.x == 0.0) // 0.0 is the clear value for the gbuffer
12-
{
13-
return vec2(0.0); // throw out this sample
14-
}
15-
else
16-
{
17-
return vec2(max(0.0, log2Depth - depthAndLog2Depth.y), 1.0);
10+
float depthOrLogDepth = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, v_textureCoordinates + padding));
11+
if (depthOrLogDepth == 0.0) { // 0.0 is the clear value for the gbuffer
12+
return vec2(0.0);
1813
}
14+
vec4 eyeCoordinate = czm_windowToEyeCoordinates(v_textureCoordinates + padding, depthOrLogDepth);
15+
return vec2(max(0.0, log2Depth - log2(-eyeCoordinate.z / eyeCoordinate.w)), 1.0);
1916
}
2017

2118
void main()
2219
{
23-
vec4 ecAlphaDepth = texture2D(u_pointCloud_ecAndLogDepthTexture, v_textureCoordinates);
24-
if (length(ecAlphaDepth.xyz) < czm_epsilon7)
20+
float depthOrLogDepth = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, v_textureCoordinates));
21+
22+
vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, depthOrLogDepth);
23+
eyeCoordinate /= eyeCoordinate.w;
24+
25+
float log2Depth = log2(-eyeCoordinate.z);
26+
27+
if (length(eyeCoordinate.xyz) < czm_epsilon7)
2528
{
2629
discard;
2730
}
2831

29-
vec4 color = texture2D(u_pointCloud_colorTexture, v_textureCoordinates);
32+
vec4 color = texture2D(u_pointCloud_colorGBuffer, v_textureCoordinates);
3033

3134
// sample from neighbors up, down, left, right
3235
float distX = u_distancesAndEdlStrength.x;
3336
float distY = u_distancesAndEdlStrength.y;
3437

3538
vec2 responseAndCount = vec2(0.0);
3639

37-
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(0, distY));
38-
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(distX, 0));
39-
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(0, -distY));
40-
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(-distX, 0));
40+
responseAndCount += neighborContribution(log2Depth, vec2(0, distY));
41+
responseAndCount += neighborContribution(log2Depth, vec2(distX, 0));
42+
responseAndCount += neighborContribution(log2Depth, vec2(0, -distY));
43+
responseAndCount += neighborContribution(log2Depth, vec2(-distX, 0));
4144

4245
float response = responseAndCount.x / responseAndCount.y;
4346
float shade = exp(-response * 300.0 * u_distancesAndEdlStrength.z);
4447
color.rgb *= shade;
4548
gl_FragColor = vec4(color);
4649

4750
#ifdef LOG_DEPTH
48-
czm_writeLogDepth(1.0 + (czm_projection * vec4(ecAlphaDepth.xyz, 1.0)).w);
51+
czm_writeLogDepth(1.0 + (czm_projection * vec4(eyeCoordinate.xyz, 1.0)).w);
4952
#else
50-
gl_FragDepthEXT = czm_eyeToWindowCoordinates(vec4(ecAlphaDepth.xyz, 1.0)).z;
53+
gl_FragDepthEXT = czm_eyeToWindowCoordinates(vec4(eyeCoordinate.xyz, 1.0)).z;
5154
#endif
5255
}

0 commit comments

Comments
 (0)