Page 1 of 1

Cornell Box Issues

Posted: Tue Mar 05, 2013 5:03 am
by colguetti
Hi everybody! While I´m trying to figure out how to make a small 3d editor, I´ve setup a scene like a Cornell Box

All shadow modes where working good, Additive, Modulative and TextureAdditive, then I added a sphere and unfortunately
TextureAdditive disappeared !!!

I don´t know what else to do, here´s the code, if somebody knows how to fix it please share, if someone finds this useful just keep it

Code: Select all

ScreenX = GetSystemMetrics_(#SM_CXSCREEN)
ScreenY = GetSystemMetrics_(#SM_CYSCREEN)

InitEngine3D(#PB_Engine3D_DebugLog)
InitSprite()
InitKeyboard()
InitMouse()

OpenWindow(0,0,0,ScreenX,ScreenY,"Cornell Box",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,ScreenX,ScreenY,1,0,0,#PB_Screen_WaitSynchronization)

KeyboardMode(#PB_Keyboard_AllowSystemKeys)

;Create Red Wall
CreateTexture(1,32,32)
  StartDrawing(TextureOutput(1))
    Box(0,0,32,32,RGB(205,0,0))
  StopDrawing()
CreateMaterial(1,TextureID(1))
CreateCube(1,1)
CreateEntity(1,MeshID(1),MaterialID(1),-16,0,0)
ResizeEntity(1,1,33,32)

;Create Green Wall
CreateTexture(2,32,32)
  StartDrawing(TextureOutput(2))
    Box(0,0,32,32,RGB(0,205,0))
  StopDrawing()
CreateMaterial(2,TextureID(2))
CreateCube(2,1)
CreateEntity(2,MeshID(2),MaterialID(2),16,0,0)
ResizeEntity(2,1,33,32)

;Create Back Wall
CreateTexture(3,32,32)
  StartDrawing(TextureOutput(3))
    Box(0,0,32,32,RGB(245,245,245))
  StopDrawing()
CreateMaterial(3,TextureID(3))
CreateCube(3,1)
CreateEntity(3,MeshID(3),MaterialID(3),0,0,-16)
ResizeEntity(3,32,32,1)

;Create Ceiling
CreateTexture(4,32,32)
  StartDrawing(TextureOutput(4))
    Box(0,0,32,32,RGB(245,245,245))
  StopDrawing()
CreateMaterial(4,TextureID(4))
CreateCube(4,1)
CreateEntity(4,MeshID(4),MaterialID(4),0,16,0)
ResizeEntity(4,31,1,32)

;Create Floor
CreateTexture(5,32,32)
  StartDrawing(TextureOutput(5))
    Box(0,0,32,32,RGB(245,245,245))
  StopDrawing()
CreateMaterial(5,TextureID(5))
CreateCube(5,1)
CreateEntity(5,MeshID(5),MaterialID(5),0,-16,0)
ResizeEntity(5,31,1,32)

;Create Blue Box
CreateTexture(6,32,32)
  StartDrawing(TextureOutput(6))
    Box(0,0,32,32,RGB(0,0,245))
  StopDrawing()
CreateMaterial(6,TextureID(6))
CreateCube(6,1)
CreateEntity(6,MeshID(6),MaterialID(6),-8,-10,-4)
ResizeEntity(6,6,12,6)
RotateEntity(6,0,30,0)

;Create Sphere
CreateTexture(7,32,32)
  StartDrawing(TextureOutput(7))
    Box(0,0,32,32,RGB(245,245,0))
  StopDrawing()
CreateMaterial(7,TextureID(7))
CreateSphere(7,4,32,32)
CreateEntity(7,MeshID(7),MaterialID(7),8,-10,4)

;Create Light
AmbientColor(RGB(4,4,4))
CreateLight(0,RGB(245,245,205),0,13,0)
LightAttenuation(0,500,0.4)

;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0,53,#PB_Absolute)
    
WorldShadows(#PB_Shadow_Additive,500,0,1024)

Repeat
  WaitWindowEvent(1)
  ShowCursor_(0)
  
  ExamineKeyboard()
  
; Use arrow keys to rotate and fly in/out
  If KeyboardPushed(#PB_Key_Left)
    KeyX=-1
  ElseIf KeyboardPushed(#PB_Key_Right)
    KeyX=1
  Else
    KeyX=0
  EndIf
  
  If KeyboardPushed(#PB_Key_Up)
    KeyY=-1
  ElseIf KeyboardPushed(#PB_Key_Down)
    KeyY=1
  Else
    KeyY=0
  EndIf
  
  MoveCamera(0,KeyX,0,KeyY)
  CameraLookAt(0,0,0,0)
  
  RenderWorld()
  
  FlipBuffers()
  
; When any system key combo is pressed, minimize to tray
  If IsScreenActive()=0
    ShowWindow_(WindowID(0),#SW_SHOWMINIMIZED)
    ShowCursor_(1)
  EndIf

Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow

Re: Cornell Box Issues

Posted: Tue Mar 05, 2013 9:46 am
by applePi
i can't cast shadow using #PB_Shadow_TextureAdditive even i have used EntityRenderMode(7, #PB_Entity_CastShadow )
i'm studying Ogre forum if this is possible using a material script file !!! it seems other people have also problems with shadow texture additive in that forum.
there is example water.pb in the 3D folder have #PB_Shadow_TextureAdditive and it works for casting the shadow of the remote mountains on the water but not for a sphere i have inserted in the example.
any way a beautiful example

Re: Cornell Box Issues

Posted: Tue Mar 05, 2013 7:19 pm
by Samuel
colguetti wrote:Hi everybody! While I´m trying to figure out how to make a small 3d editor, I´ve setup a scene like a Cornell Box

All shadow modes where working good, Additive, Modulative and TextureAdditive, then I added a sphere and unfortunately
TextureAdditive disappeared !!!

I don´t know what else to do, here´s the code, if somebody knows how to fix it please share, if someone finds this useful just keep it
I'm not a expert on shadows, but Comtois gave me an example once using EntityRenderMode(#Entity,#Mode).
All you have to do is set #Mode to 0 for the entity that you want a texture shadow to appear on.
This example should show it working.

One problem I've noticed is that the shadows disappear when you zoom out a little bit.
I've tried changing the shadow distance, but it doesn't seem to help much. So maybe someone with more knowledge can help you with that.

I hope this helps.

Code: Select all

ScreenX = GetSystemMetrics_(#SM_CXSCREEN)
ScreenY = GetSystemMetrics_(#SM_CYSCREEN)

InitEngine3D(#PB_Engine3D_DebugLog)
InitSprite()
InitKeyboard()
InitMouse()

OpenWindow(0,0,0,ScreenX,ScreenY,"Cornell Box",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,ScreenX,ScreenY,1,0,0,#PB_Screen_WaitSynchronization)

KeyboardMode(#PB_Keyboard_AllowSystemKeys)

;Create Red Wall
CreateTexture(1,32,32)
  StartDrawing(TextureOutput(1))
    Box(0,0,32,32,RGB(205,0,0))
  StopDrawing()
CreateMaterial(1,TextureID(1))
CreateCube(1,1)
CreateEntity(1,MeshID(1),MaterialID(1),-16,0,0)
ResizeEntity(1,1,33,32)

;Create Green Wall
CreateTexture(2,32,32)
  StartDrawing(TextureOutput(2))
    Box(0,0,32,32,RGB(0,205,0))
  StopDrawing()
CreateMaterial(2,TextureID(2))
CreateCube(2,1)
CreateEntity(2,MeshID(2),MaterialID(2),16,0,0)
ResizeEntity(2,1,33,32)

;Create Back Wall
CreateTexture(3,32,32)
  StartDrawing(TextureOutput(3))
    Box(0,0,32,32,RGB(245,245,245))
  StopDrawing()
CreateMaterial(3,TextureID(3))
CreateCube(3,1)
CreateEntity(3,MeshID(3),MaterialID(3),0,0,-16)
ResizeEntity(3,32,32,1)

;Create Ceiling
CreateTexture(4,32,32)
  StartDrawing(TextureOutput(4))
    Box(0,0,32,32,RGB(245,245,245))
  StopDrawing()
CreateMaterial(4,TextureID(4))
CreateCube(4,1)
CreateEntity(4,MeshID(4),MaterialID(4),0,16,0)
ResizeEntity(4,31,1,32)

;Create Floor
CreateTexture(5,32,32)
  StartDrawing(TextureOutput(5))
    Box(0,0,32,32,RGB(245,245,245))
  StopDrawing()
CreateMaterial(5,TextureID(5))
CreateCube(5,1)
CreateEntity(5,MeshID(5),MaterialID(5),0,-16,0)
ResizeEntity(5,31,1,32)

;Create Blue Box
CreateTexture(6,32,32)
  StartDrawing(TextureOutput(6))
    Box(0,0,32,32,RGB(0,0,245))
  StopDrawing()
CreateMaterial(6,TextureID(6))
CreateCube(6,1)
CreateEntity(6,MeshID(6),MaterialID(6),-8,-10,-4)
ResizeEntity(6,6,12,6)
RotateEntity(6,0,30,0)

;Create Sphere
CreateTexture(7,32,32)
  StartDrawing(TextureOutput(7))
    Box(0,0,32,32,RGB(245,245,0))
  StopDrawing()
CreateMaterial(7,TextureID(7))
CreateSphere(7,4,32,32)
CreateEntity(7,MeshID(7),MaterialID(7),8,-10,4)

;Create Light
AmbientColor(RGB(4,4,4))
CreateLight(0,RGB(245,245,205),0,13,0)
LightAttenuation(0,500,0.4)

;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,-10,23,#PB_Absolute)

;ADD THIS TO ALLOW TEXTUREADDITIVE SHADOWS ON THE REQUIRED ENTITY.
EntityRenderMode(1,0)
EntityRenderMode(2,0)
EntityRenderMode(3,0)
EntityRenderMode(4,0)
EntityRenderMode(5,0)
   
WorldShadows(#PB_Shadow_TextureAdditive,500,0,1024)

Repeat
  WaitWindowEvent(1)
  ShowCursor_(0)
 
  ExamineKeyboard()
 
; Use arrow keys to rotate and fly in/out
  If KeyboardPushed(#PB_Key_Left)
    KeyX=-1
  ElseIf KeyboardPushed(#PB_Key_Right)
    KeyX=1
  Else
    KeyX=0
  EndIf
 
  If KeyboardPushed(#PB_Key_Up)
    KeyY=-1
  ElseIf KeyboardPushed(#PB_Key_Down)
    KeyY=1
  Else
    KeyY=0
  EndIf
 
  MoveCamera(0,KeyX,0,KeyY)
  CameraLookAt(0,0,-10,0)
 
  RenderWorld()
 
  FlipBuffers()
 
; When any system key combo is pressed, minimize to tray
  If IsScreenActive()=0
    ShowWindow_(WindowID(0),#SW_SHOWMINIMIZED)
    ShowCursor_(1)
  EndIf

Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow

Re: Cornell Box Issues

Posted: Tue Mar 05, 2013 8:18 pm
by applePi
Samuel , thank you, you have solved my shadow problem with the models made from points lists such as knots and mandel3D. but the best shape of the shadow for those points models when the texture size are the biggest (4096). i thought it was not possible. really unexpected.

Re: Cornell Box Issues

Posted: Tue Mar 05, 2013 9:19 pm
by IdeasVacuum
Owch: [COMPILER] Line 22: ResizeEntity() is not a function, array, list, map or macro.

...For PB5.1x that should be: ScaleEntity() e.g. ScaleEntity(1,1,33,32,#PB_Absolute)

Before Opening the Window: AntialiasingMode(#PB_AntialiasingMode_x6)

I think this example should be distrubuted with PB! 8)

Re: Cornell Box Issues

Posted: Tue Mar 05, 2013 11:08 pm
by IdeasVacuum
....Moving the camera postion affects the shadow shape/position? :?

Re: Cornell Box Issues

Posted: Tue Mar 05, 2013 11:50 pm
by Samuel
IdeasVacuum wrote:....Moving the camera postion affects the shadow shape/position? :?
The TextureAdditive shadows only appear when within a certain distance of the objects. Thats why at times it looks like the shadows are only
partially there. Changing the distance parameter doesn't seem make them any better.

This is also the reason why I tend to avoid working with TextureAdditve shadows.
Maybe someone with more experience can point out how to make them work properly.

Re: Cornell Box Issues

Posted: Wed Mar 06, 2013 4:57 am
by colguetti
I think that TextureAdditive is not working properly, It would be a nice thing to have if you work with ultra mega large objects...

As I´ve defined the extents. limitations, style and cameras to use in my project, I only need some basic shadows...

Or better yet, well placed torches!!

Better get back to coding, don´t want to sleep with my head full of ideas and caffeine...

Thank you all guys !!!

Oh, by the way, if anyone is ready for some headaches, try turning that sphere into a glass sphere !!!

Re: Cornell Box Issues

Posted: Wed Mar 06, 2013 5:51 am
by Samuel
colguetti wrote: Oh, by the way, if anyone is ready for some headaches, try turning that sphere into a glass sphere !!!
If you wish to give a entity transparency you should check out the Purebasic example CreateTexture2.pb.
In order to make it look like glass though you will have to do some work on the texture, but it should follow the
same basic principle as that example.

Hope that helps and if you need a different example just say so and I'll post one when I have more time.

Re: Cornell Box Issues

Posted: Wed Mar 06, 2013 6:06 am
by colguetti
I´m sorry, as an IT worker, I always complain about customers that don´t read their manuals...

Thanks !!! I´ll start fiddling with it as soon as I get up tomorrow, having a broken arm has really helped my homebrew project!!!

Thanks again Samuel !!!