Cycles-Bake shows black when Displament input is used #40068

Closed
opened 2014-05-07 17:37:27 +02:00 by Dalai Felinto · 13 comments

Trying to bake this file shows black:
displacement_height.blend

This also affects bump nodes (see #40060)

I tried @brecht's suggestion below, but it shows white, as if there was no displacement at all (instead of showing the checkers pattern expected from the file).

I think the problem in that file is with the bump mapping, which fails due to missing ray differentials (sd.dP).
A quick way to solve that would be to add this after shader_setup_from_sample:

sd.dP.dx = sd.dPdu;
sd.dP.dy = sd.dPdv;

That's not quite right, really this should take the UV map used for baking and the image resolution into account, for that you could look at bake_set_vlr_dxyco in Blender Internal if you want, to see how you can get those differentials from a UV map. Getting that right would mainly help for OSL image texture lookups and advanced procedural textures that do antialiasing.

Now questions for @brecht:

  • Is this what the du_dx, du_dy, dv_dx, dv_dy were intended for?
  • If so shouldn't we calculate them in Blender, instead of Cycles?
  • Also, would that mean sd.dP.dx = make_float3(du_dx, du_dy, 1.0f) and sd.dP.dy = make_float3(dv_dx, dv_dy, 1.0f)?
Trying to bake this file shows black: [displacement_height.blend](https://archive.blender.org/developer/F87584/displacement_height.blend) This also affects bump nodes (see #40060) I tried @brecht's suggestion below, but it shows white, as if there was no displacement at all (instead of showing the checkers pattern expected from the file). >I think the problem in that file is with the bump mapping, which fails due to missing ray differentials (sd.dP). > A quick way to solve that would be to add this after shader_setup_from_sample: ``` sd.dP.dx = sd.dPdu; sd.dP.dy = sd.dPdv; ``` > That's not quite right, really this should take the UV map used for baking and the image resolution into account, for that you could look at bake_set_vlr_dxyco in Blender Internal if you want, to see how you can get those differentials from a UV map. Getting that right would mainly help for OSL image texture lookups and advanced procedural textures that do antialiasing. Now questions for @brecht: * Is this what the **du_dx**, **du_dy**, **dv_dx**, **dv_dy** were intended for? * If so shouldn't we calculate them in Blender, instead of Cycles? * Also, would that mean sd.dP.dx = make_float3(du_dx, du_dy, 1.0f) and sd.dP.dy = make_float3(dv_dx, dv_dy, 1.0f)?
Author
Owner

Changed status to: 'Open'

Changed status to: 'Open'
Brecht Van Lommel was assigned by Dalai Felinto 2014-05-07 17:37:27 +02:00
Author
Owner

Added subscriber: @dfelinto

Added subscriber: @dfelinto

Yes, that's what the du_dx, du_dy, dv_dx, dv_dy were for. Calculating them in Blender would be best I think since otherwise Cycles has to have some knowledge about what you're baking to (uv mapped image, vertex colors, ptex, ..), and that's currently nicely separated, so best keep it that way.

The formula to compute dP.dx and dP.dy is:

dP.dx = dPdu * dudx + dPdv * dvdx;
dP.dy = dPdu * dudy + dPdv * dvdy;

To compute dudx you take the difference between u at the pixel to the right of the current pixel and the current pixel, and similarly for the others values.

Yes, that's what the du_dx, du_dy, dv_dx, dv_dy were for. Calculating them in Blender would be best I think since otherwise Cycles has to have some knowledge about what you're baking to (uv mapped image, vertex colors, ptex, ..), and that's currently nicely separated, so best keep it that way. The formula to compute dP.dx and dP.dy is: ``` dP.dx = dPdu * dudx + dPdv * dvdx; dP.dy = dPdu * dudy + dPdv * dvdy; ``` To compute dudx you take the difference between u at the pixel to the right of the current pixel and the current pixel, and similarly for the others values.
Author
Owner

Added subscriber: @brecht

Added subscriber: @brecht
Author
Owner

@brecht Cycles part is done - D510, I'm tackling Bake API part of it now. Feel free to review them separately.

@brecht Cycles part is done - [D510](https://archive.blender.org/developer/D510), I'm tackling Bake API part of it now. Feel free to review them separately.

In this example file you're using the (experimental, not supported yet) displacement and subdivision feature. Displacement does not actually need ray differentials to work, only bump mapping needs it. The problem here is with the subdivision which alters the mesh topology and so the mapping to the original mesh is lost. If this used a subdivision surface modifier instead it would work.

The subdivision code at the moment doesn't even support things like preserving UV maps on meshes, it's unfinished, so I would not consider that a bug, there's a reason it's hidden behind that experimental option.

In this example file you're using the (experimental, not supported yet) displacement and subdivision feature. Displacement does not actually need ray differentials to work, only bump mapping needs it. The problem here is with the subdivision which alters the mesh topology and so the mapping to the original mesh is lost. If this used a subdivision surface modifier instead it would work. The subdivision code at the moment doesn't even support things like preserving UV maps on meshes, it's unfinished, so I would not consider that a bug, there's a reason it's hidden behind that experimental option.
Author
Owner

A simpler test file: displacement.blend

Look at the result with latest D510:
checker-displace.jpg

It seems scaled up 2x. Now if I connect the checkers texture in the diffuse node too:
checker-displace-diffuse.jpg

A simpler test file: [displacement.blend](https://archive.blender.org/developer/F87896/displacement.blend) Look at the result with latest [D510](https://archive.blender.org/developer/D510): ![checker-displace.jpg](https://archive.blender.org/developer/F87897/checker-displace.jpg) It seems scaled up 2x. Now if I connect the checkers texture in the diffuse node too: ![checker-displace-diffuse.jpg](https://archive.blender.org/developer/F87899/checker-displace-diffuse.jpg)

This issue was referenced by blender/blender-addons-contrib@31cb7e395e

This issue was referenced by blender/blender-addons-contrib@31cb7e395e656e4a1590e1c9c4531e8a4b4f32ea

This issue was referenced by 31cb7e395e

This issue was referenced by 31cb7e395e656e4a1590e1c9c4531e8a4b4f32ea

This issue was referenced by blender/blender-addons-contrib@672cebf19a

This issue was referenced by blender/blender-addons-contrib@672cebf19a8b7fe8f9ac0f732fd6e8a0df239c7f

This issue was referenced by 672cebf19a

This issue was referenced by 672cebf19a8b7fe8f9ac0f732fd6e8a0df239c7f
Author
Owner

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author
Owner

Closed by commit 31cb7e395e.

Closed by commit 31cb7e395e.
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
3 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#40068
No description provided.