Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some meshes to overlap glow #4463

Closed
PixelsCommander opened this issue Jun 7, 2018 · 27 comments
Closed

Some meshes to overlap glow #4463

PixelsCommander opened this issue Jun 7, 2018 · 27 comments
Assignees
Labels
enhancement in progress Someone is currently working on this issue rendering engine

Comments

@PixelsCommander
Copy link
Contributor

PixelsCommander commented Jun 7, 2018

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:

  • API wise have additional flag shouldExcludedOverlap: boolean
  • Solution wise to render excluded meshes to one more stencil buffer and substract it from blurred glow texture.

Any better ideas on this? @deltakosh @sebavan

@deltakosh
Copy link
Contributor

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

@sebavan
Copy link
Member

sebavan commented Jun 7, 2018

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
Copy link
Contributor Author

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

@deltakosh
Copy link
Contributor

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

@deltakosh
Copy link
Contributor

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

@PixelsCommander
Copy link
Contributor Author

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

Rewrite? Could you elaborate here please?

@deltakosh
Copy link
Contributor

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
Copy link
Contributor Author

PixelsCommander commented Jun 18, 2018

@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
Copy link
Member

sebavan commented Jun 18, 2018

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
Copy link
Member

sebavan commented Jun 18, 2018

@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 sebavan closed this as completed Jun 18, 2018
@sebavan sebavan reopened this Jun 18, 2018
@sebavan
Copy link
Member

sebavan commented Jun 18, 2018

Closed and reopen due to finger management issue ;-)

@PixelsCommander
Copy link
Contributor Author

Yeah, sure.

@sebavan sebavan added the in progress Someone is currently working on this issue label Jun 22, 2018
@sebavan
Copy link
Member

sebavan commented Jun 22, 2018

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
Copy link
Contributor Author

PixelsCommander commented Jun 22, 2018 via email

@sebavan
Copy link
Member

sebavan commented Jun 29, 2018

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.

@sebavan sebavan closed this as completed Jun 29, 2018
sebavan added a commit that referenced this issue Jun 29, 2018
Addressing Issue #4463 Overlap of mesh and effects.
@PixelsCommander
Copy link
Contributor Author

@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
Copy link
Member

sebavan commented Jun 29, 2018

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

@deltakosh
Copy link
Contributor

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

@PixelsCommander
Copy link
Contributor Author

Confirm, works as expected. Thanks a lot!!

@PixelsCommander
Copy link
Contributor Author

PixelsCommander commented Jul 10, 2018

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
Copy link
Member

sebavan commented Jul 10, 2018

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
Copy link
Contributor Author

PixelsCommander commented Jul 11, 2018

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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

@PixelsCommander
Copy link
Contributor Author

PixelsCommander commented Jul 11, 2018

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
Copy link
Member

sebavan commented Jul 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement in progress Someone is currently working on this issue rendering engine
Projects
None yet
Development

No branches or pull requests

3 participants