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 / realtime cubemaps, seem entirely too complicated

Author
Message
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 16th Feb 2010 21:01 Edited at: 16th Feb 2010 21:23
Here's a demo I made for realtime cubemaps.

The issue is, I have to use 6 cameras for each facet of each cubemap. I'll run out of cams very quickly. It seems whenever I assign a camera to do something else, the image it's linked to immediately turns black.

Are there any other easier techniques? (see attached for demo, see below for just the code)





Here's some code for a method that I think would work, but the images seem to turn out black:




Attachments

Login to view attachments
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Feb 2010 22:35
Don't make image first. And once you set a camera to an image, it's always an image unless you delete and re-create the camera.

My signature is NOT a moderator plaything! Stop changing it!
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 16th Feb 2010 23:25 Edited at: 16th Feb 2010 23:26
Ah thanks. Updated code, still doesn't work properly when only using 1 camera. Is it possible?





Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Feb 2010 00:32
No, you can't do it with 1 camera. I'm sure there's a dynamic cubemap command though?

My signature is NOT a moderator plaything! Stop changing it!
Hawkblood
15
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Feb 2010 00:38
The only cubemap stuff I have found is MIPCUBEMAP AVAILABLE and CUBEMAP AVAILABLE. Unless this command is hidden/not in the help.

The fastest code is the code never written.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Feb 2010 00:41
It's one of the undocumented commands that comes with Dark Shader.
Hawkblood
15
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Feb 2010 00:46
Oh. I don't have dark shader..... How useful is it?

The fastest code is the code never written.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2010 01:53
Yeah, SET CUBE MAPPING ON is a command in BASIC3D, unless it was added there when I installed Darkshader... Anyways, it looks like this was already in the September 2009 newsletter, with eerily similar code. So I've updated my code with a few tips from Lee Bamber, and here it is, in case anyone finds it useful:



Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Feb 2010 02:00 Edited at: 17th Feb 2010 02:01
The Dark Shader commands are already built-in to DBPro so you only need to find the documentation. It's late now. I'll see if I can dig up something tomorrow.

Quote: "How useful is it?"


Very, if you are writing shaders. I use it all the time. I can't remember when I last used anything else for that purpose.

I don't know why Lee didn't include the Dark Shader version for his snippet - it's much simpler.
Hawkblood
15
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Feb 2010 02:10
@Jerico2day. SET CUBE MAPPING ON takes 6 images and you still have to render to 6 cameras.... I thought you were looking for a way to do it with one...?

The fastest code is the code never written.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2010 02:31
Quote: "@Jerico2day. SET CUBE MAPPING ON takes 6 images and you still have to render to 6 cameras.... I thought you were looking for a way to do it with one...?"


Yes, my original example did that. If you know of a way to only use 1 camera (so I can have way more cubemaps) that would be awesome.

Hawkblood
15
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Feb 2010 04:03
What are you using the cube maps for? Normally you need a cube map for a reflective object right? I guess I need to know more to help you.

The fastest code is the code never written.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2010 04:51
I'm making a car game, and i want to have the option to give the cars real-time reflections. I plan to support around 16 cars at once, and would like at a minimum have 4-6 real-time reflections. I realize this would be very intensive, but that's okay if the hardware can handle it

Hawkblood
15
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Feb 2010 05:13
Have you thought of having just one cube map around the player's car and applying that to all the cars around it? Never tried it myself.... Of course, I don't use cube maps that much. The reason I said use one map is that your perspective is the only one that the camera (and the player) sees anyway. It shouldn't matter where in the scene the other cars are. They will apply the cube map according to their relative position in the imaginary cube.

The fastest code is the code never written.
Morcilla
22
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 17th Feb 2010 11:10 Edited at: 17th Feb 2010 11:12
Quote: "The Dark Shader commands are already built-in to DBPro so you only need to find the documentation."


Great, that means that they are ready to use
These are the functions that I've found in the header 'ShaderData.h':


Make Dynamic Cube Map( int iID, int size ); //creates a cube map of the specified resolution, valid ID = 1-10

Make Dynamic Cube Map( int iID, int size, int mipmapped ); //creates a cube map of the specified resolution, with mipmap parameter

Delete Dynamic Cube Map( int iID ); //deletes a cubemap

Render Dynamic Cube Map( int iID, int camera, float x, float y, float z ); //renders a cube map with a camera (-1 for temp camera) at a position

Apply Cube Map To Object( int objID, int stage, int iID, int shader ); //applies a cube map to an object stage, use shader=1 if using an object shader

Apply Cube Map To Object( int objID, int stage, int iID ); //applies a cube map to an object stage, shader=1

Dynamic Cube Map Exist( int iID ); //returns 1 if cube map exists


'Render Dynamic Cube Map' seems to be the first one that we are searching for.

I think I recall a snippet for using it somewhere around

Well, I look forward to see what we find here. I have in my to-do list to render dynamic cubemaps.

My idea, (obviously not tested yet):

