Vector Math's "Refract" node gives wrong results. #102068

Closed
opened 2022-10-26 00:55:26 +02:00 by G. Solis · 12 comments

Blender Version
Broken: version: 3.3.0, branch: master, commit date: 2022-09-06 15:39, hash: 0759f671ce
Worked: Never! Not since the node was introduced.

Short description of error
The "Refract" node, contained in "Vector Math", gives wrong results. An easy one to spot happens when the incident vector is not normalized, but it's not the only one.
I've checked the source code in intern/cycles/util/math_float3.h and confirmed the formula is slightly wrong.

Spotted by Ian Ambrose on devtalk

Screenshot from 2022-10-25 19-30-11.png Screenshot from 2022-10-25 19-33-42.png

Exact steps for others to reproduce the error
Use the Refract node and input a non-normalized incident vector.

**Blender Version** Broken: version: 3.3.0, branch: master, commit date: 2022-09-06 15:39, hash: `0759f671ce` Worked: Never! Not since the node was introduced. **Short description of error** The "Refract" node, contained in "Vector Math", gives wrong results. An easy one to spot happens when the incident vector is not normalized, but it's not the only one. I've checked the source code in `intern/cycles/util/math_float3.h` and confirmed the formula is slightly wrong. Spotted by [Ian Ambrose on devtalk ](https://devtalk.blender.org/t/mathematical-formula-of-vector-refraction/26207) ![Screenshot from 2022-10-25 19-30-11.png](https://archive.blender.org/developer/F13769322/Screenshot_from_2022-10-25_19-30-11.png) ![Screenshot from 2022-10-25 19-33-42.png](https://archive.blender.org/developer/F13769324/Screenshot_from_2022-10-25_19-33-42.png) **Exact steps for others to reproduce the error** Use the Refract node and input a non-normalized incident vector.
Author

Added subscriber: @Gabriel-Solis

Added subscriber: @Gabriel-Solis

Added subscriber: @edward88

Added subscriber: @edward88

Hm, i can not spot the difference. Everything inside the root function is identical with k.
So according to the formula, the calculation in the return statement should be
sqrt(k) * normal + eta * (incident - dot(normal, incident) * normal)
expand with eta
eta * incident - eta * dot(normal, incident) * normal + sqrt(k) * normal
collapse normal
eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal

Am i missing something?

Hm, i can not spot the difference. Everything inside the root function is identical with `k`. So according to the formula, the calculation in the return statement should be `sqrt(k) * normal + eta * (incident - dot(normal, incident) * normal)` expand with `eta` `eta * incident - eta * dot(normal, incident) * normal + sqrt(k) * normal` collapse `normal` `eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal` Am i missing something?
Author

Are you referring to the changes in D16341? If so, the fix is that the incident vector is now normalized before the calculation. If not, reading the patch message may clarify things a bit.

Are you referring to the changes in [D16341](https://archive.blender.org/developer/D16341)? If so, the fix is that the incident vector is now normalized before the calculation. If not, reading the patch message may clarify things a bit.

Yes i did not see the patch when i wrote that, ty

Yes i did not see the patch when i wrote that, ty
Member

Added subscriber: @CharlieJolly

Added subscriber: @CharlieJolly
Member

Hi, part of the issue is that it is based on the glsl and osl version of the function.

https://registry.khronos.org/OpenGL-Refpages/gl4/html/refract.xhtml

This is one of those bug/not bug things.

To quote the glsl docs…
The input parameters I and N should be normalized in order to achieve the desired result.

In either case the patch would need to touch the Eevee and Cycles code paths too. The other solution is to make sure the documentation and tooltips advise the inputs should be normalised.

Hi, part of the issue is that it is based on the glsl and osl version of the function. https://registry.khronos.org/OpenGL-Refpages/gl4/html/refract.xhtml This is one of those bug/not bug things. To quote the glsl docs… *The input parameters I and N should be normalized in order to achieve the desired result.* In either case the patch would need to touch the Eevee and Cycles code paths too. The other solution is to make sure the documentation and tooltips advise the inputs should be normalised.

Added subscriber: @brecht

Added subscriber: @brecht

For the vector math node it would be reasonable to make it work with unnormalized vectors, since it's more high level functionality. I would not consider that a bugfix but a useful improvement to the node.

The general math library implementation that can be used by other parts of the code should not be changed, to avoid a performance impact. A second function can be added that works with unnormalized vectors, to be used by the vector math node.

For the vector math node it would be reasonable to make it work with unnormalized vectors, since it's more high level functionality. I would not consider that a bugfix but a useful improvement to the node. The general math library implementation that can be used by other parts of the code should not be changed, to avoid a performance impact. A second function can be added that works with unnormalized vectors, to be used by the vector math node.
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev
Member

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

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

Since it was established that this is not exactly a bug and a patch was already submitted, I will archive this for now.

Since it was established that this is not exactly a bug and a patch was already submitted, I will archive this for now.
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
5 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#102068
No description provided.