viernes, 2 de agosto de 2013

Garry's Mod View Models Consistency Project

Hi all, well I have been busy latelly so I didn't put anything here about this topic so in order to give it a closure here its.
For pretty much all last year I was working time to time in a project that involved the View models of Garry's Mod, what are View Models you may ask, well those are the weapons and arms you see in Firstperson when you play, the idea came to me from something I disliked about using SWeps(Scripted Weapons) in GMod, when it used a weapon model from other game like CSS, I didn't liked that my arms where the ones from CSS and then if I changed weapon I had again the arms of HL2, also the HL2 arms where not fitting to any player model since the HL2 arms are from Gordon Freeman who uses his Orange Suit, and no one else than him uses it, anyway long story short, that always bugged me, so this time there was this big GMod update comming(gmod 13) so I tho this was a good time to try to do it my self since no one else was going to do it, had some more wisdom than before and already knewd a way to do it, replicate the L4D system, wich is quite simple, the weapon models have the weapon geometry a skeleton and anims, pretty much all BUT the arms geometry, that's in another model that is then bonemerged on top of it, bonemerge is something that's used to get two models acting like one, they even cast the same shadow, they are used since HL1 to get the weapons in the hands of the players.
So, the HL2 weapons source files from the models come with the Source SDK, I just needed to remove the arms geometry, also I tho that HL2 weapons where consistent using the same skeleton in each one so I could have the arms in other model and change it to wich ever I wanted later using bonemerge, I was wrong, for this system to work, both models, the base one and the one bonemerged on top need to share the same skeleton, or at least part of it but they need to have the same names and same hirarchy, so, the Valve guys seemed to not care about cosistency on their viewmodels so they just used the skeleton as they needed, so well.. I had to fix many of the HL2 Weapons.
As I was doing that, I started to adapt some arms from other games to work in the HL2 skeleton so I could use them in those weapons:
I also had started to decompile, fix and remove the arm geometry from the CSS weapons, at first I wanted to create sets of arms for every different game skeleton, since HL2 weapons had now a single skeleton, but then there are like 30 weapons in CSS that have a different skeleton, and then there are also weapons in DODS with another skeleton, and so In L4D2, and so in CSGO. So I tho, the hell let's do different arms skinned to each skeleton so they can work in each other, so all I had to do was remove the geometry for every CSS weapon and every DODS weapon since in L4D2 and CSGO the weapons already work with this system so they don't have the arms geometry.
In the meanwile I had made a thread about the project on Facepunch, it got a lot of attention even from Garry it self and that made me work harder on it, I then had the idea that in order to create more easy custom arms I should adapt the CSS weapons to the HL2 skeleton aswel, that at first didn't looked much hard, I had looked at the models and tho that the CSS skeleton was similar to the HL2 one and that with just some renaming of the bones and some removing of unnused ones I could pull it off, again, I was wrong.
That was my first attempt, renamed all the bones to match the HL2 skeleton names, removed the unnused ones and scaled the model %133. As you can see it looks very wrong.
So what I got from that is that many of the bones in the CSS skeleton are oriented not like the HL2 skeleton, but the proportions where almost the same(once scaled %133) so what I did was study how the bones needed to be rotated to match the HL2 skeleton, this took some time, then I created a script to do all those turns to each frame of every anim, well that took time too, and this is what I got:
Well, this looked much better, it was right, yet there was still two problems with it, one that there where no anims in the upper arm, this is because in CSS(CSGO too) the arms are just a lowerarm with a hand, so I needed to animate the missing upperarm, the second issue was that most of the CSS weapon models are left handled, I have no idea why, it's something that been arround even since the first versions of CS, and then those models are flipped ingame, this is hacky, idk why VALVe did it that way, but I was afraid that it didn't get along well with bonemerge since in CSGO they made all the weapons right handled, maybe because they tidied it up or maybe because of incompativily, anyway, I could not risk it, so then, back to research, did some SMD file format tests, came up with a script to mirror geometry without any loss:
Once I had that covered I did research to do the same with the skeleton and anims, once I nailded that too and merged the script to mirror both things along the fixing and removal of the arms geometry script I was ready, then created two 3D Max rigs, one for right handled weapons and one for left handled ones, that had the same skeleton but mirrored so it matched the mirrored anims, they were CAT rigs for the HL2 Skeleton that had the weists parented to the CSS hands, so all I had to do was load the CSS weapons anims(one by one for each weapon) sometimes make some keyframes for the spine movement in reload and draw anims and export it back to smd, it was pretty straight forward once I had the workflow set, then those anims where merged with a script to the old anims, this was to dont lose anything in 3D Max, just to add the HL2 Upper arm movement. And with some QC file magic it all worked up to this end:
Well there were some other issues I had in the path like with some weapons having a sling different skeleton like the Elites, some issues to mirror the attachment, and the fix of the disaster that was the decompiled files from the AWP, but all that was sorted out in the end, I finished the project and sent the models but they didn't get used until later on(this year) I was contacted back by MaxOf2DS who wanted my work so it could get in the game, he asked me for the source files and I had to give them to him, now in retrospective I do regret it. I thou got paid us$500 for the work, wich its something, thou, I think Garry need to have a retribution system for people who have contributed to GMod, something like they did to pay the moderators work in the forums.

