Jump to content

PBRPlanarMaterial


BartW
 Share

Recommended Posts

Hi all!

I'm terrible at shaders. I get the gist of it but I have no idea where to start. Especially when I need to extend a complex shader/material like PBRMaterial.

My use case: I have a customisable product, lets say a table. The idea is that you can specify the width and length of the table and it will animate (tween) to these dimensions. Simply scaling the table top is not an option since it consists of 9 submeshes since the edges contain a nice bevel which should keep its ratios mostly intact (like a 9-sliced tile). I've been playing around with scaling and offsetting the UV's per scaled submesh and I'm coming close to a working solution, but when the UV's are not neatly set up for me I have a hell of a job on figuring out the exact scale and offset per submesh.

A planar projection would solve this issue for me as it would layout the texture perfectly and would save me an enormous amount of UV calculations per mesh, per frame. Modifying the TriPlanarMaterial doesn't work for me since the rest of the materials are PBR instead of Standard, and the lighting is HDR only.

So my question is: how do I modify the existing PBRMaterial in such a way that it only projects textures in worldspace? Would this be a simple hack - hook into some callback or register a render process - or would I need to create an entire new material from the materialLibrary repo? Any advice would be much appreciated. A working example would really make my day. Possibly my week ;) Thanks in advance

- Bart

Link to comment
Share on other sites

Hello @BartW

I am having a hard time figuring out what you are trying to achieve exactly, could you create a playground with what you already have and I can try to hack in the shader for you or maybe even add a special mode for this kind of projection ?

As soon as I ll get a better grip on your issue I can definitely help hacking in the shader and then adding dedicating extension points in the material.

Link to comment
Share on other sites

Thanks for responding Sebavan!

PG here: http://www.babylonjs-playground.com/#BLMRX2

This should illustrate that I try to create the same effect as the TriPlanarMaterial: render textures in worldspace.

When the object scales or translates, the textures should still render at the same worldspace position.

Well maybe not when translating... The best would be when textures render in object space :)

Link to comment
Share on other sites

Awesome, that is exactly what I was looking for. Thank you so much!

So you override the actual pbr vertex shader in the store.. Is there a way to create a new entry with this adaptation and create a new PBRMaterial type that uses the new shader instead of overwriting the shader for all PBRMaterials?

Link to comment
Share on other sites

I'm browsing through the source code to figure out where this is hooked up to the shader store...

My guess is I need to hook into babylon.pbrBaseMaterial.ts line 1019:

return engine.createEffect("pbr", <EffectCreationOptions>{

Probably change "pbr" to some other prefix and inject new shaders in the store?

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...