Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tintmaps for Dragoon #91

Open
Paril opened this issue Feb 17, 2017 · 12 comments
Open

Tintmaps for Dragoon #91

Paril opened this issue Feb 17, 2017 · 12 comments
Assignees
Milestone

Comments

@Paril
Copy link
Collaborator

Paril commented Feb 17, 2017

Alright, so this will take probably a full day of work from somebody who is more good at photoshop than I am. First, grab the sample here:

guard.zip

Extract this to your local data "quetoo\default\players\guard" (not your data dir, the read-only one) and load the skin in-game, using "cg_third_person 1" to see yourself. (at the time of writing the player model menu does not support the tinting yet - we're waiting to add the HSV sliders for that)

Basically, I added a new system in the game that I'm calling a "tintmap" - this allows for player models (or, well, any model, but only client models use the tints currently) to be tinted by three separate colors that are defined and set up by the engine. The concept is similar to what games like Sim City use to randomly color buildings and stuff.

The problem is that this will require some work to convert our models to use the tintmaps. The concept is simple - you're converting this:

into these:

->

The texture, similar to normal/gloss maps, is simply plopped next to the main texture and has "_tint" appended to it. The game will automatically pick up on this. No extra work is required to get this functionality to work.

Each color channel in the tintmap represents a specific tint color; the red channel is the % of tint color 1 to use, the green channel is the % of tint color 2, and the blue channel is the % of tint color 3. The alpha channel is ignored in the color calculation, but pixels with alpha 0 are not checked for tint values. The color components must be premultiplied by the alpha! That is to say, a value of 255,0,0,0 will not work properly because of the way filtering works. All color components must be pre-multiplied by their alpha value (all empty pixels should be all zero; if you use alpha anywhere in the color masks, multiply that color component by its alpha as well).

Currently, the game uses tint color 1 for "shirt", tint color 2 for "pants" and tint color 3 for "head". I've not used tint color 3 in my sample, but it should work. Only the player model makes use of this system at the moment.

The second part to this is that you can also define what colors are used if shirt/pants/head are set to "default" via a material file. As an example, the guard above had an "upper.mat" like such:

{
	material #players/guard/default
	tintmap.shirt_default 1.0 0.38 0.125
	tintmap.pants_default 0.6 0.38 0.17
}

In this case, with those textures above, if you don't explicitly specify a shirt/pants color, you will get one that looks very close to what the old default texture had.

To assign these to tints in-game, use the userinfo cvars "shirt" and "pants" - these can be HTML hexadecimal color values ("rgb" or "rrggbb" format), or "default", which pulls the color from the material file or uses white as a fallback.

I think that covers the complete usage of this feature and hopefully Pan or whomever can take charge in editing our player models to work with this system.

@Paril Paril added this to the 1.0 release milestone Feb 17, 2017
@jdolan
Copy link
Owner

jdolan commented Feb 17, 2017

A link to the QForcer ones you did would be helpful :)

@Paril
Copy link
Collaborator Author

Paril commented Feb 17, 2017

They were shit, that's why I did the guard one instead :p this one is closer to how you're actually meant to do it - the underlying layer levels also have to be adjusted so that they are 0 to 255.

@kaadmy
Copy link
Collaborator

kaadmy commented Feb 21, 2017

I'll try to work on this one.

@kaadmy
Copy link
Collaborator

kaadmy commented Feb 21, 2017

Alpha is now used in tintmaps as a factor for blending between diffuse and tintmap.
jdolan/quetoo@e6b17731

@Paril
Copy link
Collaborator Author

Paril commented Feb 22, 2017

