Jump to content

Using dynamic textures instead of decals for more realistic damage?


Recommended Posts

I've seen the decal demo and also 1 or 2 threads related to dynamic textures. I am wanting more realistic damage than I think a simple decal can provide so am wanting to use (I think) dynamic textures to alter the diffuse, normal and specular maps to achieve a scratched and dented look. Just wondering if there's any examples of this?

Link to comment
Share on other sites

Hiya inteja... good to see you again.  https://www.babylonjs-playground.com/#I4VGK#2

It's all broken, due to stale URL's... but... there's a little bit of everything going-on there.

A possibility for you... would be to "hack" a small portion of the context2d image buffer... with a special patch of damage-texture (perhaps one of MANY damage texture-patches).  (subTextures?)  :)   Anyway, that PG might be useful.  I found it with a PG-search for context2d.  Context2d is the heart of dynamicTextures, as you likely know.  :)

Remember that dynamicTexture.update() is IMPERATIVE.  I always forgot that.  I think DK had to remind me 3 different times... about that.  I'm going brain dead.  Writing "subTextures" might be covered HERE.  There also seems to be some utility functions in THIS PG.

Link to comment
Share on other sites



Here's an exemple using Dynamic textures to display red dots on the mesh uppon clicking.

(on diffuse texture only, but it can work the same on normal and specular)

Main issue in this example : Each face share the same UV area, so the red dot appears on every face (it happens often : If you have tileable textures on your walls for example...)

If you have full control on your UV unwrapping, you can go with this method, otherwise it can be tough. Are you sure it's worth it over the Decal method ? It's flat texture in any case, so if you want to display some large hole in the wall (like a huge shell impact), you'll be limited by the amount of 3Dness you can get from Normal and Occlusion Maps, which is limited :)

Link to comment
Share on other sites

Ooh, that's a nice, clean demo, SvenF... thx!  Good words/info, too.

Inteja... you might want to keep particleSytems in mind, too.  A started PS with no emitRate, and a .manualEmitCount = 0... sits and idles, doing nothing.

When a shot hits a surface, quickly set ps.emitter to vector3 position of impact, and then set .manualEmitCount to... perhaps... 300.   A 300-particle "poof" will happen, and then the PS goes back to idle.  Remember that .emitPower will still be active/honored, even when using .manualEmitCount instead-of .emitRate.  (that is, unless you over-ride the servicing-of emitPower... via using a custom PS startPoz/update function.  More about that in a moment.)  :)

That might be handy.  Solid Particle System (SPS) can do the same thing, and you can add your own "junk" as particles... often... little pieces of ribbons and whatever other strange (parametric) shapes you can assemble.  In essence, you can make a debris generator.  Also remember that more than one particle system can run at the same time, so consider using one or more idling SPS (for chunks) and one or more idling standard PS (for dust, smoke, fire, little-chips, etc).

Also, both types of particle systems allow a "customStartPosition" and "customUpdate" function.  Update is the function that makes the particles fly, spin, change colors, check age, etc.  So you could disable most of the update func in ONE of your SPS systems.  Once that is done, wherever the startPosition func places the particles, they stay there (until their age/lifeTime expires).  SO, you could put chunks of SPS particles AROUND the impact point.  Material "shred".  :)  That would add some 3D-ness to your impacts... without any need for boolean hole-drilling into the impacted mesh.  

My goofy but world-famous sphere-o-particles is an example of custom StartPos and Update funcs.  You can also swap-out emitters quickly in the render loop.

One other "trick", if wanted, is to STILL put a decal or dot texture, like Sven showed us, but then set godrays (Volumetric Light Scattering) on that little dot.  It makes it "appear" that a light beam is shining thru the bullet hole... from behind.  It works... ok.  I don't think I have a working demo of that anymore, sorry.

Smoke, fire, chips, chunks, ripping, a guy could become a professional impact engineer/mad scientist, if wanted.  :)

I and others would like to see every version you make, if/when possible.  Few have taken projectile impacts to "the extreme", and I think it is a valuable feature and skill.  Anyone who has ever played Serious Sam... knows the enjoyment of machine-gunning the trees.  :) 

Hope this helps (overload your imagination).  cya later.

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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...