Eevee mipmaps not respecting border mode #73942

Closed
opened 2020-02-17 20:28:40 +01:00 by Nathan Vasil · 15 comments

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 432.00

Blender Version
Broken: version: 2.82 (sub 7), branch: master, commit date: 2020-02-12 16:20, hash: 77d23b0bd7
Also broken 2.83 alpha hash f6d5a95513

Short description of error
Mipmaps used by Eevee appear to always be generated using tiling border mode, as if texture access mode is just set by modulo coordinates rather than setting the border sampling mode for the hardware.

This is true for both extend and clip modes of texture access.

I can't currently select Cycles rendering engine in 2.82 (presumably a different bug) but the problem doesn't exist in Cycles in 2.83 alpha or in previous versions where I've seen this bug (2.81 and 2.80 if I remember correctly), only in Eevee.

Exact steps for others to reproduce the error

Attached file demonstrates the bug. A plane with a magenta->black gradient texture is set to clip mode. You may need to zoom out to get a visible mipmap demonstrating the problem, as the mipmap chosen should depend on your own personal resolution.

mipclipbug.blend

Change to rendered view. At a suitable zoom, a magenta bar is visible on the rightmost margin of the plane.

**System Information** Operating system: Windows-10-10.0.18362-SP0 64 Bits Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 432.00 **Blender Version** Broken: version: 2.82 (sub 7), branch: master, commit date: 2020-02-12 16:20, hash: `77d23b0bd7` Also broken 2.83 alpha hash f6d5a9551380 **Short description of error** Mipmaps used by Eevee appear to always be generated using tiling border mode, as if texture access mode is just set by modulo coordinates rather than setting the border sampling mode for the hardware. This is true for both extend and clip modes of texture access. I can't currently select Cycles rendering engine in 2.82 (presumably a different bug) but the problem doesn't exist in Cycles in 2.83 alpha or in previous versions where I've seen this bug (2.81 and 2.80 if I remember correctly), only in Eevee. **Exact steps for others to reproduce the error** Attached file demonstrates the bug. A plane with a magenta->black gradient texture is set to clip mode. You may need to zoom out to get a visible mipmap demonstrating the problem, as the mipmap chosen should depend on your own personal resolution. [mipclipbug.blend](https://archive.blender.org/developer/F8345606/mipclipbug.blend) Change to rendered view. At a suitable zoom, a magenta bar is visible on the rightmost margin of the plane.
Author

Added subscriber: @vasiln

Added subscriber: @vasiln
Author

Since this could potentially be related to specific hardware, here's a screenshot:

image.png

Also shows up in renders:

mipbug2.png

Since this could potentially be related to specific hardware, here's a screenshot: ![image.png](https://archive.blender.org/developer/F8345616/image.png) Also shows up in renders: ![mipbug2.png](https://archive.blender.org/developer/F8345620/mipbug2.png)

Added subscriber: @iss

Added subscriber: @iss

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Seems to happen only with linear interpolation in texture node.

Seems to happen only with linear interpolation in texture node.
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

I'm not sure why it behaves as it does, but it does look wrong. I can also confirm that it works as expected in Cycles.
2020-02-18 11-52-22.mp4

I'm not sure why it behaves as it does, but it does look wrong. I can also confirm that it works as expected in Cycles. [2020-02-18 11-52-22.mp4](https://archive.blender.org/developer/F8347272/2020-02-18_11-52-22.mp4)
Author

Extra info: problem exists regardless of linear, cubic, or smart filtering. No problem, of course, with closest (no mip) filtering.

Extra info: problem exists regardless of linear, cubic, or smart filtering. No problem, of course, with closest (no mip) filtering.
Member

Added subscriber: @fclem

Added subscriber: @fclem
Member

The issue seems to be that point_texco_clamp assumes lod level 0 when querying the texture size. From what I've read, we can't simply clamp between 0 and 1, because textures are sampled at pixel centers. Unfortunately, I could not figure out how access the correct mip map level. Maybe @fclem knows that.

void point_texco_clamp(vec3 vin, sampler2D ima, out vec3 vout)
{
  vec2 half_texel_size = 0.5 / vec2(textureSize(ima, 0).xy);
  vout = clamp(vin, half_texel_size.xyy, 1.0 - half_texel_size.xyy);
}
The issue seems to be that `point_texco_clamp` assumes lod level 0 when querying the texture size. From what I've read, we can't simply clamp between 0 and 1, because textures are sampled at pixel centers. Unfortunately, I could not figure out how access the correct mip map level. Maybe @fclem knows that. ``` void point_texco_clamp(vec3 vin, sampler2D ima, out vec3 vout) { vec2 half_texel_size = 0.5 / vec2(textureSize(ima, 0).xy); vout = clamp(vin, half_texel_size.xyy, 1.0 - half_texel_size.xyy); } ```

This is tricky. We could use textureQueryLod for that matter but this is not supported on all target platform.

What I would prefer is to have different samplers objects for each textures and bind the correct one for each texture nodes.

That's too late for 2.83 so I would leave that open to be tackled for 2.90.

This is tricky. We could use textureQueryLod for that matter but this is not supported on all target platform. What I would prefer is to have different samplers objects for each textures and bind the correct one for each texture nodes. That's too late for 2.83 so I would leave that open to be tackled for 2.90.

Added subscriber: @EnzioProbst

Added subscriber: @EnzioProbst

Another problem with mipmapping happens when using non-continuous texture coordinates like white noise.
I guess the automatic mip level calculation fails as dfdx and dfdy calculation does not make sense for this usage.
This only happens for Linear Interpolation.

mipmap_non_continous.png

Such a setup using white noise can be quite handy for raycasting shaders, blur effects etc.
It would be great to have an option for disabling mipmapping while still doing linear filtering. Would this be supported on all platforms?
Or even better expose a node socket for manually controlling the miplevel. Manual miplevel can also be used for number of effects like cheap blur.
while textureQueryLod is not OpenGL 3.3 textureLod is. So manual control should be doable.

Another problem with mipmapping happens when using non-continuous texture coordinates like white noise. I guess the automatic mip level calculation fails as dfdx and dfdy calculation does not make sense for this usage. This only happens for Linear Interpolation. ![mipmap_non_continous.png](https://archive.blender.org/developer/F8571979/mipmap_non_continous.png) Such a setup using white noise can be quite handy for raycasting shaders, blur effects etc. It would be great to have an option for disabling mipmapping while still doing linear filtering. Would this be supported on all platforms? Or even better expose a node socket for manually controlling the miplevel. Manual miplevel can also be used for number of effects like cheap blur. while `textureQueryLod` is not OpenGL 3.3 `textureLod` is. So manual control should be doable.

This issue was referenced by b2dcff4c21

This issue was referenced by b2dcff4c21a645fa16ca39484d206a38944168d2

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Clément Foucault self-assigned this 2020-06-03 16:24:41 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#73942
No description provided.