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

Cannot set a value of false, or 0 for uniform on version 9.0.0-alpha.15 #1741

Closed
8 tasks
Seungup opened this issue Apr 21, 2023 · 0 comments · Fixed by #1766
Closed
8 tasks

Cannot set a value of false, or 0 for uniform on version 9.0.0-alpha.15 #1741

Seungup opened this issue Apr 21, 2023 · 0 comments · Fixed by #1766
Assignees
Labels

Comments

@Seungup
Copy link
Collaborator

Seungup commented Apr 21, 2023

Actual Result

import { Model } from '@luma.gl/engine';
import { picking } from '@luma.gl/shadertools';

const model = new Model( device, { ... , modules: [ picking ]  } );

model.updateModuleSettings( {  pickingActive: 1  } ); // avaliable.
model.updateModuleSettings( {  pickingActive: true } ); // avaliable.
model.updateModuleSettings( {  pickingActive: [1] } ); // avaliable.
model.updateModuleSettings( {  pickingActive: [true]  } ); // avaliable.
model.draw();
model.updateModuleSettings( {  pickingActive: 0  } ); // not avaliable.
model.updateModuleSettings( {  pickingActive: false  } ); // not avaliable.
model.updateModuleSettings( {  pickingActive: [0] } ); // not avaliable.
model.updateModuleSettings( {  pickingActive: [false]  } ); // not avaliable.
model.draw(); // `picking_uActive` still have `true` value.
// picking.ts

...

function getUniforms(opts = DEFAULT_MODULE_OPTIONS): Record<string, any> {
  const uniforms: Record<string, any> = {};
  if (opts.pickingSelectedColor !== undefined) {
    if (!opts.pickingSelectedColor) {
      uniforms.picking_uSelectedColorValid = 0; // -> set 0
    } else {
      const selectedColor = opts.pickingSelectedColor.slice(0, 3);
      uniforms.picking_uSelectedColorValid = 1;
      uniforms.picking_uSelectedColor = selectedColor;
    }
  }
  if (opts.pickingHighlightColor) {
    const color = Array.from(opts.pickingHighlightColor, (x) => x / 255);
    if (!Number.isFinite(color[3])) {
      color[3] = 1;
    }
    uniforms.picking_uHighlightColor = color;
  }
  if (opts.pickingActive !== undefined) {
    uniforms.picking_uActive = Boolean(opts.pickingActive); // -> set false
    uniforms.picking_uAttribute = Boolean(opts.pickingAttribute); // -> set false
  }
  return uniforms;
}

...
// @luma.gl/webgl
// src/adapter/resources/webgl-render-pipline.ts

...

  _applyUniforms() {
    for (const uniformLayout of this.layout.uniforms || []) {
      const {name, location, type, textureUnit} = uniformLayout;
      const value = this.uniforms[name] || textureUnit; // when uniform value `0` or `false` the value is avaliable but result is can be `undefined` when textureUnit is `undefined`.
      if (value !== undefined) {
        setUniform(this.device.gl, location, type, value);
      }
    }
  }

...

Expected Result

If the value of the uniform is not set, it is possible that the value set in the previous frame will be used.
So, uniform value when 0 or false should be set.

Reproduce Steps

To Do List

  • Add label and assign to milestone
  • Coding
  • Test

Background

To Do List

  • Add label and assign to milestone
  • Coding
  • Doc update
  • Whats new update
  • Test
@Seungup Seungup changed the title uniform value when 0 or false cann version 9.0.0-alpha.15 uniform value when 0 or false cannt set on version 9.0.0-alpha.15 Apr 21, 2023
@Seungup Seungup changed the title uniform value when 0 or false cannt set on version 9.0.0-alpha.15 Cannot set a value of false, or 0 for uniform on version 9.0.0-alpha.15 Apr 21, 2023
@Seungup Seungup self-assigned this Jul 15, 2023
@Seungup Seungup added the bug label Jul 15, 2023
Seungup added a commit that referenced this issue Jul 15, 2023
The change involves replacing the logical OR operator (`||`) with the
nullish coalescing operator (`??`) in the `_applyUniforms()` method.
This modification addresses a specific issue where 0 or false values
were not being correctly assigned. By using the nullish coalescing
operator, the code ensures that if the value of `this.uniforms[name]` is
either 0 or false, it will be properly assigned as the value for
`value`. This change enhances the accuracy and reliability of the code
by handling these specific cases effectively.

✅ Closes: #1741
@Seungup Seungup linked a pull request Jul 15, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant