Page 1 of 1

SpotLights and shadows

Posted: Sun Mar 02, 2014 11:54 pm
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

Re: SpotLights and shadows

Posted: Mon Mar 03, 2014 1:30 am
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.

Re: SpotLights and shadows

Posted: Mon Mar 03, 2014 9:40 am
by Bananenfreak
And with WorldShadows(#PB_Shadow_TextureAdditive), you´ll have no shadow ;)