Jump to content

Triggering Shader Compilation


royibernthal
 Share

Recommended Posts

How do I trigger shader compilation for:

-Particles

-HighlightLayer with inner and/or outer glow

-Custom made shaders - what are the guidelines to finding how to trigger a specific shader?

 

For instance, in order to trigger a light shader compilation for a mesh you'd need to push that mesh into Light/includedOnlyMeshes and wait for material.isReady(mesh).

Link to comment
Share on other sites

Sorry I was completely focus and forgot to answer you:

- Particles: call particleSystem.effect.isReady()

- HighlightLayer:  call layer.currentEffect.isReady()

- Custom shaders: just all material.isReady(mesh)

Link to comment
Share on other sites

No problem :)

HighlightLayer - by layer.currentEffect are you referring to EffectLayer/_mergeEffect which is locally referred to as currentEffect in EffectLayer/render()? Other than that I can't see a currentEffect.

 

So this is how I check if they're ready, how do I trigger them?

Particles - ?

-HighlightLayer - highlightLayer.addMesh()?

-Custom shaders - applying the shader material to mesh?

Link to comment
Share on other sites

1) Would it make sense to trigger hemi light shader compilation with a different hemi light instance than the one used later on? Would the same answer apply to other lights, highlightLayer and particleSystem?

I'm asking this because it seems like the same shader is compiled regardless of instance or even settings like light direction.

 

2) It seems that EffectLayer/_mergeEffect.isReady() only takes into account meshes that are currently displayed in the scene, correct me if I'm wrong.

I'd like to trigger HighlightLayer shader compilation for meshes that are not yet displayed in the scene. I gave addMesh() a try anyway but it didn't really help much. How should I go about it?

Link to comment
Share on other sites

If you are talking about the shader I developed for you msg me. I know the answer.  Its because some of the shaders variables are on defines and need to be migrated to a uniform, so different instances can have different settings.

Link to comment
Share on other sites

After some debugging I noticed that the meshes were (intentionally) removed from the scene beforehand, which caused the highlight shaders to not compile. (Although for some reason it didn't stop light shaders from compiling)

 

Is this the equivalent of Engine/createEffect()/name in engine.onBeforeShaderCompilationObservable/onAfter...?

engine.onAfterShaderCompilationObservable.add((e) => {
	setTimeout(() => console.log(e._currentEffect._key));
});

e._currentEffect is not defined immediately in the callback, am I likely to miss some shader compilations by setting a timeout? Is there a parameter which is defined at the moment of the callback?

Link to comment
Share on other sites

Well I agree that the observables are not providing enough info here. The timeout could be the right way but it needs testing 

Link to comment
Share on other sites

Got it.

 

1) Can I see particles shader info anywhere else except for _compiledShaders?

I'm asking because _currentEffect is null when particles are compiled.

 

2) It seems for CPU ParticleSystem, the shader is compiled in the PG simply by creating an instance, animate() is not required.

http://www.babylonjs-playground.com/#7UJDBL#1

 

In my local project though, the only way it works is if I'm setting an emitter and calling start().

If an emitter is not set or if it's set and animate() is called instead of start() - no shader is compiled.

It appears as if it's only compiled when particles are actually being rendered in the scene (which is not good for my purposes). Any idea why that might happen?

 

I haven't tested yet GPU ParticleSystem.

Link to comment
Share on other sites

I think it works for CPU.

What should I do for GPUParticleSystem?

I tried this to trigger:

particleSystem._recreateUpdateEffect();
particleSystem._recreateRenderEffect();

and this to check if ready:

particleSystem._updateEffect.isReady() && particleSystem._renderEffect.isReady();

I don't see any shader compiled for it.

Link to comment
Share on other sites

This is fine:

particleSystem._recreateUpdateEffect();
particleSystem._recreateRenderEffect();

 

and to check just run particleSystem.isReady()

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...