Compositor: Unify Texture node between CPU and GPU #118377

Merged
Omar Emara merged 2 commits from OmarEmaraDev/blender:unify-texture-node into main 2024-02-16 16:21:58 +01:00
Member

The CPU and GPU implementations of the compositor Texture node sample
the texture at different locations, producing differences. This is
primarly an issue with half pixel offsets to evaluate the texture at the
center of the pixels.

The CPU compositor only adds the offsets if interpolation is disabled,
regardless if the texture is of type image or not. Further the offset
was wrong, since it was not a half pixel offset, but a full pixel one.

The offsets should always be added, since it won't make a difference in
the non interpolated case, and it should always be added especially if
interpolation is enabled. A comment in the old code mentions something
about artifacts, but it is possible that this is a consequence of the
wrong offset that was used.

This patch always adds a half pixel offset, following the GPU code.

The CPU and GPU implementations of the compositor Texture node sample the texture at different locations, producing differences. This is primarly an issue with half pixel offsets to evaluate the texture at the center of the pixels. The CPU compositor only adds the offsets if interpolation is disabled, regardless if the texture is of type image or not. Further the offset was wrong, since it was not a half pixel offset, but a full pixel one. The offsets should always be added, since it won't make a difference in the non interpolated case, and it should always be added especially if interpolation is enabled. A comment in the old code mentions something about artifacts, but it is possible that this is a consequence of the wrong offset that was used. This patch always adds a half pixel offset, following the GPU code.
Omar Emara added the
Interest
Compositing
Module
VFX & Video
labels 2024-02-16 13:40:07 +01:00
Omar Emara added 1 commit 2024-02-16 13:40:17 +01:00
2721523162 Compositor: Unify Texture node between CPU and GPU
The CPU and GPU implementations of the compositor Texture node sample
the texture at different locations, producing differences. This is
primarly an issue with half pixel offsets to evaluate the texture at the
center of the pixels.

The CPU compositor only adds the offsets if interpolation is disabled,
regardless if the texture is of type image or not. Further the offset
was wrong, since it was not a half pixel offset, but a full pixel one.

The offsets should always be added, since it won't make a difference in
the non interpolated case, and it should always be added especially if
interpolation is enabled. A comment in the old code mentions something
about artifacts, but it is possible that this is a consequence of the
wrong offset that was used.

This patch always adds a half pixel offset, following the GPU code.
Omar Emara requested review from Sergey Sharybin 2024-02-16 13:40:31 +01:00
Author
Member

To double check, here is the old implementation, where we are differencing the image we get directly from an Image node and the one we get from an Image Texture node. Notice how it looks like a horizontal partial derivative, due to the full pixel offset that the old code introduces.

20240216-141955.png

The new implementation has a zero difference.

To double check, here is the old implementation, where we are differencing the image we get directly from an Image node and the one we get from an Image Texture node. Notice how it looks like a horizontal partial derivative, due to the full pixel offset that the old code introduces. ![20240216-141955.png](/attachments/6d355adf-7846-4603-b44a-c46d8915745f) The new implementation has a zero difference.
Sergey Sharybin requested changes 2024-02-16 15:23:47 +01:00
@ -179,2 +147,2 @@
else {
it.out[0] = it.out[1] = it.out[2] = it.out[3];
TexResult texture_result;
const int result_type = multitex_ext_safe(

The multitex_ext_safe explicitly disables texture nodes. Is there a specific reason for this? Otherwise it should be something between these lines

    const int result_type = multitex_ext(texture_,
                                         coordinates,
                                         nullptr,
                                         nullptr,
                                         0,
                                         &texture_result,
                                         WorkScheduler::current_thread_id(),
                                         pool_,
                                         scene_color_manage_,
                                         false);
The `multitex_ext_safe` explicitly disables texture nodes. Is there a specific reason for this? Otherwise it should be something between these lines ``` const int result_type = multitex_ext(texture_, coordinates, nullptr, nullptr, 0, &texture_result, WorkScheduler::current_thread_id(), pool_, scene_color_manage_, false); ```
Author
Member

No specific reason, I will use multitex_ext.

No specific reason, I will use `multitex_ext`.
OmarEmaraDev marked this conversation as resolved
Omar Emara added 1 commit 2024-02-16 15:35:50 +01:00
Sergey Sharybin approved these changes 2024-02-16 16:20:20 +01:00
Omar Emara merged commit 9ab72eae38 into main 2024-02-16 16:21:58 +01:00
Omar Emara deleted branch unify-texture-node 2024-02-16 16:22:01 +01:00
Sign in to join this conversation.
No reviewers
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
2 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#118377
No description provided.