Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Multiplying blood splatters on a plane surface


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 EvilDuck   Members   -  Reputation: 109

Like
0Likes
Like

Posted 01 June 2012 - 03:25 PM

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?Posted Image

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

smp.png

Thanks!

Sponsor:

#2 dpadam450   Members   -  Reputation: 932

Like
1Likes
Like

Posted 01 June 2012 - 06:03 PM

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.

#3 dpadam450   Members   -  Reputation: 932

Like
0Likes
Like

Posted 01 June 2012 - 06:12 PM

Actually that wont work.

#4 slicer4ever   Crossbones+   -  Reputation: 3945

Like
1Likes
Like

Posted 01 June 2012 - 06:22 PM

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, 01 June 2012 - 06:25 PM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#5 EvilDuck   Members   -  Reputation: 109

Like
0Likes
Like

Posted 02 June 2012 - 02:53 PM

Thank you for your suggestions. I'll try them out and will post if any results.

#6 EvilDuck   Members   -  Reputation: 109

Like
0Likes
Like

Posted 02 June 2012 - 03:34 PM

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.

#7 dpadam450   Members   -  Reputation: 932

Like
0Likes
Like

Posted 03 June 2012 - 11:59 AM

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.

#8 EvilDuck   Members   -  Reputation: 109

Like
1Likes
Like

Posted 03 June 2012 - 12:43 PM

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);

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);

device-2012-06-03-223706.png

So that's the result I'm getting.

Thanks you, guys, for your ideas!

#9 slicer4ever   Crossbones+   -  Reputation: 3945

Like
0Likes
Like

Posted 03 June 2012 - 12:49 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS