id Tech Forums

id Tech 4 (Doom3/Prey/Q4) => id Tech 4 Textures => Topic started by: bitterman on March 25, 2017, 07:51:46 AM

Title: Lightsaber material in D3
Post by: bitterman on March 25, 2017, 07:51:46 AM
I remember there was a topic on doom3world or somewhere. Few textures and simple table based material shader.
Can anyone give me a direction?

Nice saber was realized in Jedi Academy which is based on Q3, but I don't know where I can find this material in these resources.

Thanks.
Title: Re: Lightsaber material in D3
Post by: bitterman on March 26, 2017, 06:08:34 AM
Looks like this task is more complex. Sorry for this sidestep to Q3.

There are more tuts about how to add/redesign saber, but nothing about how it works.

gfx/effects/sabers/red_glow
{
cull twosided
    {
        map gfx/effects/sabers/red_glow2
        blendFunc GL_ONE GL_ONE
        glow
        rgbGen vertex
    }
}

gfx/effects/sabers/red_line
{
cull twosided
    {
        map gfx/effects/sabers/red_line
        blendFunc GL_ONE GL_ONE
        rgbGen vertex
    }
}


Looks like glow is a particle. Any ideas?
Title: Re: Lightsaber material in D3
Post by: bitterman on March 26, 2017, 09:12:51 AM
Yes, it is possible to realize via particles.
It can be nice if spent more time.
Very powerful tool.
Title: Re: Lightsaber material in D3
Post by: argoon on March 26, 2017, 09:55:37 AM
Yes the particle editor is a complex but powerful tool, but imo not really suited for a light saber, you can easily replicate that Jedi academy light saber setup on idtech 4 or you can use a elongated face (needs to be a quad) with a flare texture on it works like a charm.  :D   
Title: Re: Lightsaber material in D3
Post by: bitterman on March 26, 2017, 11:06:24 AM
Thanks!
Well as I remember one of legendary guys from d3w realized lightsaber in D3 with all appropriate effects.
Perhaps it was IvanB or rich or some else.
Title: Re: Lightsaber material in D3
Post by: argoon on March 26, 2017, 11:27:27 AM
No problem, :)

Personally i don't remember ever seeing a lightsaber in any Doom 3 mod but i don't claim i have played them all.
Title: Re: Lightsaber material in D3
Post by: The Happy Friar on March 27, 2017, 12:00:51 PM
I don't remember a lightsaber either, but it could be done with two particle emitters that stretch the particle & have it change frames for the flicker.
Title: Re: Lightsaber material in D3
Post by: bitterman on March 28, 2017, 11:53:59 AM
Disturbance in the Force feel I ))
Title: Re: Lightsaber material in D3
Post by: motorsep on March 28, 2017, 01:37:00 PM
Lol, what makes you think Jedi Q3 games used particles for lightsabers ?

It's simply a stretched quad with lightsaber beam texture with alpha (and probably image based bloom).
Title: Re: Lightsaber material in D3
Post by: argoon on March 28, 2017, 07:57:21 PM
Quote from: bitterman on March 28, 2017, 11:53:59 AM
Disturbance in the Force feel I ))

Nice job! is that a flare material?
Title: Re: Lightsaber material in D3
Post by: bitterman on March 29, 2017, 08:56:51 PM
Quoteis that a flare material?

Thanks. Not yet. Flare mtl needs to exam.

Quotequad with lightsaber beam texture

All D3 beam mtls looks wrong for me. It don't give a 'wzzzz-wzzzz' feeling ))
Title: Re: Lightsaber material in D3
Post by: motorsep on March 30, 2017, 08:02:12 AM
Quote from: bitterman on March 29, 2017, 08:56:51 PM
All D3 beam mtls looks wrong for me. It don't give a 'wzzzz-wzzzz' feeling ))