But in the end all turned out great for the players and that always is the main idea, I would still love to see some day the other stuff I worked hard to do being added too, like the L4D and CSGO arms and the DODS weapons that where also adapted to the HL2 skeleton.

Anyway hope you enjoyed the reading, now you know that I was the guy who did that cool shit(I was mention like only once :P), so if you feel gratitude to me for doing this for GMod you may as well want to lend me a hand and give me some money please, or if you need help with some custom weapons for CSS that you want to convert to this system, contact me:

More articles and tutorials coming soon..

miércoles, 13 de marzo de 2013


Long ago I remember writing in Twitter something about me experimenting with Self Shadowed Bumpmaps, a feature in the Source engine that was released back with the Orange Box, since then all following Valve games have included them, and just a couple of days ago I found my old files and started doing more tests with them, so here will write a little of my knowleage about them, hope you will find some of it useful.

Ok so as some of you may already know to create a regular "Normal" Map or "Bump" Map there is the need of a height map, for Self Shadowing Bump Maps (SSBM from now on) those are also needed.
Unless! you have already a Normal Map that you want to convert over, now, Valve gots a set of command line tools to make both actions, "height2ssbump.exe" and "normal2ssbump.exe" respectively, you can see plenty of documentation about those in the Valve Dev Wiki,here I will talk about neither of those since I don't use them because of their lact of GUI, but I bet they can be useful to handle large amount of textures in batch ways.

The tool I use, and recomend you to use it, is the free tool called SSBump Generator, you can grab it from here: here is a mirror in case it's down.

Ok, so let's start, here it's the texture we will be creating the SSBM:

It's a HL2 texture, "props/metalcrate001d"

So, let's create a Height Map that works for that texture, I will suppose you know how heightmaps work(dark is low, white is hight), there are multiple ways to create them, you can use the base texture in grey tones and then go from there, when it's something sharp like metal I tend to recreate the texture in vectorial for a better more clean thing. There are also ways to create them with 3D tools like 3DMax or Mudbox, but I will leave that to you to learn how to do that.

Here it's the heightmap I created:

So now that we have that we go to the SSbumpmap generator's regular Bump map generator(wich is also pretty cool)

Load the heightmap, create a new layer and check how it looks:

Looks a bit boring, the real trick for a good SSBumpmap is to have a good Bump map to start from!

So let's make it sharper, let's add a Fine Detail layer on top:

Ok, it's better now, let's say it's perfect.
Now we can convert that bumpmap to a SSBumpmap:

So.. we now have this SSBM that works as regular bumpmap..
But there is something missing here.. come on, it's in the name.. you should know it.. ok, it's the shadows!

Here is the trick, you need to open the bumpmap you created before in an image editor soft and add an alpha channel to it, that alpha channel is the heightmap(can be the same or another), the one that will be used to cast shadows in our SSBM, so we do that, and now we repeat the step before but change this first:

So now it will take a bit longer, and so we got this:

The ray caster now generated this Ambient Occlussion that goes right on the texture, this is how those shadows alone look:

This effect can be made stronger, just play a bit with the sliders.

And that's it, now you have your SSBumpmap, then you can do other stuff like add an alpha channel to it to use it like a specular mask and then create the VTF with vtex.exe or VtfEdit.

Here it's how it looks without the SSBM and later with it:

Here some wisdom:

* Don't Use SSBumpmaps on floors unless it's complex terrain or the game uses a lot of low light sources with very closed angles like flashlights, else they will be not noted.

* The heightmaps for the shadows cast should be always clean, only big stuff, you can leave the small details to the heightmap you used for the bumpmap, for example:

There I overlayed another texture to the main texture and then overlayed a new normal map on top of the one we previously did, but didn't touch the heightmap that had that normal map so the shadows created by SSBM generator will not change.
* You can have only shadows(Ambient Occlussion) SSBM.

* If you material gots specular, don't abuse of Shadows, they will also deform the reflexes with potentially unwanted results, to address that you should keep it in mind when you are creating the specular mask to avoid the areas with shadows, or eliminate the shadows completelly, thou, if doing so, there is no longer a point in using a SSBM so you should stick to use a regular Bump Map instead.

* Here it's an interesting article made by Valve explaining how they work: SIGGRAPH2007_EfficientSelfShadowedRadiosityNormalMapping.pdf
Wan't the short version? ok, Regular Bump maps have 4 light sources in 2 channels, red and green, the blue one is for AO, rarelly used, SSBM have 3 lightsources with "baked" shadows in the 3 channels RGB, period.
Ok, that's all for now, just felt I needed to document a bit about this than just telling about it to my friends, also the blog needed some new ink, it's been more than a year since the last post, hopefully will write something much better soonish about Blendtextures, wich are less documented than SSBM.

I leave you with other examples of textures without SSBM and later with them: