Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Other Tricks to "Set Camera Range"

Author
Message
KenGames
11
Years of Service
User Offline
Joined: 22nd Sep 2013
Location: United States
Posted: 4th Jun 2015 04:20
Hey everyone! I'm just curious in other ways I can accomplish hiding/excluding objects a certain distance away from the camera to mimic the "Set Camera Range" command. The reason why I'm looking for a solution that is alternative to the camera range command is because I'd like to draw the skybox(far back) to the screen, while drawing objects(like bushes/trees, etc) in front of the skybox. I'd like to make objects that are a certain distance away from the camera be hidden/excluded, while retaining the ability to draw the skybox. (In order to speed up the FPS of a large mass of foliage).

A "Graphic" of the ranges from the camera that need to be shown/hidden:

(Camera)-[FoliageA]-[FoliageB]-[FoliageC]----[Skybox]
(Shown) (Shown) (Hidden) (Shown)

*My current best idea at the moment is to make a collision box that sweeps over the landscape hitting and hiding/showing objects within range. Unfortunately that currently conflicts with my player's collision box which is using automatic object collision.

Any tips/ideas would be dearly appreciated, Thanks!
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 4th Jun 2015 08:01
fast box exclusion works well



Morcilla
22
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 4th Jun 2015 13:15
Hi there,

Long time no post, but I have two ideas for you.

1st - Dark Occlusion plugin is not exactly what you need, but it seems to be worth a look. I'm starting tests with it for MPL3D Solar System project. It has a .dll demo that can be downloaded to see if it suits your project.

2nd - Please check my Code Snippet: [DBP / GDK] Angular size of an object in PIXELS - small angle formula

That algorithm will return the size in pixels for an object in a very fast way. If your object is less than 1 pixels, then you may hide and exclude it. (or 'n' pixels, as needed).

This way you can still show the skybox while hidding/excluding all objects that are less than 1 pixel in view, maintaining your far camera range as high as you need.

I hope that helps, I use that technique in MPL3D Solar System to boost performance.

Regards.

Cescano
10
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 4th Jun 2015 21:07
Ortu your snippet is not good.

You check the z distance inside the x distance.

If the x distance is for example 100000 but the z distance is within the 1000 range, the object will be still visible.

If the z distance if for example 0, the actual distance will be 100000, but the object is still rendered even if is way more far than the 1000 range you want to achieve.

Will be better something like this:



you can also remove the "exlude object off o" at the top of the code which is not required anymore, better don't call it if you don't know if exclude it or not, otherwise you may ending up calling both commands when you need just 1
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 4th Jun 2015 21:56
Quote: " the x distance is for example 100000 but the z distance is within the 1000 range, the object will be still visible."


Ah yeah, I just quickly wrote without checking it sorry, but obviously you get the concept

You will also want to check that o <> skybox to prevent that from being excluded.

Cescano
10
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 5th Jun 2015 01:56
Sure happens to everyone

Remember also to hide instead of excluding instanced objects, or you could exclude objects that you actually don't want to exclude.
KenGames
11
Years of Service
User Offline
Joined: 22nd Sep 2013
Location: United States
Posted: 5th Jun 2015 09:28
I ended up implementing Ortu's and Cescano's method to hide objects, and with a little modification it works fantastic! I was weary that maybe it might pull my FPS down a little bit, but it worked very well. Thank you guys for the help!

*And Morcilla, your code snippet on excluding 'n' pixels shown of an object is really awesome. If Ortu/Cescano's method had run my program cycles and FPS down in implementation I totally would have given your method a try. Props man! Also, good work on MPL3D, looks really cool!
WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 6th Jun 2015 02:21 Edited at: 6th Jun 2015 02:23
Check out the snippet in the following post. The size of the skybox is only 10 units. By disabling the skybox objects - zwrite, you can keep the size of the skybox small and still view the other objects in the scene. Keep in mind that the rendering order and object type and properties will affect how this will work. Here is the render list in order, courtesy of IanM. In my code I use a matrix terrain. You’ll notice that a matrix is rendered before the 3D object, even one with the zwrite disabled. So when the skybox gets rendered it will hide the matrix. This can easily be remedied by setting the matrix priority to 1.

WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 6th Jun 2015 02:25


Media included in download.

Login to post a reply

Server time is: 2025-08-09 02:29:37
Your offset time is: 2025-08-09 02:29:37