-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #7
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
Merged
Dev #7
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f701b23
Refactor Physically Based Bloom implementation and clean up shader as…
zoozooll 778c708
Refactor Physically Based Bloom implementation and clean up shader as…
zoozooll 67f52c1
Refactor ParallaxMappingScene and implement quad rendering with TBN c…
zoozooll 905649e
Update PbrScene lighting configuration and refactor shader assets
zoozooll 3cbdd18
Refactor CSM shaders and fix geometry shader initialization
zoozooll 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
...sets/shaders/csm/10.debug_quad_depth.frag → .../assets/shaders/csm/debug_quad_depth.frag
This file contains hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
.../shaders/csm/10.shadow_mapping_depth.geom → ...ets/shaders/csm/shadow_mapping_depth.geom
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
115 changes: 0 additions & 115 deletions
115
tutorial/src/main/assets/shaders/physically_based_bloom/6.new_downsample.frag
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
tutorial/src/main/assets/shaders/physically_based_bloom/6.new_upsample.frag
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
115 changes: 115 additions & 0 deletions
115
tutorial/src/main/assets/shaders/physically_based_bloom/new_downsample.frag
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| #version 320 es | ||
| precision mediump float; | ||
|
|
||
| // This shader performs downsampling on a texture, | ||
| // as taken from Call Of Duty method, presented at ACM Siggraph 2014. | ||
| // This particular method was customly designed to eliminate | ||
| // "pulsating artifacts and temporal stability issues". | ||
|
|
||
| // Remember to add bilinear minification filter for this texture! | ||
| // Remember to use a floating-point texture format (for HDR)! | ||
| // Remember to use edge clamping for this texture! | ||
| uniform sampler2D srcTexture; | ||
| uniform vec2 srcResolution; | ||
|
|
||
| // which mip we are writing to, used for Karis average | ||
| uniform int mipLevel; | ||
|
|
||
| in vec2 texCoord; | ||
| layout (location = 0) out vec3 downsample; | ||
|
|
||
| vec3 PowVec3(vec3 v, float p) | ||
| { | ||
| return vec3(pow(v.x, p), pow(v.y, p), pow(v.z, p)); | ||
| } | ||
|
|
||
| const float invGamma = 1.0 / 2.2; | ||
| vec3 ToSRGB(vec3 v) { return PowVec3(v, invGamma); } | ||
|
|
||
| float sRGBToLuma(vec3 col) | ||
| { | ||
| //return dot(col, vec3(0.2126f, 0.7152f, 0.0722f)); | ||
| return dot(col, vec3(0.299f, 0.587f, 0.114f)); | ||
| } | ||
|
|
||
| float KarisAverage(vec3 col) | ||
| { | ||
| // Formula is 1 / (1 + luma) | ||
| float luma = sRGBToLuma(ToSRGB(col)) * 0.25f; | ||
| return 1.0f / (1.0f + luma); | ||
| } | ||
|
|
||
| // NOTE: This is the readable version of this shader. It will be optimized! | ||
| void main() | ||
| { | ||
| vec2 srcTexelSize = 1.0 / srcResolution; | ||
| float x = srcTexelSize.x; | ||
| float y = srcTexelSize.y; | ||
|
|
||
| // Take 13 samples around current texel: | ||
| // a - b - c | ||
| // - j - k - | ||
| // d - e - f | ||
| // - l - m - | ||
| // g - h - i | ||
| // === ('e' is the current texel) === | ||
| vec3 a = texture(srcTexture, vec2(texCoord.x - 2. * x, texCoord.y + 2. * y)).rgb; | ||
| vec3 b = texture(srcTexture, vec2(texCoord.x, texCoord.y + 2. * y)).rgb; | ||
| vec3 c = texture(srcTexture, vec2(texCoord.x + 2. * x, texCoord.y + 2. * y)).rgb; | ||
|
|
||
| vec3 d = texture(srcTexture, vec2(texCoord.x - 2. * x, texCoord.y)).rgb; | ||
| vec3 e = texture(srcTexture, vec2(texCoord.x, texCoord.y)).rgb; | ||
| vec3 f = texture(srcTexture, vec2(texCoord.x + 2. * x, texCoord.y)).rgb; | ||
|
|
||
| vec3 g = texture(srcTexture, vec2(texCoord.x - 2. * x, texCoord.y - 2. * y)).rgb; | ||
| vec3 h = texture(srcTexture, vec2(texCoord.x, texCoord.y - 2. * y)).rgb; | ||
| vec3 i = texture(srcTexture, vec2(texCoord.x + 2. * x, texCoord.y - 2. * y)).rgb; | ||
|
|
||
| vec3 j = texture(srcTexture, vec2(texCoord.x - x, texCoord.y + y)).rgb; | ||
| vec3 k = texture(srcTexture, vec2(texCoord.x + x, texCoord.y + y)).rgb; | ||
| vec3 l = texture(srcTexture, vec2(texCoord.x - x, texCoord.y - y)).rgb; | ||
| vec3 m = texture(srcTexture, vec2(texCoord.x + x, texCoord.y - y)).rgb; | ||
|
|
||
| // Apply weighted distribution: | ||
| // 0.5 + 0.125 + 0.125 + 0.125 + 0.125 = 1 | ||
| // a,b,d,e * 0.125 | ||
| // b,c,e,f * 0.125 | ||
| // d,e,g,h * 0.125 | ||
| // e,f,h,i * 0.125 | ||
| // j,k,l,m * 0.5 | ||
| // This shows 5 square areas that are being sampled. But some of them overlap, | ||
| // so to have an energy preserving downsample we need to make some adjustments. | ||
| // The weights are the distributed, so that the sum of j,k,l,m (e.g.) | ||
| // contribute 0.5 to the final color output. The code below is written | ||
| // to effectively yield this sum. We get: | ||
| // 0.125*5 + 0.03125*4 + 0.0625*4 = 1 | ||
|
|
||
| // Check if we need to perform Karis average on each block of 4 samples | ||
| vec3 groups[5]; | ||
| switch (mipLevel) | ||
| { | ||
| case 0: | ||
| // We are writing to mip 0, so we need to apply Karis average to each block | ||
| // of 4 samples to prevent fireflies (very bright subpixels, leads to pulsating | ||
| // artifacts). | ||
| groups[0] = (a + b + d + e) * (0.125f / 4.0f); | ||
| groups[1] = (b + c + e + f) * (0.125f / 4.0f); | ||
| groups[2] = (d + e + g + h) * (0.125f / 4.0f); | ||
| groups[3] = (e + f + h + i) * (0.125f / 4.0f); | ||
| groups[4] = (j + k + l + m) * (0.5f / 4.0f); | ||
| groups[0] *= KarisAverage(groups[0]); | ||
| groups[1] *= KarisAverage(groups[1]); | ||
| groups[2] *= KarisAverage(groups[2]); | ||
| groups[3] *= KarisAverage(groups[3]); | ||
| groups[4] *= KarisAverage(groups[4]); | ||
| downsample = groups[0] + groups[1] + groups[2] + groups[3] + groups[4]; | ||
| downsample = max(downsample, 0.0001f); | ||
| break; | ||
| default: | ||
| downsample = e * 0.125; // ok | ||
| downsample += (a + c + g + i) * 0.03125; // ok | ||
| downsample += (b + d + f + h) * 0.0625; // ok | ||
| downsample += (j + k + l + m) * 0.125; // ok | ||
| break; | ||
| } | ||
| } |
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
tutorial/src/main/assets/shaders/physically_based_bloom/new_upsample.frag
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #version 320 es | ||
| precision mediump float; | ||
|
|
||
| // This shader performs upsampling on a texture, | ||
| // as taken from Call Of Duty method, presented at ACM Siggraph 2014. | ||
|
|
||
| // Remember to add bilinear minification filter for this texture! | ||
| // Remember to use a floating-point texture format (for HDR)! | ||
| // Remember to use edge clamping for this texture! | ||
| uniform sampler2D srcTexture; | ||
| uniform float filterRadius; | ||
|
|
||
| in vec2 texCoord; | ||
| layout (location = 0) out vec3 upsample; | ||
|
|
||
| void main() | ||
| { | ||
| // The filter kernel is applied with a radius, specified in texture | ||
| // coordinates, so that the radius will vary across mip resolutions. | ||
| float x = filterRadius; | ||
| float y = filterRadius; | ||
|
|
||
| // Take 9 samples around current texel: | ||
| // a - b - c | ||
| // d - e - f | ||
| // g - h - i | ||
| // === ('e' is the current texel) === | ||
| vec3 a = texture(srcTexture, vec2(texCoord.x - x, texCoord.y + y)).rgb; | ||
| vec3 b = texture(srcTexture, vec2(texCoord.x, texCoord.y + y)).rgb; | ||
| vec3 c = texture(srcTexture, vec2(texCoord.x + x, texCoord.y + y)).rgb; | ||
|
|
||
| vec3 d = texture(srcTexture, vec2(texCoord.x - x, texCoord.y)).rgb; | ||
| vec3 e = texture(srcTexture, vec2(texCoord.x, texCoord.y)).rgb; | ||
| vec3 f = texture(srcTexture, vec2(texCoord.x + x, texCoord.y)).rgb; | ||
|
|
||
| vec3 g = texture(srcTexture, vec2(texCoord.x - x, texCoord.y - y)).rgb; | ||
| vec3 h = texture(srcTexture, vec2(texCoord.x, texCoord.y - y)).rgb; | ||
| vec3 i = texture(srcTexture, vec2(texCoord.x + x, texCoord.y - y)).rgb; | ||
|
|
||
| // Apply weighted distribution, by using a 3x3 tent filter: | ||
| // 1 | 1 2 1 | | ||
| // -- * | 2 4 2 | | ||
| // 16 | 1 2 1 | | ||
| upsample = e * 4.0; | ||
| upsample += (b + d + f + h) * 2.0; | ||
| upsample += (a + c + g + i); | ||
| upsample *= 1.0 / 16.0; | ||
| } |
File renamed without changes.
Oops, something went wrong.
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.
When the scene runs with the new default
programChoice == 3,draw()bindsbloomRenderer.BloomTexture()but only uploadsprogramChoiceandexposure; no code setsbloomStrength. Since this commit removed the shader-side initializer, the uniform defaults to 0, somix(hdrColor, bloomColor, bloomStrength)always returns the original scene color and the physically based bloom path has no visible bloom.Useful? React with 👍 / 👎.