transparency ( a ghostly fish)

Everything related to 3D programming
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

transparency ( a ghostly fish)

Post by applePi »

i have read some tutorials about alpha channel and transparency for the first time, i have made a semi tranparent texture using photoshop 7, to provide a material for a fish model (i have posted before) using this function
MaterialBlendingMode(#MAT, #PB_Material_AlphaBlend)
now my purpose is to make the fish more tranparent by moving a trackbar slider. and while testing i have used this
AddMaterialLayer(#MAT, TextureID(#TEX) , #PB_Material_AlphaBlend)
it turns that when i click on the trackbar the fish become more trasparent, until the 4th click it turns as the first time show.
why is this !!!! whatever the reason this is a good feature.
also is it possible to see the purebasic word through the fish !!. there are two purebasic words, but i can see only one at a time.
the alpha channel and trasparency seems very interesting and esoteric subject.
download the fish model and skeleton and the semi transparent texture from here:
http://www.mediafire.com/?y39a7f46x3d5v41
put all the attached data files in a Data folder
Image

Code: Select all

Enumeration
   #trackbar
   #MESH
   #TEX
   #TEX_plane
   #MAT
   #MAT_plane
   #plane
   #ENTITY_FISH
   #LIGHT
   #CAMERA_ONE
   #BUTTON
   #mainwin
EndEnumeration
Global Quit.b = #False
Speed = 0.5
If OpenWindow(#mainwin, 0, 0, 500, 480, "press ESC to exit...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(#BUTTON, 0, 405, 50, 30, "stop") 
  TrackBarGadget(#trackbar, 100, 410, 150, 20, 0, 360)

;Initialize environment
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, 500, 400, 0, 0, 0)
;WorldShadows(#PB_Shadow_Additive)
;WorldShadows(#PB_Shadow_Modulative, -1, RGB(100, 250, 100))

SetFrameRate(60)

Add3DArchive("Data\", #PB_3DArchive_FileSystem)

CreateMaterial(#MAT_plane, LoadTexture(#TEX_plane, "mosaic.png"))
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))
  
LoadMesh(#MESH, "fish.mesh")
;LoadTexture(#TEX, "steelhead.png")
LoadTexture(#TEX, "ghost_fish.tga")
CreateMaterial(#MAT, TextureID(#TEX))
MaterialBlendingMode(#MAT, #PB_Material_AlphaBlend)


CreateEntity(#ENTITY_FISH, MeshID(#MESH), MaterialID(#MAT))
ScaleEntity(#ENTITY_FISH,0.5,0.5,0.5)
EntityRenderMode(#ENTITY_FISH, #PB_Entity_CastShadow)

StartEntityAnimation(#ENTITY_FISH, "swim", #PB_EntityAnimation_Manual)
MoveEntity(#ENTITY_FISH,0,1.5,3)

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
rot.l=1
;Main loop
Repeat
  Event = WindowEvent()
  If Event = #PB_Event_Gadget
    Select EventGadget()
      Case #BUTTON
        If rot = 0
          rot = 1
          SetGadgetText(#BUTTON,"stop")
          

        Else
          rot = 0
          SetGadgetText(#BUTTON,"rotate")
          
        EndIf
      Case #trackbar
        angle.f = GetGadgetState(#trackbar)
        AddMaterialLayer(#MAT, TextureID(#TEX) , #PB_Material_AlphaBlend)
        If angle > 200
          MaterialFog(#MAT, RGB(255,255,0), 1, -1, 1)
          
        Else 
          MaterialFog(#MAT, RGB(255,255,0), 0, -1, 1)
        EndIf
    EndSelect
   EndIf 
  y.l + rot
  x.l + rot
  z.l + rot
  
  RotateEntity(#ENTITY_FISH, 0, y, 0)
  
  AddEntityAnimationTime(#ENTITY_FISH, "swim", TimeSinceLastFrame * Speed)
   
   TimeSinceLastFrame = RenderWorld()
   
  FlipBuffers()

   ExamineKeyboard()
   If KeyboardReleased(#PB_Key_Escape)
      Quit = #True
   EndIf

Until Quit = #True Or Event = #PB_Event_CloseWindow