BabylonJS / Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
http://www.babylonjs.com
Apache License 2.0
23.05k stars 3.41k forks source link

Some meshes to overlap glow #4463

Closed PixelsCommander closed 6 years ago

PixelsCommander commented 6 years ago

Imagine here the stroke behind chip stack is just absent as it would happen if stroke is overlapped by the stack. This is what I d like to achieve. Currently working on PR for this but would like to have some guidance/input.

My idea is to:

Any better ideas on this? @deltakosh @sebavan

deltakosh commented 6 years ago

Hey and thank you for your interest :) How can you have more than one stencil buffer?

sebavan commented 6 years ago

Api wise, I am all good with the flag.

Solution wise I am like @deltakosh curious about your solution :-) I guess the easiest to discuss it would be to create the PR and then we could help adapting it ?

PixelsCommander commented 6 years ago

Oh. I am still bad in buffers. Lets name it a texture which we substract from blurred one.

deltakosh commented 6 years ago

ok so we are on the same page :D let's do a PR please

deltakosh commented 6 years ago

Up? I guess rewrite the mesh you want in the rendertarget before applying the glow should do the trick

PixelsCommander commented 6 years ago

TBH I tried to play around but so far cant make it work with both innerglow / outerglow.

Rewrite? Could you elaborate here please?

deltakosh commented 6 years ago

Just a thought but you should be able to render the object you want to overlap directly (as black objects) into the rendertarget texture just before applying the glow in the main scene (in order the remove the glow where they are)

PixelsCommander commented 6 years ago

@deltakosh this works for outer glow but not for inner glow. These are shots from Spector:

Outline layer drawn correctly:

screen shot 2018-06-18 at 5 36 34 pm

Outer glow drawn correctly then inner glow which spoils the picture:

screen shot 2018-06-18 at 5 36 45 pm

Also I observe some problems with depth buffer. So if I move camera a bit then it looks like:

screen shot 2018-06-18 at 6 25 31 pm

The code added is:

Object.keys(this._excludedMeshes).forEach(id => {
      this._renderPhase = RenderPhase.CleaningExcluded;

      var mesh = this._excludedMeshes[id].mesh;
      var subMeshes = mesh.subMeshes;
      var engine = this._engine;
      var previousStencilFunction = engine.getStencilFunction();
      var previousStencilOperationPass = engine.getStencilOperationPass();
      var previousStencilOperationFail = engine.getStencilOperationFail();
      var previousStencilOperationDepthFail = engine.getStencilOperationDepthFail();
      engine.setStencilFunction(Engine.ALWAYS);
      engine.setStencilOperationPass(Engine.ZERO);
      engine.setStencilOperationFail(Engine.ZERO);
      engine.setStencilOperationDepthFail(Engine.ZERO);
      subMeshes.forEach(this._renderSubMesh.bind(this));
      engine.setStencilFunction(previousStencilFunction);
      engine.setStencilOperationPass(previousStencilOperationPass);
      engine.setStencilOperationFail(previousStencilOperationFail);
      engine.setStencilOperationDepthFail(previousStencilOperationDepthFail);
      this._renderPhase = RenderPhase.InnerGlow;
   });

Any suggestions?

sebavan commented 6 years ago

Another idea would be to render the chip after the first renderLayer to hide to border.

You could rely on a second renderGroup without cleaning the depth info ?

Let me try to do a quick PG

sebavan commented 6 years ago

@PixelsCommander looking more in detail in the issue, the best way to fix it would be to allow effect layer to work per rendering group.

Thinking even deeper there are a couple of other nice changes we could do in this space.

If you are not in a rush I am planing to deploy a new version by end of week. Would that fit to you ?

sebavan commented 6 years ago

Closed and reopen due to finger management issue ;-)

PixelsCommander commented 6 years ago

Yeah, sure.

sebavan commented 6 years ago

It happens than the changes I am doing to componentize the effectlayers are getting a bit bigger but will help componentizing other modules.

I am expecting to have this for end of next week. Basically, you would be able to associate the effect layers with a rendering group ensuring that from one group to the other you could render on top of the effect.

PixelsCommander commented 6 years ago

Sounds great. Looking forward for it!

2018-06-23 0:35 GMT+02:00 sebavan notifications@github.com:

It happens than the changes I am doing to componentize the effectlayers are getting a bit bigger but will help componentizing other modules.

I am expecting to have this for end of next week. Basically, you would be able to associate the effect layers with a rendering group ensuring that from one group to the other you could render on top of the effect.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BabylonJS/Babylon.js/issues/4463#issuecomment-399601177, or mute the thread https://github.com/notifications/unsubscribe-auth/AAxer17_9s0FU5eEgVPLTFdf7P9Asw6oks5t_XEwgaJpZM4UeLoI .

sebavan commented 6 years ago

Following the PR above, you ll be able to achieve this through the use of rendering groups: https://playground.babylonjs.com/#KTR4V2

Basically you can attach an effect layer to a chosen rendering group and push the meshes that needs to overlap in a subsequent group.

Also, please turn off the auto clear for the second group or those meshes will draw on anything present in the first one as the depth buffer would be clear.

I close the issue for now and we can open it back if needed.

PixelsCommander commented 6 years ago

@sebavan Glad to see there is a progress on what you were busy with.

Is this how it intended to be rendered?

screen shot 2018-06-29 at 9 41 59 am

Then it is not what I was trying to achieve. Green one should overlap glow under it, not having a glow around.

sebavan commented 6 years ago

Nope but the nightly has not been deployed yet :-) It will after deploy

deltakosh commented 6 years ago

Should be good now :) https://playground.babylonjs.com/#KTR4V2#1

PixelsCommander commented 6 years ago

Confirm, works as expected. Thanks a lot!!

PixelsCommander commented 6 years ago

after applying the solution we got chips to be rendered on top of the scene so had to roll it back. @sebavan @deltakosh any ideas on how to prevent this keeping renderingGroup solution?

screen shot 2018-07-10 at 2 43 06 pm
sebavan commented 6 years ago

Hello,

This is the function doing the trick:

scene.setRenderingAutoClearDepthStencil(1, false, false, false);

This prevent the depth buffer to be cleaned before rendering the group 1. You should replace 1 by the group id of your chips.

PixelsCommander commented 6 years ago

Once we set rendering groups on highlight layer and chips shadows are lost on all objects which do not have renderingGroup set.

I tried to change group for the rest but this is just guessing without knowing how it works under the hood in details.

@sebavan , @deltakosh guys, any ideas?

deltakosh commented 6 years ago

Rendering groups can be seen as layers. It is a good way to have different passes.

Can you repro in the playground a simple setup that looks like your game and we can help you define the correct rendering groups

PixelsCommander commented 6 years ago

Huh, now we are confused. Not able to reproduce this in the playground. And no clue what it is so far, investigating.

http://playground.babylonjs.com/#6T9SI9

deltakosh commented 6 years ago

This is a good news if you think about it ;)

PixelsCommander commented 6 years ago

Here is a playground http://playground.babylonjs.com/#6T9SI9#1

Bug(?) is caused by generator.usePercentageCloserFiltering = true;

The similar one is reproducible in a demo here http://www.babylonjs-playground.com/#R1EVD0#3 but this time with another property of shadowGenerator.useBlurExponentialShadowMap = true; and no rendering groups. Basically, the demo is broken currently.

sebavan commented 6 years ago

I have moved the conversation to a new issue as the issue is not related to the EffectLayer.