Rain/Snow Texture technique?
by Jason Nabors · in Torque Game Engine · 01/14/2003 (6:20 pm) · 23 replies
Hi all I recently got lightning, thunder, rain, snow and custom skyboxes working. Thanks to some great tutorials I found in the resources section.
However, I found the technique for rain and snow bitmaps were less then appealing in the game. Up close the rain and snow were blocks. I used a 256x256 background with random pixels colored gray.
Anyone have a more refined technique to make the rain and snow look more relistic?
Thanks
Jason
However, I found the technique for rain and snow bitmaps were less then appealing in the game. Up close the rain and snow were blocks. I used a 256x256 background with random pixels colored gray.
Anyone have a more refined technique to make the rain and snow look more relistic?
Thanks
Jason
About the author
#2
About the billboards - setting a minimum radius as well as a maximum one could solve that. I have the same problem with snowflakes.
01/15/2003 (12:29 am)
That's roughly how it's done in Torque. Finding the perfect radius is a problem, though.About the billboards - setting a minimum radius as well as a maximum one could solve that. I have the same problem with snowflakes.
#3
If you want i can post some examples of correct bitmap for rain / snow code ? To summarize, if you use a texture with random point, it will not work properly.
01/15/2003 (12:21 pm)
If you look carefully at the code, you will see that your texture for rain & snow shoulb be divided in 4 (from memory) areas and in each area you will draw a rain droplet (is it the correct english word?). However, you can easily change the code to allow much more division in your bitmap. For example in DoP, i have changed the code to allow variables bitmap division according to our artist needs. If you want i can post some examples of correct bitmap for rain / snow code ? To summarize, if you use a texture with random point, it will not work properly.
#4
It's a 4 x 4 array of snowflake or raindrop textures. You need to define an alpha channel in png with the non-snow parts being transparent.
01/15/2003 (7:09 pm)
Snowflake, Frank :-). But snowdrop sounds quite New Age like ...It's a 4 x 4 array of snowflake or raindrop textures. You need to define an alpha channel in png with the non-snow parts being transparent.
#5
BTW, if it's interesting for someone, i can post our minor modification of the rain/snow code to allow 2x2, 4x4, 8x8, ... textures for the snowflakes and rain drop :)
Just tell me.
01/15/2003 (11:39 pm)
thanks ken ;)BTW, if it's interesting for someone, i can post our minor modification of the rain/snow code to allow 2x2, 4x4, 8x8, ... textures for the snowflakes and rain drop :)
Just tell me.
#6
01/16/2003 (1:10 am)
yes, interested. :-)
#7
01/16/2003 (2:20 am)
@falcon: ok. I will put it on my todo list and hopefully i will post it this week-end (i need to test the code with the latest torque release as DoP is not on a par with the latest head release).
#8
Jason
01/16/2003 (3:50 pm)
Yeah some example code would be great. I'd love to be able to draw a droplet made up of few pixels and have it be as small as possible. The single pixel showing up as a large grey block up close, isn't too good.Jason
#9
You can download the code at our website darkhand.webhop.org
01/19/2003 (6:29 am)
Here is the promised resource www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3781You can download the code at our website darkhand.webhop.org
#11
01/20/2003 (12:28 am)
Thanks, I'll check this out for our snowflakes.
#12
I used the existing tutorials, but had to improvise beecuase a lot of what was said turned out to be wrong (the result was untextured white square raindrops.... but I got that fixed by trial and error)
01/20/2003 (12:39 am)
I have rain and snow working without any engine changes. They are textured and all. Even my lightning is textured. A 256*256 with random pixels is the wrong approach. I have a 32*32 single raindrop (actually a few). I should look in my scripts how I did it becuase its like 6 months ago I added this.I used the existing tutorials, but had to improvise beecuase a lot of what was said turned out to be wrong (the result was untextured white square raindrops.... but I got that fixed by trial and error)
#13
So, after looking at it, it seems like I followed Desmond Fletcher's tutorial (I think), but changed a few things to get the textures working.
Here's how my rain and snow datablocks look like:
I'm using a 32*32 raindrop texture. Its a 32*32 PNG with an alpha channel for transparency.
My DML file (raindrops.dml) looks like this:
I think to get it working I had to add a blank line to it (so press enter after the texture name.
By adding multiple lines to this dml one should be able to use multiple rain textures. I removed the others because in game you just don't notice, rains falls to fast, and the drops are too small.
Now about lightning. For some reason I did not use a dml file here. Here's how my lightning datablock looks like:
As you see I have the textures defined in the datablock and not in a DML.
Now, I have textured rain, snow, lightning and the sounds, all working prefectly in my game. So this setup works without engine changes.
However, one thing I cannot solve is the rain and the snow coming inside my buildings. Use protals I hear you say.... well I'm using portals and there's othing wrong with them (I checked in the debug mode if there were'nt any leaks in my portals... and there aren't, so its a more complex problem.)
So, try it out. If you get it to work, please post your findings as a resource for others. Perhaps Desmond Fletcher can update his tutorial then (because his tutorial works but only shows non textured white square raindrops)
01/21/2003 (2:00 am)
I promised Jason I'd give him a reply on how I did it... and I found some time to look into it (sooner then expected ;) )So, after looking at it, it seems like I followed Desmond Fletcher's tutorial (I think), but changed a few things to get the textures working.
Here's how my rain and snow datablocks look like:
datablock AudioProfile(Universal_Rain_Light_1)
{
filename = "fps/data/sound/fx/environment/rain_light_1.wav";
description = AudioLooping2d;
};
datablock PrecipitationData(Rain)
{
type = 1;
materialList = "~/data/fx/precipitation/raindrops.dml";
soundProfile = "Universal_Rain_Light_1";
sizeX = 0.05;
sizeY = 0.05;
movingBoxPer = 0.35;
divHeightVal = 1.5;
sizeBigBox = 1;
topBoxSpeed = 20;
frontBoxSpeed = 30;
topBoxDrawPer = 0.5;
bottomDrawHeight = 40;
skipIfPer = -0.3;
bottomSpeedPer = 1.0;
frontSpeedPer = 1.5;
frontRadiusPer = 0.5;
};
datablock PrecipitationData(Snow)
{
type = 1;
materialList = "~/data/fx/precipitation/snowflakes3.dml";
sizeX = 0.10;
sizeY = 0.10;
movingBoxPer = 0.35;
divHeightVal = 1.5;
sizeBigBox = 1;
topBoxSpeed = 20;
frontBoxSpeed = 30;
topBoxDrawPer = 0.5;
bottomDrawHeight = 40;
skipIfPer = -0.3;
bottomSpeedPer = 1.0;
frontSpeedPer = 1.5;
frontRadiusPer = 0.5;
};I'm using a 32*32 raindrop texture. Its a 32*32 PNG with an alpha channel for transparency.
My DML file (raindrops.dml) looks like this:
raindrops1
I think to get it working I had to add a blank line to it (so press enter after the texture name.
By adding multiple lines to this dml one should be able to use multiple rain textures. I removed the others because in game you just don't notice, rains falls to fast, and the drops are too small.
Now about lightning. For some reason I did not use a dml file here. Here's how my lightning datablock looks like:
datablock AudioProfile(thunderCrash1)
{
filename = "fps/data/sound/fx/environment/thunder1.wav";
description = AudioThunder3d;
};
datablock AudioProfile(thunderCrash2)
{
filename = "fps/data/sound/fx/environment/thunder2.wav";
description = AudioThunder3d;
};
datablock AudioProfile(thunderCrash3)
{
filename = "fps/data/sound/fx/environment/thunder3.wav";
description = AudioThunder3d;
};
datablock AudioProfile(thunderCrash4)
{
filename = "fps/data/sound/fx/environment/thunder4.wav";
description = AudioThunder3d;
};
datablock AudioProfile(LightningHitSound)
{
filename = "fps/data/sound/fx/misc/lightning_impact.wav";
description = AudioExplosion3d;
};
datablock LightningData(ColoStorm)
{
strikeTextures[0] = "fps/data/fx/lightning/lightning1.png";
strikeTextures[1] = "fps/data/fx/lightning/lightning2.png";
strikeTextures[2] = "fps/data/fx/lightning/lightning3.png";
strikeTextures[3] = "fps/data/fx/lightning/lightning4.png";
strikeTextures[4] = "fps/data/fx/lightning/lightning3.png";
strikeTextures[5] = "fps/data/fx/lightning/lightning2.png";
strikeTextures[6] = "fps/data/fx/lightning/lightning1.png";
strikeTextures[7] = "fps/data/fx/lightning/lightning2.png";
strikeSound = LightningHitSound;
thunderSounds[0] = thunderCrash1;
thunderSounds[1] = thunderCrash2;
thunderSounds[2] = thunderCrash3;
thunderSounds[3] = thunderCrash4;
thunderSounds[4] = thunderCrash1;
thunderSounds[5] = thunderCrash2;
thunderSounds[6] = thunderCrash3;
thunderSounds[7] = thunderCrash4;
directDamageType = "Lightning";
directDamage = 100;
};
function LightningData::applyDamage(%data, %lightningObj, %targetObject, %position, %normal)
{
%targetObject.damage(%lightningObj, %position, %data.directDamage, %data.directDamageType);
}As you see I have the textures defined in the datablock and not in a DML.
Now, I have textured rain, snow, lightning and the sounds, all working prefectly in my game. So this setup works without engine changes.
However, one thing I cannot solve is the rain and the snow coming inside my buildings. Use protals I hear you say.... well I'm using portals and there's othing wrong with them (I checked in the debug mode if there were'nt any leaks in my portals... and there aren't, so its a more complex problem.)
So, try it out. If you get it to work, please post your findings as a resource for others. Perhaps Desmond Fletcher can update his tutorial then (because his tutorial works but only shows non textured white square raindrops)
#14
01/21/2003 (3:19 am)
Is it possible to have a transparent alpha channel in Paint Shop Pro 7.0? I tried this and when I went to save the .png, PSP told me that image format didn't support alpha channels. What am I missing?
#15
01/21/2003 (3:44 am)
I always save my PNG's as superPNG, but I use PhotoShop, so I wouldn't know how its done in PSP.
#16
01/21/2003 (5:47 am)
PNGs don't save the alpha channel; I don't know exactly how the transparency is saved but it is. Use the export PNG option after creating and saving the alpha channel. If you start with a transparent background, that transparency will be saved also.
#17
1. Make a copy of your file, and modify this so that all transparent areas are black, and paint the rest however you like. (White being opaque, and darker being more transparent.)
2. Now, in the modified copy, click on < new -> from image -> source luminance>>
3. Now save the mask as an alpha channel.
4. Now activate the original image.
5. Click on < Load from Alpha Channel >> from this dialogue you can select the Alpha channel you just saved in the other image.
6. Once the mask is loaded, click on < Save to Alpha Channel>> and save.
7. Now click on < Delete>> You will be asked if you want to merge the mask with the existing layer... click NO.
8. Now save your *.PNG file and you're good to go!
*Hope this Helps!*
01/21/2003 (6:02 am)
Not sure about PSP 7, but here's how it's done in PSP 6:1. Make a copy of your file, and modify this so that all transparent areas are black, and paint the rest however you like. (White being opaque, and darker being more transparent.)
2. Now, in the modified copy, click on <
3. Now save the mask as an alpha channel.
4. Now activate the original image.
5. Click on <
6. Once the mask is loaded, click on <
7. Now click on <
8. Now save your *.PNG file and you're good to go!
*Hope this Helps!*
#18
It occurs to me that I read something about PSP 7 having a problem with *.PNG's, but then again, maybe it was Photo Shop.
At any rate, if the above doesn't work, have a look at JASC.com to see if there's any info... I have never had a problem saving Alpha Channels into a *.PNG, nor extracting Alpha Channels FROM them either.
01/21/2003 (6:06 am)
P.S.It occurs to me that I read something about PSP 7 having a problem with *.PNG's, but then again, maybe it was Photo Shop.
At any rate, if the above doesn't work, have a look at JASC.com to see if there's any info... I have never had a problem saving Alpha Channels into a *.PNG, nor extracting Alpha Channels FROM them either.
#19
It can be tricky and buggy at times.
On a side note, I just noticed @ their website there's a new version (1.0). Maybe they've addressed some of the issues.
PNG actually supports two types of transparency: The Alpha, and single color (where one all instances of that color are transparent).
-Eric Forhan MRT
01/21/2003 (7:02 am)
Photoshop 5.x supports Alpha channels. PSP can save them in png format, but can't read them (go figger). I use SuperPNG, which is a photoshop plug-in (PSP can use most photoshop plugins). It can be tricky and buggy at times.
On a side note, I just noticed @ their website there's a new version (1.0). Maybe they've addressed some of the issues.
PNG actually supports two types of transparency: The Alpha, and single color (where one all instances of that color are transparent).
-Eric Forhan MRT
#20
The only trick, is that you can't manipulate the Alpha Channel directly you must load a mask as an Alpha, modify the mask, and save it as Alpha (deleting the current channel of course.)
Aside from that, the only other limitation is that you can only save one channel per file.
I guess I'm just not sure what you mean?!
01/21/2003 (10:02 am)
Eric... where do you get the information that PSP can't read the Alpha Channel from a *.PNG? I do it all the time!?The only trick, is that you can't manipulate the Alpha Channel directly you must load a mask as an Alpha, modify the mask, and save it as Alpha (deleting the current channel of course.)
Aside from that, the only other limitation is that you can only save one channel per file.
I guess I'm just not sure what you mean?!
Diogo de Andrade