question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to use 4 channel (32 bit) height map for `displacementMap`

See original GitHub issue

Is your feature request related to a problem? Please describe. I would like to utilize additional color channels (32 bit) when creating a displacement map to increase level of detail in my renders. I believe currently, only RGB 8-bit image is supported.

From wikipedia: “a standard RGB 8-bit image can only show 256 values of grey and hence only 256 heights. By using colors, a greater number of heights can be stored (for a 24-bit image, 2563 = 16,777,216 heights can be represented (2564 = 4,294,967,296 if the alpha channel is also used)).”

Describe the solution you’d like I’d like to see the option to pass in a displacement map with more channels (32 bit). A solution has been suggested on this StackOverflow thread but I think others would benefit from an official implementation.

Current displacementmap_vertex.glsl:

transformed += 
	normalize( objectNormal ) * (
		texture2D( displacementMap, vUv ).x * displacementScale + displacementBias
	);

If I’m not mistaken, three.js uses the RGBA color representation (vs say ARGB), so this could be done something like so for three channels:

transformed +=
	normalize(objectNormal) *
		(
			texture2D(displacementMap, vUv).r * 256.0 * 256.0  +
			texture2D(displacementMap, vUv).g * 256.0  +
			texture2D(displacementMap, vUv).b 
		) * displacementScale + displacementBias;

Four channels:

transformed +=
	normalize(objectNormal) *
		(
			texture2D(displacementMap, vUv).r * 256.0 * 256.0 * 256.0  +
			texture2D(displacementMap, vUv).g * 256.0  * 256.0 +
			texture2D(displacementMap, vUv).b * 256.0 +
                         texture2D(displacementMap, vUv).a
		) * displacementScale + displacementBias;

Describe alternatives you’ve considered It is possible to convert 4 channel height maps to single channel before using, but at the cost of accuracy and detail.

Additional context

An example of non vs colored height maps:

6127bw 6127

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
WestLangleycommented, May 1, 2021

Something like this should work.

const displacementMapChunk = [

	'#ifdef USE_DISPLACEMENTMAP',

		'transformed += normalize( objectNormal ) * ( unpackRGBAToDepth( texture2D( displacementMap, vUv ) ) * displacementScale + displacementBias );',

	'#endif'

].join( '\n' );

material.onBeforeCompile = function( shader ) {

	shader.vertexShader = shader.vertexShader
		.replace( '#include <common>', '#include <common>\n#include <packing>' )
		.replace( '#include <displacementmap_vertex>', displacementMapChunk );

};
1reaction
Mugen87commented, May 1, 2021

Since this feature request is a bit specific, I do not vote to change the shader code but let the user patch the displacementmap_vertex shader chunk via Material.onBeforeCompile() for now.

If more users come up with this, we can reconsider this approach. Or just provide a solution based on node material.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extracting a 32bit Displacement Map from ZBrush
In this walkthrough, we'll be using ZBrush to extract a 32bit displacement map and Maya/Arnold to test the map.
Read more >
Bake PERFECT Displacement Maps (with blender) - YouTube
I'm touring all over the displacement mappatreon and stuff https://www.patreon.com/cg_matterwebsite www.cgmatter.combusiness ...
Read more >
How to Use Displacement Maps in Blender (Tutorial) - YouTube
Check out Sketchfab 3D models: https://shrsl.com/3b1vs (Affiliated Link)Apply to become a seller: https:// bit.ly/skfbstore-applyIn this ...
Read more >
Displacement Map - ZBrush Docs
The 3 Channels will export a 3 channel RGB displacement map in TIFF format. This button will only work when the Create and...
Read more >
Free Height (Displacement) Map Rig for Cinema 4D
Free C4D-Native Height Map Creation Rig. This rig is used to create an 8K x 8K (or any size) Linear 32-bit height map...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found