Jump to content
The Dark Mod Forums

Wind system concept


MirceaKitsune

Recommended Posts

I should start by saying the suggestion was inspired by this exact feature being successfully implemented in the FPS Red Eclipse (Cube / Tesseract engine) for a long time with very good looking results. I'm a developer or at least mapper for RE as well, if you need more information I'll ask its admin Quin for more technical data on how the system works. I can also find or create a video showing how the wind mechanism functions if anyone can use that.

TheDarkMod currently lacks any real system for simulating wind: If you want to make a FM that takes place in a stormy environment that looks good, you're out of luck. All we have is a handful of animated props animated to appear as if swaying in the wind, namely a tree and banner that move slightly: You can't adjust the intensity nor the direction of the wind effect, at best you can maybe tweak the animation speed to match the wind strength you'd like to depict.

There is a much better way using vertex shader deforms defined in the global shader. The first step is defining wind direction, this can be done as a property of the location info and / or using an entity for radial wind direction. When touched by a wind value above zero, models (static or animated) will play a sine wave animation on vertices, its direction and distance and frequency defined by the wind entity spawnargs and the entity's distance from its epicenter. Obviously models must specify which vertices should be wavy, the most common way is using vertex colors though an intensity texture also works if that's preferred, in any case models must include per-vertice information to specify which points should sway in the wind and by how much. Particles also need to be blown away by the wind but that should be very simple, further effects like affecting the direction of noise transmission are optional and can be done later at best.

Existing assets will need to be modified to make use of this. This includes every tree and grass so branches and leaves are affected by wind the further they are from the trunk and the base of the tree, obviously this should also be done for all banners and even the clothes on AI so you can see the the sleeves of characters flutter in the wind. All particles should be affected including flames and smoke so torches blow to the side. Note that old maps would not be affected even after the assets are modified since they'd need to specify wind information for the effect to activate.

Edited by MirceaKitsune
Link to comment
Share on other sites

Bonus 1: The system can also be used to simulate simple soft body physics. Obviously collisions will not be affected and vertex deforms are done by shader and purely visual. But it can also be used to make movables with soft parts have those bits that lag behind when moved, for example a pillow can have its edges pushed behind slightly if you frob to pick it up then throw it or move the camera around to make it dance in the air.

Bonus 2: Explosions such as mines or the fire arrow should also create a temporary wind source, in RE grenades do this and make all trees move away from the blast.

Bonus 3: If portals connect rooms with different wind values, opening a door should make vertices and particles near it waver to simulate drafts through doors and windows.

Link to comment
Share on other sites

I forgot what technique that demo used but it was quite impressive. I'm away on my laptop and using mobile data so I can't watch too many videos just in case, but I remember seeing that a while ago though not exactly what it did and how. Particles are one component, the equally important part is GPU deforming vertices on any mesh in the direction of wind.

In the meantime I need to patch up my idea as I realized there's an even simpler way of going about it. We shouldn't even need a new entity at all, wind can be done as a sound property on speakers: Just like s_shakes allows a sound to make the camera move for the earthquake effect, so too could we have an s_wind defining the magnitude by which vertices and particles move away from the source, similar to how lights flicker based on the lamp's electrical noise. The existing sound propagation system may be usable to make wind blow through open doors depending on how cheap that is, but having the wind noise itself do it definitely makes sense.

Link to comment
Share on other sites

On 8/24/2024 at 9:17 PM, freyk said:

That demo used MD5 skeletal animation. That's not the best solution for large fields of grass.

Funny, I actually just made this:

It's a combination of func_pendulum rotation and deform turbulent shader applied to some patches. With func_pendulum speed and phase can vary for more randomness. Here's the material:

deform_test_01
{
    surftype15
    description "foliage"
    nonsolid
    {
    blend
    specularmap map _white
    rgb 0.1
    }
    deform turbulent sinTable 0.007 (time * 0.3) 10
    {
    blend diffusemap
    map models/darkmod/nature/grass_04
    alphatest 0.4
    }
}

It doesn't really deform vertices but rather the texture coordinates. One small problem is that when applied to diffusemaps, only the mask gets animated - the color of the texture stays in place:

Whereas if you use any of the shadeles modes, both the color and the mask get distorted, as you would expect:

 

  • Like 1

It's only a model...

Link to comment
Share on other sites

That's very interesting, thanks for laying out the current possibilities so well. It's better than nothing at all. But as can be easily seen, they are very limited in how far you can go. Engine changes would be needed but greater and more difficult things were achieved.

The worst thing is like you said we can only deform texture coordinates not real vertice positions. Essentially TDM only lets you use fragment shaders but not vertex shaders, and it's the later we need to apply a sine deform to, although in other engines GLSL lets you use both as necessary. Vertex deforms need to be exposed in our shaders to allow any realism for banners swaying in the wind or the clothes and hair on AI as they walk through windy areas.

Then there's the issue that the direction and intensity of the deform doesn't match that of the wind. This can be manually done to some extent, by adjusting the direction of the func_pendulum for each grass blade, but it's so tedious you'd need to use a complex script to set it especially if you want to spawn a lot of grass with a seed across complex terrain so it's not worth it. With the system I'm envisioning, the mapper places the same func_static flag model in multiple locations and each will be pushed away from the wind source automatically, also the flame particles on torches as well as candles the player is carrying will be automatically pushed away in the correct direction wherever they're located or moved.

There's also no actual variation this way. My idea of using sound intensity like for flickering lights would allow making plants and particles pushed by the wind based on the volume of its sound at that moment, of course multiplied by attenuation based on the distance of the wind speaker and the distance of each vertice / particle from it. We can even apply a delay based on distance from the sound source, so whenever it gets louder you see the wave traveling across cloth and grass blades, once the base system is in place details like this should be far easier and look amazing :)

Link to comment
Share on other sites

Here's one using deform move:

deform_test_01
{
    description "foliage"
    nonsolid
    {
    blend
    specularmap map _white
    rgb 0.1
    }
    deform    move    10*sintable[time*0.5] // *sound
    {
    map models/darkmod/nature/grass_04
    alphatest 0.4
    }
}

Here's one using deform expand:

deform_test_01
{
    description "foliage"
    nonsolid
    {
    blend
    specularmap map _white
    rgb 0.1
    }
    deform    expand    4*sintable[time*0.5]
    {
    map models/darkmod/nature/grass_04
    alphatest 0.4
    }
}

Both not working well with diffusemaps. These are actually moving vertices, but all at once.

  • Like 1

It's only a model...

Link to comment
Share on other sites

On 8/24/2024 at 7:28 PM, Arcturus said:

That demo used MD5 skeletal animation. That's not the best solution for large swaths of grass.

Funny, I actually just made this:

It's a combination of func_pendulum rotation and deform turbulent shader applied to some patches. With func_pendulum speed and phase can vary for more randomness. Here's the material:

deform_test_01
{
    surftype15
    description "foliage"
    nonsolid
    {
    blend
    specularmap map _white
    rgb 0.1
    }
    deform turbulent sinTable 0.007 (time * 0.3) 10
    {
    blend diffusemap
    map models/darkmod/nature/grass_04
    alphatest 0.4
    }
}

It doesn't really deform vertices but rather the texture coordinates. One small problem is that when applied to diffusemaps, only the mask gets animated - the color of the texture stays in place:

Whereas if you use any of the shadeles modes, both the color and the mask get distorted, as you would expect:

 

Oh that's funny, didn't realize that's your channel! I commented on a few of the videos.

  • Like 1

I always assumed I'd taste like boot leather.

 

Link to comment
Share on other sites

Posted (edited)

Ok, so our shaders already support vertex deform, it just wasn't used yet. This is a good start! Though the surfaces seem to disappear if they move too far away from the source, is that something that can be avoided?

Can you make a video of that demo showing the two deform types mixed? I think neither looks realistic on its own, but combined they might look better. We need grass to look like it's wavering, the bottom fixed and the top more flexible.

Also what does it look like on a cloth banner? Obviously use a patch instead of a brush so it has enough vertices to deform, bend it a little if necessary to give it enough initial geometry since I remember patches would self-optimize.

Edited by MirceaKitsune
Link to comment
Share on other sites

You can't seem to be able to mix two deform functions. You can have deform mixed with some transformation of the map - scale, rotate, shear, translate:

deform_test_01
{
    nonsolid
    deform    expand    4*sintable[time*0.5]
    {
    map models/darkmod/nature/alpha_test
    translate    time * 0.1 , time * 0.2
    alphatest 0.4
    }
}

 

deform_test_01
{
    nonsolid
    deform    expand    4*sintable[time*0.5]
    {
    map models/darkmod/nature/alpha_test
    translate    time * 0.1 , time * 0.2
    alphatest 0.4
    vertexcolor
    }
    {
    blend add
    map models/darkmod/nature/alpha_test
    rotate    time * -0.1
    alphatest 0.4
    inversevertexcolor
    }
 }

 

It's only a model...

Link to comment
Share on other sites

Posted (edited)

I think those look a bit better: They inflate / deflate the original mesh across its normals which is the best pattern. The only issue I see there is the deform is constant, vertices should be waving in order and out of sync with the order unique per instance. The other issue is you can't limit and scale the effect per vertex using some kind of mask, which would be necessary for pinning the roots of grass blades or clothes on AI so they don't come off and cause visible gaps in the mesh. If that can be fixed, just add deforming from the intensity of a speaker and do the same for pushing particles.

Edited by MirceaKitsune
Link to comment
Share on other sites

Deform expand doesn't work with diffusemaps, unless you want to use shadeless materials.

Here's animated bumpmap. With heathaze, to better sell the effect:

table customscaleTable { { 0.7, 1 } }

deform_test_01
{
    nonsolid
	{
	blend
	specularmap map _white
	rgb 0.1
	}
	diffusemap models\darkmod\props\textures\banner_greenman
	{
	blend bumpmap
	map textures\darkmod\alpha_test_normalmap
	translate	time * -1.2 , time * -0.6
	rotate	customscaleTable[time * 0.02]
	scale	customscaleTable[time * 0.1] , customscaleTable[time * 0.1]
	}
}
	
textures/sfx/banner_haze
{
	nonsolid
	translucent
	{
		vertexProgram		heatHazeWithMaskAndDepth.vfp
		vertexParm			0		time * -1.2 , time * -0.6	// texture scrolling
		vertexParm			1		2		// magnitude of the distortion
		fragmentProgram		heatHazeWithMaskAndDepth.vfp
		fragmentMap			0		_currentRender
		fragmentMap			1		textures\darkmod\alpha_test_normalmap.tga   // the normal map for distortion
		fragmentMap			2		textures/sfx/vp1_alpha.tga   // the distortion blend map
        fragmentMap         3       _currentDepth
	}
}

At the moment using md3 animation is probably the best option for animated banners:

 

It's only a model...

Link to comment
Share on other sites

That's unfortunate and I hope it can be fixed. We definitely want it working on materials that have diffuse + specular + normal map. Not doing so sounds like a bug, even if in the form of an ancient limitation from original idTech 4 that was always there somehow.

Other than that unfortunate limitation, this last video looks just like the result I was thinking of! Even until we had vertex pinning and sound based radial deformation, that alone could be used to simulate more realistic soft objects.

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.

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.

  • Recent Status Updates

    • nbohr1more

      Hidden Hands: Blood and Metal is out
       
      · 1 reply
    • taaaki

      Apologies for the unplanned downtime. A routine upgrade did not go to plan, and the rollback had its own issues
      · 2 replies
    • freyk

      Got tdm 2.12 running on my android phone. For more info, read the latest post in the topic on subforum techsupport.
      · 2 replies
    • snatcher

      TDM Modpack v4.5 released!
      Introducing... The Loop
      · 1 reply
    • Ansome

      Taking a break to alleviate burnout. In retrospect, I probably shouldn't have jumped into a map-making contest so quickly after just finishing another project and especially with my busy schedule, but I do believe I have something that the community will enjoy. No clue if I'll be able to finish it on time for the competition if I factor in a break, but I'd rather take my time and deliver something of quality rather than engage in development crunch or lose part of the map's soul to burnout.
      · 1 reply
×
×
  • Create New...