Page 10 of 11

Posted: Thu Apr 27, 2006 7:21 pm
by Preludian
Hi, it's only recently that I have purchased pb and thought it would be wiser to directly stay with pb 4 beta 11, even if it's a beta.

My main interest is 3D, mainly for realtme architectural visualisation.
I have been fussing around quit a bit now with the 3d functionality, at first I thought it couldn't do very much ;) but it's getting cool.

So, in my quest of finding ou wht's possible and what not, I messed around quite some time trying to get some shadows on my terrain, but nothing worked. Lastly I have found this thread and fortunately found this thread. My luck ;)
But a few questions remain...

1. Is it possible to have shadows on terrains? I couldn't manage to do it.
2. AmbientColor doesn't do anything, neither the last shadow.pb nor in my terrain script, which btw. is simply a poked version of the terrain of the examples. I added other meshes from xsi, lights and '''shadows'''
But even tere no go with AmbientColor. MaterialAmbientColor on the other hand works fine.
3. Where do I have to put WorldShadows? I first had it after the skydome (before the repeat proc) and it would slow the window to a crawl. At fullscreen it behaved normaly. Then I moved WorldShadows at the top, directly under If Screen3DRequester() and it even worked in a window (besides the shadows of course ;) )

Heres my xsitestterrain if you would like to have a look. You ca simply change the mesh/texture/animation to the standard values Robot.mesh/...
if you want to test it


;
; ------------------------------------------------------------
;
; PureBasic - Terrain
;
; (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 5

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
Add3DArchive("Data\" , #PB_3DArchive_FileSystem)

InitSprite()
InitKeyboard()
InitMouse()

If Screen3DRequester()

WorldShadows(#PB_Shadow_Additive)

AmbientColor(RGB(128,128,128))


CreateMaterial (0, LoadTexture(0, "Terrain_Texture.jpg"))
AddMaterialLayer(0, LoadTexture(1, "Terrain_Detail.jpg"), 1)

CreateTerrain("Terrain.png", MaterialID(0), 1, 1, 1, 4)

LoadMesh (0, "test1.mesh")

CreateMaterial(1, LoadTexture(1, "jaiqua_red20.jpg"))

MaterialAmbientColor(1,RGB(100,100,100))

CreateEntity(0, MeshID(0), MaterialID(1), 128,0,128 )
CreateEntity(1, MeshID(0), MaterialID(1), 120, 0, 128)
CreateEntity(2, MeshID(0), MaterialID(1), 136, 0, 128)

EntityRenderMode(0,#PB_Entity_CastShadow)
EntityRenderMode(1,#PB_Entity_CastShadow)
EntityRenderMode(2,#PB_Entity_CastShadow)

AnimateEntity(0, "Jaiqua_walk_Preset_Clip")

CreateLight(0, RGB(0,0,255), 120, 20, 120) ; Blue light
CreateLight(1, RGB(255,0,0), 140, 20, 130) ; Red light

CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 128, 25, 128)

SkyDome("Clouds.jpg",10)





Repeat
Screen3DEvents()


If ExamineKeyboard()

If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf

If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf

EndIf

If ExamineMouse()
MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
EndIf

Height.f = TerrainHeight(CameraX(0), CameraZ(0))
EntityLocate (0, EntityX(0), TerrainHeight(EntityX(0),EntityZ(0)),EntityZ(0))
EntityLocate (1, EntityX(1), TerrainHeight(EntityX(1),EntityZ(1)),EntityZ(1))
EntityLocate (2, EntityX(2), TerrainHeight(EntityX(2),EntityZ(2)),EntityZ(2))

RotateCamera(0, MouseX, MouseY, RollZ)
MoveCamera (0, KeyX, -CameraY(0)+Height+8, KeyY)

RenderWorld()
Screen3DStats()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf

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

End
Thx :)

Posted: Wed Jun 14, 2006 12:25 am
by Preludian
oh jesus, such a long a time and no reply :shock: tststs 3d with pb is well in its child-shoes ey :wink:

Another prob, if I change Orthographic to Perspective in Freds example I have no shadows anymore. Why is that??

Posted: Thu Jun 15, 2006 10:22 am
by Num3
Terrain functions are buggy in PB :P
No shadows on them, sorry about that.

You're code is correct, and should work, if it was not for the bugs...

Posted: Thu Jun 15, 2006 10:46 am
by Preludian
oh shiesh, what a pitty :(
And wha about the orthographic and perspective mode in Freds' shadow.pb? Is it a bug or what is wrong?

Posted: Thu Jun 15, 2006 11:48 am
by Comtois
Preludian wrote:And wha about the orthographic and perspective mode in Freds' shadow.pb? Is it a bug or what is wrong?
try this

Code: Select all

LightLocate(0, CameraX(0)+450, CameraY(0)+50, CameraZ(0)-450)

Posted: Thu Jun 15, 2006 12:15 pm
by Preludian
Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh, merci beaucoup, je suis vraiment trop bete ;)

But I am even more studid I'm afraid :oops: because I don't understand why. I have a point light at the postion of the camera x2000,y2000,z2000, if it were a spotlight and it would point elsewhere than ok, but it's a simple omni light! Please explain to me :?

Posted: Thu Jun 15, 2006 1:14 pm
by Thalius
@Preludian

did you get the shadows running?
Terrainshadows work iirc in the latest PB-OGRE Version 1.0.7 ( Azatoth ), however i had some Trouble with a few Drivers (ATI and Nvidia) leading to wierd flickering and poly-errors ( new drivers solved this ).

Sadly theres still the terrain height limit bug =/

can post a screenif needed.

Cheers, Thalius

Posted: Thu Jun 15, 2006 1:27 pm
by Preludian
Well no, it doesn't work, do you have the the dll from the PB4, or do you have another one? Maybe you could send me the working source to examine?

Posted: Thu Jun 15, 2006 2:22 pm
by Thalius
I use the PB4 Ogre Version currently.

Just call this before your mainloop:

Code: Select all

WorldShadows(<Mode>) ; 0 = none 1 = Modulative 2 = Additive
or use for mode:
#PB_Shadow_Modulative
#PB_Shadow_Additive

Result here using Modulative:


Image

Cheers, Thalius

Posted: Thu Jun 15, 2006 7:49 pm
by Preludian
:shock: looking great. Putting WorldShadows right before the loop instead of the beginning helped alot. BUT it gets so awfully slow now in window mode and even crashed in fullscreen mode. I have the latest driver and didn't encounter any problems with my GraCa yet (GForce TI4200) Is it my animated mesh?? Shadows on the terrain look destroyed too??

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Terrain
;
;    (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 5

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  Add3DArchive("Data\", #PB_3DArchive_FileSystem)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()

  
    AmbientColor(RGB(128,128,128)) 

    CreateMaterial  (0, LoadTexture(0, "Terrain_Texture.jpg"))
    AddMaterialLayer(0, LoadTexture(1, "Terrain_Detail.jpg"), 1)
    
    CreateTerrain("Terrain.png", MaterialID(0), 1, 1, 1, 4)

    LoadMesh   (0, "test1.mesh")

    CreateMaterial(1, LoadTexture(1, "jaiqua_red20.jpg"))
    
    MaterialAmbientColor(1,RGB(100,100,100))
    
    CreateEntity(0, MeshID(0), MaterialID(1), 128,0,128 )
    CreateEntity(1, MeshID(0), MaterialID(1), 120, 0, 128)
    CreateEntity(2, MeshID(0), MaterialID(1), 136, 0, 128)
    
    EntityRenderMode(0,#PB_Entity_CastShadow)
    EntityRenderMode(1,#PB_Entity_CastShadow)
    EntityRenderMode(2,#PB_Entity_CastShadow)
    
    AnimateEntity(0, "Jaiqua_walk_Preset_Clip")

    ;CreateLight(0, RGB(0,0,255), 120, 100, 120)   ; Blue light
    CreateLight(1, RGB(255,0,0))  ; Red light
    
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 128, 25, 128)
    
       
    SkyDome("clouds.jpg",10)
    
    WorldShadows(1)
    
    Repeat
      Screen3DEvents()
      
            
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
                  
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf

      EndIf
      
      If ExamineMouse()
        MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
        MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
      EndIf
      
      Height.f = TerrainHeight(CameraX(0), CameraZ(0))
      EntityLocate (0, EntityX(0), TerrainHeight(EntityX(0),EntityZ(0)),EntityZ(0))
      EntityLocate (1, EntityX(1), TerrainHeight(EntityX(1),EntityZ(1)),EntityZ(1))
      EntityLocate (2, EntityX(2), TerrainHeight(EntityX(2),EntityZ(2)),EntityZ(2))

      RotateCamera(0, MouseX, MouseY, RollZ)
      MoveCamera  (0, KeyX, -CameraY(0)+Height+8, KeyY)
      LightLocate(1,EntityX(0)+20,EntityY(0)+50,EntityZ(0)-20)      
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End

Posted: Fri Jun 16, 2006 5:39 pm
by Thalius
Ah the TI - i dont think that card has a shadow processing unit .. which since the newest Ogre seems to be needed for this kind of calculations, the emulation is kind of VERY slow ( depending on bus speed , because the data has to be copied back and forth per frame .. ) and the shadows seem to be destroyed.

Atm i can't test your example but it looks fine. I will make a screen once i am back in office to run it there.

Cheers, Thalius

Posted: Fri Jun 16, 2006 11:10 pm
by Preludian
Oh my, is my GraCa so old ;) four+ years only :) Funny thing I don't have these problems with games, ok it may be slower than on a new card, but it looks great. I tried the ogre demos and they all looked fine too. Unfortunately the Ogre terrain is without shadows :) but the other demos look really fine and are reasonably fast.

Thanks for trying the code out.

Posted: Mon Jun 26, 2006 7:46 pm
by Preludian
@Thalius: Did you have the chance to try my code out, if you have shadows on terrains, you can simply change the meshes to standard robots...

Posted: Tue Jun 27, 2006 4:35 pm
by Thalius
Yup! works here =)

See:

Image

Cheers,

Thalius

Posted: Tue Jun 27, 2006 4:43 pm
by Preludian
:cry: :cry: :cry: Even DAZ told me that my GraCa was too old for the AO in Hexagon2 :( :( :( I'm glad it works for you though, but funny thing is that the Ogre demos show no faulty behaviour, maybe it's because 1.2 has enhanced compatibility??
Thank you very much for testing !!