Obviously it's not due to limitation of D3 material system ;)
Title: Re: Lightsaber material in D3
Post by: bitterman on March 30, 2017, 12:33:58 PM
Now I think about The Happy Friar advice.
Title: Re: Lightsaber material in D3
Post by: motorsep on March 30, 2017, 01:24:44 PM
Lol, art is not all 1s and 0s. You need to paint beam with glow and alpha, make 3d model (stretched quad with proper UV map), make material for it (which uses painted beam texture) and use animated table to drive flicker. Will be cheaper (performance wise) than particles and look as good or better.
Title: Re: Lightsaber material in D3
Post by: The Happy Friar on March 31, 2017, 11:49:34 AM
Quote from: motorsep on March 30, 2017, 01:24:44 PM
Lol, art is not all 1s and 0s. You need to paint beam with glow and alpha, make 3d model (stretched quad with proper UV map), make material for it (which uses painted beam texture) and use animated table to drive flicker. Will be cheaper (performance wise) than particles and look as good or better.

Best way, yup.  I don't have JK2 any more (not missing that game. :) ) so I can't take a look at how they did it, but the glow is a really important part.  Using one of the graphic enhancement mods for D3 might make up for that with it's post processes effects.
Title: Re: Lightsaber material in D3
Post by: bitterman on April 08, 2017, 07:42:29 AM
Can you remind few things for me:

1) how to create/export model (md5 or ase) with few separated materials (Blender's export);

2) can I add any particle emitter to this model (looks like these .prt into .def like smoke_wound etc are predefined in Code)?

Thanks.
Title: Re: Lightsaber material in D3
Post by: argoon on April 08, 2017, 10:02:21 AM
Quote from: bitterman on April 08, 2017, 07:42:29 AM
Can you remind few things for me:

1) how to create/export model (md5 or ase) with few separated materials (Blender's export);

2) can I add any particle emitter to this model (looks like these .prt into .def like smoke_wound etc are predefined in Code)?

Thanks.

I already said this so i will just quote my self here:

1a)
Quote

First you need to have a working md5 exporter for blender.

Second you need to know how to correctly use that exporter, the one i use (the one graciously given by the arx team), needs the exported bones to be in a separated layer, layer 5 to be exact. That is so you can have a complex animating rig in one layer and only export the bones you need in another.

Third the root bone MOST be called origin, is a requirement and it is used as the root point of the animated model, as well has the "floor" for characters, so it should be put where it makes sense, like between the feet of a character. Btw i don't know if this is really necessary but i heard that you should animate the root bone as well when you want a model to move from a place to another ingame.

Four you need to make a .def file for the animated model, is a requirement, in this .def file you define, the md5 mesh and the md5 animations, this file is very important and very powerful, on it you can define, particle effects to particular sounds that come from particular bones or animation frames, plus other things.

Five a idle animation should always be defined, it can be a single frame.

six be careful with weight painting the mesh, sometimes you think you have all bones perfectly weighted but they are not.

About bone limitations, i'm no expert but this is what i recall, idtech 4 supports max 256 bones on a single character (the animation rig on blender or others can have more but it should be baked to 256 bones or less) and a vertex on the mesh can only be assigned to a single bone, but the bone can influence many vertex's (this is equal to many other engines), md5 only supports bone animation. 

Right now i don't have the link for the Arx exporter but i think it is posted somewhere on this forum.

1b) I personaly don't recommend ase, Blender supports lwo files natively, and idtech 4 has very nice support for static lwo, but blender lwo support is not on by default you need to turn the plugin on,  file -> user preferences -> import-export section.

Btw ase is a text based file (just like md5) and lwo is a binary file, so in principle it should be easier to work with ase but on Doom 3 ase is not very well implemented because you need to edit the material or texture link naming in the file after export by hand (even if you renamed the material on blender to the correct name path) to be able to open it on idtech 4, in the case of lwo just rename the material to the name of the material on the idtech4 .mtr file something like (textures/somefoulder/somename) and it just automagically works.

