Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semi transparent material #37

Closed
haitaoli opened this issue Dec 10, 2017 · 5 comments
Closed

Semi transparent material #37

haitaoli opened this issue Dec 10, 2017 · 5 comments

Comments

@haitaoli
Copy link

haitaoli commented Dec 10, 2017

I have some textures (such as glass) that have alpha channel. But if I make a block with it then the parts with alpha become full transparent. I did a little research on this and it seems babylon standard material does alpha testing instead of alpha blending, so any pixel with alpha < 0.5 becomes fully transparent. To support alpha channel, opacityTexture needs to be set on the material. But after looking through the code it's not obvious where to set this.

@fenomas
Copy link
Owner

fenomas commented Dec 10, 2017

Hey, really good question. The short version is that I think I have this implemented, but I'm not personally using any alpha textures in my project right now so I'm not sure if it works.

The relevant code is, to pass in a texHasAlpha flag when registering the material via noa.registry.registerMaterial. The mesher should then see that property here when building the terrain mesh, and set the hasAlpha property for the Babylon texture.

Can you try that and let me know if it works? It's a while since I looked at this, so BJS may have changed. Also the above is assuming that there's just one texture with alpha - if you wanted to apply a separate texture for the opacity then I don't have any code for that yet, though I don't think it would be very hard to support.

@haitaoli
Copy link
Author

Setting hasAlpha enables alpha testing but not alpha blending. I was able to "fix" it by setting mat.opacityTexture to the same texture, and I found it works the same if I use ambientTexture instead of diffuseTexture. But then I hit a rendering bug. Some blocks get clipped when viewed from specific angles:

screen shot 2017-12-10 at 9 24 47 am

@fenomas
Copy link
Owner

fenomas commented Dec 10, 2017

Okay, the texture parameters get into an area I'm not very familiar with. My recollection is that setting hasAlpha used to be sufficient, but only if something else was true, or somesuch. Babylon has a couple of different settings related to opacity and I'm not sure what the "correct" combination is. It's easy to change, if only we know what the working combination of settings is.

For the clipping thing, do both the grass and the brown bricks in that screenshot have some kind of alpha enabled? Clipping like that is expected if multiple parts of the terrain need alpha blending (since terrain voxels are merged into large per-chunk meshes), but I don't know why it would happen for opaque meshes. Can you describe more about what's going on?

@haitaoli
Copy link
Author

haitaoli commented Apr 6, 2018

I finally got some time to look into this issue one more time. If I set opacityTexture for images without alpha, then it may get clipped. I don't understand why, possibly a bug in babylon.

@fenomas
Copy link
Owner

fenomas commented Nov 22, 2018

Closing this for now, but if it resurfaces please do file it. (Maybe as a new issue, since I think Babylon has versioned up since this was filed, so the behavior's probably changed..)

@fenomas fenomas closed this as completed Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants