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 / It's time for me to throw in the sponge

Author
Message
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th May 2010 18:57 Edited at: 12th May 2010 18:58
Here it is.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th May 2010 18:58
Screenshot attached.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 12th May 2010 19:01
That's cool.

There isn't a double meaning to the subject line though is there?

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 12th May 2010 19:20
wha?

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 12th May 2010 20:08
1 fps

Rawwrr. Sig Fail.
Newcastle is awesome
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 12th May 2010 20:11
0 FPS

You're not leaving us are you, Green Gandalf??

Stay, please...?

Slayer rules!!! Yeaaah, man!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th May 2010 20:17
Quote: "1 fps "


Sorry.

Forgot to warn you all that it needs a fast machine. I get about 70 fps uncapped. You can speed it up by reducing the value of "slices" from 32 to about 16 in the shader. But the image quality isn't so good if you do that. Alternatively, move the camera further away from the object - I can get the fps over 2000 if I do that (but can't see any details of course ).
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th May 2010 20:20
Quote: "There isn't a double meaning to the subject line though is there?"


Quote: "You're not leaving us are you, Green Gandalf??"


I really shouldn't tease you all like this.

No I'm not leaving - unless I'm banned for upsetting the sensitive souls that inhabit this place.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 12th May 2010 20:38
Quote: "No I'm not leaving"


Ok good.

Just so you know, the humor in the title wasn't lost.

The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 12th May 2010 20:47
Aaaaahhh,...what a relief!

So glad you're back, GG!

Cheers

Slayer rules!!! Yeaaah, man!
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 12th May 2010 21:16
phew, we just dodged a bullet

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Sepnon
16
Years of Service
User Offline
Joined: 7th Feb 2010
Location: Brazil
Posted: 12th May 2010 21:21
11-25 fps
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 12th May 2010 21:46
That does look a lot like a sponge, but you should work on the framerate.
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 12th May 2010 21:56
200-285 fps

God is real unless declared integer.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th May 2010 22:07
Quote: "but you should work on the framerate."


I'm open to suggestions.

The real problem is the raycast, pixel by pixel, through the volume texture just to find the first "solid" part of the "sponge". According to my understanding, shaders (PS2 anyway) have to use the whole unrolled loop so I can't simply skip instructions when I find a hit - I have to use logic to carry the result forward through all the unnecessary iterations.

Still, getting something looking like a sponge is the first step - optimizing it comes next and that raycast loop is the thing to look at. My first thought was a binary search but I don't think it will work in this case unless I missed something.
Jeff032
18
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 12th May 2010 22:21 Edited at: 12th May 2010 22:26
Very nice, I've been working on volume raymarching recently, too.

Mine renders a foot (reaches the 60 fps cap doing 256 iterations on a 8800 GTS)

(Though mine is in C++/DirectX and also C++/OpenGL. Maybe I should make a DBP version as well)



baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th May 2010 22:22
Cool, I get about 60fps. I'd like to see it with some bigger holes (like swiss cheese).

I'd even consider changing its name to "cheese.fx" just cos it's funny...

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 12th May 2010 22:59
@GG
I don't think you need to do raycasting, you can use the built in Z-buffer. Just render each side as a number of layers. Each layer might be 1 pixel into the volume texture. This is the same way as parallax mapping works, I think...

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th May 2010 23:07
Quote: "Maybe I should make a DBP version as well"


Yes please.

Quote: "I'd like to see it with some bigger holes (like swiss cheese)."


Try changing this:



to this:



It's not quite right as you'll see - but close.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th May 2010 23:13
Quote: "I don't think you need to do raycasting, you can use the built in Z-buffer. Just render each side as a number of layers. Each layer might be 1 pixel into the volume texture. This is the same way as parallax mapping works, I think..."


Interesting idea.

But each render might amount to much the same thing don't you think? And you still need to test whether you are inside the object or not, etc. Or have I missed something?
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th May 2010 00:52
Well the hardware is not well optimised for loops inside pixel shaders. I think it would be faster to do it using layers. Some people were getting about 1FPS in this demo, whereas I expect they can render 192 planes at a much faster rate (that's assuming you do 32 passes, when you'll probably need much fewer)

