GetMaterialColor() problem ?

Everything related to 3D programming
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

GetMaterialColor() problem ?

Post by Psychophanta »

The alpha channel of a Material can be managed using the stuff below.
However, after putting a value with SetMaterialColor() to the material, then when reading it back with GetMaterialColor() , the readed value is wrong.

Code: Select all

RX.u=1024:RY.u=768
InitEngine3D()
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,RX,RY,"tip",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,RX,RY,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Parse3DScripts()
luz.i=CreateLight(#PB_Any,$EEEEEE,4,4,2,#PB_Light_Point)
camara.i=CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(camara.i,0,0,3,#PB_Absolute)
cuerpotextura.i=LoadTexture(#PB_Any,"soil_wall.jpg")
cuerpomaterial.i=CreateMaterial(#PB_Any,TextureID(cuerpotextura.i))
cuerpomalla.i=CreateSphere(#PB_Any,0.5)
cuerpo.i=CreateEntity(#PB_Any,MeshID(cuerpomalla.i),MaterialID(cuerpomaterial.i))
MaterialBlendingMode(cuerpomaterial.i,#PB_Material_AlphaBlend)
SetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor,RGBA($FF,$FF,$FF,$AF))
Repeat
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_M)
    SetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor,RGBA($FF,$FF,$FF,$6F))
    Debug Hex(Alpha(GetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor)),#PB_Long); <- got $FF (should be $6F)
  ElseIf KeyboardReleased(#PB_Key_N)
    SetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor,RGBA($FF,$FF,$FF,$AF))
    Debug Hex(Alpha(GetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor)),#PB_Long); <- got $FF (should be $AF)
  EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: GetMaterialColor() problem ?

Post by applePi »

in fact it display the blue component which is here $F3

Code: Select all

SetMaterialColor(cuerpomaterial,#PB_Material_DiffuseColor,RGBA($F1,$F2,$F3,$6F))
Debug Hex(Alpha(GetMaterialColor(cuerpomaterial,#PB_Material_DiffuseColor)),#PB_Long)
i have searched the Docs and there is no RGBA in SetMaterialColor or GetMaterialColor
only RGB is applicable
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: GetMaterialColor() problem ?

Post by applePi »

in fact i am confused, i remembered i have used RGBA with SetMaterialColor a few days ago but forget it completely, this scenario:
CreateMaterial(2, LoadTexture(2, "snow_1024.jpg"))
MaterialBlendingMode(2, #PB_Material_AlphaBlend)
SetMaterialColor(2, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 100))

will make the material semitranparent and if change the 100 to other number from 0 to 255 the transparency will change. so your question Psychophanta still valid, it is possible the docs is wrong
here the Garage is semi transparent (it is part from a project i.m planning to post here):
needs PB v5.62 or V5.70 ( because i have used the mesh of car)

Code: Select all

#CameraSpeed = 0.1
Define.f KeyX, KeyY, MouseX, MouseY
Global FrameTime.f

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

OpenWindow(0, 0, 0, 800, 600, "use keys and mouse to move the Camera", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)

Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 2, 8)
CameraLookAt(0, 0,0,0)

CreateLight(1, RGB(220,220,220), 0,100,20)

CreateMaterial(1, LoadTexture(1, "White.jpg"))
DisableMaterialLighting(1, #True)

CreateMaterial(2, LoadTexture(2, "snow_1024.jpg"))
MaterialBlendingMode(2, #PB_Material_AlphaBlend)
SetMaterialColor(2, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 100))
CreateMaterial(3, LoadTexture(3, "RustyBarrel.png"))

CreateCube(500, 1)

;create ground entity using the Cube mesh number 500 created above 
CreateEntity(500, MeshID(500), #PB_Material_None, 0, -0.9, 0)
; and then we scale it to resemble a ground
ScaleEntity(500, 10,0.5,10)

; the Garage
CreateEntity(510, MeshID(500),MaterialID(2), 1.2,1,-1)
ScaleEntity(510, 0.2,3,4)
CreateEntity(520, MeshID(500),MaterialID(2), -1.2,1,-1)
ScaleEntity(520, 0.2,3,4)
CreateEntity(530, MeshID(500),MaterialID(2), 0,1,-3)
ScaleEntity(530, 2.6,3,0.2)
CreateEntity(540, MeshID(500),MaterialID(2), 0,2.6,-1)
ScaleEntity(540, 2.6,0.2,4)

car = LoadMesh(#PB_Any , "chassis.mesh")
car = CreateEntity(#PB_Any, MeshID(car),MaterialID(3), 0,0,-0.8)
ScaleEntity(car, 0.8,0.8,0.8)


Repeat
    Repeat
    event = WindowEvent()
  Until event = 0
  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
      
      If ExamineMouse()
        MouseX = -(MouseDeltaX()/10)
        MouseY = -(MouseDeltaY()/10)
      EndIf

      
       MoveCamera  (0, KeyX, 0, KeyY)
       RotateCamera(0,  MouseY, MouseX, 0, #PB_Relative) 
       
            
      RenderWorld()
      
      FlipBuffers()


  
    Until KeyboardPushed(#PB_Key_Escape)
    
    
  
  
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: GetMaterialColor() problem ?

Post by Psychophanta »

applePI, my first post shows alpha channel really works for SetMaterialColor() , contrary to manual statements.
And also, what my first post shows is that GetMaterialColor() should get the alpha value, just for consistence with her sister SetMaterialColor().

Other aspect is the fact Alpha() results in a Blue() . It is an evident lie.
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: GetMaterialColor() problem ?

Post by DK_PETER »

Hey Psychophanta and applePi

The alpha is working just fine. The value from GetMaterialColor is returned in an odd way, though. :)

Code: Select all

Declare.s GetRGBA(Value.i)

RX.u=1024:RY.u=768
InitEngine3D()
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,RX,RY,"tip",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,RX,RY,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Parse3DScripts()
luz.i=CreateLight(#PB_Any,$EEEEEE,4,4,2,#PB_Light_Point)
camara.i=CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(camara.i,0,0,3,#PB_Absolute)
cuerpotextura.i=LoadTexture(#PB_Any,"soil_wall.jpg")
cuerpomaterial.i=CreateMaterial(#PB_Any,TextureID(cuerpotextura.i))
cuerpomalla.i=CreateSphere(#PB_Any,0.5)
cuerpo.i=CreateEntity(#PB_Any,MeshID(cuerpomalla.i),MaterialID(cuerpomaterial.i))
MaterialBlendingMode(cuerpomaterial.i,#PB_Material_AlphaBlend)
SetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor,RGBA($FF,$FF,$FF,$AF))
Repeat
  Repeat : Until WindowEvent() = 0
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_M)
    SetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor,RGBA(25,155,205,128))
    Debug "Colorset RGBA(25,155,205,128)"  
    Debug "ColorReturn: " + GetRGBA(GetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor)); <- got $FF (should be $6F)
  ElseIf KeyboardReleased(#PB_Key_N)
    SetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor,RGBA(55,100,211,75))
    Debug "Colorset RGBA(55,100,211,75)"
    Debug "ColorReturn : " + GetRGBA(GetMaterialColor(cuerpomaterial.i,#PB_Material_DiffuseColor)); <- got $FF (should be $AF)
  EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

Procedure.s GetRGBA(Value.i)
  ProcedureReturn  Str(Green(Value)) + "," + Str(Blue(Value)) + "," + Str(Alpha(Value)) + "," + Str(Red(value))
EndProcedure
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.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: GetMaterialColor() problem ?

Post by applePi »

Thank you DK_PETER for clarifying the issue.
so the problem is in the number returned from GetMaterialColor . it should be cooked so to swap Red with alpha.
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: GetMaterialColor() problem ?

Post by Psychophanta »

:shock:

Thank you DK_PETER, so to me there is clearly a bug.
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
Post Reply