SnowFall and SnowAccumulation demo winter 2014

Community Forums/Showcase/SnowFall and SnowAccumulation demo winter 2014

RemiD(Posted 2014) [#1]
Hello,

This is a demo that i have made these past few days.

This demo is about snow fall (with falling snowflakes) and snow accumulation (with melted snowflakes)

Here is a screenshot of the scene before/after :


Here is a link to the demo if you want to try :
(see post#23)

Controls :
Mouse X axis -> look turn left right
Mouse Y axis -> look up down
z -> move forward
s -> move back
q -> move left
d -> move right

Tab -> change the interactionmode (allows you to either control the camera and to turn move in the scene or to "free" the cursor if you want to do something else while the snowflakes are falling and accumulating)

If the window "loses focus", the graphics will not update correctly, to prevent that, you can click on the window bar and drag it a little, this will put the focus on the window and the graphics will update correctly.

The demo will run slow if your cpu or your gpu are too low end/old because at the end there will be a lot of tris !

Some interesting things about this demo :
->the texture of the snowflake and of the meltedsnowflake has been made by capturing a filtered texel of the same size than those of the terrain so that they look the same.
->the falling snowflakes are copies (copyentity) of one mesh with one texture
->the melted snowflakes are merged in a few surfaces in one mesh with one texture
->i had to define the entityorder of the terrain to draw it first (behind) because there was some zfighting or rather "pixel alpha zfighting" between the melted snowflakes and the layer of the terrain where i draw the texels of the melted snow.

That's it. I hope that you like it. The graphics are low tris and with only a few colors but i like this kind of render.
(finally the blitzresearch's fairylights are lighting and glowing !)


Pingus(Posted 2014) [#2]
Crashing here... black screen at start, sorry (Win XP)


RemiD(Posted 2014) [#3]
What do you mean by "crashing" ?
There may be a mav at renderworld if your gpu is too low end/old because there are up to 32000 vertices and 32000 triangles per surface, but some graphics cards apparently don't support that !

The other graphics problem (graphics not updated correctly) may happen because the windows loses the focus, i will have to find a solution to this... For now the only solution to prevent this is to click on the window bar and to drag it a little.


Rick Nasher(Posted 2014) [#4]
Hi RemiD. Very nice! Running pretty smooth here. But such a beautiful piece and no source? Shame on you.. Santa and his reindeers will not be pleased. ;-)

Ho-ho-ho, Merry X-mas indeed!


RemiD(Posted 2014) [#5]
Thanks for your comments. :)


no source?


I can explain how i have made something if you want to understand, and even provide a simplified code example to demonstrate how something works, but because i plan to reuse some procedures functions, i don't want to post the full source. (this may become a game in the future...)


RGR(Posted 2014) [#6]
I have to *shake* the window several times to get a steady snow production of about 1460 SnowflakesOnAirCount - otherwise production ends after 5 seconds and SnowflakesOnAirCount is down to 0 - 1

Anyway. nice demo - reminds me at GameStudio A8 Snowdemo


RemiD(Posted 2014) [#7]

I have to *shake* the window several times to get a steady snow production of about 1460 SnowflakesOnAirCount - otherwise production ends after 5 seconds and SnowflakesOnAirCount is down to 0 - 1


RGR>>Oh... very strange. Can you please post the specifications of your os and of your computer ?
Also can you tell me what is the value of "SC" when this problem happens ?

Thanks for your comments.


Rick Nasher(Posted 2014) [#8]
Ahah.. Game on the way. Good for you. I do have some snowy code already for a certain game idea(s) I have, not of the accumulating type though and just never hurts to look at someone's code, especially if is running smoothly. I guess low poly is the key to what you're doing? So, yes interested in your explanation. :-)


RemiD(Posted 2014) [#9]
@Rick>>
For the falling snowflakes, they are just copies (with copyentity) of one quad mesh with one texture.

The target position of the snow accumulation of a falling snowflake is determined with a linepick from up to down.

For the snow accumulation on the terrain, it is a texture with 8x8 texels per 1x1 unit, see : http://www.blitzbasic.com/codearcs/codearcs.php?code=3093

For the snow accumulation on the things (blitz3d sculpture, happy new year card, rocks, pine trees, wild lettuces) it is one mesh with the minimum of surfaces possible with a maximum of 32000 vertices and 32000 triangles per surface and one texture.

The maximum of 32000 vertices and 32000 triangles per surface is to prevent a mav at renderworld on some graphics cards.

In this demo there is a maximum of 100 000 meltedsnowflakes, each meltedsnowflake is a quad mesh, it has 4 vertices and 2 triangles, so in order to merge all these meltedsnowflakes, you need (100 000 * 4 / 32000 = 12.5) 13 surfaces.

You need a variable (SurfaceId%) to know in which surface to put the next meltedsnowflake, so you start at SurfaceId = 1 and before adding a new meltedsnowflake to the surface, you need to check if the current surface has less than 32000 vertices and less than 32000 triangles.
if yes
you add this meltedsnowflake to the current surface
if no
you increase the SurfaceId (SurfaceId = SurfaceId + 1)
you add this meltedsnowflake to this surface

Here is an example on how to add a surface to another :
http://www.blitzbasic.com/Community/posts.php?topic=102895

This should give you a good start...
But keep in mind that this is only a demo, maybe this effect can work on a 128x128units terrain but not on a bigger terrain or it will be really slow...

Another approach would be to "texels fill" and "uv map" the meshes of the things (blitz3d sculpture, happy new year card, rocks, pine trees, wild lettuces) so that the texel size has the same size than the texel size on the terrain, and then color the texel on the texture at the picked position... A good "texels filler" "uv mapper" allows you to display a grid to see the texel size, you may manage to do this manually. (with Wings3d for example)


Rick Nasher(Posted 2014) [#10]
I was afraid for that. Probably wont work on large terrains. But nice effect nevertheless.this would be nice in a snowball like this:
http://www.blitzbasic.com/Community/post.php?topic=101692&post=1249861

Add a nice admospheric town with lights from buildings, streetlights and a camera fly through and you have the perfect demo.


RGR(Posted 2014) [#11]
@RemiD OK ...
When I start the program
FPS = 415
SC = 0,035

SnowFlakesOnAir = 20
after 5 Seconds SnowFlakesOnAir = 0

Then I grab the Window several times and move it slightly aside
Each time the SnowFlakesOnAir get higher - up to 1460
Then FPS = 156
SC = 0,09 to 0,1
MainLoopTime = 7

[ADDED] After 10 Minutes: SnowFlakesOnAirCount = 1280


Specs:
Prozessor x64 Intel(R) QuadCore(TM) i7-2600K CPU @ 3.40GHz, 3401 MHz, 8 logic Processors
8 GB Memory
Windows 7 Pro
NVIDIA GeForce GTX 770 4096 MB
Monitor1 1920x1080
Monitor2 1920x1080
3DVision
DirectX-Version DirectX 10
Creative Soundblaster Z SB 1500
1 TB SSD
500 GB SSD


RemiD(Posted 2014) [#12]
RGR>>Thanks for the report, if you have some time, please test the new version (i have just added a flip(true) to limit the fps to 60). Maybe this will work because your computer seems very fast !


Blitzplotter(Posted 2014) [#13]
Working Well here RemiD:




RemiD(Posted 2014) [#14]
Blitzplotter>>Thanks for the test!


RGR(Posted 2014) [#15]
@RemiD
Now it's ok. Reaches SnowFlakesOnAirCount = 1480 in part of a second - no grabbing the window needed anymore.


Blitzplotter(Posted 2014) [#16]
No problem RemiD, happy to test - its a great showcase of what is capable with Blitz3D, Happy New Year ;)


RemiD(Posted 2014) [#17]
@RGR>>Good to know... Thanks for the test !
So it seems that a FPS limiter is required if you want an app/game to run well on fast computers. I take note.


RGR(Posted 2014) [#18]
So it seems that a FPS limiter is required if you want an app/game to run well on fast computers. I take note.

The better way could be to take a look into the logic of your code again.
Actually it should work the same - no matter how high the FPS are. Maybe you have to multiply the adding of snow particles with a faktor which is calculated considering the frame rate.


RemiD(Posted 2014) [#19]

Maybe you have to multiply the adding of snow particles with a faktor which is calculated considering the frame rate.


That's what i already do but it does not seem to work with a too high fps...

;at the start of the mainloop (before any code)
MainLoopStart% = millisecs()

;at the end of the mainloop (after the flip())
MainLoopTime% = millisecs() - MainLoopStart
If(MainLoopTime < 1)
 MainLoopTime = 1
endif

SC# = Float(15) / 1000.0 * Float(MainLoopTime) ;(15 represents the minimum acceptable FPS so i define the value of the turns moves assuming the game will run at least at 15FPS...)

;every turn move is multiplied by SC
turnentity(PlayerRoot,0,-1*SC,0)
moveentity(PlayerRoot,0,0,0.1*SC)

;to create snowflakes i also multiply by SC :
For i% = 1 To 10*1*SC Step 1

next


Now it works well on your fast computer and it works well on 5 others computers (old and recent) that i have here, so i think that's good enough.

I use this :
http://www.blitzbasic.com/codearcs/codearcs.php?code=2916


Rick Nasher(Posted 2014) [#20]
Really nice. Now if only it would snow for real, like say a meter or 2 so wouldn't have to go to work tomorrow. ;-)


RemiD(Posted 2014) [#21]
It's snowing where i live, but not much, only a few centimeters on the ground...


Rick Nasher(Posted 2014) [#22]
That's not nearly enough. I want it to be so high I would need to dig a tunnel to the supermarket down the street. Ah, wishful thinking..


RemiD(Posted 2016) [#23]
Slight corrections + one version with bilinear filtering and one version without bilinear filtering, just to see the differences in the renders...


(not sure what i have done with the blendmode of the texture of the snowflake with bilinear filtering but it is less white...)

http://rd-stuff.fr/SnowFall-and-SnowAccumulation-demo-20160226EXE.zip