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 / Fastest way to apply reflections

Author
Message
Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 24th Nov 2011 17:15
Is there any way to make 50+ objects with relatively high poly count appear reflective in an instant?

My problem is that I am building rounded polygon parts for making up cars. Although they have a relatively high polygon count (as they are not "cubes") everything runs at decent frame rates even on a Turion X2 2.0 GHz Notebooks with integrated graphics, even the process of creating these parts is fast enough to do in real time (although that part needs some more optimization, as frame rates drop to about 20).

Right now I have a "polish" button in the game which does nothing else then create every part again (which is done in realtime when scaling) and applying an additional "SET CUBE MAPPING ON ..." to make it look reflective. Works great, looks good but takes a couple of minutes to complete. Just "FROM SET CUBE MAPPING ON" for about 50 parts. Once applied everything runs smoothly again but the long time to apply it really is a pain in the ***.

And yes, THAT one command for each part is the only difference. Any ideas or tricks how to do this on the fly without the game appearing to have crashed?

If you want to take a look at what I mean you can download the alpha test version in this WIP thread.

In the game just press new game, in the lower half press the symbol with the test tube on it, taking you to the research screen, click on the car body in the upper left to go the the body section, press the "add new project" button there and click on the empty photo to get to the body editor. In the lower left is a menu you can open which contains said "polish" button.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Nov 2011 19:21
Probably the fastest way is to use a pre-prepared cube map (such as one you might use with a skybox) and apply it with a shader.

However, instead of set cube mapping on you would have two statements, i.e. set object effect and texture object to use with each object. Perhaps the set up time for those would be a problem as well. I'm away from my machines at the moment so I can't check. Are you using dynamic images for your reflections?
Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 24th Nov 2011 20:18
Nope, it's a static image since it's only intended to make it look like a polished surface. I tried sphere mapping but that doesn't appear to be much faster (haven't taken the time though) and I produced some ugly effects on some parts of the generated car.

Unfortunately I never looked into shaders so far so I don't know how to set that up yet. I played with that Dark Shader setup or preview tool a bit but the thing is constantly messing up in loosing any object I load for testing. Plus the machine I'm currently at is way too slow for that tool.

It's a mystery to me anyway that essentially applying a texture can take that long. It renders fast enough, the only problem is the time it takes to apply.


Daniel wright 2311
User Banned
Posted: 24th Nov 2011 20:28
Just set up a routeen to where you inc or dec applytex

if apply tex=0 then texture object objectnumber ,1,0

if apply tex=1 then texture object objectnumber ,2,0

so on and so forth,this way all the textures will be loaded into a array or even a memory block holing it into memory alreay and also you can load in the effects into memory speeding up the prosses,Im shure this is what you ment right? If Im wrong sorry,I tryed.

my signature keeps being erased by a mod So this is my new signature.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Nov 2011 21:01 Edited at: 24th Nov 2011 21:04
Quote: "It's a mystery to me anyway that essentially applying a texture can take that long. It renders fast enough, the only problem is the time it takes to apply."


Yes, that puzzles me too - but I can't check till I'm back home. Sounds like sphere or cube mapping ought to be simple enough - and I don't see why they would be slower or faster than shaders. Shaders give you more control over the finer points which isn't your problem yet.

Edit Just noticed your original post says "create every part again". Why do that instead of simply applying cube mapping etc to the existing objects?
Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 24th Nov 2011 22:11 Edited at: 24th Nov 2011 22:36
@Daniel wright 2311
Not sure if I understand you correctly but it sounds as if you though the game would reload the textures. That is not the case they are already loaded.

Quote: "Edit Just noticed your original post says "create every part again". Why do that instead of simply applying cube mapping etc to the existing objects? "


Simply put, creating the parts again can remove potential display errors, since it's basically a complete refresh of what the player has created. While the player changes the car only parts detected to have changed will be recreated to keep the framerate up.

I could sort through all the parts and just update them with the cube mapping and if that would save any noticable amount of time I would do that. But the entire car with all it's parts is created in less then 50 ms anyway and THE ONLY difference in creating a polished looking part and a dull part is that in the line

the value of reflection is 1. (Yes it uses the same texture on all sides, as it only aims to make the material appear to be polished not actually reflect any existing surrounding)

Edit: I just stopped the time: On my slow test system applying the reflection texture takes ~ 555 +/- 10 ms per part, apparently it doesn't matter if the part has 4 vertices, 20, 100 or 780.
Edit 2: Small correction I restopped the creation time. Creating the entire default car from scratch takes 77 ms on my slowest system with some background stuff eating some processing time as well. It's made up of 54 parts - each of which would need about 555 ms to apply a cube map, totaling it at 54*555+77 = 30047. That's effectivly a 30 second freeze.