There's also a nice model viewer and converter called Noesis here (http://richwhitehouse.com/index.php?content=inc_projects.php), that can view and convert many file formats including both md3 (it seems idtech 4 still supports md3 just needs some scripting magic for it to work see the thread on Dark Mod forums, still a good format for vertex animation) and more importantly md5 files.

2) About particle attachment to bones, afaik it should work with any particle, provided you don't change the key name, in your example smoke_wound should still be called smoke_wound, only the .prt file name could be anything.
Btw i have still to try it my self but i don't see why it would be impossible to make a custom key/value particle for a existent monster, imo is just a case of making a particle, write a custom key name in the monster file "my_smoke" give it a custom particle name "my_particle.prt" (i think an .fx file also works) then make a script something like so:

pseudo code this was not tested:


entity Monster_ent;
entity emiter;
vector jointPos;
string effect;

Monster_ent = sys.getEntity("monster name");
effect = Monster_ent.getkey("my_smoke");
jointPos = Monster_ent.getJointPos(joint number); // never used this before i'm not sure how to get the joint number  :S

emiter = sys.spawn("func_emiter");
emiter.setSpawnArg("model", effect);
emiter.setSpawnArg("start_off", 1); // if you want it to be off at spawn time
emiter.bindToJoint(Monster_ent, "bone_name", 1);   // bindToJoint( entity master , string boneName , float rotateWithMaster )
emiter.setOrigin(jointPos); // don't know if this is needed

// if emiter is off
if (enemySomeAction)
{
    sys.trigger(emiter);
}



Hope this gets you on the right track.   
Title: Re: Lightsaber material in D3
Post by: The Happy Friar on April 08, 2017, 10:11:54 AM
What blender are you using to export?  I still use 2.49b (I like it, no need to try to convert me to 2.7x.  :) ) & the XReal md5 exporter is the best one I've seen for 2.49b.
Exporters are here: http://idtechforums.fuzzylogicinc.com/index.php?topic=17.0
If there's more I don't have there, post in that thread & I'll add them to the main post.
Title: Re: Lightsaber material in D3
Post by: bitterman on April 08, 2017, 11:41:34 AM
argoon thanks for detailed answer. I will exam it.

I also exported some models before. In fact the question is in "few separated material" (few material decls described in .mtr).

