Is there a way to change the alphaMode of each PolyNewStrip?

Previous topic - Next topic

Alex_R

Hello everyone!

I'm trying to create a particle emitter using a PolyVector for all the particles, separating each one by a PolyNewStrip. I also want each particle to fade away independently.

My problem is that with this approach it seams I can only change the AlphaMode of the whole PolyVector, instead of the alphaMode of each separated PolyNewStrip (so that each particle can disappear at a random time). I've seen that there is an OpenGL instruction to tint each PolyVector with an RGBA color (which I'd use to tint each particle with an increasing alpha), but I can't seem to find an equivalent instruction in GLBasic.

I'm also open to (and will welcome) any new approach you can give me.

Thank you in advance!

monono

No, that works. You can use individual ALPHAMODEs before each POLYVECTOR. You can even change just one point. You cannot go over zero in one POLYSTART-END call.

Ian Price

You can do this with TYPEs within POLYVECTOR too.
I came. I saw. I played.

matchy

Have a look here: http://www.glbasic.com/forum/index.php?topic=7472

The easy way is to set the alphamode before each polyvector.
Code (glbasic) Select

STARTPOLY...
ALPHAMODE n
POLYVECTOR...
ALPHAMODE n
POLYVECTOR...
ALPHAMODE n
POLYVECTOR...
ENDPOLY



Alex_R

That was it!

My problem was that I tested if it worked using something like this:
Code (glbasic) Select
STARTPOLY...
ALPHAMODE 0.1
POLYVECTOR...
(...)
POLYNEWSTRIP
ALPHAMODE 1
POLYVECTOR...
(...)
ENDPOLY

And if you do that (use 1 for the last AlphaMode) then both PolyNewStrips use AlphaMode 1 (is this a bug?). I never thought of using a number close to 1 instead of 1 (i.e., 0.99). Now it works perfectly.

Thank you all very much!!

spicypixel

I am having exactly the same issue using POLYNEWSTRIP. In my main code I have the STARTPOLY and ENDPOLY commands and this function gets called numerous times within my loop to blit sprites onto the screen. So for example if I have..

Code (glbasic) Select

ALPHAMODE -1
PV_SPRITEZOOM (192, 100, 100)
ALPHAMODE 0
PV_SPRITEZOOM (192, 132, 100)
ALPHAMODE 1
PV_SPRITEZOOM (192, 164, 100)


Every sprite is set to ALPHAMODE 1, I'm using v11.414, is this a bug???

... PVSPRITE Function
Code (glbasic) Select

FUNCTION PV_SPRITEZOOM: sprite, xpos#, ypos#, scale#=1
// Auto Position
xpos# = xpos# * ZOOM#
ypos# = ypos# * ZOOM#
scale# = scale# * ZOOM#

// Texture UV Info.
patx      = SPR_PV[sprite].SPR_PV_X
paty      = SPR_PV[sprite].SPR_PV_Y
patxx     = SPR_PV[sprite].SPR_PV_X + SPR_PV[sprite].SPR_PV_W
patyy     = SPR_PV[sprite].SPR_PV_Y + SPR_PV[sprite].SPR_PV_H

// Sprite Info.
pminx = xpos
pminy = ypos
pmaxx = pminx + SPR_PV[sprite].SPR_PV_W * scale#
pmaxy = pminy + SPR_PV[sprite].SPR_PV_H * scale#

POLYVECTOR pminx, pminy, patx , paty , RGB(255,255,255) // Top-Left
POLYVECTOR pminx, pmaxy, patx , patyy, RGB(255,255,255) // Bottom-Left
POLYVECTOR pmaxx, pminy, patxx, paty , RGB(255,255,255) // Top-Right
POLYVECTOR pmaxx, pmaxy, patxx, patyy, RGB(255,255,255)// Bottom-Right
POLYNEWSTRIP
ENDFUNCTION
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

fivesprites

Works fine for me with v414.

I use a single STARTPOLY/ENDPOLY to draw absolutely everything - including particles with varying levels of alpha:
Code (glbasic) Select

ALPHATESTING 0.001

STARTPOLY ID_ATLAS, 2
map.draw()
particleManager.draw()
game.draw()

ALPHAMODE 0.999
Prnt("FPS:" + fps, 40*sX, 10*sY, 0xffffff, 0x00ff00, 0.3*sX, 0.3*sY)
ALPHAMODE -0.0001
ENDPOLY

Each of the draw commands (and the Prnt) all just draw with POLYVECTOR and POLYNEWSTRIP as you do. I wonder if it's how you're using the alphamode (haven't looked in ages, I got it working and left it!) :)

//Andy

spicypixel

When you say how I'm using ALPHAMODE, what do you mean? Seems we're both doing the same here :-) I am using VIEWPORT higher up in the code but this shouldn't make any difference right.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

fivesprites

I don't use viewport, but can't see that being an issue.

Try putting ALPHAMODE -0.0001 after you've finished drawing (just before ENDPOLY)

//Andy


spicypixel

Quote from: Ocean on 2013-Jul-12
Can someone please explain why you would want to use transparency for 3D object creation VERSUS putting the transparency into the texture bitmap?
I hate to admit that I don't have an in-depth understanding of the discussion so far.. :(

I'm using polyvectors for sprites and some do have transparency in them which is fine, but doesn't help if I want to fade sprites out or make some bright for additive effects. However so far when trying the ALPHAMODE setting in between each POLYNEWSTRIP it does nothing and just keeps the first or last ALPHAMODE setting.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

spicypixel

If I use.. ALPHAMODE -1 or ALPHAMODE -0.99999999 before my ENDPOLY then all the ALPHA settings are the same regardless. However if I use ALPHAMODE -0.99999997 before the ENDPOLY it works. Something is broken in Kansas surely?????

EDIT: The negative alphas work but switching between + and - only the negative work :/
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

fivesprites

You can't switch between -ve and +ve in a polyvector operation (start/endpoly) as that means you're trying to change the blend mode.  It will use whichever you started with and then clamp to those limits.  If you're using -ve values then 0 is seen as a different mode, so you need to use a value less than this.  Similarly, if you're using +ve (additive blend) then you need to keep all values over 0.

spicypixel

Quote from: fivesprites on 2013-Jul-12
You can't switch between -ve and +ve in a polyvector operation (start/endpoly) as that means you're trying to change the blend mode.  It will use whichever you started with and then clamp to those limits.  If you're using -ve values then 0 is seen as a different mode, so you need to use a value less than this.  Similarly, if you're using +ve (additive blend) then you need to keep all values over 0.

Aha, why thank you :)
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

aroldo

[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2

spicypixel

Quote from: aroldo on 2013-Jul-27
Alex_R

Take a llok at this code, he is using a particle like system with STARTPOLY
http://www.glbasic.com/forum/index.php?topic=4251.msg54989#msg54989

Will take a nose at the alpha side of thing but I think my issue is going from +1 to -1 and passing the 0 threshold which won't work in a single start/endpoly cycle, might just have 2 setup, one for alpha and shadows and then one for multiplied brightness, but thanks for the link, always good to nose at other code. Just have to study the variables more as its not in native language of English but the code is there to show what everything is :D
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.