Quote: "And you still need to test whether you are inside the object or not"


If you mean to make it darker, all you need to do is draw deeper layers in a darker colour. You can pass parameters to the pixel shader from inside a pass, so it could look like this:



Where the parameter is the depth of the layer to draw. There is a further optimization here too: because higher layers are drawn first, most of the pixels from subsequent levels can be discounted before they are processed, because of the Z buffer.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th May 2010 01:32
I see what you mean. Thanks. There probably won't be any need for a "within object" check because each layer can be constructed to be within the object.

Quote: "If you mean to make it darker, all you need to do is draw deeper layers in a darker colour."


No. That's not what I meant. If the raycast (using my method) is at a shallow angle then part of the ray can protrude beyond the object. Your method might ensure that doesn't arise so no test would be needed.

Quote: "most of the pixels from subsequent levels can be discounted before they are processed, because of the Z buffer."


How would that be implemented exactly? If it's simply a matter of clipping in the pixel shader according to the value read from the volume map then your method certainly seems straightforward. I'll see what I can come up with.

Quote: "If you mean to make it darker, all you need to do is draw deeper layers in a darker colour."


Yes - and your method makes this even easier.

Thanks for those suggestions, I'll try to implement them and report back. Won't be for a few days though because we're going away to celebrate my Nth birthday.

