Hartha Posted October 29, 2017 Share Posted October 29, 2017 Hello guys, see the GIF please https://ibb.co/kZkrBR. I wonder how to do something like this in babylonjs, I did this in opengl project by sending a value to a uniform in fragment shader. should I do the same with babylonjs ? ; should I modify babylonjs shaders ?, or there is a better way to do that. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted October 29, 2017 Share Posted October 29, 2017 if(gl_FradCoords.y > amount)discard; or something like that on the shader Hartha 1 Quote Link to comment Share on other sites More sharing options...
Arte Posted October 29, 2017 Share Posted October 29, 2017 Hi Hartha, mat.Fragment_Custom_Diffuse Hartha 1 Quote Link to comment Share on other sites More sharing options...
Hartha Posted October 30, 2017 Author Share Posted October 30, 2017 @Pryme8 and @Arte, Thank you guys very mush, very helpful answers, I have to update the amount "y", but it seems not to work when I put mat.Fragment_Custom_Diffuse('if( vPositionW.y >'+ y +' ){ discard; }'); in registerBeforeRender, it just take the first call. I will look to the implementation to find a solution. Thank you very much again :). Quote Link to comment Share on other sites More sharing options...
Arte Posted October 30, 2017 Share Posted October 30, 2017 @Hartha Could you show you problem using PG? Hartha 1 Quote Link to comment Share on other sites More sharing options...
Hartha Posted October 30, 2017 Author Share Posted October 30, 2017 Of course, https://playground.babylonjs.com/#AFRP1L#1 Quote Link to comment Share on other sites More sharing options...
Arte Posted October 30, 2017 Share Posted October 30, 2017 @Hartha It is not the best answer, but you need to change material dynamically each time. Working PG Hartha 1 Quote Link to comment Share on other sites More sharing options...
Hartha Posted October 30, 2017 Author Share Posted October 30, 2017 @Arte Yes, it is not the best answer but it maybe be convenient to my case, Thanks Arte. Quote Link to comment Share on other sites More sharing options...
Arte Posted October 30, 2017 Share Posted October 30, 2017 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted October 30, 2017 Share Posted October 30, 2017 just build a custom shader from the default one so you keep all the rendering options, and add the new line of discard set to play off a uniform then just update your uniform on the before render function and you wont have to keep assigning the material. Quote Link to comment Share on other sites More sharing options...
Arte Posted October 30, 2017 Share Posted October 30, 2017 @Pryme8 Can you provide sample? Quote Link to comment Share on other sites More sharing options...
Hartha Posted October 30, 2017 Author Share Posted October 30, 2017 @Pryme8 in CustomMaterial class there is a function to add a uniform, but I don't find how to update it, and in the StanderdMaterial class I find how to add and update a uniform but I don't know where to add a discard condition -.-. Sorry for this but can you provide sample as Arte side ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 30, 2017 Share Posted October 30, 2017 Ping @NasimiAsl who is the father of the CustomMaterial Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted October 30, 2017 Share Posted October 30, 2017 I would ask @NasimiAsl on how to add a uniform to the Custom Material, I have never used it. but once you have it in place it should be as simple as material.setFloat('nameOfFloat', value); inside a render loop or pre render loop. but here is an example with setfloathttp://www.babylonjs-playground.com/#1L8D9Y Arte 1 Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted October 30, 2017 Share Posted October 30, 2017 4 hours ago, Hartha said: @Pryme8 in CustomMaterial class there is a function to add a uniform, but I don't find how to update it, and in the StanderdMaterial class I find how to add and update a uniform but I don't know where to add a discard condition -.-. Sorry for this but can you provide sample as Arte side ? hi customMaterial and standardmaterial both can update uniform with this material.getEffect().setFloat() and others uniforms type @Hartha Sample : https://playground.babylonjs.com/#AFRP1L#4 @Deltakosh Bug : https://playground.babylonjs.com/#AFRP1L#5 look line 48 ,49 50 when a new mesh created or ( i think ) new standardMaterial created all set Effect function is freezed is this depend to StandardMaterial ** for check you can set any Uniform in standard material notice that custom material inherited from standard material Arte 1 Quote Link to comment Share on other sites More sharing options...
Hartha Posted October 31, 2017 Author Share Posted October 31, 2017 Thanks @NasimiAsl for help, I guess it is not a bug, you can see the log : babylonjs WebGL: INVALID_OPERATION: uniform1f: location not for current programit is means that the active shader program is not the program which obtained the uniform locations from, we need to do something like gl.useProgram or update the uniform when we sure that the current active program is for the material we need to update. 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.