TShadowObject

Started by Midimaster, December 03, 2021, 17:41:25

Previous topic - Next topic

Midimaster

I can see in the OpenB3D a lot more functions than in old MiniB3D or Blitz3D. But I cannot find a systematic manual, what they are good for and how to use them.

At the moment I tried to find out what this "TShadowObject" is good for, but I was not able to do more than creating it:
Code (BlitzMax) Select
SuperStrict
Import openb3d.b3dglgraphics

Graphics3D(800, 600,32,-1)
Global Camera:TCamera = CreateCamera()
MoveEntity Camera, 0,0,-9

Global Cube:TMesh= CreateCube()
Global Floor:TMesh= CreateCube()
MoveEntity Floor, 0,-1,0
ScaleEntity Floor, 20,0.1,20
Global Shadow:TShadowObject=CreateShadow(cube,False)
Global Light:TEntity = CreateLight()

' UPDATE BUG:
' MoveEntity Light,-5,-5,-8  !!! wrong light position for seeing a shadow:
' NOW BETTER:
MoveEntity Light,-15,15,-8

While Not KeyHit(KEY_ESCAPE)
AmbientLight 50,40,30
TurnEntity Cube,0.01,0.02,0.03

UpdateWorld
RenderWorld()
Flip 0
Wend


Does anybody know how to continue? A Tutorial?
...back from North Pole.

markcwm

#1
There's a simple stencil shadow example in the openb3d.docs extended folder.
https://github.com/markcwm/openb3d.docs/blob/master/extended/stencil_shadows.bmx

Angros has released an Openb3d manual, it has some info on shadows, I've yet to update the wrapper with this.
https://sourceforge.net/projects/minib3d/files/OpenB3D%20reference%201.26.zip/download

Stencil shadows have hard edges. As you might expect, meshes with alpha textures do not cast alpha stencil shadows. Stencil shadows are not stopped by other meshes, so will pass through walls, etc. They also cast self-shadows.

Midimaster

Thank you for pointing me to docs and the examples. This makes a lot of things easier. I found my bug and was able to see the shadow.

But that raises the next question... In my example and also in the stencil_shadow.bmx the lighting on the turning cube looks terrible unreal, because the light comes like "switched on/off immediately" when a cube face turnes into light. Is this normal? Is there a strategy to get more "increasing" lighting on turning objects?
...back from North Pole.

angros47

Stencil shadows are "all or nothing", but it is possible a workaround by using the accumulation buffer. I described the method here:

https://freebasic.net/forum/viewtopic.php?t=22745

Code is in FreeBasic, but I see no reasons why it couldn't be ported to BlitzMax

Midimaster

Oh sorry... I did not mean the shadows, but the lighting of the cubes.
...back from North Pole.

angros47

The lighting on the cube is the shadow: it is called "self shadow", because an object in reality can cast part of the shadow on itself (and, while some algorithms don't implement that, the one used in OpenB3D implements it). The solution proposed in the link fixed that, too