SpotLights and shadows

Everything related to 3D programming
MightyMAC
User
User
Posts: 42
Joined: Thu Apr 11, 2013 5:47 pm

SpotLights and shadows

Post by MightyMAC »

Hi guys,

I found out that shadows are not dynamic when using a spotlight. Shadows are casted from the source of the spotlight no matter in which direction it shines. To show what I mean I altered the LightDirection example a bit:

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - LightDirectionX/Y/Z
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

#PB_Material_SelfIlluminationColor = 3 

IncludeFile "Screen3DRequester.pb"

Define.f x, y, z, Distance = 1500

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts"             , #PB_3DArchive_FileSystem)
  Add3DArchive("Data/GUI", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    KeyboardMode(#PB_Keyboard_International)  
    WorldShadows(#PB_Shadow_Modulative)
    
    ; Ground
    CreateMaterial(0, LoadTexture(0, "Dirt.jpg"))
    CreatePlane(0, 1000, 1000, 50, 50, 1, 1)
    CreateEntity (0, MeshID(0), MaterialID(0))
    
    ; Light
    CreateLight(0, RGB(255, 255, 255), 0, 400, 0, #PB_Light_Spot)
    SpotLightRange(0, 1, 30, 3)
    AmbientColor(RGB(50,50,50))
    
    ; spot
    CreateSphere(1, 20, 50, 50)
    GetScriptMaterial(1, "Color/Yellow")
    SetMaterialColor(1, #PB_Material_SelfIlluminationColor, RGB(185, 155, 65))
    CreateEntity(1, MeshID(1), MaterialID(1), LightX(0), LightY(0), LightZ(0))
    
    ; Cube(rt)
    CreateCube(2,150)
    CreateEntity(2, MeshID(2), MaterialID(1), 150, 50, 150)
    
    
    ; Camera
    ;
    CreateCamera(0, 0, 0, 100, 100) 
    MoveCamera(0, 0, 900, 1000, #PB_Absolute)
    CameraLookAt(0, 0, 0, 0)
    CameraBackColor(0, RGB(0, 0, 30))
    
    ShowGUI(128, 1) ; Display the GUI, semi-transparent and display the mouse cursor
    
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        
        InputEvent3D(MouseX(), MouseY(), MouseButton(#PB_MouseButton_Left))
        
        If MousePick(0, MouseX(), MouseY()) >= 0
          LightLookAt(0, PickX(), PickY(), PickZ())
        EndIf
        
      EndIf
      
      ExamineKeyboard()
      
      x = LightX(0) + LightDirectionX(0) * Distance
      y = LightY(0) + LightDirectionY(0) * Distance
      z = LightZ(0) + LightDirectionZ(0) * Distance
      CreateLine3D(10, LightX(0), LightY(0), LightZ(0),  RGB(0, 255, 0), x, y, z, RGB(0, 255, 0))   
      
      RenderWorld()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
Shouldn't the shadow that the cube casts vary as you move the spotlight around?

Regards
MAC
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: SpotLights and shadows

Post by Samuel »

Someone will have to correct me if I'm wrong, but I believe that's a limitation not a bug.
http://www.ogre3d.org/docs/manual/manual_73.html wrote: Modulative shadows are an inaccurate lighting model, since they darken the areas of shadow uniformly, irrespective of the amount of light which would have fallen on the shadow area anyway. However, they can give fairly attractive results for a much lower overhead than more ’correct’ methods like Additive Light Masking
You could give WorldShadows(#PB_Shadow_Additive) a try. It seems to work for me.
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: SpotLights and shadows

Post by Bananenfreak »

And with WorldShadows(#PB_Shadow_TextureAdditive), you´ll have no shadow ;)
Image
Post Reply