Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

"Alpha Bending"

Sign in to follow this  


One of the things I've learned from this project is that Blending is the solution to many, many problems.

A simple linear blend can help things seem more natural, from animation, to sound, decals, and terrain.

Our level designer recently added a mountain under the mountain temple level. It looked, great, except for the nasty transition between the path and the mountain side.

The engine has a great decal system, but it's not set up to blend with tileable texures like the ground or mountain - it's for spot effects. One could use decals to lay out a path by splatting one or more decal texures along it, but with a grassy texture, the repeating would be pretty obvious.

I had been thinking about layers for a long time, and an earlier version of the engine supported up to 2 layers on every texture, with the blend map stored as part of the main lightmap texture, but support for this was dropped, as it wasn't worth maintaining for the very small use it would see, plus the editor had no way of specifying the blend factors or handling layers.

So, over the past week my partner and I took a few minutes here and there during builds to come up with a better way to do blending for the path->mountain case. When I woke up at 4:30 am the yesterday for some reason, I felt I was ready to tackle it, and managed to get it in there, tested and fixed in about 5 hours or so total.

It works like so - each material has a float called 'blend under' and one for 'blend over', each of which default to 0. Floor type textures that may bleed over other nearby surfaces are given blend under and blend over of 1. Floors made of stone or marble, would have a blend under of 1, but a blend over of zero - who ever heard of overgrown marble?

Then, at level export time in the editor, for each triangle with a blend over > 0 - let's say 'sand' - it finds all neighboring tris with a different material, and with a blend under > 0, and a blend over < than the sand material we're currently doing. If the triangle is not facing to the side too much, it is saved as part of the 'blend mesh' for this material. The blend mesh has texture coordinates calculated as if it were part of the sand, although it occupies the space of the triangles just bordering the sand tris. The vertices of the blend mesh tri that touch the sand texture are given an alpha of 1, and the other vertices get zero. This provides the smooth gradient.

At runtime, each material with some tris to blend, called a blendmesh, has its bounding box culled vs the frustum. If it's partly visible, it is blended in after the main terrain is drawn, but before decals are applied. After a few tweaks to materials, it looks pretty good.

Right now the blending is purely linear, but I'm prepared to modulate in a noise texture as well if it becomes noticeable. Right now the textures involved are fairly noisy themselves.

Here are a couple of before and after shots :

Sign in to follow this  


Recommended Comments

Neat trick - those second two shots look excellent to me (btw, the first http://spies.net/lake_bad.jpg is broken). I guess it all depends on the context, but in my experience tiling textures are most noticeable in screenshots - during gameplay its a lot harder to spot. Also, if your player is spending more time analyzing the graphics engine for those sorts of thing its probably a good indication that the gameplay needs tweaking [lol]

Keep up the good work!

Share this comment

Link to comment
Well done, I like the lowest screenshot. In the upper two, is that supposed to be reflective grass? It looks a bit strange.

Share this comment

Link to comment
No, it's water over some grass. Obviously grass shouldn't be able to live under the water, so replacing it with sand seems like a good idea...

Share this comment

Link to comment
Okay, sorry, I see. I'm sure that it looks better when things are moving than in a screenshot. :)

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!