testure Posted August 4, 2014 Share Posted August 4, 2014 The standard material doesn't seem to have a setting to change the blend mode, so I'm trying to create a custom shader that is additive. I opened up the particle and lens flare shaders that come with babylon, but when I start hacking those shaders up and using parts of them for my own purposes, they don't blend with the background at all. Any shader gurus able to point me in the right direction? Thanks! Quote Link to comment Share on other sites More sharing options...
testure Posted August 4, 2014 Author Share Posted August 4, 2014 to clarify- I can get additive blending working in the fragment shader just fine with something like gl_FragColor = baseColor + vColor;The problem is that it doesn't blend with what's in the scene at all. I'm pretty sure I need to set the gl blend mode to one/one, but I'm not sure how to do that with babylon. Any ideas? Quote Link to comment Share on other sites More sharing options...
Temechon Posted August 4, 2014 Share Posted August 4, 2014 Hey, I don't know if this can help you, but you can add two options when you create your ShaderMaterial : ShaderMaterial(name, scene, shaderPath, options)options is an set of parameters, two in particular, that you can define like this : {needAlphaBlending:true, needAlphaTesting:true}They are set to false by default. Maybe I'm totally wrong, I'm not a shader expert Cheers, Quote Link to comment Share on other sites More sharing options...
testure Posted August 4, 2014 Author Share Posted August 4, 2014 Hey, I don't know if this can help you, but you can add two options when you create your ShaderMaterial : ShaderMaterial(name, scene, shaderPath, options)options is an set of parameters, two in particular, that you can define like this : {needAlphaBlending:true, needAlphaTesting:true}They are set to false by default. Maybe I'm totally wrong, I'm not a shader expert Cheers, I'm trying to test this now- and I was about to report back that it did not work, but I just realized that no matter what change I make to my shader file it doesn't get updated in-game! The file is definitely named correctly and in the correct location- I can put blatant errors in the shader and it doesn't even throw an error. Does babylon cache the compiled shaders somewhere? If so, how would one go about forcing a shader to recompile? Quote Link to comment Share on other sites More sharing options...
Temechon Posted August 4, 2014 Share Posted August 4, 2014 Do you have a demo somewhere ? Maybe the shader file is in your browser cache, try to refresh it ! Quote Link to comment Share on other sites More sharing options...
testure Posted August 4, 2014 Author Share Posted August 4, 2014 yea, it was definitely some sort of caching issue. I renamed the shader and the changes I made appeared. At any rate, I'm back at square one, setting needAlphaBlending and needAlphaTesting to true didn't seem to work. It did enable the use of alpha, if I set the textureSampler to use a transparent png, it renders correctly- but it's just alpha blended, not additive. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 4, 2014 Share Posted August 4, 2014 Yes right now this is based on the following code:this.setDepthWrite(false); this._gl.blendFuncSeparate(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE); this._gl.enable(this._gl.BLEND);perhaps I can add an event on mesh to allow you to change this ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 4, 2014 Share Posted August 4, 2014 Actually you can already do that mesh.registerBeforeRender(function() { engine.setAlphaMode(BABYLON.Engine.ALPHA_ADD);}); Quote Link to comment Share on other sites More sharing options...
testure Posted August 4, 2014 Author Share Posted August 4, 2014 Actually you can already do that mesh.registerBeforeRender(function() { engine.setAlphaMode(BABYLON.Engine.ALPHA_ADD);});Yeah, I actually just now found that digging through the mesh and engine classes and was coming here to post my results. This is working great for my purposes. Thanks! 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.