Jump to content

Rain - possible?


Hover
 Share

Recommended Posts

So well let's see...

 

I bought the Leadwerks Engine the last day because of the great price in the Steam Sale :)

 

But what about rain? Is rain actually build-In or are there other ways to create some?

 

If not: Is a rain / snow functionality planned for the future?

 

Thanks for your answers! ;)

Link to comment
Share on other sites

So well let's see...

 

I bought the Leadwerks Engine the last day because of the great price in the Steam Sale smile.png

 

But what about rain? Is rain actually build-In or are there other ways to create some?

 

If not: Is a rain / snow functionality planned for the future?

 

Thanks for your answers! wink.png

 

rain/snow could be done with particles I think so, but you have to do it your self. not sure what is the most efficient way of doing this. but no it's not built-in yet, and carving tool, vertex editing/ vegetation tool , etc is suppose to come this year. I don't think this is planned for this year, but josh did say depending on time after getting those planned he may be able to do a few other things like this.

 

Edit: best way of this is a shader

OS: Windows 7

Processor: AMD A6-3420M APU integrated Radeon HD Graphics 1.50 GHz

Link to comment
Share on other sites

But what about rain? Is rain actually build-In or are there other ways to create some?

You just use particles in a cylinder shape falling around the player or in front of it.

So you just need to make that particle effect child object of your player object in scene editor, so it will follow your player.

And you can switch rain off and on by pausing or running the particle emitter.

 

Your partilcles needs some Y initial speed like 30 , than a stronger acceleration like -60 , you can adjust that in the particle editor.

Stop toying and make games

Link to comment
Share on other sites

Okay thank you guys for the answers!

 

I think i would build something with particles, but first of all i had to learn how to work with the full editor and then the particle system.

But i really like that support here in the forum. That builds me a good picture of all that here :)

Link to comment
Share on other sites

You might want to try this PostFx-Shader I derived from

http://glsl.herokuapp.com/e#14949.0

 

You might want to play around with some of the values but I think, it's a good start.

 

Vertex-Shader:

#version 400
uniform mat4 projectionmatrix;
uniform mat4 drawmatrix;
uniform vec2 offset;
uniform vec2 position[4];
in vec3 vertex_position;
void main(void)
{
gl_Position = projectionmatrix * (drawmatrix * vec4(position[gl_VertexID]+offset, 0.0, 1.0));
}

 

Fragment-Shader:

#version 400
float torad(float deg){
return deg*3.14/180;
}
uniform bool isbackbuffer;
uniform float currenttime;
uniform vec2 buffersize;
uniform sampler2D texture1;
out vec4 fragData0;
uniform mat4 projectioncameramatrix;
void main( void ) {
vec2 tcoord = vec2(gl_FragCoord.xy/buffersize);
if (isbackbuffer) tcoord.y = 1.0 - tcoord.y;
float aspect = buffersize.y/buffersize.x;
tcoord.x = clamp(tcoord.x,0.0,1.0);
tcoord.y = clamp(tcoord.y,0.0,1.0);

vec2 position = ( gl_FragCoord.xy -  buffersize.xy*.5 ) / buffersize.x;
position.y+=projectioncameramatrix[1][3];
position.y-=1.0;
// 256 angle steps
float angle = atan(position.y,position.x)/(2.*3.14159265359);
angle -= floor(angle);

float rad = length(position);

float color = 0.0;
for (int i = 0; i < 10; i++) {
 float angleFract = fract(angle*256.);
 float angleRnd = floor(angle*256.)+1.;
 float angleRnd1 = fract(angleRnd*fract(angleRnd*.7235)*45.1);
 float angleRnd2 = fract(angleRnd*fract(angleRnd*.82657)*13.724);
 float t = currenttime*.005+angleRnd1*10.;
 float radDist = sqrt(angleRnd2+float(i));

 float adist = radDist/rad*.1;
 float dist = (t*.1+adist);
 dist = abs(fract(dist)-.5);
 color += max(0.,.5-dist*40./adist)*(.5-abs(angleFract-.5))*5./adist/radDist;

 angle = fract(angle+.61);
}
fragData0 = texture(texture1,tcoord);
fragData0 += vec4( color )*.3;
}

  • Upvote 1
Link to comment
Share on other sites

@Ma does this stop raining inside? The biggest issue with particles, that don't have physics, as rain is having it not clip inside buildings. The test being standing inside a a buildings doorway and looking outside and seeing rain outside but having none inside. That's usually been the challenge with LE and rain in the past.

Link to comment
Share on other sites

The biggest issue with particles, that don't have physics, as rain is having it not clip inside buildings

This has a big cost because it uses collisions.

But you can use some raycast volumes and determine where some groups of particles should fall if they fall vertically.

Stop toying and make games

Link to comment
Share on other sites

raycasts have a cost as well though. A brute force way might be able to define a few areas in your map and each area makes the particle live a certain duration. So the areas over nothing the duration will last until it hits the ground and the areas over shelter will only last until the top of the shelter. It's sort of a pain to set this up but it's an easy but tedious manual way.

Link to comment
Share on other sites

That assumes the shelter doesn't have an interior. If it does have an interior there will be a navmesh inside so this wouldn't work. The most user friendly way is particles with physics. Other engines have this and there are tricks I'm sure that are done to make it not take that much processing power to do so, but I believe this requires Josh to setup as part of the engine.

 

A library could possibly be made that runs on startup of the game and does some analysis on your level and creates all these particle emitters with a given area and duration to make it so buildings will have emitters over it where particles only last to the top of the building. It won't be perfect though with slopped roofs and such, but it could be all automatic.

Link to comment
Share on other sites

A library could possibly be made that runs on startup of the game and does some analysis on your level and creates all these particle emitters with a given area and duration to make it so buildings will have emitters over it where particles only last to the top of the building

 

Plugins, once LE3 will grow more , plugins will be the next big thing to have, and people will make such editor addons smile.png

Stop toying and make games

Link to comment
Share on other sites

Yes you can use the depth texture for that if you know the distance to the wall/window/door.

 

That seems like it might be a pain to work out. You could have any number of doors or windows in a interior. You'd almost have to label each one (key) then do an ForEachEntityInAABBDo to see which ones are around you and which are visible.

 

 

Or a rendertarget, render interior to one buffer and everything else to another, and just apply rain to the one.

 

This is interesting. Can you think of how you would identify such things as interior vs exterior such that the shader would know what to render where?

Link to comment
Share on other sites

This is interesting. Can you think of how you would identify such things as interior vs exterior such that the shader would know what to render where?

 

We don't really have a safe method for this other than using 2 worlds I think, which complicates stuff a alot for such a simple effect.

 

Or you can always do some hacky stuff, like give all interior materials an alpha value of non 1 and just apply rain shader on everything alpha != 1, but you'll run into problems sooner or later when you add other alpha stuff.

 

Maybe Josh have some better tip for this.

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

First you have to create a new shader with the given code.

  1. To do that navigate to "Shaders/PostEffects" in the "Assets"-Tab.
  2. Right-Click on the dark grey area and choose "New"->"Shader"
  3. Give it a name, e.g. "rain"
  4. Double-Click the newly created file. The script-editor should open. Navigate to the Vertex-Shader by pressing "Vertex" in the white area on the left of the script-editor and paste the Vertex-Shader-Code
  5. Navigate to the Fragment-Shader by pressing "Fragment" and paste the Fragment-Shader-Code and save.
  6. Close the script-editor and select the Root-Object in the "Scene"-tab
  7. Under "Post Effects" add the newly created shader
  8. Select your camera and check the "Use Post-Effects"-Checkbox in the "Camera"-Tab

  • Like 1
  • Upvote 1
Link to comment
Share on other sites

  • 1 year later...

Hallo,

 

i have a question to this :

 

If i put my rain.Script to PostEffect (under Root) then it looks good.

 

but if i use a trigger to aktivate the Posteffect, then it looks like the second Picture

 

I put this in my player Script to activate the rain:

 

function Script:Change()--in
self.camera:AddPostEffect("Shaders/PostEffects/Rain.shader")

end

 

can someone explain me what i do wrong?

 

thanks

post-13719-0-35692400-1484988195_thumb.png

post-13719-0-42248700-1484988219_thumb.png

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...