Jump to content

Recommended Posts

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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, 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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!

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