What is the best way to pass a float map to the shader?

I’ve been using DataTexture with float values in order to pass elevation values to the shader.

var elevation = new THREE.DataTexture(Float32Array.from(elevationArray), 32, 32, THREE.RedFormat, THREE.FloatType);

This works fine until version r135. From r136 onwards, texture2D always retrieves 0, at least on my machine.

<= r135:

>= r136:

Here’s a fiddle :
Three DataTexture test - JSFiddle - Code Playground

Is there a better or more robust way to pass a map of float values to the shader or could this be a bug?

Hi!
Try to call
elevation.needsUpdate = true;
right after the line you provided in the main post.

1 Like

yes that was it :star_struck:

1 Like

Is there a reason why needsUpdate isn’t set to true in the constructor of a DataTexture by default? I haven’t seen any case where a DataTexture worked out of the box without explicitly setting this to true… :thinking:

1 Like

@Harold
Once, I’ve bumped into this problem and found some explanation on github: DataTexture should have needsUpdate = true when constructed with existing data · Issue #23783 · mrdoob/three.js · GitHub

1 Like

As well as – DataTexture: needsUpdate true by default by EliasHasle · Pull Request #17491 · mrdoob/three.js · GitHub

2 Likes

Ahh that explains. Thanks for the links, guys!

1 Like