ich habe Dein Bespiel mal erweitert, also die Entities werfen immer Schatten (siehe Beispiel) ausser anscheinend bei Texture-Additive, das wirft keinen Schatten. Die Funktion #PB_Entity_CastShadow ist also unnütz. Im englischen Forum habe ich das aber noch nicht geschrieben.
Code: Alles auswählen
EnableExplicit
Define.f degree
Define.i x, y, tempTexture, tempMaterial, tempMesh, camera, light, entLight, entGround, entBall1, entCube1, entBall2, entCube2, shadowType = #PB_Shadow_Modulative
; init
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindow(0,0,0,1024,768,"Schatten - Modulative",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0, #PB_Screen_WaitSynchronization)
WorldShadows(shadowType, 500, RGB(32, 32, 32), 1024)
MaterialFilteringMode(#PB_Default, #PB_Material_Anisotropic, 8)
; create entity for light position
tempTexture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(tempTexture))
Plot(0,0,RGB(255,0,255))
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
MaterialBlendingMode(tempMaterial, #PB_Material_Phong)
tempMesh = CreateSphere(#PB_Any, 1)
entLight = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial))
; create ground entity
tempTexture = CreateTexture(#PB_Any, 32, 32)
StartDrawing(TextureOutput(tempTexture))
Box(0,0,16,16,RGB(128,128,128))
Box(0,16,16,16,RGB(225,225,225))
Box(16,0,16,16,RGB(225,225,225))
Box(16,16,16,16,RGB(128,128,128))
For y = 0 To 31 Step 4
For x = 0 To 31 Step 4
If Random(1)
Plot(x, y, RGB(128,128,128))
EndIf
Next
Next
For y = 0 To 31 Step 4
For x = 0 To 31 Step 4
If Random(1)
Plot(x, y, RGB(225,225,225))
EndIf
Next
Next
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
MaterialShadingMode(tempMaterial, #PB_Material_Phong)
tempMesh = CreatePlane(#PB_Any, 100, 100, 1, 1, 1, 1)
entGround = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial), 0, 0, 0)
; create shadowcaster entities
tempTexture = CreateTexture(#PB_Any, 32, 32)
StartDrawing(TextureOutput(tempTexture))
Box(0,0,8,32,RGB(154,205,50))
Box(8,0,8,32,RGB(255,215,0))
Box(16,0,8,32,RGB(154,205,50))
Box(24,0,8,32,RGB(255,215,0))
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
MaterialShadingMode(tempMaterial, #PB_Material_Phong)
tempMesh = CreateSphere(#PB_Any, 5)
entBall1 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial), -20, 10, -20)
entBall2 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial), 20, 10, 20)
EntityRenderMode(entBall2, #PB_Entity_CastShadow)
tempTexture = CreateTexture(#PB_Any, 32, 32)
StartDrawing(TextureOutput(tempTexture))
Box(0,0,16,16,RGB(70,130,180))
Box(0,15,16,16,RGB(255,69,0))
Box(15,0,16,16,RGB(70,130,180))
Box(15,15,16,16,RGB(255,69,0))
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
MaterialShadingMode(tempMaterial, #PB_Material_Phong)
tempMesh = CreateCube(#PB_Any, 10)
entCube1 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial), -20, 10, 20)
entCube2 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial), 20, 10, -20)
EntityRenderMode(entCube2, #PB_Entity_CastShadow)
; create light
light = CreateLight(#PB_Any, RGB(225, 225, 225), 0, 100, 50, #PB_Light_Directional)
LightLookAt(light, 0,0,0)
; create camera
camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera, 0, 75, 50, #PB_Absolute)
CameraLookAt(camera, 0, 0, 0)
AmbientColor(RGB(64,64,64))
FreeMesh(tempMesh)
FreeMaterial(tempMaterial)
FreeTexture(tempTexture)
Repeat
While WindowEvent() : Wend
ExamineKeyboard()
; switch shadow type
If KeyboardReleased(#PB_Key_F1)
If shadowType = #PB_Shadow_Modulative
shadowType = #PB_Shadow_Additive
SetWindowTitle(0, "Schatten - Additive")
ElseIf shadowType = #PB_Shadow_Additive
shadowType = #PB_Shadow_TextureAdditive
SetWindowTitle(0, "Schatten - TextureAdditive")
ElseIf shadowType = #PB_Shadow_TextureAdditive
shadowType = #PB_Shadow_None
SetWindowTitle(0, "Schatten - None")
ElseIf shadowType = #PB_Shadow_None
shadowType = #PB_Shadow_Modulative
SetWindowTitle(0, "Schatten - Modulative")
EndIf
WorldShadows(shadowType, 500, RGB(32, 32, 32), 1024)
EndIf
; move light
degree + 0.5
If degree >= 360
degree - 360
EndIf
x = 40 * Cos(Radian(degree))
y = 40 * Sin(Radian(degree))
MoveLight(light, x, 30, y, #PB_Absolute)
LightLookAt(light, 0,0,0)
MoveEntity(entLight, LightX(light), LightY(light), LightZ(light), #PB_Absolute)
RenderWorld()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
End