GLSL 'clamp' issue? #83494

Closed
opened 2020-12-07 11:13:19 +01:00 by Stanislav Blinov · 16 comments

System Information
Operating system: Linux 5.9.10-arch1-1
Graphics card: NVIDIA GTX 980Ti 455.45.01

Blender Version
Broken: 2.91, 2.92 master
Worked: ???

Short description of error

According to GLSL spec, clamp(x, a, b) == min(max(x,a), b). So then, clamp(0, 1, 0) should yield 0. But that doesn't seem to be the case, at least on my system. With this node setup:

image.png

...the output should be black. However...

Eevee material preview:

image.png

Eevee render:

image.png

Cycles render:

image.png

Exact steps to reproduce error

  • Switch to the Shading workspace
  • Remove Principled BSDF
  • Add the Converter -> Clamp node
  • Set mode to 'Min Max', Value to 0, Min to 1 and Max to 0
  • Connect Clamp's output to the Material Output (Surface)

Observe difference between material/render with Eevee vs. Cycles. Every time Eevee is used (material preview and render), the ouput will be white, though it should be black. Cycles render produces correct result.

Sample blend file:
clamp_issue.blend

**System Information** Operating system: Linux 5.9.10-arch1-1 Graphics card: NVIDIA GTX 980Ti 455.45.01 **Blender Version** Broken: 2.91, 2.92 master Worked: ??? **Short description of error** According to GLSL spec, clamp(x, a, b) == min(max(x,a), b). So then, clamp(0, 1, 0) should yield 0. But that doesn't seem to be the case, at least on my system. With this node setup: ![image.png](https://archive.blender.org/developer/F9487762/image.png) ...the output should be black. However... Eevee material preview: ![image.png](https://archive.blender.org/developer/F9487778/image.png) Eevee render: ![image.png](https://archive.blender.org/developer/F9487782/image.png) Cycles render: ![image.png](https://archive.blender.org/developer/F9487786/image.png) **Exact steps to reproduce error** - Switch to the Shading workspace - Remove Principled BSDF - Add the Converter -> Clamp node - Set mode to 'Min Max', Value to 0, Min to 1 and Max to 0 - Connect Clamp's output to the Material Output (Surface) Observe difference between material/render with Eevee vs. Cycles. Every time Eevee is used (material preview and render), the ouput will be white, though it should be black. Cycles render produces correct result. Sample blend file: [clamp_issue.blend](https://archive.blender.org/developer/F9500498/clamp_issue.blend)

Added subscriber: @Stan_Pancakes

Added subscriber: @Stan_Pancakes

Added subscribers: @fclem, @brecht, @mano-wii

Added subscribers: @fclem, @brecht, @mano-wii

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

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

Thanks for the report, but I would not say that this is a bug.
It is expected that users set the maximum value to something always greater than the minimum.
If they don't, the result is unpredictable and will depend on the engine.
Apparently in Eevee it was decided that the minimum value prevails while in Cycles it is the maximum value.

Although consistency is more appreciated, this is something to decide outside the bug tracker. (https://wiki.blender.org/wiki/Communication/Contact#User_Feedback_and_Requests).
So I'm closing the report for now.

(Cc @fclem, @brecht)

Thanks for the report, but I would not say that this is a bug. It is expected that users set the maximum value to something always greater than the minimum. If they don't, the result is unpredictable and will depend on the engine. Apparently in Eevee it was decided that the minimum value prevails while in Cycles it is the maximum value. Although consistency is more appreciated, this is something to decide outside the bug tracker. (https://wiki.blender.org/wiki/Communication/Contact#User_Feedback_and_Requests). So I'm closing the report for now. (Cc @fclem, @brecht)

I cannot reproduce. It feels like it's an issue with the Nvidia driver. Are you using proprietary driver? please attach your system_info.txt.

We could patch the GLSL code but it seems like this is a quite basic thing to expect from driver to properly implement a clamp!

I cannot reproduce. It feels like it's an issue with the Nvidia driver. Are you using proprietary driver? please attach your `system_info.txt`. We could patch the GLSL code but it seems like this is a quite basic thing to expect from driver to properly implement a clamp!

@mano-wii, please don't do that. The two clamp options aren't called "Range" and "Implementation-defined". They're called "Range" and "Min Max".

@fclem Of course. See also https://www.shadertoy.com/view/Ms33R4 . I see this:

image.png

system-info.txt

@mano-wii, please don't do that. The two clamp options aren't called "Range" and "Implementation-defined". They're called "Range" and "Min Max". @fclem Of course. See also https://www.shadertoy.com/view/Ms33R4 . I see this: ![image.png](https://archive.blender.org/developer/F9499892/image.png) [system-info.txt](https://archive.blender.org/developer/F9499867/system-info.txt)

Added subscriber: @dfelinto

Added subscriber: @dfelinto

I cannot reproduce it either on:

Operating system: Linux-5.4.0-56-generic-x86_64-with-debian-bullseye-sid 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 450.80.02

As in, I don't get the Cycles black render either.

I cannot reproduce it either on: Operating system: Linux-5.4.0-56-generic-x86_64-with-debian-bullseye-sid 64 Bits Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 450.80.02 As in, I don't get the Cycles black render either.

@dfelinto I've attached an example file in the description, so that we're on the same page.

@dfelinto I've attached an example file in the description, so that we're on the same page.

Added subscriber: @Foaly

Added subscriber: @Foaly

I get the same result as @radcapricorn.

Quote from the GLSL 4.6 spec:

Returns min(max(x, minVal), maxVal). Results are undefined if minVal > maxVal.

So if EEVEE wants to implement this consistently across platforms, I'd argue the clamp function cannot be used.
Or we can make it undefined as well in the documentation. I assume the Min Max type exists only for performance reasons anyway?

I get the same result as @radcapricorn. Quote from the GLSL 4.6 spec: > Returns min(max(x, minVal), maxVal). **Results are undefined if minVal > maxVal.** So if EEVEE wants to implement this consistently across platforms, I'd argue the clamp function cannot be used. Or we can make it undefined as well in the documentation. I assume the *Min Max* type exists only for performance reasons anyway?

Changed status from 'Archived' to: 'Confirmed'

Changed status from 'Archived' to: 'Confirmed'

We don't want to expose undefined behavior to users, so this is a bug then.

We don't want to expose undefined behavior to users, so this is a bug then.

(right, with the sample file I can reproduce - I couldn't with only the clamp node directly linked to the Material output)

(right, with the sample file I can reproduce - I couldn't with only the clamp node directly linked to the Material output)

This issue was referenced by fe5d2448c6

This issue was referenced by fe5d2448c6e1348be1f82f10a65d65b992f2477b
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Jeroen Bakker self-assigned this 2020-12-18 10:30:27 +01: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
8 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#83494
No description provided.