WIP: Cycles octahedral normals (and tangents) #121704

Draft
Alex Fuller wants to merge 2 commits from boberfly/blender:feature/octahedral_tangents into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
First-time contributor

While experimenting with corner normals, an issue coming up is the extra memory overhead that would incur if there was a hypothetical swap from vertex normals as the default. One of the known effective compression techniques is octahedral normals:

https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/
https://twitter.com/Stubbesaurus/status/937994790553227264
https://jcgt.org/published/0003/02/01/paper.pdf
https://www.shadertoy.com/view/llfcRl

I went with compressing/quantising to a single uint, it seems to have enough precision and is 1/3rd the memory usage over float3.

Another concern is any performance overheads that would incur from this approach, so there is some benchmark data. Octahedral is just the normals, and octahedral_tangents combines both normals and tangents (as well as compressing tangent_sign to a char/8-bit value that gets a cast to float).

I've only just tested on CPU and OptiX (Nvidia RTX 2070) but the results seem like they do add overhead, and junkshop has the best memory savings probably due to using more normal maps than the other tests.

Renders seem to 'match' enough, the quantisation probably causes some samples to differ very slightly.

While experimenting with corner normals, an issue coming up is the extra memory overhead that would incur if there was a hypothetical swap from vertex normals as the default. One of the known effective compression techniques is octahedral normals: https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/ https://twitter.com/Stubbesaurus/status/937994790553227264 https://jcgt.org/published/0003/02/01/paper.pdf https://www.shadertoy.com/view/llfcRl I went with compressing/quantising to a single uint, it seems to have enough precision and is 1/3rd the memory usage over float3. Another concern is any performance overheads that would incur from this approach, so there is some benchmark data. Octahedral is just the normals, and octahedral_tangents combines both normals and tangents (as well as compressing tangent_sign to a char/8-bit value that gets a cast to float). I've only just tested on CPU and OptiX (Nvidia RTX 2070) but the results seem like they do add overhead, and junkshop has the best memory savings probably due to using more normal maps than the other tests. Renders seem to 'match' enough, the quantisation probably causes some samples to differ very slightly.
Alex Fuller added 1 commit 2024-05-12 05:10:48 +02:00
Alex Fuller force-pushed feature/octahedral_tangents from ba15d4fde0 to 3cd950f8b1 2024-05-14 15:21:47 +02:00 Compare
Author
First-time contributor

I made a modification in this latest version. I've updated the functions to be templated so you can specify the precision of the octahedral quantisation. I've made this so I could compress tangents into 30 bits instead of 32 bits so I can also fit tangent_sign in there, as it only needs to store 1.0f or -1.0f (with the default as 1.0f) which also simplifies the code quite a bit across the board. I needed to make it compatible with OSL but I've not tested that codepath yet.

Memory should go down a little bit more and visually I can't see a difference - but I'd appreciate more eyes on the signage code, or a unit test that can verify that the flag is working as intended - looks like 97.13mb less in junkshop from the previous commit (or 336.81mb less from main branch).

I made a modification in this latest version. I've updated the functions to be templated so you can specify the precision of the octahedral quantisation. I've made this so I could compress tangents into 30 bits instead of 32 bits so I can also fit tangent_sign in there, as it only needs to store 1.0f or -1.0f (with the default as 1.0f) which also simplifies the code quite a bit across the board. I needed to make it compatible with OSL but I've not tested that codepath yet. Memory should go down a little bit more and visually I can't see a difference - but I'd appreciate more eyes on the signage code, or a unit test that can verify that the flag is working as intended - looks like 97.13mb less in junkshop from the previous commit (or 336.81mb less from main branch).
Alex Fuller force-pushed feature/octahedral_tangents from 3cd950f8b1 to 680ad333ab 2024-05-14 15:40:59 +02:00 Compare
Author
First-time contributor

...and one minor tweak so that non-default tangents are correctly tagged for encoding/decoding.

...and one minor tweak so that non-default tangents are correctly tagged for encoding/decoding.
Alex Fuller force-pushed feature/octahedral_tangents from 680ad333ab to f12776cdb2 2024-05-14 15:52:30 +02:00 Compare
Alex Fuller force-pushed feature/octahedral_tangents from f12776cdb2 to a627942c02 2024-05-14 16:27:14 +02:00 Compare
Brecht Van Lommel requested review from Brecht Van Lommel 2024-05-21 19:46:00 +02:00
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u feature/octahedral_tangents:boberfly-feature/octahedral_tangents
git checkout boberfly-feature/octahedral_tangents
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser Project (Legacy)
Interest
Asset System
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
1 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#121704
No description provided.