At now it possibly works only if I created two separated mesh with separated materials. Then I select both of them  and export as one model (it's .ase exactly to see in ascii). In this case I have two BITMAP fields and can set two materials in my .mtr. But perhaps this way is not correct.

The Happy Friar - it's 2.6 but I think the concept  (few materials) must be one for any version.
Title: Re: Lightsaber material in D3
Post by: argoon on April 08, 2017, 02:13:01 PM
No problem i'm glad to help.

I have done plenty of multi materials on a single model for idtech 4, using lwo of course, i didn't do anything special but just assign different materials to different parts of the model, just selected the faces i want to have a different material and assign a material id to it, if you don't know how to do that i can only recommend you to see some Blender tutorial about that subject.
I have done the same using Blender but just for md5 models, personally only used .ase once.   
Title: Re: Lightsaber material in D3
Post by: bitterman on April 09, 2017, 08:08:53 AM
Perhaps there's no need to bind any emitter to the model.

It is possible to assign any face of this model as particle's emitter - make material for this and set 'deform particle2 myPrtName' in main stage.

See at 'emitter' plane on picture below.

In the game this plane will used to emit specified particles, not to draw it.

It can be used to create very interesting effects.

Not sure about how to test performance.




Title: Re: Lightsaber material in D3
Post by: bitterman on April 15, 2017, 12:17:46 PM
How to make this (glowing trace when blade is moving)?

How it is realised (as base idea)?

Thanks.
Title: Re: Lightsaber material in D3
Post by: argoon on April 15, 2017, 03:20:44 PM
Quote from: bitterman on April 15, 2017, 12:17:46 PM
How to make this (glowing trace when blade is moving)?

How it is realised (as base idea)?

Thanks.

There's a doom 3 mod that uses swords that has that effect i seam to remember seeing it or playing it.

But the general idea is, (don't think this is possible with simple script) for some interval of frames create two vertex's one at the tip of the sword other at the beginning of the sword blade, then using the next two vertex's create a polygonal face, merge many side by side to create a row of faces, representing the movement on space then just assign a material to this surface.

Perhaps the source code for the create line, create circle, etc can be helpful.     
Title: Re: Lightsaber material in D3
Post by: bitterman on April 16, 2017, 05:00:30 AM
Thanks but looks like too complex for me.

I think about additional plane with fade out/scroll image.

*********** upd ******************

Perhaps this is the point:

/*
---------------------------------------------------------
void WP_SaberDamageTrace( gentity_t *ent, int saberNum, int bladeNum )

  Constantly trace from the old blade pos to new, down the saber beam and do damage

  FIXME: if the dot product of the old muzzle dir and the new muzzle dir is < 0.75, subdivide it and do multiple traces so we don't flatten out the arc!
---------------------------------------------------------
*/
#define MAX_SABER_SWING_INC 0.33f
void WP_SaberDamageTrace( gentity_t *ent, int saberNum, int bladeNum )
Title: Re: Lightsaber material in D3
Post by: bitterman on April 19, 2017, 11:24:37 AM
From left to right: particle's trace (anim gif), flickertable, flickertable + particles.
Title: Re: Lightsaber material in D3
Post by: The Happy Friar on April 19, 2017, 12:24:57 PM
Very nice looking.  How's it look moving faster?
Title: Re: Lightsaber material in D3
Post by: argoon on April 19, 2017, 12:58:03 PM
Nice work!

Btw found the mod that i played with similar effect here.

http://www.moddb.com/mods/ruiner (http://www.moddb.com/mods/ruiner) 
Title: Re: Lightsaber material in D3
Post by: bitterman on April 20, 2017, 09:40:53 AM
Thanks, guys. I seen video about Ruiner before. Great work, indeed.

QuoteHow's it look moving faster?

It's driven by func_pendulum. Don't know how make it moving faster  :-[
Title: Re: Lightsaber material in D3
Post by: The Happy Friar on April 20, 2017, 12:35:34 PM
use a func_mover instead.  func_pendulum is depreciated from previous id games, you can do everything with a func_mover AND have more options.  Just change the origin of the object (manually) to the rotation point in the editor.
Title: Re: Lightsaber material in D3
Post by: bitterman on April 23, 2017, 11:27:18 AM
Test))
Title: Re: Lightsaber material in D3
Post by: argoon on April 23, 2017, 08:28:02 PM
 ;D nice, lets cut us some demons!
Title: Re: Lightsaber material in D3
Post by: The Happy Friar on April 24, 2017, 09:37:46 PM
Sweet.  Needs a light that uses the correct color so it glows a bit.  But nice looking.  :)
Title: Re: Lightsaber material in D3
Post by: bitterman on May 06, 2017, 10:31:31 AM
Quotelets cut us some demons!

Done:  https://www.youtube.com/watch?v=AChwnWYewhA (https://www.youtube.com/watch?v=AChwnWYewhA)
Title: Re: Lightsaber material in D3
Post by: bitterman on June 24, 2017, 02:59:36 AM
Suddenly))

After some digging in Wepon.cpp I've found that in D3XP we can add any particle & light to view weapon's model without any C++ changes (via .def and .script only).

Seems like this possibility is not used in vanilla d3xp assets.

And I thought that I'm a Pioneer but then I've found this improved code in Denton's mod.

Well, this is nice laser pointer for standard pistol (pure d3xp code plus some adds .def & .script).

So I belive that technically lightsaber can be constructed by same principles.

Is anyone needs to expand his arsenal? ))