->To use cubemaps for sky spheres.
A cube map renders the surrounds of an object. Now if that texture is applied to a regular sky sphere, then it should conform the panorama, allowing to hide all objects in the distance, as they would be already drawn in the sky sphere texture. (Wouldn't they?)

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Feb 2010 12:36
Quote: "'Render Dynamic Cube Map' seems to be the first one that we are searching for."


Those are the commands I was talking about - but you need to make the cube map first if I recall correctly.
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Feb 2010 13:00
Quote: "Those are the commands I was talking about"

Me too.

My signature is NOT a moderator plaything! Stop changing it!
Morcilla
22
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 17th Feb 2010 14:44
Quote: "...but you need to make the cube map first if I recall correctly."

Ah, then it could start with something like:



Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 17th Feb 2010 14:53
guys, the set blend mapping on, is shaderless, but it can be a good start point for him, not?
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Feb 2010 15:07
Quote: "set blend mapping on"

This is a multi-texturing command, not a cube-mapping command.

My signature is NOT a moderator plaything! Stop changing it!
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2010 16:08
While the commands highlight, they output this error:

Could not understand command at line 17.



Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Feb 2010 16:11
Sounds like you haven't got the right DLL in the compiler folder. Which version of DBPro are you using?
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2010 16:17
7.4. Should I go to the U75 beta?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Feb 2010 17:13
No, it should be in U7.4.

You should have the ShaderData.dll file in the Compiler/Plugins-user folder. Is it there?

If it is perhaps you misspelt the command? What line of code gave the error?
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2010 18:17 Edited at: 17th Feb 2010 18:19
Ah yep, I put in the perenthesis

The following code doesn't work, I'm not 100 percent sure how to do this:


Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Feb 2010 19:36
Hmm? I can only get it working with a shader. Something to look into. Bug report?

I guess you're stuck with your other idea.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2010 19:58
Quote: "I can only get it working with a shader."


How do you make it work with a shader?

Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 17th Feb 2010 21:13 Edited at: 17th Feb 2010 21:15
Quote: "This is a multi-texturing command, not a cube-mapping command."


You can cube map with that command. Maybe that command is not so well documented. I'm documenting it in another thread to share with the community.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2010 23:37
Ok, so I turned my handy dandy code into a few functions, but now I can't sync the cameras properly. I must use syncmasking because I'll need to hide objects (specifically the object that I'm cubemapping).

Here's the code, it requires matrix1util to dynamically find free cameras.

Anyone know what's causing this weird behavior? I've tried a few different methods of determining the mask, and I've tried putting the cams in order from least to greatest in case that matters and am not having any luck. Here's the code:



Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Feb 2010 23:49
Why don't you print out the values of the camera and image numbers you are actually using? I can't see what they are from your code.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 18th Feb 2010 00:11
Ah, right.

Here's the values I get each time I run:



Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2010 01:54
Those won't work correctly. Camera ID's must be assigned in sequence, i.e. cameras 1-15, 18 and 20 must also exist. Do they?

Looks like you'd better find a better way of choosing your camera numbers. The image numbers look a bit odd too - but are probably OK.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 18th Feb 2010 02:39
The numbers are generated by Matrix1util. Probably picks a random number to make things faster. Looks like I should file a bug complaint with IanM. I'll just write up my own function

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Feb 2010 13:07 Edited at: 18th Feb 2010 13:09
Quote: "Looks like I should file a bug complaint with IanM"

It's not a bug. It's as he designed it to speed up searching for unused things. (It's quicker to check a random number, than to increment from 1 upwards looking for an unused one, as the more you find, the longer it takes to search.)

It's not hard to create your own though...



My signature is NOT a moderator plaything! Stop changing it!
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2010 13:13
Exactly.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 18th Feb 2010 14:30
If I see someone suggesting usage of an RNG anywhere near(even in the same source file) a free index routine again my head will explode. This is by far the crappest method imaginable, it has a terrible worst-case scenario(so bad it's unbounded) and wastes an impressive amount of memory because I'm pretty sure DBPro stores a list of pointers for its indices of everything, thus creating object one billion will require some crazy resizing(unless it uses a linked list, but that would be stupid).

There is actually a very efficient way to handle finding a free index of anything, and that is to only store a list of removed indices and the highest returned index. If the removed list is empty then increment the highest index and return it, else pop from the removed index list. And to speed that up you don't even have to pop from it, you can just store another index for how many there are and resize the array in powers of two, thus the retrieval speed is effectively constant and the deletion speed will be(most of the time).

My head will also explode the next time I hear mention of using dummy objects to do simple maths.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2010 14:42
What happens if you delete a camera from the middle of a sequence of existing cameras. Does DC's head explode?
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 18th Feb 2010 14:53
I haven't tested it in DBPro, but in GDK at least, deleting a camera that points to a render target causes a memory leak, so yes. In fact, a lot of things in GDK cause memory leaks, they should really be fixed.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Feb 2010 15:36
I believe that memory leak has been fixed - in DBPro at least. You could ask Lee if he's fixed it for the GDK.

Login to post a reply

Server time is: 2025-06-27 20:22:16
Your offset time is: 2025-06-27 20:22:16