Materials and Alphablending doesn't seem to work properly

Everything related to 3D programming
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Materials and Alphablending doesn't seem to work properl

Post by DK_PETER »

@Hoessi666

Try this. Using scripts can solve a lot of issues.

Alpha script: Save file to a folder named "script" - Filename: somefilename.material

Code: Select all

//PNG with alpha blend
material BILLB
{
    technique
    {
         pass
        {
            depth_check off
            separate_scene_blend alpha_blend modulate
            texture_unit
            {
                texture grass1.png
            }

        }
    }
}
Your code with some minor changes:

Code: Select all


#CameraSpeed = 1

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
 
  InitSprite()
  InitKeyboard()
  InitMouse()
 
  OpenWindow(0, 0, 0, 800, 600, "Bill is on the board", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
   
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive("script", #PB_3DArchive_FileSystem)
    Parse3DScripts()

    Material = GetScriptMaterial(#PB_Any, "BILLB")
    If Material = 0
      Debug "error - Material not loaded!"
    EndIf
    
    Billboard = CreateBillboardGroup(#PB_Any, MaterialID(Material), 10, 10, -20, 0, -40)
    AddBillboard(Billboard,   0, 0, 0)
    AddBillboard(Billboard,   0, 0, 40)
    AddBillboard(Billboard,   0, 0, 80)
    
    Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
    CameraBackColor(Camera, $EB8E57)
    
    Repeat
      
      Repeat
        ev = WindowEvent()
      Until ev = 0
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
     
      If ExamineKeyboard()
       
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
       
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
       
      EndIf
     
      RotateCamera(Camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(Camera, KeyX, 0, KeyY)
     
      RenderWorld()

      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
 
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Materials and Alphablending doesn't seem to work properl

Post by Samuel »

DK_PETER wrote: Try this. Using scripts can solve a lot of issues.
Unfortunately with this method, you will still have to deal with the objects being out of order at times.
Try lining up the grass blades at different angles and you should see some of the far away blades covering the close ones.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Materials and Alphablending doesn't seem to work properl

Post by DK_PETER »

Samuel wrote:
DK_PETER wrote: Try this. Using scripts can solve a lot of issues.
Unfortunately with this method, you will still have to deal with the objects being out of order at times.
Try lining up the grass blades at different angles and you should see some of the far away blades covering the close ones.
@Samuel
You're right. The previous script is still a 'see through'.

For the grass1.png - a way around it could be to use the 'alpha-rejection greater_equal 128'.

Code: Select all

material BILLB
{
    technique
    {
         pass
        {
            depth_check on
            depth_write on
            alpha_rejection greater_equal 128
            texture_unit
            {
                texture grass1.png
                colour_op alpha_blend
            }
        }
    }
}
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply