Page 1 of 1

Self-shadowing in PureBasuic

Posted: Wed Aug 13, 2014 7:06 pm
by maslobojik
What about self-shadowing in PureBasuic?
How is it possible?

Re: Self-shadowing in PureBasuic

Posted: Wed Aug 13, 2014 7:26 pm
by Bananenfreak
I think it´s possible with Additive and Modulative.
With TextureAdditive, a mesh has to be a receiver OR a caster.

With using OGRE, there is also a possibility to write shadowthings yourself (I don´t know much about that).
But this isn´t implemented yet.

Re: Self-shadowing in PureBasuic

Posted: Wed Aug 13, 2014 8:34 pm
by applePi
as said by Bananenfreak it is possible , self shadowing http://en.wikipedia.org/wiki/Self-shadowing
here the robot arm cast a shadow on his body
but what is that red big plane under the ground ??

Code: Select all

Define.f KeyX, KeyY, MouseX, MouseY, SpriteX, SpriteY


If InitEngine3D()
ExamineDesktops()
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/models", #PB_3DArchive_FileSystem)
Add3DArchive(".", #PB_3DArchive_FileSystem)    
  
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
    
DeskWidth=DesktopWidth(0)
DeskHeight=DesktopHeight(0)
  
  OpenWindow(0, 0, 0, DeskWidth, DeskHeight, "shadow ", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

  OpenWindowedScreen(WindowID(0), 0, 0, DeskWidth, DeskHeight, 0, 0, 0)
      
  LoadMesh(0, "robot.mesh")
    
    CreateMaterial(0, LoadTexture(0, "clouds.jpg"))
    
    CreateEntity(1, MeshID(0), MaterialID(0), 10, 0, 0)
        
    StartEntityAnimation(1, "Walk")
    WorldShadows(#PB_Shadow_Modulative)
    
      ;- Ground
    ;
    CreateMaterial(5, LoadTexture(5, "MRAMOR6X6.jpg"))
    MaterialCullingMode(5, #PB_Material_NoCulling        ) 
    CreatePlane(2, 1500, 1500, 40, 40, 15, 15)
    CreateEntity(2,MeshID(2),MaterialID(5))
        
  SetMaterialColor(5, #PB_Material_SelfIlluminationColor, $FFFFFF)
  MaterialCullingMode(5, #PB_Material_NoCulling )
  ;Sky
  SkyDome("clouds.jpg", 80) 
    
    ;- Camera
    ;
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 300, 100, 100, #PB_Absolute)
    RotateCamera(0,0,65,0)
    CameraBackColor(0, $FF)
    
    ;- Light
    ;
    CreateLight(0, RGB(255, 255, 255), 20, 100, 20)
    AmbientColor(RGB(80, 80, 80))
    
  
   MaterialCullingMode(0, #PB_Material_NoCulling )
  
    Repeat
     Repeat
     Until WindowEvent() = 0
      
      If ExamineMouse()
        MouseX = -MouseDeltaX()/10
        MouseY = -MouseDeltaY()/10
      EndIf
      
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -10
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 10
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -10
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 10
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End

Edit: added While WindowEvent():Wend as Danilo said
thanks Samuel for the red plane problem solution

Re: Self-shadowing in PureBasuic

Posted: Wed Aug 13, 2014 8:45 pm
by Danilo
Works better on MacOSX by inserting simple event handling into the main loop:

Code: Select all

While WindowEvent():Wend
Keyboard and mouse don't work without event handling. Had to end the task with task manager (ALT+CMD+ESC). ;)

Re: Self-shadowing in PureBasuic

Posted: Wed Aug 13, 2014 8:50 pm
by Samuel
applePi wrote: what is that red big plane under the ground ??
That's normal when using a skydome as they don't cover the bottom of the world. You're just seeing the camera background color.

Also as danilo said you should make sure you handle the window events. On windows 7 it crashes after a few seconds if you don't.

Re: Self-shadowing in PureBasuic

Posted: Wed Aug 13, 2014 11:32 pm
by maslobojik
Ok. Right. But how to make self-shadowing by means of a shader (cg or hlsl) and Shadow_Texture?

Re: Self-shadowing in PureBasuic

Posted: Wed Aug 13, 2014 11:55 pm
by Samuel
We can't do this in Purebasic, yet. Apparently in OGRE 2.0 stencil and texture shadows are going to be removed.
Meaning the only option is Depth shadow maps (which are much better) and they are shader based.

Which means that Purebasic will have to have a built in depth shader and/or allow us to create our own shadow shaders.
As to when this will all happen is anyone's guess.

There is also the possibility that we will be able to use our own shadow shaders before OGRE 2.0.
As this feature already exists within OGRE.

Here's a basic guide on how to implement it within OGRE.
http://www.ogre3d.org/tikiwiki/Depth+Shadow+Mapping

Notice at the end it implements self shadowing within the OGRE source.
Those are the commands that we are missing in Purebasic.