BASIC

Author Topic: 3D transparency  (Read 2260 times)

Offline sf-in-sf

  • Mr. Drawsprite
  • **
  • Posts: 92
  • Artist F.P. Brixey
    • View Profile
    • My computed art project
3D transparency
« 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
« Last Edit: 2013-Oct-30 by sf-in-sf »
On the day the atom is a cube I will start believing in the square pixel.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4949
  • O Rly?
    • View Profile
Re: 3D transparency
« Reply #1 on: 2013-Oct-31 »
i think the only way is gl.gbas.
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2600Mhz Ram, HIS 7970 GHz Edition @3GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3318
  • Integrated Brain
    • View Profile
Re: 3D transparency
« Reply #2 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...


Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: 3D transparency
« Reply #3 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.
« Last Edit: 2013-Nov-01 by kanonet »
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Snoopy

  • Mr. Polyvector
  • ***
  • Posts: 158
    • View Profile
Re: 3D transparency
« Reply #4 on: 2013-Oct-31 »
The alpha blending it's for pixels not for the vertices.

kanonet  :good: small function. Very useful  :)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1577
  • Particle Hawk
    • View Profile
    • Silver Volumetric Software
Re: 3D transparency
« Reply #5 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 )

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

http://silver.binhoster.com/

Offline sf-in-sf

  • Mr. Drawsprite
  • **
  • Posts: 92
  • Artist F.P. Brixey
    • View Profile
    • My computed art project
Re: 3D transparency
« Reply #6 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!
On the day the atom is a cube I will start believing in the square pixel.

Offline Snoopy

  • Mr. Polyvector
  • ***
  • Posts: 158
    • View Profile
Re: 3D transparency
« Reply #7 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.  ;)

Offline Snoopy

  • Mr. Polyvector
  • ***
  • Posts: 158
    • View Profile
Re: 3D transparency
« Reply #8 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  ;)

« Last Edit: 2013-Nov-06 by Snoopy »