GLBasic forum

Feature request => 3D => Topic started by: sf-in-sf on 2013-Oct-30

Title: 3D transparency
Post by: sf-in-sf on 2013-Oct-30
Hi!
I need an X_ALPHAMODE, or an X_OBJADDVERVERTEX with RGBA colors. Any idea?
Not easy I guess. GL ES for android makes it even worse...

Code: (glbasic) [Select]
// --------------------------------- //
// Project: test-3D-transparency
// Start: Wednesday, October 30, 2013
// IDE Version: 10.283


SETCURRENTDIR("Media") // go to media files

CONSTANT MK3D1%=1, MK3D2=256, MK3D3=80 // zfar down to 16 is still o.k. for this example!
LOADSPRITE "smallpicture.png",1
DRAWSPRITE 1, 3,3

X_OBJSTART 0
X_OBJADDVERTEX -1.0,-1.0,0.0,  0.0,1.0, 0xffffff //SW
X_OBJADDVERTEX -1.0, 1.0,0.0,  0.0,0.0, 0xffffff //NW
X_OBJADDVERTEX 1.0 ,-1.0,0.0,  1.0,1.0, 0xffffff //SE
X_OBJADDVERTEX 1.0 ,1.0 ,0.0,  1.0,0.0, 0xffffff //NE
// Note: is there no way to enter an alpha color?
// As soon as you use a color different from 0xffffff
// the ALPHAMODE stops working, stopping transparency.

// Problem: I must choose either vertex colors or transparency,
// but I need both.
X_OBJEND

X_MAKE3D MK3D1, MK3D2, MK3D3//1,256,80
X_CAMERA 0,0,3,  0,0,0
X_SETTEXTURE 1,-1
ALPHAMODE -0.33

FOR i%= -4 TO 0
X_MOVEMENT 0,0,i
X_DRAWOBJ 0,0
NEXT

SHOWSCREEN
MOUSEWAIT
END
Title: Re: 3D transparency
Post by: Schranz0r on 2013-Oct-31
i think the only way is gl.gbas.
Title: Re: 3D transparency
Post by: mentalthink on 2013-Oct-31
I do test with the OpenGL Library of GLbasic, and you can do very very intersting things...
About change the value of transparency I'm not sure, but we have a lot of kind of transparency using directly the library...

Really it's very very easy do your own function with OpenGL, if you need help, comment me and I sned my work, you can see a lot of nice effects, and if you know a bit of graphics, don't programming, you can false a lot of things... basically it's do little tricks...

Title: Re: 3D transparency
Post by: kanonet on 2013-Oct-31
Maybe not really helpful, but: wouldnt it be better to use textures to achieve this? Other idea would be using shaders, could easily be done there (but no gl es with GLB).
BTW. RGBA = bOR(RGB(r,g,b), ASL(a, 24)) but I dont know if this works on this commands.

EDIT: forgot a ) in the function.
Title: Re: 3D transparency
Post by: SnooPI on 2013-Oct-31
The alpha blending it's for pixels not for the vertices.

kanonet  :good: small function. Very useful  :)
Title: Re: 3D transparency
Post by: Hemlos on 2013-Nov-03
rgba vertice color is a color addition(blended) to a texture surface, if not mistaking.
if you want no color addition, then dont use color addition at the vertice (eg. 0,0,0 )

Title: Re: 3D transparency
Post by: sf-in-sf on 2013-Nov-05
Thanks guys. The problem is not solved but I found a way around it.
BTW. RGBA = bOR(RGB(r,g,b), ASL(a, 24))
-> yes I tried it but didn't work.  :( (something like vertex color = 0x77ffffff and 0x77ffffee)
However I made an interesting discovery that does the job if speed is no issue:
after drawing something transparent in 3D, go back shortly to 2D before the next 3D element. The results are excellent -but a bit slow. How it works, what I believe: when you go back to 2D the z-buffer is reset, so everything already there is considered as 2D. The next 3D drawing happens on top of a 2D sprite, with no z-buffer fuss. 3D transparency becomes perfect like that. You still need all vertex colors at 0xffffff, but color and alpha can be on the texture sprite. ALPHAMODE works in 3D then, both positive and negative. Try it too and show us your results!
Title: Re: 3D transparency
Post by: SnooPI on 2013-Nov-06
I repeat : alpha blending is a graphic effect not a 3d effect.

it's for pixels not for vertices.
it's normal that the small (but good) function of kanonet didn't work.  ;)
Title: Re: 3D transparency
Post by: SnooPI on 2013-Nov-06
sf-in-sf i think that GLB works a little like this:

Code: (glbasic) [Select]
//NOT GLB CODE, BUT ANSI C CODE

// Clear Buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// 3D
//BLENDING?  for drawing 3d transparent texture (objects or polygons with vertex (colored or not), polygons multitextured or not ....)
if(BLENDING3D)   
{
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     glEnable(GL_BLEND);
}
else
     glDisable(GL_BLEND);

//DRAW 3D
.....................
........................

// 2D
//Go to Ortho Mode(2d)
OrthoMode(0, 0, screen_width, screen_height);  // (in this function : glMatrixMode, glPushMatrix, glLoadIdentity, glOrtho, ......)
       
//BLENDING?     for drawing 2d transparent sprite
if(BLENDING2D)   
{
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     glEnable(GL_BLEND);
}
else
     glDisable(GL_BLEND);
         
//DRAW 2D
.....................
........................
 
//Go to Perspective Mode (3d)
PerspectiveMode();   // (in this function : glMatrixMode, glPopMatrix, glMatrixMode, ......)


..............

......


It's just a simplified example of i use in my old 3d opengl engine  ;)