@kaadmy Lovely job on the Qforcer default and Guard default.tga!
I have a few things that I need you to do before we can button this one up, though.

  • Before doing the below, fix up the code to resolve issues Jay had with the setup; he didn't want the game to use SHIRT/PANTS/HEAD in the constants or material parsing. Maybe we should just change those to TINT_R, TINT_G and TINT_B or something, to keep it generic and so the code knows easily which channels are related to what bits.
  • Guard has Shotgun Guard and Machinegun Guard skins in there (they were sgss and mgss) that could be tinted as well. Don't be scared to tint something other than the shirt/pants for those channels - this is for customization purposes after all, and nobody's going to complain if "pants" or "helmet" modifies the backpack instead :)
  • Make sure that the shirt_default/pants_default colors are set up to look as close as possible to the skin as it was in pre-tint state.
  • Guard had a special CTF skin (red.skin/blue.skin) that you need to tint. Call this skin "ctf" - that's what the game will load for teamplay games. Don't worry about any of the other color skins, that's the only one I'm worried about.
  • Don't put the #default material in both upper.mat and lower.mat - this creates two entries in the material table and won't work properly. Just use one .mat file for everything (upper.mat is probably the best option). head.mat can stay where it is since it has special stuff for the visor.
  • Gork will be fairly simple, but Bunker and Dragoon also have a CTF skin that you should have in a ctf.skin/.tga/_tint.tga setup.
  • Supporting tints on other models is fairly easy - you just need to set up the "tints" pointers to whatever color value you want to tint it with. You could make a generic "EF_TEAM_TINT" effect, which reads team index from s.client or s.animation1, and pulls the color from the global teams table (the team colors are passed in a configstring called CS_TEAM_INFO). To make things simple, -don't- calculate tints themselves every frame, just pass a pointer to a tint that is already calculated (CS_TEAM_INFO parsing, if it's not done already, you can store tint info in there - see Cg_LoadClient for how I calculate tints for shirt/pants vars)
  • Add "helmet" tint serverinfo cvar & parsing for said cvar.
  • Player model menu is pretty easy to hook up; see lines 282 which just sets the pointers to some random tint values. The reason the player model is white right now is because the player model menu uses the "null" program, which doesn't implement tints and just implements the very basic required for rendering the menus. Ideally we'd have a separate program for rendering that though, with tint support, just without lighting/fog/etc.. it might be possible to just use "default" for it honestly, I have not tested this. Anyways, basically you'd pass them through in updateBindings (see the g_snprintf there which builds the clientinfo), and use this->client pants/shirt colors. When you have hsv sliders for the color, you can hook them up to modifying the vec3_t and the shirt/pants cvars.

I think that's all that needs to be done to call this done 4 good

@kaadmy
Copy link
Collaborator

kaadmy commented Mar 11, 2017

Is a helmet CVar needed? All the skins I've been doing don't use them, should they affect the head trim colors?

@jdolan
Copy link
Owner

jdolan commented Sep 2, 2017

Can we get a status update on this? Are Guard and QForcer supported? What about Bunker, Dragoon and Gork? In the near future, I'd love to add Nitro and Brianna as well.

@jdolan
Copy link
Owner

jdolan commented Sep 2, 2017

Also, we should update the pk3's for our models to only include the "default" tint-enabled skin. That means the skin select in the user interface need only concern itself with model names, and the tint controls will work across the board.

@kaadmy
Copy link
Collaborator

kaadmy commented Sep 2, 2017

Having a skin selection would be nice for some more variety, removing them and keeping only the default is probably good enough though.

@SpineyPete
Copy link
Collaborator

@Paril

I noticed some hard seams on the edges of my bunker tintmaps. But it's also on the other skins, I think it's due to the branching in the shader. Also, the tintmaps are supposed to use premultiplied alpha, but the formula in the shader seems to be more of an alpha blending thing?

void TintFragment(inout vec4 diffuse, in vec2 texcoord)
{
	if (TINTMAP) {
		vec4 tint = texture(SAMPLER6, texcoord);

		if (tint.a > 0) {
			for (int i = 0; i < 3; i++) {
				if (TINTS[i].a > 0 && tint[i] > 0) {
					diffuse.rgb = mix(diffuse.rgb, TINTS[i].rgb * tint[i], tint.a);
				}
			}
		}
	}
}

tintmaps

Anyway, I changed it to this, and that seems to solve it:

void TintFragment(inout vec4 diffuse, in vec2 texcoord)
{
	// tintmaps use premultiplied alpha textures
	if (TINTMAP) {
		vec4 tint = texture(SAMPLER6, texcoord);
		diffuse.rgb *= 1.0 - tint.a;
		diffuse.rgb += (TINTS[0].rgb * tint.r);
		diffuse.rgb += (TINTS[1].rgb * tint.g);
		diffuse.rgb += (TINTS[2].rgb * tint.b);
	}
}

tintmaps2

Okay if I push the fix?

@jdolan
Copy link
Owner

jdolan commented Feb 23, 2018

  • Bunker's tintmap (shirt, pants, helmet (maybe eyes instead for giggles?))
  • Qforcer's tintmap (shirt, pants (instead of boots), and helmet)

@jdolan jdolan changed the title Pants/shirt/head color masks for our default skins Tintmaps for Dragoon Jan 1, 2021
@jdolan
Copy link
Owner

jdolan commented Jan 1, 2021

Dragoon is currently the only player model included in the game data that does not include tintmaps for his default and CTF skins. Would anyone be interested in knocking those out and updating player-dragoon.pk3 to include them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants