Blend State on First Display of Content

Hello, and I am debugging some content which is a combination of generated meshes, imported meshes, and Node Materials. The scene is being generated dynamically and displayed when a user clicks within the site. The first load of the scene, when the cache does not exist or has been flushed, has incorrect alpha for the meshes with Node Materials assigned. Subsequent loads of the same scene appear exactly as expected.

In Spector, I can see that there are errors with the contents of the buffers in the first load. The Blend State information is also different.

Failed Frames:

  • BLEND: false
  • BLEND_COLOR: 0, 0, 0, 0
  • BLEND_DST_ALPHA: ONE
  • BLEND_DST_RGB: ONE_MINUS_SRC_ALPHA
  • BLEND_EQUATION_ALPHA: FUNC_ADD
  • BLEND_EQUATION_RGB: FUNC_ADD
  • BLEND_SRC_ALPHA: ONE
  • BLEND_SRC_RGB: SRC_ALPHA
  • disabledCommandIds: 2

broken_alpha_blend

Successful Frames:

correct_alpha_blend

  • BLEND: true
  • BLEND_COLOR: 0, 0, 0, 0
  • BLEND_DST_ALPHA: ONE
  • BLEND_DST_RGB: ONE
  • BLEND_EQUATION_ALPHA: FUNC_ADD
  • BLEND_EQUATION_RGB: FUNC_ADD
  • BLEND_SRC_ALPHA: ZERO
  • BLEND_SRC_RGB: SRC_ALPHA

It appears that the buffer is attempting to blend against a background which does not exist, but it is not clear why it succeeds on subsequent loads.

looks like the blend state is not accounted for. Would you happen to have a repro to share ?

Hey, and it is tucked pretty deeply into the following page:

You can see the effect the first time you load the content (swing your head around to enable the laser). Any load after that will be okay, including page refreshes, but a hard reset (clear cache) will recreate.

r

can you repro in the playground instead ? it is really hard to follow what is happening from the site :slight_smile: but the effect looks great !!!

I wonder if it could be cause the material is created before the texture has loaded ?

I will try and extract out the logic, but would ask which texture you mean? Regarding blend state, what is the expected value and how is it being set on first load? The blend mode being described would account for the error we see.

Fail:

BLEND_COLOR: 0, 0, 0, 0
BLEND_DST_ALPHA: ONE
BLEND_DST_RGB: ONE_MINUS_SRC_ALPHA
BLEND_SRC_ALPHA: ONE
BLEND_SRC_RGB: SRC_ALPHA

vs:

BLEND_COLOR: 0, 0, 0, 0
BLEND_DST_ALPHA: ONE
BLEND_DST_RGB: ONE
BLEND_SRC_ALPHA: ZERO
BLEND_SRC_RGB: SRC_ALPHA

Is it possible I am blending against a buffer which hasn’t been initialized?

My guess is the texture you use in the material are not ready so it ends up like it should not blend until the texture is ready. Not sure how it could happen though and it is where the repro could help.

Thanks, and I believe the missing texture is the glow buffer. Disabling it causes the issue to go away completely, although the problem is only with a cloned NodeMaterial (created from snippet) and on first load of the page.

Is there helper function or some logic to ensure that the glow layer is initialized? I have tried changing the order that the nodes are created in, and waiting until sceneReady to attach the glow, but the problem persists.

I am using:

// create
const glowLayer = new GlowLayer('GlowLayer', scene, {
  alphaBlendingMode: Constants.ALPHA_ADD,
  blurKernelSize: 64,
  mainTextureFixedSize: 1024,
  mainTextureSamples: 4,
});
glowLayer.intensity = 1.85;

// attach
const parentMaterial =  await NodeMaterial.ParseFromSnippetAsync('TRQVN6#44', scene);

const nodeMaterial = parentMaterial.clone('ClonedMaterial');
const glowMask = nodeMaterial.getBlockByName('GlowMask');
if (glowLayer) {
  if (glowMask) {
    (glowLayer as GlowLayer).onBeforeRenderMeshToEffect.add(() => {
      (glowMask as InputBlock).value = 1.0;
    });
    (glowLayer as GlowLayer).onAfterRenderMeshToEffect.add(() => {
      (glowMask as InputBlock).value = 0.0;
    });
  }
}

const mesh = goGetAMesh(scene);
glowLayer.referenceMeshToUseItsOwnMaterial(mesh);



Please create a repro in the forum it will be simpler for us to help, this is really hard without it