-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Remove dependence on WEBGL_color_buffer_float for EDL #6801
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wanted to still use a varying instead of
gl_FragCoord.z
, since apparently on some platforms this has the same precision problems as depth textures, but I couldn't get it to work for some reason... the EDL effect happened, but it seemed like the depth value was wrong in some places.However! I've only observed the precision problem on newer iPads, and the iPad lacks other necessary extensions, so in practice it shouldn't make a difference to just use
gl_FragCoord.z
. It's also cleaner.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.
For posterity: mrdoob/three.js#9092 (comment)