Combining alpha mask and a texture

I’m not entirely sure this is possible to do, at least in a fast way (preferably by blending things). I’d like to have my particles use the texture of the ground where they hit, I know how to do this part… but I’d like those particles to have a shape, preferably based on the alpha values of a second texture. The idea is something could hit the ground which might be grass or dirt (or possibly water even) I’d like to have a kind of splash effect dependant on what type of terrain is hit.



I’m not sure there is a simple way to accomplish this in a program, I suspect that it’d be done by creating a texture in memory that merges the two images (alpha from one and the rest of the texture for the other). I suspect I could save a step, by making it so that all my terrain fields contain an alpha mask shaped the way I want my particles to be shaped, they should show up the same when blending isn’t being used (which would be normal) and when used as the texture for a particle with alpha blending it should appear shaped like the alpha mask.



Is there a better way to do this (like maybe through multi-texturing)? I suspect that using the actual terrain texture might be a bad idea, since those will be much larger textures than what a particle would even be visible as, and I should probably just have a few preset colors that match the terrain color approximately.

Currently, its not possible to collision detect with a single particle as the entire particle system is just one trimesh.



Having said that, you can use the PhysicsParticleManager to get collisions at particle level and then simply add another particle manager where the particle hit the ground.



It seems long winded, but its actually alot easier than what you are planning to do.



DP

I didn’t mean for each particle to be a different texture, basically what I meant was where a bullet hits the ground, I generate a set of particles using the same texture as the ground where the bullet hit, all the particles would share a texture. It’d be nice if the particles could share the texture but use different coordinates instead of trying to cram a 256x256 texture onto a 3 pixel particle or smaller, graphics cards probably handle that like it’s nothing though. I don’t think anything like that is available without extending the class, though it seems to me it’d be a useful feature, possibly tell the particle manager you want to use a texture, and then tell it you want to use it like an 8x8 grid (32x32 pixel coordinates). I strongly suspect this would look ugly though, so probably not a worthwhile feature, unless someone has another reason to use that (say for example… they want a set of lucky charms for particles… they’d just make a texture with the various shapes).

I see what your asking now. Right, what you need to do is upon collision, obtain the texture state of the spatial you hit. You can do this by:



Spatial spat = ...
TextureState ts = (TextureState)spat.getRenderStateList()[RenderState.RS_TEXTURE];
Image img = ts.getTexture().getImage();



So now you have the image to the texture, simply create a new texture, set the texture's image to that image, and create a new textureState and set teh texture to be that new texture. And your done.

Btw, i haven't tried this, i assumed it would work. However, there might be some referencing issues with getImage()...

DP

I think my best route is to use a quad in place of particles, I can’t seem to get the particles looking quite how I want them to. I figure I can setup a quad with a texture and use a few sets of texture coordinates to animate the quad. Particles seem to be better suited for making fire/smoke/explosion type effects, though it might be cause I don’t fully understand all the params of a particle manager that I can’t get things to work like I want (even when using ren’s particle editor).