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 Discussion / Reflecting and rippling water in DarkBasic(classic)

Author
Message
Attila
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 17th Aug 2004
Location:
Posted: 3rd Nov 2008 15:00 Edited at: 3rd Nov 2008 15:04
In this forums was said that it is impossible to create reflective and rippling water in DBClassic because the missing possibility to use shader.



I posted the source, the media and a executable at http://forum.thegamecreators.com/?m=forum_view&t=139364&b=6.

(to the snippets archive (Download))

The program is a proof of concept, to show it is possible to do. the reflections and the movement of the water are all calculated in the program.

And as a nice side effect the program will run fine on a older graphic card without shader support (with DX8).

Credits: The rippling of the water is based on Coldfire's code (from the snippets forum)
BlobVanDam
15
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 3rd Nov 2008 20:22
I don't have DBC, but looking at the code, it seems it only takes a screencap, textures it onto the matrix, and doesn't update it within the main loop at all. So it's not really a true reflection. Also, the reflection isn't accurate, because the texture UVs aren't being projected from the camera (which I don't think is even possible in DBC or with a matrix anyway). I still don't believe a true rippling reflection is possible in DBC.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 3rd Nov 2008 21:14
Quote: "I still don't believe a true rippling reflection is possible in DBC"


I think it could be simulated enough to be passable.

Quote: "Also, the reflection isn't accurate, because the texture UVs aren't being projected from the camera "


If the camera position is changed and a snapshot taken from the new position, the UVs don't change but the texture itself changes.

Quote: "The program is a proof of concept, to show it is possible to do"


Conceptually sound. Repositioning the camera and taking an updated snapshot could improve the angles of the reflection - though hard to manage without jitter and speed loss. Though a matrix doesn't tile textures well without losing pixels on the edges, a 3d object may be better...

Enjoy your day.
Attila
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 17th Aug 2004
Location:
Posted: 3rd Nov 2008 23:09
I used the matrix to make the 'water movement' possible.

To update the image in every loop would slow down the program (writing and reading a file is slow) but can easily be added. I got 60 FPS when testing though the program is fast enough to show fluid movements.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Nov 2008 02:57 Edited at: 4th Nov 2008 04:51
Ok. Here's an updating camera reflection angle thingy. I didn't calculate the actual light angles because the camera is only pointing straight up at the clouds(cubes) and turning. If I had an actual environment where the pool existed, then a more elaborate camera positioning/snap shot could be used.

I use kelebrindae's memblock to matrix object library. That allows me to update the texture without some of the problems that can occur with a matrix. It's a little slower because of updating the vertices through a memblock - but if used with a DLL that updated them, it would be much faster.

The right hand window shows the camera looking up at the cubes. The left hand window shows the updated texture from the different camera angles on the rippling surface.



Enjoy your day.
Attila
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 17th Aug 2004
Location:
Posted: 4th Nov 2008 13:48
@BlobVanDam
No it is not accurate, but if you look at the back paintings in movies - they are never accurate but sufficient. The viewer will look at the action in the front and he sees the water reflections in the back. but does not concentrate an accuracy - he is occupied elsewhere. To create a accurate I would use a static object to show the captured images, but this would heavily increase the work for the CPU and therefore slow down the program.

@latch
The algorithm looks good, but the program seems to be DBPro. There you could use a shader.

The idea behind the code was to create the illusion of reflecting water in DBclassic with a minimum of resources. Because even a 'non accurate' reflection looks better than a ghosted plane - as mostly used in DBclassic - to represent water.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Nov 2008 18:48 Edited at: 4th Nov 2008 19:21
@Attila
I was backing you up Big Guy! This is DarkBASIC Classic. The whole point is to prove that the reflections can be based on the camera angle and be made accurate (with a bit more work) in DBC and to support that a ripple effect can be created in DBC without shaders.

The example was written for DBC 1.20 . To make it non 1.20, comment out the lines that read SET OBJECT AMBIENT and SET OBJECT SPECULAR. Even after that adjustment, one would still need DBC enhanced to be able to use the memblocks that help to create the grid.

I'll also try mapping it to a matrix instead of a 3d object like your original example so one doesn't need 1.20 or memblocks.

Ok, here's an example that just uses a matrix and should be compatible with DBC without the enhancements. It took a minute to figure out how to set the camera view without a lot of flashing. 1.20 and 1.13 behave differently and I'd forgotten how to do it with 1.13. Apparently DBC 1.13 calls a sync automatically when using SET CAMERA VIEW.

The matrix texturing didn't turn out too bad.

Again the whole point of the rotating camera is to show that the texture can be updated based on what the camera sees. In this case, it's just a bunch of cubes high above the pool. If there was a landscape or structures around the pool, we would calculate an angle of incidence and an angle of reflection, place the camera relative to the position of the viewer and the pool and point it at the proper reflected angle to capture the appropriate "reflection" as an image. Still a bit slow, but possible to get fairly accurate reflections with the nice ripple effect.



Enjoy your day.
Attila
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 17th Aug 2004
Location:
Posted: 5th Nov 2008 13:53
@latch

Sorry for the misunderstanding. I'm using the oldest variant (1.08 is displayed) because it supports DX7. Though the MEMBLOCK does not work.

Supporting older hardware is essential for me, when programming casual games, because the client who buys a casual game is not the same client as the one buying a new PC (or GPU) for each new game. Casual games are also played at lunch time on business PCs with weaker graphic hardware (look at the VIA Chrome 9, a.e. build today in HPs 2133 notebooks, http://www.notebookcheck.net/VIA-Chrome9-HC.3712.0.html).

I'll attach code and media for a variant of the program where you can walk around, and the reflections are made on a plane object (not on a matrix) giving a more accurate reflection. It would be nice, If you could add the code to move the 'reflection plane'.

Attachments

Login to view attachments
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Nov 2008 00:44
@Latch
That runs painfully slow on my machine, about 50 seconds per frame!
shame, I'd like to see what it does.

A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Nov 2008 05:10
@Obese
Strange... The first example you can only run in DBC 1.20. The second example you can only run in 1.13 or less. Because of the way sync and set camera view behave, they do not run in both DBC versions without alterations.

Also, I run all my DBC stuff on a 1.5ghz processor. Slow by today's standards, and both examples run at 35 fps.

Here's the second example setup for DBC 1.20. It's nothing flashy.



Enjoy your day.

Login to post a reply

Server time is: 2024-04-19 10:38:05
Your offset time is: 2024-04-19 10:38:05