OpenB3D Plus 0.12

Started by angros47, January 30, 2022, 01:20:40

Previous topic - Next topic

angros47

Due to an issue with nvidia driver on Linux, I had to switch to nouveau generic drivers, and I realized that most shaders I wrote didn't work with it: looks like the nvidia proprietary driver is more permissive, while the nouveau implementation has a stricter syntax enforcement.

The new version of OB3D Plus is 64 bit, but can still be compiled to 32 bit if needed.

OB3D Plus is a helper library, to be used with OpenB3D, that adds: High Dynamic Range, Screen Space Ambient Occlusion, Material Capture, Fur Shading, simple Deferred Rendering, Interior Mapping, glass material, toon shading, Depth of Field, Bump Mapping, Shadow Mapping, and some post processing effects like pixel art, or fisheye. Also, it allows to save videos of the rendering.

https://sourceforge.net/projects/minib3d/files/

Amon

I'm assuming the .bi file goes in the lib folder and the ..dll in the project directory?

angros47

The .bi file is the header for FreeBasic. Blitzmax would need its own header.

Amon

So, currently it won't work in blitzmax without the .bi header file? How would I go about generating one?

angros47

It can be used from C++ or from C, so it can be imported in BlitzMax as well as long as an header for it is made

Kronos

shadow mapping you say. Is that using the deferred light commands?

GW

Quote from: Kronos on February 01, 2022, 19:28:18
shadow mapping you say.
The Holy Grail of 3D in Blitz?   
I would very much like to see an example of how that's used in Bmax.

angros47

My implementation of shadow mapping doesn't use deferred rendering. It uses a shader that has to be applied to the object receiving the shadow

Here is a sample in FreeBasic:
#include "ob3dplus.bi"

declare function CreateShadowMap cdecl alias "CreateShadowMap" (byval light as any ptr) as any ptr
declare sub UpdateShadows cdecl alias "UpdateShadows" ()


screen 18,  32, , &h10002


Graphics3d 640,480,32,1,1

var camera=createcamera(0)
cameraclscolor camera,0,0,255





var cube=createcube()
entitycolor cube,255,0,0

var plane=createplane()'cube():scaleentity plane, 100,.1,100
moveentity plane,0,-1.4,15
scalemesh plane, .001,1,.001


var light=createlight()
var camlight=createcamera(light)
CameraViewport camlight,0,0,512,512
hideentity camlight
var ShadowMap=CreateTexture(512,512)



moveentity light,10,10,-3
pointentity light,cube
moveentity camera,-2,0,-5

var shadow=createshadowmap(light)
shadeentity plane, shadow

shadeentity cube, shadow
entitytexture cube, loadtexture("diffuse.png")


dim key as string
do

'depthbuffertotex ShadowMap, CamLight
updateshadows

key=inkey
        if key="a" then moveentity cube,0,0,1
        if key="z" then moveentity cube,0,0,-1

        if key=chr(255)+"H" then turnentity cube,1,0,0,0
        if key=chr(255)+"P" then turnentity cube,-1,0,0,0
        if key=chr(255)+"M" then turnentity cube,0,-1,0,0
        if key=chr(255)+"K" then turnentity cube,0,1,0,0
updateworld 1
renderworld
sleep 1
flip
loop until key=chr(27)


CreateShadowMap creates a shader that must be applied to the objects receiving a shadow. It accepts a light as argument. You don't need to add a shadow individually to any object casting it (as you have to do with stencil shadows): the resulting shadow is less precise than stencil shadows, but it is affected by masked textures (so you can have shadows of foliage, for example)

UpdateShadows must be called each frame

The main disadvantage is that the mesh receiving the shadow has to use this specific shader, and so cannot have a different one (since only one shader at time can be applied on an object). So, no shadows on a bump mapped surface, for example.

Amon

How do I generate a declares file for BlitzMax?

Midimaster

#9
Quote from: Amon. on February 03, 2022, 13:28:05
How do I generate a declares file for BlitzMax?

