Skip to content

Commit

Permalink
Remove NaN uniform (#9174)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Palmer <[email protected]>
  • Loading branch information
Pessimistress and felixpalmer authored Sep 23, 2024
1 parent 03145fb commit 9067f45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type AggregatorTransformProps = {
binIdRange: NumberArray4;
isCount: NumberArray3;
isMean: NumberArray3;
naN: number;
bins: Texture;
};

Expand All @@ -25,7 +24,6 @@ export const aggregatorTransformUniforms = {
uniformTypes: {
binIdRange: 'vec4<i32>',
isCount: 'vec3<f32>',
isMean: 'vec3<f32>',
naN: 'f32'
isMean: 'vec3<f32>'
}
} as const satisfies ShaderModule<AggregatorTransformProps>;
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export class WebGLAggregationTransform {
this.device = device;
this.channelCount = props.channelCount;
this.transform = createTransform(device, props);
// Passed in as uniform because 1) there is no GLSL symbol for NaN 2) any expression that exploits undefined behavior to produces NaN
// will subject to platform differences and shader optimization
this.transform.model.shaderInputs.setProps({aggregatorTransform: {naN: NaN}});
this.domainFBO = createRenderTarget(device, 2, 1);
}

Expand Down Expand Up @@ -145,6 +142,8 @@ flat out vec2 values;
flat out vec3 values;
#endif
const float NAN = intBitsToFloat(-1);
void main() {
int row = gl_VertexID / SAMPLER_WIDTH;
int col = gl_VertexID - row * SAMPLER_WIDTH;
Expand All @@ -155,7 +154,7 @@ void main() {
aggregatorTransform.isMean
);
if (weights.a == 0.0) {
value3 = vec3(aggregatorTransform.naN);
value3 = vec3(NAN);
}
#if NUM_DIMS == 1
Expand Down Expand Up @@ -199,11 +198,6 @@ flat in vec3 values;
out vec4 fragColor;
void main() {
#if NUM_CHANNELS > 1
if (isnan(values.x)) discard;
#else
if (isnan(values)) discard;
#endif
vec3 value3;
#if NUM_CHANNELS == 3
value3 = values;
Expand All @@ -212,6 +206,7 @@ void main() {
#else
value3.x = values;
#endif
if (isnan(value3.x)) discard;
// This shader renders into a 2x1 texture with blending=max
// The left pixel yields the max value of each channel
// The right pixel yields the min value of each channel
Expand Down

0 comments on commit 9067f45

Please sign in to comment.