All we need now is to work out how to do this for an irregularly shaped sponge.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 13th May 2010 04:55
!!Happy Birthday!!

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th May 2010 12:56
Thanks (it's actually tomorrow).

I've got a "stay of execution" for a few hours yet.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 13th May 2010 18:36
Almost a Gemini. Mine is on the 24th.

Math89
22
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 13th May 2010 20:10
This shader made me implement the famous Mandelbulb fractal in DBPro:
.
It is extremely slow (and I think I've done something wrong, actually), but still very enjoyable. The sources are attached.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th May 2010 20:45
Quote: "How would that be implemented exactly?"


It would happen automatically as long as you draw higher levels first. If you draw the top layer first, then the Z buffer will be filled with high Z values except where the holes are. You would have to use the same transparency mode as is used for leaves on trees. (IE. pixels below a certain alpha do not write depth information to the Z buffer. It's in the help files for set object transparency anyway!)

As soon as the buffer is filled with high Z values, pixels in subsequent layers will be completely skipped unless they are behind a hole in all of the previous layers.

Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 13th May 2010 20:52 Edited at: 13th May 2010 20:58
Just wanted to put my two cents in regarding FPS.

I have Windows 7 with Intel Core 7. The video card is NVIDIA GeForce GTS 240. Not the top of the line but faster than I have ever had. Can't remember the onboard memory size but it is maxed.

Using it at the sync rate of 60, I get (depending on the angle of the rotation) between 44 and 60. I am not a real fan of big-time FPS rates because I find there can be a lot of jerkiness and it just doesn't make sense to go faster than a motion picture rate anyway which is 24 - 30 FPS. Quake is 18 FPS.

How many frames per second can the human eye see?
This is a tricky question. And much confusion about it is related to the fact, that this question is NOT the same as:

How many frames per second do I have to have to make motions look fluid?

And it's not the same as

How many frames per second makes the movie stop flickering?

And it's not the same as

What is the shortest frame a human eye would notice?

I like to keep my FPS to around 40. And if you set the sync rate to 40 the cousin to sponge Bob rotates much more smoothly at a consistent 39 to 40 FPS.

Do you think it is important that a graphics card can display 250 fps in your favourite game, because that's a feature they write about in PC magazines and on covers?

This is just a figure to show how fast the card is, not to show that you need such a high frame rate. It's like with cars: 100km/h in 5 seconds. So, when will you ever need to go 100km/h in 5 seconds?

Sorry if this was a tad bit off topic. That is a great achievement GG. I love it. Now we can make sponge Bob games.

HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 13th May 2010 20:53
@Math89

I think mine runs at -900 fps as it lock everthing up. Looks great, now to see how it works.

Dark Physics makes any hot drink go cold.
Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 13th May 2010 21:06
@Math89

On your Mandelbulb I get 35-39 with it uncapped. Hardware really does make a difference.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th May 2010 22:41 Edited at: 16th May 2010 22:43
Math89

Very nice.

Diggsey

Quote: "You would have to use the same transparency mode as is used for leaves on trees."


By whom? I've usually relied on alpha blending - but I see from your comments that the other modes might be faster (not convinced though - doesn't pixel clipping interfere with the parallel computations of the GFX card?).

I guess you mean one of the following modes. I haven't used those much mainly because I've had mixed results with them - which probably means I made a mistake or misunderstood something.

Quote: "4 - draw second alpha test (only render beyond 0x000000CF alpha values)
5 - water line object (seperates depth sort automatically)
6 - combination of 3 and 4 (second phase render with alpha blend AND alpha test, used for fading LOD leaves)"


I'll try those anyway, thanks.

I'll report back as soon as I can (only returned this afternoon).
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th May 2010 01:18 Edited at: 19th May 2010 15:24
[Edit Oops. I forgot I changed various things in the demo. I've attached the whole new project here. Hopefully the new version will work now.]

Here's my first attempt at implementing Diggsey's suggestion. It uses the object's normals to adjust the object's vertices for each of 32 render passes. Works reasonably well for a sphere but not for a cube. (The problem is my implementation - Diggsey's idea is fine. )

Here's the revised .dba code:



and here's the revised shader:



This version seems to be faster as Diggsey claimed. It has the additional advantage that it compiles using PS2 which is supported by a wider range of graphics cards - and the main vertex and pixel shader codes are simpler. There are problems near the edges of the objects when viewed from certain angles - I'll see if I can fix those tomorrow. For the moment though the important thing is that Diggsey's idea works.
Dr Tank
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 19th May 2010 05:34 Edited at: 19th May 2010 06:25
This seems like an interesting thing to study, but i can't get the new version to work.

I tried copy and pasting the code into a new .dba, and a shader entitled "sponge v2.fx". It needs "sponge64.dds", which I do not have, so I changed the filename to "sponge128.dds" from earlier version. Program compiles and runs without error, and framerate is something like 5 fps, so the shader is trying to do something. However, screen is blue, which probably means that the shader isn't rendering.

Maybe I made an error with my copy and pasting. Perhaps it needs to use sponge64 ( i don't see any reference to 64 apart from how the # passes is 64/2). Perhaps my comp can't cope with all the passes.

If you attached a project folder i'd be able to rule out the first two possibilities.

Edit: i've played around, an i can get it to render something by changing the object transparency flag, but it what's rendered looks nothing like the first example. Sponge is much more transparent than it should be with lots of noise on it. I did some tinkering, and think with the other transparency modes, only one of the passes is drawn, or something like that. I mean the first one that isn't totally transparent. Guesswork but is one explanation for the result. This means that it the transparency of this pass is low, you'll see the backdrop. So i changed


Out.col = float4 (pow(darken, layer)*spongeColour.rgb, hole);

to


Out.col = float4 (pow(darken, layer)*spongeColour.rgb, hole*20);

and it gets back to looking sort of like a sponge again. As you increase the size of the added factor, artifacts where you can see the backdrop through the sponge become less likely.

Think maybe my graphics card doesn't like transparency modes 4 or 6. Should do some more testing with this but need sleep first.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th May 2010 15:21 Edited at: 19th May 2010 15:21
Sorry. I should have uploaded the whole project - I forgot I'd fiddled with various things. I've added the complete project to my previous post.

In the meantime here's a screenshot of the latest version. As you can see it's not quite right. I haven't had time to fix it yet. Diggsey's solution (or my implementation of it anyway) makes the sponge render faster - but makes the separate layers visible.

Login to post a reply

Server time is: 2026-07-25 16:20:05
Your offset time is: 2026-07-25 16:20:05