Openb3d wrapper (Part 4)

BlitzMax Forums/MiniB3D Module/Openb3d wrapper (Part 4)

markcw(Posted 2016) [#1]
Since the 3nd thread has exceeded 250 posts I started a new thread. As usual please post new issues with the wrapper here. Thanks.

Download: You can download the latest version of the wrapper with examples and my small fixes to the C++ source HERE. Now available courtesy of GitHub.
You can find the official Openb3d libraries and source HERE.

To install MinGW follow this guide.

The original thread about Openb3d is here and the Freebasic thread is here.
Other Openb3d wrapper threads: 1st, 2nd, 3rd.


markcw(Posted 2016) [#2]
Recent issues posted in separate threads.

Hardware Multisampling (MSAA) with OpenB3D/OpenGL [solved]
Shadows and PerPixel Lighting with Alpha Textures [solved]
Smoothing or Managing Terrain LOD/Quality
OpenB3D Bump Mapping Issue


RustyKristi(Posted 2016) [#3]
I believe you can mark the MSAA issue solved for now. The postfx camera method seems to be stable enough and now with multipass ( thanks to you! :D ) to eventually write shaders that deal with AA. Maybe on future updates you can find some way to get this hardware multisampling enabled again like in minib3d but that will be just icing on the cake! ;-)

Great stuff.


markcw(Posted 2016) [#4]
Great, I need to read the MSAA thread yet.

Angros. I edited texture.cpp to remove all Global::height-height as y parameters in depth/backbuffertotex. This was so I don't have to invert y in CameraViewport which uses GraphicsHeight and would break if anything else is wanted.
I also noticed the CameraToTex declaration is missing in functions.h.

And I've removed inverting v texture coords in the postfx shader and now use ScaleTexture tex,1,-1 before LoadShader. This is a fix specifically for glMatrixMode(GL_TEXTURE) and glScalef. ScaleTexture isn't needed for a 2 pass shader as it seems to re-invert the texture.

While I was there I added the ability to view the depth texture in sl_depthfield.bmx.

I also added ima747's great 3d sound mod, see examples/sound for demos. Could do with better sounds.


Hezkore(Posted 2016) [#5]
I'd like to see some texture filter options if possible. :)


markcw(Posted 2016) [#6]
Hezkore wrote:
I'm wondering if there's any way to remove the filtering on textures?
I'd like small textures to be big pixels instead of smoothed.
ClearTextureFilters() doesn't help.

I wrote:
I'm sure this is the tex.flag set in LoadTexture (which doesn't seem to be working when I set it which may be a problem with pointers in the wrapper) this sets glTexParameter GL_LINEAR which should disable mipmaps but it doesn't seem to work.

I was wrong, flags in LoadTexture work, the problem was that Openb3d and Minib3d use Linear filtering (by glTexParameter) but this is smooth and looks the same as mipmaps. I changed the render code in mesh.cpp and material.cpp to use Nearest and now you see sharp pixels (fix is from NeHe lesson 7). Look in examples/texturefilter.bmx as I added a handy command TextureFlags which sets tex.flags.

I also found out the brush.tex[] array needs to be updated on commands like EntityTexture and PaintMesh as it's a list of objects that changes after init, it was crashing on Null objects when I tried to access ent.brush.tex[0].


RustyKristi(Posted 2016) [#7]
I'd like small textures to be big pixels instead of smoothed.


I think you can you do this by applying a material shader filter effect like some sort of pixelate.

@munch

The 3d sound support added is awesome munch! I was curious about the new depth/backbuffertotex updates as I have made some adjustment on some simple and current shaders, will that be affected as well? I have not made the update yet but planning to do so when I get something done with my stuff later on.

Thanks


Hezkore(Posted 2016) [#8]
@RustyKristi
What I'm doing atm. is just rendering everything to a very small image and stretching it out, that gives me some big nice pixels.
But you can still very much see the bilinear filtering on textures and sprites, especially up close.

New version fixes that though.

@munch
MaxGUI example uses an older version of my function.
Here's what it should be using:



markcw(Posted 2016) [#9]
I was curious about the new depth/backbuffertotex updates as I have made some adjustment on some simple and current shaders, will that be affected as well?

The backbuffertotex update removed inverting the y in the cpp and removed reinverting in cameraviewport in the wrapper but it won't make any difference to existing code.

Shaders are also changed to use nearest/sharp instead of linear/smooth and I'll add an example to show this.


markcw(Posted 2016) [#10]
I added the fix to UpdateCanvas, although it seemed to work fine without the extra SetGraphics.

I discovered what's going on with ScaleTexture in a 2 pass shader. ScaleTexture won't invert unless you pass the uv coords which is done in the vert by multiplying by gl_TextureMatrix[n]:
texCoord0/gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

I added a 2 pass gaussian blur example which also lets you view the horizontal or vertical blur on Space key.

I fixed a bug created by my update brush.tex fix in EntityTexture and other commands, when brush didn't exist it was crashing on Null, it was happening on sprites.

Hezkore, I tested retro dungeon crawler with FreeEntity on ubuntu and it didn't crash after I broke all the blocks. Nice gfx btw. :)


RustyKristi(Posted 2016) [#11]
The backbuffertotex update removed inverting the y in the cpp and removed reinverting in cameraviewport in the wrapper but it won't make any difference to existing code.

Shaders are also changed to use nearest/sharp instead of linear/smooth and I'll add an example to show this.


Awesome, good to know munch!


Hezkore(Posted 2016) [#12]
@munch
The newer versions seems to be a bit more stable somehow?
I haven't had a single FreeEntity crash yet!

And thanks!
I'm working on a new fully 3D retro dungon crawler atm., just got clouds and norther lights done. :)




markcw(Posted 2016) [#13]
Holy moly, how on earth did you do that? Very professional!

Good to hear it's stable now, I didn't change FreeEntity the major bug fix was updating brush.textures with EntityTexture, etc. but that always gives a Null object error when I try to access them.


Hezkore(Posted 2016) [#14]
Thank you munch!
Just using layered textures and alphas. (I can't write shaders heh)
It kinda works as the water example I showed you in that other forum post. :)

I'll report back if I get any crashes!


Hezkore(Posted 2016) [#15]
I've got loads of crashes again.
I've made an extreme test and after about 5 seconds or so this causes the FreeVBO crash.

(Source & Compiled for Windows)
https://dl.dropboxusercontent.com/u/2842751/freevbo_crash.zip


RustyKristi(Posted 2016) [#16]
By debugging it kinda stops at CreateMesh function in your LoadObj. I haven't had any luck with any other 3d format loader either but it somehow works with older X format.

I'm sure there are other obj loaders you can try. I wonder if the BlitzAssimp works with OpenB3D..


Hezkore(Posted 2016) [#17]
The Obj loader is fine, I've used it for a long time with a lot of other projects but always with an older build of OpenB3D.
The newer builds of OpenB3D sometimes crashes at TSurface.bmx > FreeVBO()


RustyKristi(Posted 2016) [#18]
Ah ok. thanks for the heads up


markcw(Posted 2016) [#19]
Thanks Hezkore, but I can't reproduce the crash.


Hezkore(Posted 2016) [#20]
I've updated it.
Same link: https://dl.dropboxusercontent.com/u/2842751/freevbo_crash.zip
This instantly crashes on my machine, complaining about FreeVBO.
Make sure you actually unpack the zip before you run it, so that the ship mesh gets loaded.
And try to compile it in debug mode, it crashes more often with that.

Here's where it points me in debug mode https://github.com/markcwm/openb3d.mod/blob/master/openb3d.mod/inc/TSurface.bmx#L365
I've tried changing the code to make sure that GetInstance(Self) isn't null before FreeVBO gets called, but that doesn't seem to be the issue.
Here's a debug log if that helps - https://www.irccloud.com/pastebin/c4D27EzM/


RustyKristi(Posted 2016) [#21]
Actually that update worked for me Hezkore, using debug and release. I'm seeing now the ship spinning without any crash so far.

I also used your crash.debug.exe if that makes any difference.


Hezkore(Posted 2016) [#22]
Yeah I'm not sure if it's somehow FPS related or something?
My slower computers all run this fine, but the faster ones all crash after a while.
If I create a bunch of meshes, lowering my FPS, I don't get crashes as often.


RustyKristi(Posted 2016) [#23]
I'm not sure, maybe it's graphic card related with OpenGL. OpenB3D is using OpenGL 1.2 right?

btw, I'm using a fast pc (i7) with gtx card and it's been running now for around 10mins and going :-)

PS: I have not upgraded yet to munch's latest openb3d updates since the depthbuffer stuff, but I am running your exe build for comparison.


Hezkore(Posted 2016) [#24]
Maybe it's an ATi thing?
Or Window 10?


RustyKristi(Posted 2016) [#25]
That could possible with the ATi issue, it's a common thing if we're talking about graphic stuff. Windows 10 or platform wise, I'm not sure and it's unlikely. I have not used windows 10 yet and still on win7.


Hezkore(Posted 2016) [#26]
The issue still exists on nVidia though.
I've got this project I'm working on and almost everyone get the FreeVBO crash.

I guess I could share the executables here (Windows only)
If you try to walk outside of the cave and back in a few times (so that the crashed ship gets loaded and unloaded) the game will sometimes crash.
(Walk with Arrow keys or WASD, strafe with Q and E. No mouse needed)

*link removed, problem fixed*
Project is still very much in concept demo stage, so art is place holder stuff.


RustyKristi(Posted 2016) [#27]
Looks great! and yea, no crashes yet so far. I've been in and out of the cave around 10 times already lol. I also minimized it so I can fast reply here hehe

It could be a driver issue but I'm not sure, what's your full spec?

At least it's not a definite crash issue as it could be just some hard/software incompatibility problem as far as this benchmark thing is going. ;-)


RustyKristi(Posted 2016) [#28]
Btw Hezkore, do you have the full objloader with texture, normals and everything? or is the demo sample already complete?

I need some kind of 3d format alternative besides b3d just for test reasons, thanks.


markcw(Posted 2016) [#29]
Ok, I think the problem is in TSurface.bmx Delete method I call FreeVBO when I shouldn't as that's handled by the library. So uncomment that and rebuild.


Hezkore(Posted 2016) [#30]
That is the full Obj loader, I've commented out the last part where it loads textures though.
See the "rem" at the end.

As for my specs.
Currently using AMD Radeon R9 390 8GB with the Crimson Edition 16.4.1 drivers.
Not that my CPU probably matters, but AMD FX 9590 (4.7GHz 8 Cores)

@munch
That... seems to fix it! :o
Weird though seeing as deleting the same buffer address multiple times is valid in OpenGL.


RustyKristi(Posted 2016) [#31]
Nice great to hear! and awesome fix munch!

Btw, does it work also with loading multiple textures?


markcw(Posted 2016) [#32]
According to this the crash happens when you don't remove the reference to the buffer after you delete it, which I think is what I was doing.

I've updated the repo with this fix now.


RustyKristi(Posted 2016) [#33]
Hey munch, I have a quick question. I'm trying to implement my own simple particle system together with the postfx, but when I hooked the camera to my functions and initialize before the main loop, I can only see sort of the depthbuffer being rendered but my system works ok.

My functions uses CameraProject and takes the camera entity as parameter when initialized. Do you have any ideas on how I can resolve this?

Thanks.


markcw(Posted 2016) [#34]
Maybe an extra camera for postfx stuff so you know what to expect in the main camera.


RustyKristi(Posted 2016) [#35]
Thanks, can you give me an example on how to go about this? I only know multi-cameras when using viewports like rear view or minimap.


markcw(Posted 2016) [#36]
RustyKristi, I updated the post process examples. I'm not sure this will help you but it did boost fps a little (from 9 to 13 on 2 pass).

I was also calling RenderWorld too many times, Camera/DepthBufferToTex have their own Render in them, so if you're doing a 2 pass you should only need 3 render functions.

Also for the 2 pass, it wasn't working until I put ShowCamera before the 2nd CameraToTex so the 2nd pass uses the main camera. It may be possible to do it with the 2nd camera but I don't know.

Also I notice often, randomly there's mesh vertex data corrupted in those examples, not sure what's causing it.


RustyKristi(Posted 2016) [#37]
Thanks munch, I just upgraded my copy of openb3d with your latest commit. I thought I would test all the demos again first before anything else, particularly the new examples so I can give you some quick feedback. That was really an awesome update with the 3D sound and the demos wow! :D Depthbuffer adjustment looks great. I definitely have not made any single changes on my code including some simple custom shaders.

* Pixellight2 example has some Z-Order fighting isses, but alpha textures works great. Btw, since you already put a demo out there in GitHub with the tree exampl and stuff, please do go ahead and include the tree model and textures. It's a royalty free asset that I got somewhere and I made sure it has no problems with it in terms of licensing.

* With my previous openb3d version, I have also noticed that the stencil shadows is somehow always on top and fully dark when I render my camera projected particle system. My particle obviously uses some alpha textures so I don't know if this has some effect on it. I'm only using the default openb3d commands and not sure how it is causing that weird layer ordering issue.

Lastly, I thought the latest technique with 2pass and blurpass is really awesome. Thanks for the tip and I still have to do some thorough testing my custom particle system with your update and example later on so I got my fingers crossed.. ;-)


RustyKristi(Posted 2016) [#38]
Hey munch, so after some rigorous testing the issue is now fixed either with the main camera or postfx_camera when using shaders and my projected particle system.

The only problem that I'm seeing now is the stencil shadow seems to be way darker.



If I remove my particle system stuff, it looks ok and back to normal.



Thanks again.


markcw(Posted 2016) [#39]
Try using SetShadowColor(r,g,b,a) as int 0..255.


RustyKristi(Posted 2016) [#40]
I tried it but same thing if I activate my custom particle, it does that. I even copied the array format with one of your examples to set the color just be sure I'm doing it right.


markcw(Posted 2016) [#41]
Well it looks like the particle code is affecting the alpha of shadows. I have no ideas what to do.


RustyKristi(Posted 2016) [#42]
Thanks munch, I could post the init code that seems to be creating the issue if you would like to check them out. It's kinda weird because I'm just using standard OpenB3D commands inside a Type Method for the particle stuff. Do you think it has a similar problem with the depth buffer before?


markcw(Posted 2016) [#43]
Well, I can have a look. Send me a mail with your code if you prefer.

I've split up openb3d.mod into openb3dex.mod just so that blitz3d functions have their own docs page to extended functions.

I also added the per pixel fog shader so see here for more.

I included the pixellight2 example media as well, so thanks RustyKristi.


RustyKristi(Posted 2016) [#44]
Great, thanks I'll send them after I sorted some stuff out because I'm just starting to piece this and it's kind of a mess.

Awesome new examples, that solved it and with the addition of openb3dex! :D


markcw(Posted 2016) [#45]
Pixellight2 example has some Z-Order fighting isses, but alpha textures works great.

I did get that as I was working on the example (some branches disappearing/reappearing at random) but I fixed it by removing color.a (light color) from the gl_FragColor result.


RustyKristi(Posted 2016) [#46]
Great, thanks! But I'm not that familiar to do those changes, can you update the example shader? :)


RustyKristi(Posted 2016) [#47]
Also, I think I found the part of my code that is messing up the stencil shadows, I also got a partial fix after some hours playing around with it. This example is how I initialize my particle stuff and I really have no idea how this affects the stencil shadow. So for the actual test, try adding these lines anywhere in stencil_shadows2.bmx or any simple scene with shadows.

Local mesh1:TMesh , mesh2:TMesh
Local surface1:TSurface , surface2:TSurface
mesh1    = CreateMesh()
surface1 = CreateSurface( mesh1 )
mesh2    = CreateMesh()
surface2 = CreateSurface( mesh2 )
EntityBlend( mesh1, 1 )
EntityBlend( mesh2, 3 )
EntityFX   ( mesh1, 1+8+16+32 )
EntityFX   ( mesh2, 1+8+16+32 )


Setting the EntityFX flags on the last line triggers the darkening issue. For me, I tested it with flags 2 and 8 (use vertex colors and disable fog). How I got it fixed is by adding another mesh with surface and just setting EntityBlend with flag total 3.

I don't know how that really works with the stencil shadows, but I'm glad I don't have to worry about this for now and thanks again for all the help. :)


markcw(Posted 2016) [#48]
Thanks RustyKristi, I would suspect EntityBlend mode 3 (add) is the problem, when it's the last entity rendered it could affect shadow alpha values.


RustyKristi(Posted 2016) [#49]
Great, thanks munch. So, I would assume this is a normal thing, right?


RustyKristi(Posted 2016) [#50]
Btw munch, can you update the PixelLight example in the repo with the corrected alpha/z order fighting issue? thanks


markcw(Posted 2016) [#51]
I wasn't able to reproduce this darkened shadows issue but I've only tested on Linux yet. Edit: tested in Win and couldn't reproduce it either.

I've just found a bug too, this only happens in Win in the stensilshadows2 example, when I do the multipass render it crashes randomly but consistently at renderworld, the problem stops when I comment the createshadow out so I suspect it is in the shadow update code. I was thinking it is where cameraclsmode is used but the previous values are not restored.


RustyKristi(Posted 2016) [#52]
Ok got it. I will just send the exact code and a screen later today. thanks


RustyKristi(Posted 2016) [#53]
Here you go munch, I placed it right before the main loop. I also added my temp fix and uncomment it for your own testing.

http://pastebin.com/wySTa7Km

screen with altered stencil shadows




t3K|Mac(Posted 2016) [#54]
I am a former Blitz3D User and i stumbled across Blitzmax and Openb3D. I'd love to start coding again, but i cannot get Openb3D to install correctly in Blitzmax. Is there any link to a guide/how to? I tried OpenB3D 1.12 with latest BlitzMax IDE... any help appreciated!


markcw(Posted 2016) [#55]
Hi t3K, what version of GCC do you have? You might have better luck using OS Bmx, see here for guide, it's aimed at Windows but all you have to do on Mac is run install.bat.

Currently I don't have a Mac which will run Openb3d and haven't for several months so I've no idea if it works there Atm. It needs a minimum of GL 2.0 (so it won't run on older Macbooks that have GL 1.4) and if you have GL 3.0 the shaders won't work. I am planning on getting a GL 3.0 Mac some time soon but I've no idea how that will go. It is at least working fine on my Win7 and Ubuntu systems.


t3K|Mac(Posted 2016) [#56]
GCC? None.. i just downloaded Blitzmax and the OpenB3D Files... i have a late 2012 macmini, but i would like to code on both systems (windows 7 & macos). i found the thread, but what is minGW? All i want is to use blitz3d'ish commands in bmax.

i will re-read the thread to understand what to install. maybe it helps ;)


markcw(Posted 2016) [#57]
MinGW is GCC in Windows (Minimal GNU for Windows) and GCC is the compiler (GNU Compiler Collection) which you need to build module (archive .a) files. The guide I wrote here should be enough to get TDM MinGW installed in Win7.

Openb3d requires that you build it as a module using GCC ("./bmk makemods -a openb3d" from bin folder) and doesn't supply any pre-built archives as that would be too much trouble (Minib3d also needs to be built with GCC). You get conflicts when you try to build modules with different compiler versions. This is okay for DLLs but not archives, as they are static (built into the exe) so need to be the same version.

For Mac you get GCC bundled with the XCode tools from Apple's developer site here. From a search it seems Mountain Lion needs xcode 5.11 and Yosemite needs xcode 6.4, those are the highest versions compatible. For Snow Leopard I've used xcode 3.22 which was the highest free version until 7.

I recommend using MacPorts a commandline package manager for free open source software (mainly Unix) which has things like Git. Here is their xcode advice (it seems GCC is a separate download above xcode 4).

Apple's Xcode Developer Tools (version 7.0 or later for El Capitan, 6.1 or later for Yosemite, 5.0.1 or later for Mavericks, 4.4 or later for Mountain Lion, 4.1 or later for Lion, 3.2 or later for Snow Leopard, or 3.1 or later for Leopard), found at the Apple Developer site, on your Mac OS X installation CDs/DVD, or in the Mac App Store. Using the latest available version that will run on your OS is highly recommended.

Apple's Command Line Developer Tools are found at the Apple Developer site, or they can be installed from within Xcode 4. Users of Xcode 3 or earlier can install this by ensuring that the appropriate option(s) are selected at the time of Xcode's install ("UNIX Development", "System Tools", "Command Line Tools", or "Command Line Support").



markcw(Posted 2016) [#58]
Setting the EntityFX flags on the last line triggers the darkening issue. For me, I tested it with flags 2 and 8 (use vertex colors and disable fog). How I got it fixed is by adding another mesh with surface and just setting EntityBlend with flag total 3.

Thanks for the sample RustyKristi (http://pastebin.com/wySTa7Km). I can see the problem now but couldn't work out a fix, so the workaround is as you posted making the last mesh rendered to have alpha enabled either by using EntityBlend 2 or 3, EntityFX 32 or EntityAlpha <1.0.


markcw(Posted 2016) [#59]
Just a small update, mainly to add LoadTextureAlpha which allows you to choose a rgb channel to use as alpha, this is a workaround for the lack of texture blending with alpha in Openb3d/Minib3d. It works like LoadTexture but has an alphamask parameter which should be $FF for red, $FF00 for green, etc. It's also used by LoadTexture to replace the STB image loader for jpeg so the progressive format can be loaded. See the alphamap example. To load alpha from another image you would have to write a custom function.

There is also an example of how to use EmitterParticleFunction to set up a "callback function" for particles. This is called particle_smoke and shows how to change alpha, scaling and add randomness. It can be used as a base for more complex things. It's not a single surface though and I don't think the callback supports that.

I added a fix for Text when texture blending is on and the text background fills in.

And I moved all examples to sub-folders just to tidy things up a bit more, so most things are now in examples/openb3d.


t3K|Mac(Posted 2016) [#60]
So munch, i managed to get gcc working and i compiled all the mods - but now i got a "module does not match commandline module" error when trying to compile some examples ???


Hezkore(Posted 2016) [#61]
I've found a problem with Terrains and EntityOrder.
I'm trying to place a box behind a terrain, but the EntityOrder function doesn't seem to work combined with a Terrain mesh.

Here's an example.


markcw(Posted 2016) [#62]
module does not match commandline module

I think this means you haven't compiled the module, check the openb3d.mod/openb3d.mod folder has .a and .i files. Try compiling Minib3d and running its examples with "import sidesign.minib3d".


angros47(Posted 2016) [#63]
EntityOrder does not affect terrains, only meshes and sprites. Terrains and planets are rendered immediately, since they are usually the background, then meshes are added. The same issue affected warner's engine, too. The issue should occur only in case of transparent terrains, by the way.


markcw(Posted 2016) [#64]
Hezkore, yeah you're right currently EntityOrder only works on meshes. I'm not sure why you want to do this as not setting any entity order draws it where it should be, unless you want to draw it as a background object. You can render background objects before foreground ones by disabling the camera color buffer.
	HideEntity terrain
	ShowEntity cube
	CameraClsMode camera,0,1 ' don't clear color buffer so we can draw over rest of scene
	RenderWorld
	
	HideEntity cube
	ShowEntity terrain
	RenderWorld
	
	Flip(1)



markcw(Posted 2016) [#65]
I've been trying to fix the crash with stencil shadows and multipass renders but was only able to narrow it down to this: if you call HideEntity on the shadow caster then it crashes at RenderWorld but this is random and happens about 1/10 times and seems only to happen in Windows. I tried hacking around in ShadowObject::RenderVolume or ShadowObject::Update but nothing really to report.

Edit: one thing it might be is an issue with GL 2.0 (or drivers) which would explain why it works in 2.1 in which case there's no fix.


Hezkore(Posted 2016) [#66]
Well normally when you do something like a sky box or sky dome you want to have it rendered behind the terrain.
And it's a bit of a pain to hide every single object in the world (especially if you've got a big world) just to draw the sky, then show every object again and render again.
I'm not actually using a terrain, I just found the issue randomly.
And the issue is still there without transparent terrains.


RustyKristi(Posted 2016) [#67]
thanks munch. The workaround that I discovered kind of worked somehow, so that should be fine for now. Maybe this can be solved later on and now with the new 2.0 changes coming. :-)


angros47(Posted 2016) [#68]
@Hezkore

First of all, if the terrain is not alpha blended entity order should not be an issue, since depth testing will prevail over entity order. Entity order is useful only when an entity is transparent, because it does not set the depth buffer.
So, unless you use a transparent terrain (to create a sea, maybe? Well, an isosurface would be more suitable for that), no problem should occur. With a terrain that is not transparent, maybe you forgot to create a depth buffer when setting opengl?

Anyway, to perform two passes rendering, there is another solution, if you don't want to hide/unhide all objects at each frame: just use two cameras, one in the world, the other inside the sky map; you will only need to hide the first camera and unhide the second, to render all the objects


markcw(Posted 2016) [#69]
Angros, I just discovered an issue with alpha, alpha only works when there is a non-alpha mesh being rendered with it.

In the example the cubes have alpha set but the sphere is solid, the cube in the middle only renders as alpha when the sphere is visible. It works fine in Minib3d.
' alpha.bmx

Strict

Framework Openb3d.B3dglgraphics

Graphics3D 800,600,0,2
ClearTextureFilters

Local camera:TCamera=CreateCamera()
CameraClsColor camera,80,160,240

Local light:TLight=CreateLight()

Local tex:TTexture=LoadTexture("../media/Smoke.png",1)
'Local tex:TTexture=LoadTextureAlpha("../media/Smoke.png",1,$FF00)
Local sprite:TMesh=CreateCube()
'Local sprite:TSprite=CreateSprite()
PositionEntity sprite,0.1,0.1,0.1
EntityAlpha sprite,0.5
'EntityFX sprite,1+32
EntityTexture sprite,tex
'EntityBlend sprite,3

Local cube:TMesh=CreateCube()
PositionEntity cube,1,1,10
EntityAlpha cube,0.5
'EntityFX cube,1+32
EntityTexture cube,tex

Local sphere:TMesh=CreateSphere()
PositionEntity sphere,1,1,-10
'EntityFX sphere,32

Local frame%

' fps code
Local old_ms%=MilliSecs()
Local renders%, fps%

While Not KeyHit(KEY_ESCAPE)

	frame :+ 10
	PositionEntity camera, Cos(frame * 0.1) * 8, 3, Sin(frame * 0.1) * 8
	PointEntity camera, sprite
	
	'UpdateWorld
	RenderWorld
	
	' calculate fps
	renders=renders+1
	If MilliSecs()-old_ms>=1000
		old_ms=MilliSecs()
		fps=renders
		renders=0
	EndIf
	
	Text 0,0,"FPS: "+fps
	
	Flip
		
Wend
End



markcw(Posted 2016) [#70]
Just another small update. This fixes a FreeShadow memory leak which I traced back to ShadowVolume TSurface so I removed that for now. ShaderTexture now returns the texture the shader has been passed, it required a few changes to the library not sure how it works with multiple textures yet, see sl_texturefilter.bmx. FreeStencil is added from Spinduluz's version, see stencil.bmx. Fix for TSprite InitFields wasn't calling it's super method. Also, stencil_shadows2 has a workaround for a 2 pass render with shadows in GL 2.0 as it MAVs when a shadow caster is hidden.


markcw(Posted 2016) [#71]
Hey Angros, trying to write a FreeShader function but am confused about how to access DeleteVertShader, am I doing this wrong (in material.cpp). Thanks.
void Shader::FreeShader(){
	if(!arb_program) return;
	arb_program.DeActivate(); // Ensure the shader is not used
	
	list<ShaderObject*>::iterator it;
	for(it=arb_program.vList.begin();it!=arb_program.vList.end();it++){
		ShaderObject* obj=*it;
		obj->DeleteVertShader(obj);
	}
	for(it=arb_program.fList.begin();it!=arb_program.fList.end();it++){
		ShaderObject* obj=*it;
		obj->DeleteFragShader(obj);
	}
	
	glDeleteProgram(arb_program);
	arb_program=0;
	delete this;
}



angros47(Posted 2016) [#72]
You used "." instead of "->" in some places

void Shader::FreeShader(){
	if(!arb_program) return;
	arb_program->DeActivate(); // Ensure the shader is not used
	
	list<ShaderObject*>::iterator it;
	for(it=arb_program->vList.begin();it!=arb_program->vList.end();it++){
		ShaderObject* obj=*it;
		obj->DeleteVertShader(obj);
	}
	for(it=arb_program->fList.begin();it!=arb_program->fList.end();it++){
		ShaderObject* obj=*it;
		obj->DeleteFragShader(obj);
	}
	
	glDeleteProgram(arb_program->Program);
	//arb_program=0;
	delete this;
}



markcw(Posted 2016) [#73]
Cool, thanks Angros.

I got the code from Spinduluz's fork in programobject.cpp so as you see the first line should be "if (!arb_program->Program) return".
ProgramObject::~ProgramObject(){
	if(!program) return;
	glUseProgram(0); // Ensure the shader is not used
	for(ShaderObject *shader : shaderobjects){
		shader->attached.remove(this);
		shader->DestroyRef();
	}
	shaderobjects.clear();
	glDeleteProgram(program);
#if defined(BLITZMAX_DEBUG)
	DebugLog("Deleted ProgramObject %s",name.c_str());
#endif
	program=0;
}



RustyKristi(Posted 2016) [#74]
Hey munch, I'm getting this on the latest build when I tried to compile the example with sounds:




markcw(Posted 2016) [#75]
Thanks RustyKristi, I was importing Openb3d instead of Openb3dex in B3dsound.

I've added FreeShader now but I have to report there was a crash until I removed "vList.remove(vShader);" in DetachVertShader and the same in the frag function. The suggestion was remove/clear list only crash if there is a corruption somewhere. And DetachFragShader had a typo as "for(it=fList.begin();it!=vList.end();it++)".

I also turned openb3d.openb3d into a dummy just for the Blitz3d docs since it's not being used.


RustyKristi(Posted 2016) [#76]
I'm glad to report this and it works great now! thanks :D I'm still doing some test just in case.

I still have some freeshadows issue, I'm not sure if I'm doing it right.

Most of the time, the shadows are left in the ground/terrain or sticking to other ai mobs.


RustyKristi(Posted 2016) [#77]
Hey munch, one more thing. Since I got back on tinkering with NG again. I tried OpenB3D with NG and it works great except for the 3DSound module which keeps throwing an undefined "HearingPoint" type.

thanks


Hezkore(Posted 2016) [#78]
I finally had a look at my Shader Camera module and made it compatible with the newer OpenB3D versions.
It comes with a greyscale, blur and shimmer example.
You can invert the height/y of the screen easily and also set a "virtual resolution" for the screen.
Setting screen size to 25% combined with ClearTextureFilters() makes everything look "retro".
I find it a lot easier to use than the screen sprite examples.

https://bitbucket.org/Hezkore/shader-camera


Cocopino(Posted 2016) [#79]
Hi!

I'm in the process of creating procedural worlds/levels using OpenB3d, and would like to export those to b3d files.
My code crashes using OpenB3d, but does not when using Minib3d. The crash involves "GetSurfaceBrush".

Example:
(TExportMesh.bmx can be found here: http://www.blitzmax.com/codearcs/codearcs.php?code=3278)

SuperStrict

'Import sidesign.minib3d
Import openb3d.b3dglgraphics

Include "TExportMesh.bmx"

Graphics3D 1024, 768

Local mesh:TMesh = CreateMesh()
Local brush:TBrush

For Local i:Int = 0 To 9

	Local cube:TMesh = CreateCube()

	brush = LoadBrush("texture_" + (i Mod 3) + ".jpg")
	PaintMesh(cube, brush)
	PositionMesh(cube, i * 3, 0, 0)
	AddMesh (cube, mesh)
	HideEntity(cube)
	FreeEntity(cube)

Next

Local camera:TCamera = CreateCamera()
camera.PositionEntity(0, 0, -15)
camera.PointEntity(mesh)

Local export:TExportMesh = New TExportMesh
export.mesh = mesh
export.SaveMesh("tester.b3d")



Ferret(Posted 2016) [#80]
Hello,

I'm looking for ways to speed up rendering allot of cube meshes.

The cubes are already optimized, only visible quads are build and rendered using single surface techniques.

What should i look into for speeding up the rendering?
Can i use display lists, shaders or anything else to speed up rendering?


RustyKristi(Posted 2016) [#81]
You should look up if OpenB3D supports hardware instancing. I have not confirmed this yet only with bOGL but it uses similar OpenGL 2 so you have something to look into there.


angros47(Posted 2016) [#82]
If the cubes are static, you can combine them into a single mesh using MeshCGS.

A similar trick is used in games like MineCraft


Ferret(Posted 2016) [#83]
Compiling:openb3dsdl.bmx
Compile Error: Can't find interface for module 'pub.opengles'
[D:/BlitzMax/mod/openb3d.mod/openb3dsdl.mod/openb3dsdl.bmx;38;1]
Build Error: failed to compile D:/BlitzMax/mod/openb3d.mod/openb3dsdl.mod/openb3dsdl.bmx


After updating i got this error.


RustyKristi(Posted 2016) [#84]
Rollback to your previous one, anything related to opengles is broken atm.


Ferret(Posted 2016) [#85]
Ok, thx.


Ferret(Posted 2016) [#86]
I need spheres with LOD for planets, i don't know how to write this myself.
A geosphere has LOD but there is a texture problem, is there a way to fix this?


Kryzon(Posted 2016) [#87]
Instead of Sphere -> LOD Sphere for your planets, why not Sphere -> Impostor sprite?
http://blog.wolfire.com/2010/10/Imposters

There's a range of distance between the camera and the object where you softly transition between the 3D mesh and the prerendered sprite (using transparency), until only one of either is shown (mesh if you're close, sprite if you're far).

A prerendered sprite should look better than a low level-of-detail mesh.
Also, I think user Krischan has done some star system demos with MiniB3D: http://www.blitzbasic.com/Community/posts.php?topic=97336#1132526


Ferret(Posted 2016) [#88]
@RustyKristi
I don't know much about hardware instancing, need to do some research, but thx for the tip.

@angros47
They are not static so MeshCGS is to slow, what i was doing is faster.
I droped the idea of a complete voxel world, destroyable voxel objects will do.

@Kryzon
I always use a sprite as the lowest LOD, but going straight from mesh to sprite is new to me, a good idea.
I know who Krischan is, i'm a fan since Blitz Tiles :)


angros47(Posted 2016) [#89]
You can either use an isosurface, or an octree, then.

An octree can combine many cube mesh, and also allows LOD.


angros47(Posted 2016) [#90]
Just a quick update: at the moment, I am working on an Emscripten port of Open3D. Some simple demos already work.


icebeararmy(Posted 2017) [#91]
Hi

Is there a problem with CameraPick and shaded entities? I can't pick them when I do a "ShadeEntity" on them. Without the shader, it works fine.

EDIT: Same goes for collisions.


RustyKristi(Posted 2017) [#92]
That could be the camera sprite which handles the postfx shaders that is blocking your input. It was discussed how it works on munch's recent post here if you do some search.

Maybe you can do some toggling or pick intervals between shader sprite hide and show. There are examples in recent working versions where it shows 2 postfx executed in a queue. You can then get some idea on how you can work that with your picking routine.


icebeararmy(Posted 2017) [#93]
Well, the problem still exists even without the postfx sprite.

I can pick entities and Collisions work fine with every entity, that's not shaded, with or without camera sprite.


RustyKristi(Posted 2017) [#94]
I can pick entities and Collisions work fine with every entity, that's not shaded, with or without camera sprite.


Sorry but I have never used ShadeEntity because OpenB3D's normal mapping is kinda weak. It does not support directional light properly (It does, but does not look right)

With that, I don't really know or confirm if this is really an issue. I stopped with OpenB3D because I'm done with my personal projects.


icebeararmy(Posted 2017) [#95]
Sorry but I have never used ShadeEntity because OpenB3D's normal mapping is kinda weak.

I am not using OpenB3D's normal mapping. You can use ShadeEntity with your own OpenGL-Shaders. ;)


RustyKristi(Posted 2017) [#96]
yes I know that, but never dug deep with shaders and openb3d. I know openb3d shaders is very much like common OpenGL shaders, with just some small adjustments.

Anyway moving to your topic, if you can't use shadeentity and camera picking then just dig into the source and check what seems to be the problem or if this is directly related to the source so you could also get some help from angros47, as this is his original project, the wrapper is a separate thing with diff author (munch).


angros47(Posted 2017) [#97]
Both collisions, and picking, are managed by a part of the library that is independent from the shader management.

Likely, the vertex shader has some error that makes the mesh be drawn in a different place than where it is supposed to be. Since shaders don't affect the internal way of storing geometry for collision detecting, OpenB3D would not be able to detect the displaced mesh


icebeararmy(Posted 2017) [#98]
Well, vertex-shader seems to be okay:
void main() {
	V = vec3(gl_ModelViewMatrix * gl_Vertex);
	VInverse = gl_ModelViewMatrixInverse * gl_Vertex;
	N = normalize(gl_NormalMatrix * gl_Normal);
	
	vLightdir = normalize(gl_LightSource[0].position.xyz);
	
	vLightpos = (gl_ModelViewMatrix * vec4(gl_LightSource[0].position.xyz,1.0)).xyz;
	
	vHalfvector = gl_LightSource[0].halfVector.xyz;
	
	vView = -gl_ModelViewMatrix[3].xyz;
	
	gl_TexCoord[0] = gl_MultiTexCoord0;
	
	refView = gl_ModelViewProjectionMatrix * gl_Vertex - vView;
	vReflection = reflect(refView, gl_Normal);
	
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}



angros47(Posted 2017) [#99]
I just tried camera picking on a mesh using a custom shader, in FreeBasic, and it works fine. So, I can't reproduce your issue


icebeararmy(Posted 2017) [#100]
Hmm weird. Then the issue has to be in my code. Thanks anyway :)


icebeararmy(Posted February) [#101]
Another problem, but this time without shaders. :)

The DepthBuffer seems to be glitched for me, since it's only plain white, when rendered to a texture. In my code I am placing some cubes in random distances (up to 200 units away from the camera):
For i =0 To 14
	cube[i]=CreateCube
	PositionEntity cube[i],Rnd(-50,50),Rnd(-20,20),Rnd(5,200)
Next

depth_tex=CreateTexture(800,600,1+256)
ScaleTexture depth_tex,1.0,-1.0
DepthBufferToTex depth_tex,Camera
	
fx_sprite=CreateSprite()
ScaleSprite fx_sprite,1.0,0.75
EntityOrder fx_sprite,0
EntityParent fx_sprite,camera
MoveEntity fx_sprite,0,0,1.0 
EntityTexture fx_sprite,depth_tex


### LOOP ###


        updateworld
        HideEntity Camera
        ShowEntity fx_cam

        DepthBufferToTex depth_tex,fx_cam
        EntityTexture fx_sprite,depth_tex

        HideEntity fx_cam
        ShowEntity Camera
        renderworld

But the cubes don't show up in the depthbuffer-texture.

For the moment, I am using a grayscale texture from CameraToTex, but I would prefer the actual depthbuffer.


Krischan(Posted May) [#102]
I've been experimenting with OpenB3D again and was successful to combine it with my map BSP loader. It works so far with simple shader support but there are still a few problems / questions left:

- EntityFX doesn't seem to have an effect beside that shaders don't work the right way?
- Vertex Colors don't work?
- I don't know how to add the included lightmap as a basic level lighting here?
- my Alpha door textures are not transparent anymore? FX32 doesn't help?

Perhaps you could take a look at my demo and give some hints how to fix this? :-) WASD=Move, RMB=Torchlight on/off and the shaders are applied to the surfaces in the inc/q3bsp.bmx file.

http://www.christianhart.de/bmax/openb3d/Bumptest2.zip




Edit: added a minib3D version for comparison.




Krischan(Posted May) [#103]
OK I think I've managed it myself. The solution lies in the shaders and how they must be applied to my BSP loading constructor. First I had to distinguish between Alpha and Solids with two different shaders. The Alphamap for the doors was simple but the lightmap was a hard one. But finally I understood how to load and mix it with the shaders and how to use the second UV set there. The torchlight is actually a spotlight as this looks cooler when you look around with the mouse to see the shader bump effect in darker areas. I couldn't implement shadows yet but my first experiments were really disillusioning, either the level is already too complex or I did it completely wrong.

But wow, IMHO the result is still stunning at this stage of development. If I don't find any serious bugs in OpenB3D I think I can create the whole project with OpenB3D and shaders, goodbye MiniB3D :-D But see yourself, no - walk yourself :-D WASD=Move and RMB=Torchlight including source, candy and whatever (only a part of the level has been constructed for tests):

http://www.christianhart.de/bmax/openb3d/Bumptest3.zip








EdzUp MkII(Posted May) [#104]
looking good :)

Is there a OpenGL 1.x version of this or is it 2.x only?


Krischan(Posted May) [#105]
I'm not sure as I'm not very familar with the differences yet. But I guess most of the graphic cards should be able to handle at least 2.0 today?


EdzUp MkII(Posted May) [#106]
I only ask as I have a old netbook which is 1.4 and minib3d is 1.4 but apparently openb3d is 2.x


markcw(Posted May) [#107]
Yes, Openb3d does not work in GL1, it's really a GL2 engine as shaders changed for GL3 in a non-backwards compatible way and like Krischan says, GL1 is so old as to not be worth supporting (shaders in 1.4 needed every extension checked). There are no GL3 samples as I never had GL3 but maybe that could happen now as I feel like reviving the wrapper, although I can't do the mobile stuff but it would be nice to tidy up what's been contributed at least.


EdzUp MkII(Posted May) [#108]
Good to know :)


RemiD(Posted May) [#109]
@Krischan>>looks good, i suggest you take a look at the game "shadow tower" (ps1) and "king's field" (ps1/ps2), the graphics style / ambiance is similar and may give you some ideas...