Multiplying blood splatters on a plane surface

Started by
7 comments, last by slicer4ever 11 years, 10 months ago
Hello,

I'm working on a seemingly simple task. I have a simple 2D ortho game level with a textured background as a plane. Level is limited. Background is textured with tiled texture. What I need is to be able to add blood splatters as enemies die. These splatters must remain forever and multiply into each other (overlap and get darker).
I'm guessing, since I need hundreds of splatters I can't actually make them as geometry, so I need to somehow render them into original texture or something like that. I'm using OpenGl ES 2.0 and can't figure out how I "burn" splatters into the tiled texture. Any suggestions please?smile.png

I have attached a simple example of the desired effect made in Photoshop.

[attachment=9177:smp.png]

Thanks!
Advertisement
http://www.opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml
glBlendFunc(src, dst)
You probably can do glBlendFunc(GL_DST_COLOR, GL_ZERO);
Which should multiply the src*dst, and dst*0
so output = src*dst + 0 = red*green in your picture.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Actually that wont work.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

if you are using the same texture repeateadly, then you can't "merge" the blood splatter without it being repeated across the entire world.

so, here are some suggestions:

A: depending on the size of each texture, and the number of tiles, you could generate a "super" texture and render your geometry across that 1 super texture, instead of being repeated, as such, when your blood spatter occurs, you can update the texture with glTexSubImage2D, and well probably require storing a client-side version of the texture, so you can blend the blood with the existing texture.

B: forgo the idea of unlimted blood spatter, and reduce it down to something like 100 spatter's or so, and create a triangle rectangle batch, positioned with the terrain(using GL_LEQUAL depth test, and drawn after drawing the terrain), combined with blending, this should sufficiently create your effect, without having too serious of a perfomance hit, particularly if you batch the splatters, and use glBufferSubData to upload them/add/modify existing splatters, and using a counter for counting up the blood spatters and controlling where to write the next blood splatter into.

those are really the best available actions you can take imo, but perhaps someone else well have a better idea.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
Thank you for your suggestions. I'll try them out and will post if any results.

Actually that wont work.


Well, it did work to some extent. I have tried just drawing some splatters after texture with following blending equations:

GLES20.glBlendFunc(GLES20.GL_DST_COLOR, GLES20.GL_ONE_MINUS_SRC_ALPHA);

It blends exactly as I need it to. Now I need to figure out how to combine them more efficiently. And here I will try @slicer4ever suggestions.
Post a pic of several splats layered. src*dest or green*red = 0,0,0 so thats why I said it wouldnt really work. And the ONE_MINUS only relates to the green so I'm confused how you get any red in the image.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Ok, what I ended up with now is rendering splats to a one big texture (levels are small in my game) using FBOs with white initial background and following blending.



GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_DST_COLOR, GLES20.GL_ONE_MINUS_SRC_ALPHA);


[attachment=9260:device-2012-06-03-224010.png]

I need white background for a texture because I can't multiply with zero color obviously.

Then I draw grass tiles and render this texture in a big quad with:



GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_DST_COLOR, GLES20.GL_ZERO);


[attachment=9261:device-2012-06-03-223706.png]

So that's the result I'm getting.

Thanks you, guys, for your ideas!
good to hear mate=-), looks great=-)!
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

This topic is closed to new replies.

Advertisement