-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6801 from likangning93/edl2.0
Remove dependence on WEBGL_color_buffer_float for EDL
- Loading branch information
Showing
3 changed files
with
50 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 22 additions & 19 deletions
41
Source/Shaders/PostProcessStages/PointCloudEyeDomeLighting.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,55 @@ | ||
#extension GL_EXT_frag_depth : enable | ||
|
||
uniform sampler2D u_pointCloud_colorTexture; | ||
uniform sampler2D u_pointCloud_ecAndLogDepthTexture; | ||
uniform sampler2D u_pointCloud_colorGBuffer; | ||
uniform sampler2D u_pointCloud_depthGBuffer; | ||
uniform vec3 u_distancesAndEdlStrength; | ||
varying vec2 v_textureCoordinates; | ||
|
||
vec2 neighborContribution(float log2Depth, vec2 padding) | ||
{ | ||
vec2 depthAndLog2Depth = texture2D(u_pointCloud_ecAndLogDepthTexture, v_textureCoordinates + padding).zw; | ||
if (depthAndLog2Depth.x == 0.0) // 0.0 is the clear value for the gbuffer | ||
{ | ||
return vec2(0.0); // throw out this sample | ||
} | ||
else | ||
{ | ||
return vec2(max(0.0, log2Depth - depthAndLog2Depth.y), 1.0); | ||
float depthOrLogDepth = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, v_textureCoordinates + padding)); | ||
if (depthOrLogDepth == 0.0) { // 0.0 is the clear value for the gbuffer | ||
return vec2(0.0); | ||
} | ||
vec4 eyeCoordinate = czm_windowToEyeCoordinates(v_textureCoordinates + padding, depthOrLogDepth); | ||
return vec2(max(0.0, log2Depth - log2(-eyeCoordinate.z / eyeCoordinate.w)), 1.0); | ||
} | ||
|
||
void main() | ||
{ | ||
vec4 ecAlphaDepth = texture2D(u_pointCloud_ecAndLogDepthTexture, v_textureCoordinates); | ||
if (length(ecAlphaDepth.xyz) < czm_epsilon7) | ||
float depthOrLogDepth = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, v_textureCoordinates)); | ||
|
||
vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, depthOrLogDepth); | ||
eyeCoordinate /= eyeCoordinate.w; | ||
|
||
float log2Depth = log2(-eyeCoordinate.z); | ||
|
||
if (length(eyeCoordinate.xyz) < czm_epsilon7) | ||
{ | ||
discard; | ||
} | ||
|
||
vec4 color = texture2D(u_pointCloud_colorTexture, v_textureCoordinates); | ||
vec4 color = texture2D(u_pointCloud_colorGBuffer, v_textureCoordinates); | ||
|
||
// sample from neighbors up, down, left, right | ||
float distX = u_distancesAndEdlStrength.x; | ||
float distY = u_distancesAndEdlStrength.y; | ||
|
||
vec2 responseAndCount = vec2(0.0); | ||
|
||
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(0, distY)); | ||
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(distX, 0)); | ||
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(0, -distY)); | ||
responseAndCount += neighborContribution(ecAlphaDepth.a, vec2(-distX, 0)); | ||
responseAndCount += neighborContribution(log2Depth, vec2(0, distY)); | ||
responseAndCount += neighborContribution(log2Depth, vec2(distX, 0)); | ||
responseAndCount += neighborContribution(log2Depth, vec2(0, -distY)); | ||
responseAndCount += neighborContribution(log2Depth, vec2(-distX, 0)); | ||
|
||
float response = responseAndCount.x / responseAndCount.y; | ||
float shade = exp(-response * 300.0 * u_distancesAndEdlStrength.z); | ||
color.rgb *= shade; | ||
gl_FragColor = vec4(color); | ||
|
||
#ifdef LOG_DEPTH | ||
czm_writeLogDepth(1.0 + (czm_projection * vec4(ecAlphaDepth.xyz, 1.0)).w); | ||
czm_writeLogDepth(1.0 + (czm_projection * vec4(eyeCoordinate.xyz, 1.0)).w); | ||
#else | ||
gl_FragDepthEXT = czm_eyeToWindowCoordinates(vec4(ecAlphaDepth.xyz, 1.0)).z; | ||
gl_FragDepthEXT = czm_eyeToWindowCoordinates(vec4(eyeCoordinate.xyz, 1.0)).z; | ||
#endif | ||
} |