Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Dynamic 3D clouds + shading model?  (Read 15031 times)
0 Members and 1 Guest are viewing this topic.
Offline wondersonic

Senior Newbie





« Posted 2010-11-08 13:39:41 »

Hi all,
as my first post here, I would like to know if someone already implemented (and would share experience/best practices/sources) 3D clouds + volumetric shading (isotropic or anisotropic)?

I'm currently working on a game spin-off and so far, I've got only a blue sky with a sun (implementation of "GPU Gems 2, chapter 16 - Accurate Atmospheric Scattering") Cool



I've started the implementation of the following paper: "Realistic and Fast Cloud Rendering" but as it is old (2003), I was thinking about posting here before.

Notes:
- the sources of the project are available (for free) to everybody interested
- I'm looking for opengl 2.0 (max.) implementation for compatibility
- a video of my WIP (poor sound quality Sad )

Thanks in advance for your help.

Regards,
WS
Offline gouessej
« Reply #1 - Posted 2010-11-08 16:24:09 »

Hi!

Where is the source code? Thanks for sharing.

Offline wondersonic

Senior Newbie





« Reply #2 - Posted 2010-11-08 16:39:07 »

Hi!

Where is the source code? Thanks for sharing.

For this effect: you have the source code (not cleaned) here.

For the game levels, I'll have to upload it (soon) on google code (so be patient Wink please)

WS
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2010-11-08 18:01:08 »

Does it need to be realtime, as in moving clouds, or would you accept billboards?

This is what I cooked up years ago:
http://indiespot.net/files/cuage/

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline wondersonic

Senior Newbie





« Reply #4 - Posted 2010-11-08 18:55:12 »

Does it need to be realtime, as in moving clouds, or would you accept billboards?

This is what I cooked up years ago:
http://indiespot.net/files/cuage/

Hello Riven,
I indeed intend to at least animate them as explained in the paper (dissipation, colors changing). I did not precise but the code on the LWJGL forum is an animation as the sun is slowly disappearing behind the ground producing a cool sunset thus the colors must be also dynamically set. Finally with a shading model (not necessarily complex) the effect will be great.

Note: in the beginning of this level, some ennemy armada will appear behind and through distant clouds.

Anyway the pictures are cool. Do you have one bilboard per cloud? Or are there multiple "particles" possibly animated (RGBA speaking) separately?

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2010-11-08 19:01:04 »

Thousands of sprites, that are lit with a volume tracer (sun-to-sprite). It was far from realtime: 45sec per render.

The narrow white smoke column was 2D, mostly faked and realtime though.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline wondersonic

Senior Newbie





« Reply #6 - Posted 2010-11-08 20:05:44 »

Thousands of sprites, that are lit with a volume tracer (sun-to-sprite). It was far from realtime: 45sec per render.

The narrow white smoke column was 2D, mostly faked and realtime though.

Ok, maybe something I could start with Smiley (if you propose to share your code).

I think the paper mentioned above uses the same technic regarding multiple sprites but for the colors, it uses some short-cuts (manually chosen colors). You can see some aspects of another implementation of it (according to me) here (see section "Illumination").

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2010-11-08 20:51:49 »

Looks extremely fake, compared to mine Wink

Last year, I came up with a much faster algorithm, that I haven't turned into code yet. The idea is this:

You have a massive grid  (both in volume and in memory size). Think of it like: byte[w*h*d]

You image the light-source infinitely far, so all light-rays have the same vector, but different initial positions (as in: directional light).

Every cell in your 3D grid is filled with air/watervapor (determines translucency). Naturally, tracing through this grid for every cell is extremely slow, as you'll find yourself doing ray-cube intersections. There is a shortcut however:

Take 1 ray, and make its directional vector length tiny (say 0.05, where the grid cellsize is 1.0). Now slowly advance your position and check in which cell you are (casting x,y,z to int). Once you determine you left the current cell, put that cell in a list. After tens of thousands of iterations, you end up with a path with a reasonable amount of integer 3d coordinates. Compare the adjacent coords in the path and you'll (obviously) see the delta in each axis is either -1, 0 or +1. Put these delta's into a list.

Now you have a list (or array, for performance reasons) of deltas that allows you to step through the grid at incredible speed, no geometry intersection-checks.

It would look like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
byte[] density3d = new byte[w*h*d];
int[] illumination3d= new int[w*h*d];
int x,y,z;
int[] stepper3d;
int rayLight = 10000;

for(int p=0; ??? && rayLight > 100; p++)
{
    int index3d = (d*width*height) + (y*width) + x; // replace with bit-fiddling

    int density = density3d[index3d] & 0xFF; // 0..255

    int absorb = rayLight * (0xFF-density) / 0xFF;
    rayLight -= absorb;
    illumination3d[index3d] += absorb;

    // follow your stepper, multiple times.
    int step3d = stepper3d[p%stepper3d.length]; // obviously use bit-masking here, not modulo
    x += (step3d / 1 % 3) -1;
    y += (step3d / 3 % 3) -1;
    z += (step3d / 9 % 3) -1; // 0..2 => -1..+1, also turn this into bit-magic

// faster code would look like:
// x += ((step3d>>0)&2)-1;
// y += ((step3d>>2)&2)-1;
// z += ((step3d>>4)&2)-1;
}


Naturally it'd suffer from jittering artifacts, so you create 4 (or more) paths, with adjusted initial position (say 0.5*cellsize).


1  
2  
3  
4  
5  
6  
7  
  |       |              TOP VIEW
--+-------+--
  + x   x +
  +       +              x    means where the 4 paths initiate
  + x   x +
--+-------+--
  |       |


You can use these 4 paths to trace your entire volume (or part of it every frame), by starting at the edge-cells of your 3d grid. It won't be 100% accurate, but it will be more than adequate.

If you'd wish, you can do a 3d blur as a last step. Now you have the luminance of each cell in your 3d grid. When you place your sprites, you can lookup these values to set the vertex-colors.

</brain-dump>

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline wondersonic

Senior Newbie





« Reply #8 - Posted 2010-11-10 09:55:03 »

Riven, I see your point (although int computing indeed may bring strange artifacts).

Just for me to understand, the massive grid represents a cloud or general atmosphere conditions for the scene being rendered?

BTW, I've started to implement the paper and following is my first screenshot (in order to see progression Wink ).



I use this texture atlas:



Goal, get something like:



So a big work regarding shading awaits me...
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2010-11-10 11:37:21 »

Riven, I see your point (although int computing indeed may bring strange artifacts).
Hence the blur.

Just for me to understand, the massive grid represents a cloud or general atmosphere conditions for the scene being rendered?
Whatever you want it to be. If you want shading per cloud, you can make a grid for each cloud. If you want clouds casting shadows on other clouds, you should make your grid either huge, or come up with a more efficient datastructure (lots of sub-grids, no hierachy).

BTW, I've started to implement the paper and following is my first screenshot (in order to see progression Wink ).
Both images fail to load.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wondersonic

Senior Newbie





« Reply #10 - Posted 2010-11-10 13:14:48 »

Both images fail to load.

Pictures moved to my wiki.
Offline wondersonic

Senior Newbie





« Reply #11 - Posted 2010-11-15 22:29:42 »

Clouds at sunset...

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2010-11-15 23:28:00 »

The problem you're having is that your sprites contain shade. They must be 100% white, only the transparency should vary. Once you get rid of all the baked in shading, it's time to add your own.

Otherwise every batch of cloud sprites will look like an explosion. (self illuminating)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #13 - Posted 2010-11-16 00:31:49 »

I guess you are all aware of this?
Quite old, but runs blisteringly fast on modern hardware.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #14 - Posted 2010-11-16 05:37:29 »

I guess you are all aware of this?
Quite old, but runs blisteringly fast on modern hardware.
Yes. But you first have to render the images that will be projected on the impostors. In the end you still have to do volume tracing, because everything else looks fake.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Abuse

JGO Knight


Medals: 14


falling into the abyss of reality


« Reply #15 - Posted 2010-11-16 10:24:44 »

Yes. But you first have to render the images that will be projected on the impostors. In the end you still have to do volume tracing, because everything else looks fake.

I'm not even going to attempt to understand the differences between the volume tracing algorithm you are discussing here, and the various scattering processes highlighted in that article. (which, btw contains the source to the flightsim demomstrating the clouds.)

However the use of imposters removes the necessity for the algorithm to be real-time, doesn't it?
My understanding is that it gives you several orders of magnitude more processing time with which to compute the realistic lighting.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline wondersonic

Senior Newbie





« Reply #16 - Posted 2010-11-16 12:16:37 »

The problem you're having is that your sprites contain shade. They must be 100% white, only the transparency should vary. Once you get rid of all the baked in shading, it's time to add your own.

Otherwise every batch of cloud sprites will look like an explosion. (self illuminating)

Indeed! I set them whiter and the result is really better. However one more question regarding the textures used. The alpha channel is derived from luminosity the texture alpha components go from 0 to 255. Should I set it to 255 or 0 only?

And indeed now, I've got to work the shading; I've thought about you proposal and it may bring good results Smiley

BTW, did you look at Cloudwright?

The tool contains shaders and 3 tutorials explain (in the help file) the different parameters that modify generated cloud appearance.

They seem to use some grid (warping) concept + fractal/marching.

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #17 - Posted 2010-11-16 17:57:47 »

However the use of imposters removes the necessity for the algorithm to be real-time, doesn't it?
My understanding is that it gives you several orders of magnitude more processing time with which to compute the realistic lighting.

The problem with volume tracing is that even with using impostors, it's hard to get realtime performance. The clouds are also dynamic, so the impostors have to be rerendered every few seconds.

It's not a simple problem. Most game engines cheat, with nice, but far from correct results. It's all about how much priority you give it - faking it often is good enough.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline wondersonic

Senior Newbie





« Reply #18 - Posted 2010-11-16 21:07:51 »

More realistic clouds thanks to whiter textures:



Sunset impacting clouds color:



And now very basic shading (dot product between center cloud to particle vector and center to sun vector):





Offline nicolas_bol

Senior Newbie





« Reply #19 - Posted 2010-11-22 14:53:32 »

Hello sonic,

Have you tried to take a look at "5.3 Volumetric Clouds and Mega Particles by Homam Bahnassi and Wessam Bahnassi" from shaderx5 ?

When you are done, try to add a light scattering effect, I wrote an openGL port http://fabiensanglard.net/lightScattering/index.php, based on GPU Gems 3 article.
Offline wondersonic

Senior Newbie





« Reply #20 - Posted 2010-11-24 16:06:16 »

Hello sonic,

Have you tried to take a look at "5.3 Volumetric Clouds and Mega Particles by Homam Bahnassi and Wessam Bahnassi" from shaderx5 ?

When you are done, try to add a light scattering effect, I wrote an openGL port http://fabiensanglard.net/lightScattering/index.php, based on GPU Gems 3 article.

Hi Mister Smiley
It seems the Mega particles algorithm is made for single cloud effect. Regarding the light scattering effect, sure I'll do that it is really good Smiley

While I was surfing I found some incredible articles more or less related to this thread:

- A thoroughly modern particle system.

- Volume Rendering 101

- Miles Macklin's blog

- Volumetric clouds (an implementation of the paper in XNA)

- GPU Gems 3 / Chapter 13. Volumetric Light Scattering as a Post-Process

- The Art and Technology of Whiteout (starting at page 55)

- GPU Gems / Chapter 38. Fast Fluid Dynamics Simulation on the GPU

- GPU Gems / Chapter 39. Volume Rendering Techniques

Enjoy!

WS
Offline wondersonic

Senior Newbie





« Reply #21 - Posted 2010-12-02 22:18:25 »

And a video!
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #22 - Posted 2010-12-02 22:22:26 »

Cool! The airplane should be obscured by clouds about a third of the time Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline SimonH
« Reply #23 - Posted 2010-12-03 02:25:55 »

Looks great - realistic! Maybe make the plane more realistic too?

People make games and games make people
Offline wondersonic

Senior Newbie





« Reply #24 - Posted 2010-12-03 14:23:37 »

Cool! The airplane should be obscured by clouds about a third of the time Smiley

It's a good idea!  Smiley

Offline wondersonic

Senior Newbie





« Reply #25 - Posted 2010-12-03 14:24:19 »

Looks great - realistic! Maybe make the plane more realistic too?

Thanks, regarding the ship, I can't since I've no pixel-art talent  Cry
Offline SwampChicken
« Reply #26 - Posted 2010-12-06 00:15:55 »

Just watched the video, and I noticed that having fantastic looking clouds makes the actual ship and bullets look a lot more cheezy.  Grin
Offline wondersonic

Senior Newbie





« Reply #27 - Posted 2010-12-07 13:08:49 »

Just watched the video, and I noticed that having fantastic looking clouds makes the actual ship and bullets look a lot more cheezy.  Grin

Is it a proposal to pixel-art these sprites for me?  Grin

But you are right! If I get the time for that the result would be "grandiose".
Offline cylab

JGO Ninja


Medals: 55



« Reply #28 - Posted 2010-12-07 16:40:05 »

What about doing "fake" lighting with normal- and specular-maps on the sprites.  If you render your background and foreground to textures, you could even use the normal-maps to do "fake" reflections/radiosity to make your sprites fit more into the level theme.

Mathias - I Know What [you] Did Last Summer!
Offline wondersonic

Senior Newbie





« Reply #29 - Posted 2010-12-10 12:35:52 »

What about doing "fake" lighting with normal- and specular-maps on the sprites.  If you render your background and foreground to textures, you could even use the normal-maps to do "fake" reflections/radiosity to make your sprites fit more into the level theme.

A good idea but I'm not yet ready for this kind of technic  Grin

BTW, I've just implemented the Light Scattering effect.

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (35 views)
2014-12-09 22:41:13

BurntPizza (70 views)
2014-12-08 04:46:31

JscottyBieshaar (32 views)
2014-12-05 12:39:02

SHC (44 views)
2014-12-03 16:27:13

CopyableCougar4 (40 views)
2014-11-29 21:32:03

toopeicgaming1999 (108 views)
2014-11-26 15:22:04

toopeicgaming1999 (94 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!