Jump to content
  • Advertisement
Sign in to follow this  
EvilDuck

OpenGL Multiplying blood splatters on a plane surface

This topic is 2333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. Edited by slicer4ever

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!