Jump to content

weather system


Rick
 Share

Recommended Posts

So I'm trying to think of different ways to make a weather system object that you can drag into your scene. I'd be interested in hearing other ideas you all have.

 

It would be a physics body that you can size to your liking (while in editor mode it would provide a semi-transparent texture so you can see the size changes you are making without having to turn on physics. This wouldn't appear when in game mode). It would have settings like:

Rain

Snow

Fog

 

These would also have some settings to allow specific timing or % or what would happen, etc. You can select any or just 1 or 2 that you want to happen inside this physics body.

 

When the main camera collides with the physics body is when you would get the full screen effect that is showing this weather effect happening.

 

Thoughts?

Link to comment
Share on other sites

Nice idea. Any thoughts on how you would prevent the rain/snow when inside buildings or under cover?

 

I suppose you could use line picks to detect overhead meshes or parhaps check for being inside model AABBs but then you'd still want to see it raining outside the window. Maybe someone has past experience of this out there who might like to comment.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

That's a very good question that I failed to think about lol. I'm open to suggestions.

 

My first thought, which is probably brute force, would be to have more weather boxes that are sort of void weather boxes. When the camera collides with them it cancels the screen weather effect. The question then would be how do you make it look like it's raining on the outside when you are inside looking out.

Link to comment
Share on other sites

The only way you could do that is if you rendered Terrain, followed by Weather Emitters, then render Models on top of that.

 

A friend of mine and I coded a system for this in Garry's Mod to simulate rain:

 

1) Line Picks were used to test if you hit the sky box, if so, then a wobbly quad was drawn full screen with some DOF effects for rain.

 

2) If rain was on at all, emitters were drawn, but in the same world as the normal meshes so the buildings would draw overtop of the particles.

 

3) If inside a building and looking out, a test was done to convert the visible outside 3D portion to a 2D Screenspace, and the rain effect was only drawn over that area.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

What about if you had a radius of rain particles that followed the player around and started at a certain height (way up high). Would need particle collision to destroy the particle when it collides with something though so it doesn't go through buildings. Are we able to get any sort of particle collision in LE, or could we simulate it somehow. All we would really need to know is if a particle hit something and if it did, destroy it instantly. Wouldn't need to know anything else like velocity or point of collision or anything.

 

If you were looking from the outside at this character it would look strange because they would have this radius of rain following them, but from the characters point of view it would look like real rain.

Link to comment
Share on other sites

1. Move the emitter around with the camera.

 

2. Render the scene to a depth-only buffer with an orthogonal camera over the player's head looking down. Then use this depth buffer in the particle fragment shader to discard fragments that are behind what the depth buffer sees. This is how STALKER handles rain. Not easy, but if you look at some of the shadow shaders everything you need is there. I have been meaning to do this, but just haven't had time.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Then use this depth buffer in the particle fragment shader to discard fragments that are behind what the depth buffer sees

 

You seem to understand this Pixel. I'll ask you so Josh can do other more important things. So what does this mean? How would this stop rain from going into places it shouldn't? I get that if you are looking down on your player and take a depth snapshot, the things closest to the camera will come through, but not following that last part.

Link to comment
Share on other sites

It will perform like a shadow map.

 

If you think about it, a shadowmap tells the light shader where NOT to light. The "rain map" would tell the particle shader where to NOT show particles, by simply discarding those fragments.

 

In an orthogonal camera projection, there is no perspective, and everything will be the same size no matter the distance.

  • Upvote 1

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

So any good sites to learn this stuff because looking at mesh_shadow.frag:

 

uniform sampler2D texture0;
varying vec2 texcoord0;

void main(void) {
if (texture2D(texture0,texcoord0).a<0.5) discard;
}

 

I'm pretty lost. I can assume texture0 is the texture0 that I assign in the .mat file, but after that I'm lost.

 

I mean, I see the discard which is good since that's what I'd need, but no clue what texture2D(texture0, texcoord0).a is and why it's being checked if it's < 0.5. Some comments in these things would be handy.

Link to comment
Share on other sites

Sorry Rick, although I could understand the concept when it comes to shaders I'm as lost as you are. I'm guessing the above code is sampling the alpha channel (possibly where the depthmap is stored) and discarding anything less that 0.5

 

I wish I understood shaders better too!

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

So any good sites to learn this stuff because looking at mesh_shadow.frag:

 

uniform sampler2D texture0;
varying vec2 texcoord0;

void main(void) {
if (texture2D(texture0,texcoord0).a<0.5) discard;
}

 

I'm pretty lost. I can assume texture0 is the texture0 that I assign in the .mat file, but after that I'm lost.

 

I mean, I see the discard which is good since that's what I'd need, but no clue what texture2D(texture0, texcoord0).a is and why it's being checked if it's < 0.5. Some comments in these things would be handy.

 

 

I recon you might be able to learn some of this stuff through guessing and trial and error. As for me I think that texcoord0 is the used section of that texture0 and .a is an alpha transparency value for each pixel. So any pixel in that section that is less than 0.5 transparent, discard it.

 

Josh has some vids in the tute section where he messes around with shaders a little, so that might help as well.

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

I recon you might be able to learn some of this stuff through guessing and trial and error. As for me I think that texcoord0 is the used section of that texture0 and .a is an alpha transparency value for each pixel. So any pixel in that section that is less than 0.5 transparent, discard it.

 

Josh has some vids in the tute section where he messes around with shaders a little, so that might help as well.

 

 

That makes sense. What sucks is that it looks like the value is assigned somewhere. Like texcoord0 is assigned somewhere hidden from us. Well not obvious in that code anyway.

Link to comment
Share on other sites

Will this be written as a full screen shader, or a per-mesh shader?

 

Most full-screen post processing effects follow this:

texture0 = Color Buffer

texture1= Depth Buffer

texture2 = Normal Buffer

texturen... = Bloom Blur Buffer, Caustics, etc.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

That makes sense. What sucks is that it looks like the value is assigned somewhere. Like texcoord0 is assigned somewhere hidden from us. Well not obvious in that code anyway.

 

In a fragment shader, a "varying" prefixed variable is a value interpolated per-pixel, which is assigned to in the vertex shader. So mesh_shadow.vert will define texcoord0. Typically one does:

varying vec2 texcoord0;

 

void main()

{

texcoord0 = gl_MultiTexCoord0.xy;

}

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Shadow Shader for convenience if we reference it in the thread again:


varying vec2 texcoord0;
uniform float apptime;
uniform vec3 cameraposition;
uniform float meshlayerrange;
uniform float meshlayerheight;
uniform float vegetationviewdistance;
uniform float vegetationheight;

void main(void) {

vec4 modelvertex = gl_Vertex;

Include "GetMatrix.vert"

#ifdef LW_SKIN
	mat = GetAnimMatrix( int(boneindices[0]) ) * gl_Color[0];
	mat += GetAnimMatrix( int(boneindices[1]) ) * gl_Color[1];
	mat += GetAnimMatrix( int(boneindices[2]) ) * gl_Color[2];
	mat += GetAnimMatrix( int(boneindices[3]) ) * gl_Color[3];
	//mat = animmatrix[ int(boneindices[0]) ] * gl_Color[0];
	//mat += animmatrix[ int(boneindices[1]) ] * gl_Color[1]; 
	//mat += animmatrix[ int(boneindices[2]) ] * gl_Color[2];
	//mat += animmatrix[ int(boneindices[3]) ] * gl_Color[3];
#endif

#ifdef LW_MESHLAYER
	mat[3].y=0.0;
#endif

modelvertex = mat * modelvertex;

#ifdef LW_MESHLAYER
	//Align to terrain height
	modelvertex.y += GetTerrainHeight(modelvertex.xz);
	float mld = length(modelvertex.xyz - cameraposition )/vegetationviewdistance;
	mld = clamp( (mld-0.75)*4.0, 0.0, 1.0 );
	modelvertex.y -= mld * vegetationheight;
#endif

#ifdef LW_SWAY
	float seed = mod(apptime / 100.0 * 0.25,360.0);
	seed += mat[3].x*33.0 + mat[3].y*67.8 + mat[3].z*123.5;
	seed += gl_Vertex.x + gl_Vertex.y + gl_Vertex.z;
	vec4 movement = vec4( vec3( gl_Color.x * gl_Normal * LW_SWAY * (sin(seed)+0.25*cos(seed*5.2+3.2)) ),0.0);		
	modelvertex += movement;
#endif

gl_Position = gl_ModelViewProjectionMatrix * modelvertex;

texcoord0=gl_MultiTexCoord0.xy;

#ifdef __GLSL_CG_DATA_TYPES
	gl_ClipVertex = gl_ModelViewMatrix * modelvertex;
#endif

}

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

This is from postfilter.frag:

 

In this code fragcoord is a 0.0 to 1.0 texture coordinate that corresponds to the full screen quad that is drawn for the given effect.

 

0,0 is top left.

0,1 is bottom left;

1,0 is top right

1,1 is bottom right

 

varying vec4 fragcolor;
varying vec4 fragcoord;


//==========================================
//Textures
//==========================================
uniform sampler2D texture0; //color
uniform sampler2D texture1; //depth
uniform sampler2D texture2; //normal
uniform sampler2D texture3; //blurred bloom buffer
uniform sampler2D texture4; //unblurred bloom buffer
uniform sampler2D texture5; //caustics frame 1
uniform sampler2D texture6; //blurred DOF texture
uniform sampler2D texture7; //wobble texture / caustics frame 2
uniform sampler2D texture10; //noise texture for effects
uniform sampler2D texture11; //ssao texture


uniform float contrast = 1.0;
uniform float brightness = 1.0;
uniform float saturation = 1.0;

//==========================================
//Automatic uniforms
//==========================================
uniform float apptime;
uniform vec2 buffersize;
uniform vec2 camerarange;
uniform float camerazoom;


include "depthtozposition.frag"

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

If I can get around to it later today I will write a document explaining shaders in Leadwerks. I have wanted to do it for a long time both to help other people out with it, and to use as a reference while I take on rewriting the mesh shaders to be more robust (they are pretty unoptimized too).

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

It will perform like a shadow map.

 

If you think about it, a shadowmap tells the light shader where NOT to light. The "rain map" would tell the particle shader where to NOT show particles, by simply discarding those fragments.

 

In an orthogonal camera projection, there is no perspective, and everything will be the same size no matter the distance.

 

 

Ok, so I'm trying to understand how this would go down. I made a small scene. The first image is a side shot of what is in the scene. A water plane at the ground level, a barrel at the ground level, and a locker model that is higher floating in the air. The second image is when I turn my camera looking straight down on these items (which is what Josh suggested). The third image is when I turn the camera projection to orthogonal with the following command:

 

// Allows me to switch back and forth

if KeyHit(KEY_P) == 1 then CameraProjMode(fw.main.camera, 1) end

if KeyHit(KEY_O) == 1 then CameraProjMode(fw.main.camera, 2) end

 

 

So what am I seeing in that last image? It's just a flat rectangle. I assume that's the locker? I don't see the barrel or the water plane. How would taking the depth buffer of the orthogonal image help me to determine where rain doesn't go like Josh was saying?

post-112-12630529843884_thumb.jpg

post-112-12630530038383_thumb.jpg

post-112-12630530176837_thumb.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...