WebGLRenderer: Explicitly specify precision for all sampler types #27482
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.
Description
Most of the code written using Three.js (and Three.js itself in the case of shadow mapping) doesn't use depth textures to store depth values — RGBA8 textures are used instead by storing depth in an encoded format. However, there are cases when you want to render scene depth into a depth texture directly and subsequently sample depth values from this texture.
It seems like on some Android devices if you sample a depth texture without specifing a precision qualifier in the shader code then the precision ends up to be very low. It leads to noticable artifacts which can be described as banding.
This PR adds precision qualifiers for all possible sampler types to make sure that the precision value specified when creating a
WebGLRenderer
gets applied to all samplers.WebGL1 sampler types are listed here: https://www.khronos.org/files/webgl/webgl-reference-card-1_0.pdf
And WebGL2 sampler types are listed in this card: https://www.khronos.org/files/webgl20-reference-guide.pdf
See screenshots below from
webgl_depth_texture
example taken on Google Pixel 7a. Note much smoother depth rendering on the second screenshot.precision highp sampler2D;
)precision highp sampler2D;
)