Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsignedIntType THREE.RedIntegerFormat dataTexture not working in wgslFn #27879

Closed
Spiri0 opened this issue Mar 7, 2024 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@Spiri0
Copy link
Contributor

Spiri0 commented Mar 7, 2024

Description

I think this is also just a minor problem. I have an unsignedIntType THREE.RedIntegerFormat dataTexture and i assign it to a wgslFn. I chose <u32> as the format and also tested <i32>. I got the information from the webgpu shading language manual.

Screenshot_20240307_095255_Chrome

Unfortunately this doesn't work and warnings appear in the console. I created a codePen and attached a code snippet here. It just seems to be an internal type mismatch, but I'm just guessing.

Reproduction steps

  1. create an UnsignedIntType data texture
  2. assign the data texture to a wgslFn
  3. try to include the texture in the wgslFn with texture_2d<u32> or texture_2d<i32>

Code

const size = 8;
const dataArray = new Uint32Array(size ** 2).fill(255);
const dataTexture = new THREE.DataTexture(dataArray, size, size);
dataTexture.format = THREE.RedIntegerFormat;
dataTexture.type = THREE.UnsignedIntType;
dataTexture.wrapS = THREE.ClampToEdgeWrapping;
dataTexture.wrapT = THREE.ClampToEdgeWrapping;
dataTexture.minFilter = THREE.NearestFilter; 
dataTexture.magFilter = THREE.NearestFilter;
  

const wgslParams = {
  uv: uv(),
  dataTexture: dataTexture
}
  
const wgslColorShader = wgslFn(` 
  fn mainFunction(
    uv: vec2<f32>,
    dataTexture: texture_2d<u32>  //here is the issue
  ) -> vec4<f32> {
    
    var texCoord = vec2<f32>(uv.x * 8, uv.y * 8);
    //var texel = textureLoad(dataTexture, vec2<i32>(texCoord), 0).r;
    return vec4<f32>(1, 0, 0, 1);
  }
`);
  
const material = new MeshBasicNodeMaterial();
material.colorNode = wgslColorShader(wgslParams);
const geometry = new THREE.BoxGeometry();
let cube = new THREE.Mesh(geometry, material);
scene.add(cube);  

Live example

https://codepen.io/Spiri0/pen/XWQmoLV?editors=0010

Screenshots

No response

Version

161

Device

No response

Browser

No response

OS

No response

@Mugen87 Mugen87 added the WebGPU label Mar 7, 2024
@Spiri0
Copy link
Contributor Author

Spiri0 commented Mar 12, 2024

I guess something like this is necessary here in case RedFormat:

case UnsignedIntType:
  formatGPU = GPUTextureFormat.R32Uint;
  break;

R32Uint is already defined in WebGPUConstants.js

Screenshot_20240312_102907_Chrome

What is not yet clear to me is where I would have to add texture_2d<u32>. I'm guessing in WebGPUTexturePassUtils.js, because I see texture_2d<f32> there.

@sunag
Copy link
Collaborator

sunag commented Mar 15, 2024

@Spiri0 Thanks for the material, it helps a lot as always. The solution is a little more complex, but I think I should finish it this week.

@Spiri0
Copy link
Contributor Author

Spiri0 commented Mar 15, 2024

@sunag I'm glad if it helps. I'm trying to understand three.js better.
If it's a more extensive matter like you write, no stress. Until then, I'll provisionally use a rgba floattype data texture in which I only use the r channel. It's not as elegant and robust as a redInteger texture but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants