Additive/Blending Problem with background

Blitz3D Forums/Blitz3D Programming/Additive/Blending Problem with background

Fuller(Posted 2006) [#1]
I'm having some trouble with what I think is additive or blending with the background

Image:


Notice the two red and one blue circles. They blend in black areas with the background. These are .png sprites from photoshop with a MASKED flag applied. The background is a .jpg sprite with normal color flags.


jfk EO-11110(Posted 2006) [#2]
I'm not sure if I get you right. Maybe you're talking about darkish blended contours of the masked textures, like a dark border? This is well known "feature". Since masked textures require to use black as transparent color (even with TGA), and Texturefiltering will kind of blur things (as well as mipmapping does), you will be forced to use

A) A solution posted in the archives that will paint black texels with a neutral background color while leaving the alpha channel of the loaded mesked texture intact. I have posted such a solution too, not so long ago.

B) Use the new texture formats DDS, specificly DDS DXT3 with alpha information. You need to cut out the black parts, so they become transparent (not talking about a 4th channel for alpha!). Then select the outline of the masked thing, select border (eg. 4), then blur it (more), so the alpha channel will also be blured and allow directx to use smooth vector curves for the mask contour. In short: use DXT3 with alpha, then load it in mask mode. This is the reccomended way.

(nvidia offers a free PS export plugin I think)


Fuller(Posted 2006) [#3]
Well, I'll try to explain better.

Problem 1) The black borders appear around sprites when another sprite gets close to it.

Problem 2) In the above screenshot those circle bubble things are supposed to be completely solid no alpha (but they are masked). Why are they looking like I applied an EntityAlpha to them.

And while i'm at it, what is the best way to make an object turn around and the peak of its flight?


jfk EO-11110(Posted 2006) [#4]
1) I have no idea
2) Instead of Loadsprite use CreateSprite, then Looadtexture and EntityTexture sprite,tex.
3)"and the peak of his fight"? Not sure what you mean.


Fuller(Posted 2006) [#5]
Oh! Yeah! Stupid me, they're not sprites, they're single-surface meshes with textures. Not sure if this changes
anything though.

For the "peak of flight thing" Heres a diagram:


Hopr this helps. Sorry i'm having to write these pretty fast, haven't had much time lately...


Ross C(Posted 2006) [#6]
.


Ross C(Posted 2006) [#7]
Well, what i'd do is use sin/cos. Have an angle variable, and constantly add values to it.

Graphics 800,600
setbuffer backbuffer()

Global angle
Global x#,y#
x = 300
y = 200

While Not KeyHit(1)

   cls
   angle = angle + 1
   oval x,y + (sin(angle)*200) ; 200 is just a number to multiple the effect enough to see it.
   flip
wend
end



Ross C(Posted 2006) [#8]
In the above code, you would probabl add the sin(angle) effect onto the Y co-ord.

Another way to do this, would be to have waypoints and make the entity follow a curving waypoint system.

You could generate the waypoints, based on the entity's position. When it needs to turn, generate a waypoint system. Read it in from data statements or something.


Ross C(Posted 2006) [#9]
Something like this:

Save your waypoints to a type arrangement, or array, looking something like this...

www.rosscrooks.pwp.blueyonder.co.uk/waypoints.jpg

When you decide you want the entity to turn, generate the waypoint's, based on the entities position and orientation, like so:

www.rosscrooks.pwp.blueyonder.co.uk/waypointplacement.jpg

Obviously, don't parent them to the entity :oP Just get the entity to follow the waypoints. Let the waypoint control code know when you've reached the last waypoint path. Then let normal control take over.

Using this method you can have your entities do pretty cool stuff :o)


Fuller(Posted 2006) [#10]
I see what you mean, but I'm not sure if waypoints are fast enough. I mean, I have 5 - 10 objects on screen at one time.

But really the turning around not's the problem, the transpaerency is.


b32(Posted 2006) [#11]
The dark lines around transparent sprites is a very common glitch. I believe there is code in the archives that deals with that.
There is a mask and an alpha flag. Masked textures are drawn without any black pixels. (RGB=0,0,0) About alpha, I think I've read that blitz can only handle 2 alpha steps, on and off, but I'm not sure.


jfk EO-11110(Posted 2006) [#12]
Alpha can handle 256 levels of transparency, like rgb, hence 32bit argb.

When a DXT3 is saved with Alpha and then loaded as Mask in Blitz, the countours will be interpolated, as I said before.

For the peak thing I'd suggest to use a decreasing gravity variable, something like this:

jump#=2.0

while game

y#=y+jump
jump=jump-.1
if jump<-2 then jump=2
...


Fuller(Posted 2006) [#13]
I suppose I get what you mean. You can't seem to search the code archives. Is what you're talking about, Bram32, recent or is it awhile back?


jfk EO-11110(Posted 2006) [#14]
What he sais is what I already said before, BTW. Dark outlines on masked textures due to mipmapping.
http://www.blitzbasic.com/codearcs/codearcs.php?code=1806


Fuller(Posted 2006) [#15]
sorry, thanks.


Fuller(Posted 2006) [#16]
Nope. Still not working

{Edit: Download Removed by Author}

Sorry about all this, I'm just having a lot of trouble with my coding recently


jfk EO-11110(Posted 2006) [#17]
Will check this out later tonight. Got to go and get some fresh air ATM.


jfk EO-11110(Posted 2006) [#18]
I'm currently trying your code. I don't get this fully, do I have to click the rockets somehow?

You should have say the user has to type in "FireWorks" in the prompt on startup.

I see dark borders on the "stage" messages that are using the mask flag. Or are those masked 2D images? Anyway, in the 3rd level I get an Error, entity does not exist in Function Reload_Back():

Case 3
...
MoveENtity back,0,20,-18 ; <<<<<<<<<<<< this fails

Anyhow, I can't get to the screen with the red and the blue spheres for some reason. So how should I test this? EDIT ok, I was blind, got to tye "Water" instead of "FireWorks".

I take it you want the spheres to be masked (round shape), but fully opaque in the inner part, right?

Since you loaded the texture with flag 4, (the OptimizeALphaChannel function does fix the black border problem, but not the transparency problem), I have only one conclusion: the Mesh (quad) that is used by the particle engine must be blended in additional mode, instead of default alpha. I'll check this right now...


jfk EO-11110(Posted 2006) [#19]
You know, the more I try this, the more I think the bubble.png "sprites" are ok, but the background images, that are sprites too may use additive blending and are layed ONTOP of the bubble spheres?


jfk EO-11110(Posted 2006) [#20]
Bingo. You have loaded the background sprites with default texture flag, this seems to be additive. Simply Add the flag 4 to the loadsprite commands for the backgrounds, in the functions "Loadsprites" and Reload_back().

Additionally you have to add this line at the end of both functions:

EntityOrder back,1

To make sure the foreground is not drawn behind the background.

This was pretty tricky.


jfk EO-11110(Posted 2006) [#21]
How about this: now that I helped you to fix this, may I use your "fire.jpg" sprite? That's a nice one.


Fuller(Posted 2006) [#22]
Actually that's from a royalty free (I think) sprite pack included in the Devil Particle system.

You can download it from his website. Lots of nice sprites.

And About the typing stuff in, that's just temporary till I get GUI going. The Error after level 3 is becuase I didn't make a "level 3" sprite.

Thanks for your help!