SpaceToast Posted August 10, 2018 Share Posted August 10, 2018 I'm picking up an older project again, and moving it to the current version of BJS. This is a pain, though, because I'd been extending the StandardMaterial shader within a copy of the BJS framework itself. The project made extensive use of noise and shape functions to simulate textures within the GPU by altering the diffuse, specular and normal values of the StandardMaterial, based on a flag hacked into the framework. The advantage of this method vs. ShaderMaterial was getting unlimited resolution textures at no bandwidth cost without having to reimplement all the goodies in the StandardMaterial--SSAO2, fog, shadows, etc. The disadvantage: Lack of portability, and having to find a way to re-minify everything myself before deployment. (My kingdom for uglify.js to support the `` multiline literal...) Before I start migrating my hacks, I wanted to ask this of the smart people around the water cooler: Can anyone suggest a more elegent way to do this, without modifying BJS itself? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 10, 2018 Share Posted August 10, 2018 We have a BABYLON.CustomMaterial, but it’s not well documented. I would recommend playground code search and dig up some samples. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 10, 2018 Share Posted August 10, 2018 Adding @NasimiAsl author of the custom material. NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 10, 2018 Share Posted August 10, 2018 Also it would be good to know a bit more about the customization you did to see how we could make them fit best in. NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted August 11, 2018 Share Posted August 11, 2018 hi @SpaceToast we can make your needed sample if you make any PG here Quote Link to comment Share on other sites More sharing options...
SpaceToast Posted August 12, 2018 Author Share Posted August 12, 2018 Thanks @Pryme8, @Sebavan and @NasimiAsl. CustomMaterial looks like exactly what I need. Unfortunately, it doesn't seem to be production-ready just yet, based on the other forum threads. I could see saving a bit of trouble by replacing the StandardMaterial object with a custom version at runtime--one containing my changes. I'm not really familiar with JavaScript modules, however: They seem to be designed specifically to prevent code from tinkering around inside their scope. Quote Link to comment Share on other sites More sharing options...
SpaceToast Posted August 13, 2018 Author Share Posted August 13, 2018 I was 100% wrong about that last comment. Replacing the StandardMaterial's shaders is as simple as: BABYLON.Effect.ShadersStore["defaultVertexShader"] = ` //Copy the StandardMaterial's vertex shader code in here, and modify away. //Template literals are your friend. `; BABYLON.Effect.ShadersStore["defaultPixelShader"] = ` //Copy the StandardMaterial's pixel shader code in here, and modify away. `; Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 13, 2018 Share Posted August 13, 2018 Yup this would work as well, the only drawback is that you will apply the change to all the standard materials. Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted August 13, 2018 Share Posted August 13, 2018 this is what happen in builder inside the custom material Quote Link to comment Share on other sites More sharing options...
SpaceToast Posted August 17, 2018 Author Share Posted August 17, 2018 On 8/13/2018 at 8:17 AM, Sebavan said: Yup this would work as well, the only drawback is that you will apply the change to all the standard materials. That's not a drawback in this case. Unfortunately, after 6 hours trying to understand the source code, I'm no closer to figuring how to inject a new uniform into the StandardMaterial object at runtime. It's just too amazingly complicated. Afraid I'll have to go back to my previous method. ? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 17, 2018 Share Posted August 17, 2018 You just want a custom uniform I got you. https://www.babylonjs-playground.com/#LRGH45 for some reason the added uniforms are non-accessible as far as I can tell. as demonstrated by: https://www.babylonjs-playground.com/#LRGH45#2 so what you need to do is bind the uniform to a varying on the vertex Shader and pass it that to the fragment. https://www.babylonjs-playground.com/#LRGH45#4 ❤️ Sebavan 1 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.