Skip to content

Commit

Permalink
fix(coew): boolean uniform fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Aug 20, 2023
1 parent 69cbd2b commit 747096b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
12 changes: 2 additions & 10 deletions examples/showcase/instancing/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ varying vec3 color;
void main(void) {
gl_FragColor = vec4(color, 1.);
gl_FragColor = dirlight_filterColor(gl_FragColor);
// TODO -
gl_FragColor = picking_filterColor(gl_FragColor);
}
`;
Expand Down Expand Up @@ -91,11 +90,6 @@ class InstancedCube extends Model {
const colorsBuffer = device.createBuffer(colors);
const pickingColorsBuffer = device.createBuffer(pickingColors);

// TODO - Should we really be setting global hooks in a simple example?
// const pipelineFactory = PipelineFactory.getDefaultPipelineFactory(device);
// pipelineFactory.addShaderHook('vs:MY_SHADER_HOOK_pickColor(inout vec4 color)');
// pipelineFactory.addShaderHook('fs:MY_SHADER_HOOK_fragmentColor(inout vec4 color)');

// Model
super(device, {
...props,
Expand All @@ -122,7 +116,7 @@ class InstancedCube extends Model {
},
bufferMap: [
{name: 'instanceColors', format: 'unorm8x4'},
{name: 'instancePickingColors', format: 'unorm8x2'},
{name: 'instancePickingColors', format: 'uint8x2'},
],
parameters: {
depthWriteEnabled: true,
Expand Down Expand Up @@ -233,9 +227,7 @@ export function pickInstance(
sourceX: pickX,
sourceY: pickY,
sourceWidth: 1,
sourceHeight: 1,
// sourceFormat: GL.RGBA,
// sourceType: GL.UNSIGNED_BYTE
sourceHeight: 1
});

if (color[0] + color[1] + color[2] > 0) {
Expand Down
6 changes: 5 additions & 1 deletion modules/core/src/adapter/utils/decode-vertex-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export function decodeVertexFormat(format: VertexFormat): VertexFormatInfo {
type,
components,
byteLength: decodedType.byteLength * components,
integer: decodedType.integer,
// It is not the vertex memory format that determines if the data will be treated as an integer,
// it is the shader attribute declaration.
// Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
// but as far as we can tell, WebGPU does not.
integer: false, // decodedType.integer,
signed: decodedType.signed,
normalized: decodedType.normalized
};
Expand Down
2 changes: 1 addition & 1 deletion modules/shadertools/src/modules/picking/picking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void picking_setPickingColor(vec3 pickingColor) {
// if (!picking_uAttribute) {
// Stores the picking color so that the fragment shader can render it during picking
picking_vRGBcolor_Avalid.rgb = pickingColor; // * COLOR_SCALE;
picking_vRGBcolor_Avalid.rgb = pickingColor * COLOR_SCALE;
// }
} else {
// Do the comparison with selected item color in vertex shader as it should mean fewer compares
Expand Down
7 changes: 3 additions & 4 deletions modules/webgl/src/adapter/helpers/set-uniform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function setUniform(
gl: WebGLRenderingContext,
location: WebGLUniformLocation,
type: GL,
value: number | Float32Array | Int32Array | Uint32Array
value: number | Float32Array | Int32Array | Uint32Array | boolean
): void {
const gl2 = gl as WebGL2RenderingContext;

Expand Down Expand Up @@ -37,13 +37,12 @@ export function setUniform(
}
}

// @ts-expect-error
if (value === true) {
value = 1;
}
// @ts-expect-error

if (value === false) {
value = 1;
value = 0;
}
const arrayValue = (typeof value === 'number') ? [value] : value;

Expand Down

0 comments on commit 747096b

Please sign in to comment.