BartW Posted August 1, 2018 Share Posted August 1, 2018 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 Quote Link to comment Share on other sites More sharing options...
BartW Posted August 1, 2018 Author Share Posted August 1, 2018 I guess what I'm trying to do is hack into the PBRMaterial's vertex shader and reset the uv's by setting uv = worldPos.xz, right? Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 1, 2018 Share Posted August 1, 2018 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. Quote Link to comment Share on other sites More sharing options...
BartW Posted August 2, 2018 Author Share Posted August 2, 2018 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 Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 2, 2018 Share Posted August 2, 2018 Here it is : http://www.babylonjs-playground.com/#BLMRX2#2 I am really not sure it is a common behavior so I do not think to make it a feature but a cleaner way would be to simply replace the mainUV part without setting offset nor scale on the texture: http://www.babylonjs-playground.com/#BLMRX2#3 Let me know if that works for you. babbleon 1 Quote Link to comment Share on other sites More sharing options...
BartW Posted August 2, 2018 Author Share Posted August 2, 2018 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? Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 2, 2018 Share Posted August 2, 2018 Yes, you could but you would need to dupplicate the pbr code. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 2, 2018 Share Posted August 2, 2018 @BartW You could also modify the pbrBaseMaterial class to allow using a different shader this could be customized in the constructor for instance. Quote Link to comment Share on other sites More sharing options...
BartW Posted August 2, 2018 Author Share Posted August 2, 2018 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? Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 3, 2018 Share Posted August 3, 2018 Yup, exactly ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.