I noticed a strange behaviour involving pickmasks, alphablended materials, and shadows:
If you set the 'PickMask' parameter to zero for an entity, it disables its shadow.
BUT if this entity's material is alphablended, shadows seen through it will be displayed correctly.
So, there's two different bugs interacting here:
- Alphablended materials breaks the shadows seen through them;
- PickMask = 0 disables an entity's shadow, correcting aforementioned bug.
Code: Select all
; Bug description:
;------------------
; If you set the 'PickMask' parameter to zero for an entity, it disables its shadow.
; BUT, if this entity's material is alphablended, shadows seen through it will be displayed correctly.
;
; So, there's two different bugs interacting here:
; - Alphablended materials breaks the shadows seen through them;
; - PickMask = 0 disables an entity's shadow, correcting aforementioned bug.
#PICKMASK_0 = 0 ; <= only this one produces the strange behaviour
#PICKMASK_1 = %01
;- Initialization
InitEngine3D()
InitSprite()
InitKeyboard()
;- Window
OpenWindow(0, 0, 0, 800, 600, "Pickmask affects shadows/alphablending interaction", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, 800,600, 0, 0, 0,#PB_Screen_SmartSynchronization)
;-Texture
txBlank = CreateTexture(#PB_Any,4,4)
StartDrawing(TextureOutput(txBlank))
Box(0, 0, 4,4, $FFFFFF)
StopDrawing()
txTerrain = CreateTexture(#PB_Any,256, 256)
StartDrawing(TextureOutput(txTerrain))
Box(0, 0, 256, 256, $007700)
Line(0,256,256,-256, $00BB00)
StopDrawing()
TxText1 = CreateTexture(#PB_Any,64, 64)
StartDrawing(TextureOutput(TxText1))
DrawText(4,4,"This wall")
DrawText(16,18,"has")
DrawText(1,32,"PickMask")
DrawText(20,46,"#0")
StopDrawing()
TxText2 = CreateTexture(#PB_Any,64, 64)
StartDrawing(TextureOutput(TxText2))
DrawText(4,4,"This wall")
DrawText(8,24,"has no")
DrawText(1,44,"PickMask")
StopDrawing()
;-Materials
mtTerrain = CreateMaterial(#PB_Any,TextureID(txTerrain))
mtGlass = CreateMaterial(#PB_Any,TextureID(txBlank))
SetMaterialColor(mtGlass,#PB_Material_DiffuseColor,$BBBB00)
MaterialBlendingMode(mtGlass, #PB_Material_Add)
mtRed = CreateMaterial(#PB_Any,TextureID(txBlank))
SetMaterialColor(mtRed,#PB_Material_DiffuseColor,$0000FF)
mtText1 = CreateMaterial(#PB_Any,TextureID(txText1))
mtText2 = CreateMaterial(#PB_Any,TextureID(txText2))
;- Meshes
dimX.f = 20:dimZ.f = 20
planeMesh = CreatePlane(#PB_Any,1,1,1,1,1,1)
cubeMesh = CreateCube(#PB_Any,1)
;- Entities
; Ground
ground = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(mtTerrain),0,0,0)
ScaleEntity(ground,dimX,0,dimZ)
; Transparent walls
wall1 = CreateEntity(#PB_Any,MeshID(cubeMesh),MaterialID(mtGlass),-3.5,2,8,#PICKMASK_0)
ScaleEntity(wall1,2,4,0.25)
wall2 = CreateEntity(#PB_Any,MeshID(cubeMesh),MaterialID(mtGlass),3.5,2,8)
ScaleEntity(wall2,2,4,0.25)
; Boxes
For i=0 To 3
temp = CreateEntity(#PB_Any,MeshID(cubeMesh),MaterialID(mtRed),4 - Random(50)/100.0,0.5 + i,5)
RotateEntity(temp,0,Random(90),0)
temp = CreateEntity(#PB_Any,MeshID(cubeMesh),MaterialID(mtRed),-4 + Random(50)/100.0,0.5 + i,5)
RotateEntity(temp,0,Random(90),0)
Next i
; Texts
text1 = CreateEntity(#PB_Any,MeshID(planeMesh),MaterialID(mtText1),-6,1,7.5)
ScaleEntity(text1,2,2,2)
RotateEntity(text1,90,180,0,#PB_Relative)
text2 = CreateEntity(#PB_Any,MeshID(planeMesh),MaterialID(mtText2),6,1,7.5)
ScaleEntity(text2,2,2,2)
RotateEntity(text2,90,180,0,#PB_Relative)
;- Camera
CreateCamera(0,0,0,100,100)
;-Light
AmbientColor($333333)
light = CreateLight(#PB_Any,$FFFFFF,0,40,20)
WorldShadows(#PB_Shadow_Additive)
;- Main loop
KeyboardMode(#PB_Keyboard_International)
camPos.f = 0 : displayShadows = #True
Repeat
Delay(1)
While WindowEvent() : Wend
ExamineKeyboard()
;- Press 'S' to toggle Shadows
If KeyboardReleased(#PB_Key_S)
displayShadows = 1 - displayShadows
If displayShadows
WorldShadows(#PB_Shadow_Additive)
Else
WorldShadows(#PB_Shadow_None)
EndIf
EndIf
; Move camera
campos.f + 0.01
MoveCamera(0,8 * Cos(camPos),5,20,#PB_Absolute)
CameraLookAt(0,0,0,0)
; Render
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End