Rounding error in ColorRamp node #74198

Open
opened 2020-02-25 15:07:18 +01:00 by Dustin Frank · 20 comments

System Information
Operating system: Windows 10
Graphics card: GeForce GTX 1080 8K

Blender Version
Broken: 2.83.4, a322b43e3d, 2020-02-24

Short description of error
In the Cycles implementation of the ColorRamp node, marker positions seem to be rounded to the next higher multiple of 1/255, leading to unexpected output, especially when set to 'Constant' interpolation.

EDIT: Happens in EEVEE too, but only when there are two or more markers set on the ColorRamp, and with multiples of 1/256.

Exact steps for others to reproduce the error

rounding error.blend

  • Open the attached .blend file and switch the 3D View to Rendered mode
  • See ColorRamp node in the Shader Editor
  • Set yellow marker to a position just slightly above a multiple of 1/255, e.g. 0.2197 (> 56/255)
  • Set 'Fac' input to just slightly below the next higher multiple, e.g. 0.2235 (< 57/255)

The node will output the red color from the left of the spectrum, even though the input value is greater than the yellow marker's position. This only occurs in Cycles, EEVEE correctly outputs yellow.

As a side note, 0.2335 should be rounded up to 0.234 when displayed with three decimals, but isn't.

EDIT: To reproduce in EEVEE:

  • Steps 1 & 2 from above
  • Add a third marker to the ColorRamp and slide it to 1.0, where it shouldn't affect the other markers
  • Set yellow marker to a position just slightly above a multiple of 1/256, e.g. 0.5001
  • Set 'Fac' input to just slightly below the next higher multiple, e.g. 0.5039

(As with Cycles)

