miércoles, 18 de noviembre de 2015

Blend Modulate Textures

It's been a wile since I promised to do this tutorial so I finally decided to write it.
Sometime ago I came across a feature in the Source engine games that is called Blend Modulate Textures, they are a 2 channel texture that tells the LightmappedGeneric shader how to blend from $basetexture to $basetexture2.

Here is the wiki article: https://developer.valvesoftware.com/wiki/$blendmodulatetexture

Ok, so every texture has 4 channels Red Green Blue Alpha, blend modulate textures only uses the first 2 of those.
The Red channel controls the roughtness/smoothness of the blending, the more white the more soft the transition is. Try to avoid completelly black because that causes the shader to not have transition at all directly making a cut between the basetextures.
The Green channel is a multiplier texture of the blend, so the whiter it is the more $basetexture is going to be in that area, the darker more $basetexture2 is used.

So let's see how this can be used for improving a lot you level.

This is valve's most used blend modulate texture, it's pretty good and works nicely in most cases.
To blend dirt, grass, gravel, etc use the valve stock one. But if you are going to blend something with a bit more complexity, you may want to create a custom blend modulate texture.

This is one I made for one of the maps I'm working on:
Here is how the material looks in the game without any blendmodulatetexture.
Here it's how it looks with the valve stock one.
And finally here it's with the custom blend modulate texture made by me:
Take a closer look and you can see how the moss gets inside the cracks of the stone blocks, this really makes the transition to look a wole lot more natural.

This textures can be autored in any image editing software.
I suggest you to use for the Red channel some noise as base and then overlay like a height map of the texture if you have it so the deeper parts get a more easy/rought transition(remember to not go totally black).
In the Green channel again use as a base a heightmap from the basetexture if you have it, or an ambient occussion map that can be taken from the blue channel of your normalmap, blur it a little to smooth the transition and then add some noise to it.

It's a matter of testing it in the engine, I recomend making a small test map and when you create the material use the measurement orange texture as basetexture2 so you can see more clearly how your textures are mixing.

Here are some previous experiments I made on the matter:
Well. I think that's it for now. I will try to post again soonish.

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: http://steamcommunity.com/id/inakistuff/

More articles and tutorials coming soon..