I wrote a tutorial about "BlitzMax interacting with C" some month ago.

The tutorial
https://www.syntaxbomb.com/tutorials/blitzmax-interacting-with-c/

My wrapper
https://github.com/MidimasterSoft/BlitzMax-Miniaudio-Wrapper

The discussions
https://www.syntaxbomb.com/blitzmax-blitzmax-ng/how-to-write-a-wrapper/

The theme was to build a "wrapper" or  "how to call all functions of a C-library". I did this (for the first time in my life) with MiniAudio and wrote down my experiences in this tutorial.

As your OB3D-Zip contains already a similar "wrapper" for a other language ( See "op3dplus.bi" ) you have a good chance to translate all those lines into BlitzMax.

Only the first steps are difficult. If you solved  your first problems, most of the following code lines are treaded the same way.

Example:

one line in your op3dplus.bi looks like this:
declare function CreateBump cdecl alias "CreateBump" (byval light as any ptr, byval show_diffuse as integer=1, byval mode as integer=4) as any ptr

Of course first you have to know (investigate) what this function is good for and what is the meaning of the parameters.

As a second aspect to have to know, how to transfer the various variable types into BlitzMax variable types.

BlitzMax would look something like this:

Code (BlitzMax) Select
Extern "C"
Function CreateBump:Byte Ptr  (light:Byte Ptr , show_diffuse:Int Ptr, mode:Int Ptr) = "CreateBump"
' here next line...
End Extern



...back from North Pole.

Kronos

Hi Angros, thanks for the shadow code example. Is there any chance you can compile a win32 version of the openb3dplus dll. My blitzmax installation/wrapper code doesn't seem to work with 64 bit dlls.

angros47


Kronos

#12
Got it working once I figured out every shadow receiver needs the texture applied to it. I am getting multiple shadows duplicated across the plane surface though.
I think you possibly need to change

ShadowSampler=CreateTexture(512,512,1,1);
to
ShadowSampler=CreateTexture(512,512,1+16+32,1);
to clamp the texture in the function CreateShadowMap

Would also be nice if we could define the size of the shadowmap through the function ;)


Include "openb3d.bmx"

'wrapper stuff
Global libPlus:Int = LoadLibraryA("ob3dPlus_32.dll")
Global CreateShadowMap:Int(light:Int) "C" = getprocaddress(libPlus, "CreateShadowMap")
Global UpdateShadows() "C" = getprocaddress(libPlus, "UpdateShadows")


Graphics3D(1024,768)

camera = CreateCamera()
CameraClsColor(camera, 0, 0, 255)

cube = CreateCube()
EntityColor(cube, 255, 0, 0)
MoveEntity(cube,0,5,0)

anothercube=CreateCube()
MoveEntity(cube,1,0,0)



plane = CreateCube()
MoveEntity(plane,0,-4,0)
ScaleEntity(plane, 100, 1, 100)


light = CreateLight()

PositionEntity(light, 0, 20, 0)
PointEntity(light, cube)
MoveEntity(camera, -2, 0, -5)

shadow=CreateShadowmap(light)

ShadeEntity(plane, shadow)
ShadeEntity(anothercube, shadow)

tex = LoadTexture("media/test.jpg")

EntityTexture(anothercube, tex)
EntityTexture(plane,tex)

While Not KeyHit(key_escape) And Not AppTerminate()


UpdateShadows()

If KeyDown(KEY_W) Then MoveEntity(camera, 0, 0, 1)
If KeyDown(KEY_S) Then MoveEntity(camera, 0, 0, -1)
If KeyDown(KEY_A) Then MoveEntity(camera, 0, -1, 0)
If KeyDown(KEY_D) Then MoveEntity(camera, 0, 1, 0)
PointEntity(camera,cube)

TurnEntity(cube, 1, 1, 1)

       
UpdateWorld()
RenderWorld()
Flip()

Wend



Hotshot

How fast is openb3d compare to BlitzMax ng?