**System Information** Operating system: Windows 10 Graphics card: GeForce GTX 1080 8K **Blender Version** Broken: 2.83.4, a322b43e3d08, 2020-02-24 **Short description of error** In the Cycles implementation of the ColorRamp node, marker positions seem to be rounded to the next higher multiple of 1/255, leading to unexpected output, especially when set to 'Constant' interpolation. EDIT: Happens in EEVEE too, but only when there are two or more markers set on the ColorRamp, and with multiples of 1/256. **Exact steps for others to reproduce the error** [rounding error.blend](https://archive.blender.org/developer/F8369357/rounding_error.blend) - Open the attached .blend file and switch the 3D View to Rendered mode - See ColorRamp node in the Shader Editor - Set yellow marker to a position just slightly above a multiple of 1/255, e.g. `0.2197` (> 56/255) - Set 'Fac' input to just slightly below the next higher multiple, e.g. `0.2235` (< 57/255) # The node will output the red color from the left of the spectrum, even though the input value is greater than the yellow marker's position. ~~This only occurs in Cycles, EEVEE correctly outputs yellow.~~ As a side note, 0.2335 should be rounded up to 0.234 when displayed with three decimals, but isn't. EDIT: To reproduce in EEVEE: - Steps 1 & 2 from above - Add a third marker to the ColorRamp and slide it to 1.0, where it shouldn't affect the other markers - Set yellow marker to a position just slightly above a multiple of 1/256, e.g. `0.5001` - Set 'Fac' input to just slightly below the next higher multiple, e.g. `0.5039` # (As with Cycles)
Author

Added subscriber: @DustInCompetent

Added subscriber: @DustInCompetent

#101205 was marked as duplicate of this issue

#101205 was marked as duplicate of this issue

#100694 was marked as duplicate of this issue

#100694 was marked as duplicate of this issue

#91769 was marked as duplicate of this issue

#91769 was marked as duplicate of this issue

Added subscriber: @TheOldBen

Added subscriber: @TheOldBen

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

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

Can reproduce with sample file and from scratch.

Can reproduce with sample file and from scratch.
Author

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

Changed status from 'Confirmed' to: 'Needs Triage'
Dustin Frank changed title from Rounding error in Cycles ColorRamp node to Rounding error in ColorRamp node 2020-02-25 16:55:18 +01:00

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

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

image.png
Can confirm, using 2.83.4
Not sure if this is a "known issue", either. I could not find it in the tracker at any rate.

![image.png](https://archive.blender.org/developer/F8369497/image.png) Can confirm, using 2.83.4 Not sure if this is a "known issue", either. I could not find it in the tracker at any rate.
Member

Added subscriber: @CharlieJolly

Added subscriber: @CharlieJolly
Member

Color Ramps are converted to a texture and then sampled from a 256 px wide image, this low resolution is prone to sampling errors and is not exact. There is an optimisation in Eevee when there are only two stops which explains why it breaks after adding another stop. See the following thread from twitter: https://twitter.com/BartekMoniewski/status/1229063557330984960

Color Ramps are converted to a texture and then sampled from a 256 px wide image, this low resolution is prone to sampling errors and is not exact. There is an optimisation in Eevee when there are only two stops which explains why it breaks after adding another stop. See the following thread from twitter: https://twitter.com/BartekMoniewski/status/1229063557330984960
Member

Added subscribers: @RMK-1, @PratikPB2123, @SteffenD

Added subscribers: @RMK-1, @PratikPB2123, @SteffenD

Added subscriber: @jgilhutton

Added subscriber: @jgilhutton

Is there any updates on this one? Or should we asume this is how the node will work for ever? I'm asking with scripting purposes in mind.
If we inspect the color ramp visually, we won't take long before we realise there's something wrong; but problem comes when we deal with the colorramp node factor input via scripting.
The real issue here is that the user/programmer will expect and trust that the input factor on the colorramp won't be rounded o the nearest 1/256 multiple. At least we could add an item to Blender's known limitations or something like that because this deviates from what's natural on the software.
Unfortunately in my case, I didn't realise of this issue until it was too late :(

Is there any updates on this one? Or should we asume this is how the node will work for ever? I'm asking with scripting purposes in mind. If we inspect the color ramp visually, we won't take long before we realise there's something wrong; but problem comes when we deal with the colorramp node factor input via scripting. The real issue here is that the user/programmer will expect and trust that the input factor on the colorramp won't be rounded o the nearest 1/256 multiple. At least we could add an item to Blender's known limitations or something like that because this deviates from what's natural on the software. Unfortunately in my case, I didn't realise of this issue until it was too late :(
Member

Added subscribers: @Fluffies, @OmarEmaraDev, @deadpin, @scurest

Added subscribers: @Fluffies, @OmarEmaraDev, @deadpin, @scurest

Added subscriber: @akirabeta

Added subscriber: @akirabeta
Contributor

Removed subscriber: @scurest

Removed subscriber: @scurest
Philipp Oeser removed the
Interest
Render & Cycles
label 2023-02-09 14:01:28 +01:00

A question for those still watching this: It's obvious the 255 vs 256 discrepancy between Cycles and Eevee should be fixed and of course documented. But what should the number be fixed to?

Using 255 or 256 for both would result in the least amount of visual change from prior versions. Going down to 250 would provide a more even/natural 0.004 step between each stop rather than 0.003906 but has lower resolution than before and might produce visually different results. The next highest resolution that would produce natural stops would be to use a resolution of 400. However this has downsides in both Cycles and Eevee with increased ramp calculation times, memory usage, and (maybe) sampling times in Cycles though it's hard to measure.

A question for those still watching this: It's obvious the 255 vs 256 discrepancy between Cycles and Eevee should be fixed and of course documented. But what should the number be fixed to? Using 255 or 256 for both would result in the least amount of visual change from prior versions. Going down to 250 would provide a more even/natural 0.004 step between each stop rather than 0.003906 but has lower resolution than before and might produce visually different results. The next highest resolution that would produce natural stops would be to use a resolution of 400. However this has downsides in both Cycles and Eevee with increased ramp calculation times, memory usage, and (maybe) sampling times in Cycles though it's hard to measure.
Author

But what should the number be fixed to?

256, if anything. Increasing or decreasing it to some other "round" number doesn't solve the underlying issue, there would always be some case where it's not perfectly divisible, even if you set it to 240 or something.

Since the workaround is having an ugly staircase of Greater Than and RGB Mix nodes, I'd like to have a checkbox option in the Color Ramp node to explicitly enable stepless markers at the cost of reduced performance.

As an afterthought, maybe the width of the ramp texture could be made configurable too, if that'd be easier to implement and make less of a performance impact.

> But what should the number be fixed to? 256, if anything. Increasing or decreasing it to some other "round" number doesn't solve the underlying issue, there would always be some case where it's not perfectly divisible, even if you set it to 240 or something. Since the workaround is having an ugly staircase of Greater Than and RGB Mix nodes, I'd like to have a checkbox option in the Color Ramp node to explicitly **enable stepless markers at the cost of reduced performance**. As an afterthought, maybe the width of the ramp texture could be made configurable too, if that'd be easier to implement and make less of a performance impact.
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
9 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#74198
No description provided.