Daniel wright 2311
User Banned
Posted: 24th Nov 2011 23:44
As I LOOK INTO YOUR CODE I see It is like I thought,this is what i ment my friend.This way everything is slow only one time,the first load is slow but everything after that everything is alreay loaded into memory and will be fast.

this is only another way to do what it is you whant to do That I see.

cool program

example





my signature keeps being erased by a mod So this is my new signature.
Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 25th Nov 2011 11:59
I'm sorry but I don't understand what you mean.

How would increasing an integer value (reflection) and going through otherwise unchanged if-blocks based on what the integer value is prevent any loading?

You do understand, that the "set cube mapping"-command is called just once when a part is created, right? And that the image-file for the reflection is just being loaded ONCE at the very beginning of the program?


Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 25th Nov 2011 15:50
Correct me if I missed anything posted above; but would it be an issue to apply cube / sphere mapping on all active cars during initiation anyway? Detailed reflection texture for the polished, and blank textures for the unpolished. Then polishing will only be a matter of changing a texture Id; or 6. It took a minute to polish on my machine aswell. The minutes you have to wait takes place during program initiation; but this is still too slow for what it is worth.

How well did the SET REFLECTION SHADING ON command perform? ( I've never used it)

I do not think applying internal or third part shaders on a series of objects will ever run quickly; I have never seen any game in the past 10 years switch complex shaders on and off quickly without some kind of delay; but a minute is too long as you say.

I must say that using limbs for parts would improve performance by a longshot; since the limbs would be loaded directly into video memory without having to perform recursive CPU instructions in DBASIC. It also gives the internal system less work; less object-by-object checks to do when updating during the Sync; so they say. Changing parts can be a small matter of hiding, showing, adding and removing limbs. But your current method is obviously still viable; there are not that many objects in the scene.

If you do not like Dark Shader but feel like using FX shaders, I recommend just downloading the Shader Pack project files by Evolved and playing around with the examples. Even in runtime, you could update the .FX files as strings and reload effects as you test without recompiling; all with a little bit of initial effect management code.

There is also manual reflection mapping, if you fail to get any of the above to work. With this you texture the car with an image used as a camera render target, and use blend mapping over a diffuse colour texture; adjust the opacity of the camera texture and rotate the extra camera to view the desired reflection; usually the opposite direction of the main camera. Not realistic, but it's not bad for simple metalic shine applications.

Nice game by the way; it feels cool to be able to configure the cars and it is also interesting to be able to work on old fashion models.

Daniel wright 2311
User Banned
Posted: 25th Nov 2011 21:02
Quote: "You do understand, that the "set cube mapping"-command is called just once when a part is created, right? And that the image-file for the reflection is just being loaded ONCE at the very beginning of the program?
"


I did not know that,sorry,I tryed to help,I hope you find a good soulution.

my signature keeps being erased by a mod So this is my new signature.
Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 25th Nov 2011 23:40
Quote: "I did not know that,sorry,I tryed to help,I hope you find a good soulution."


I know and I appreciate that, so thanks anyway.

@Chris Tate
Thanks for all the input!

1. Unfortunately applying the cube map at the game's initialization is not an option as the pieces of the car are being generated on the fly.

2. SET REFLECTION SHADING ON also is not an option as it would work on only one part and reflect the scene around it which makes it both performance hungry and useless as there is no scene (not yet) around the car to be reflected. Both points would also be a problem with the manual reflection you suggested.

3. Where can I get that Shader pack project by Evolved? Sounds interesting and a little trying couldn't hurt.

4. The thing with the limbs might also be a solution although it would require some heavy recoding of the creation functions. (The parts are not being hidden or scaled they are recalculated from scratch). I might experiment in that direction if nothing else works.

I am really puzzled by how long it takes to apply cube maps...

I'm glad you like the game. There will be an update soon, so if you still have it it should offer to update once there is an update


Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 26th Nov 2011 03:38
Quote: "Unfortunately applying the cube map at the game's initialization is not an option as the pieces of the car are being generated on the fly."


Wow, generated! I thought they where modelled.

The Shader Pack: http://forum.thegamecreators.com/?m=forum_view&t=79849&b=8

Enjoy!

Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 27th Nov 2011 12:40
Quote: "Wow, generated! I thought they where modelled."


I'll take that as a compliment so thanks

I am downloading the shader pack now to take a look. Thanks for that as well.


Login to post a reply

Server time is: 2026-07-10 21:41:38
Your offset time is: 2026-07-10 21:41:38