Page 2 of 2

Posted: 25 May 2006, 11:04
by Cheesecan
Fanger ol' buddy ol' pal we believe ya!

What Forboding Angel described is what map SMDs uses, they have 3 variables, RGB but 0-1.0 unlike windows which uses 0-255. The weapons in your TDF files use only one variable which works the way Fanger described it, with color corresponding to what you get when you play with hue and set sat & lum to the specified values.

Now one could wonder why they don't use 3 RGB variables like in the SMDs, I'm guessing it's there to keep it compatible with older mods.

Posted: 25 May 2006, 11:51
by TradeMark
Fanger wrote:color=x; is the hue

color2=x; is the saturation
Ya, i understanded that, but it doesnt work. The color doesnt change when i change color2.

Edit:
Cheesecan wrote:The weapons in your TDF files use only one variable which works the way Fanger described it, with color corresponding to what you get when you play with hue and set sat & lum to the specified values.
Oh, so i was right! only one color affects?


Edit2:
Fanger wrote:you have leave lum at about 120, and sat at 240 to get the color roughly you will end up with.
I think the right values are 128 and 255 (not much difference), means: only hue value affects.

Posted: 25 May 2006, 14:38
by Caydr
Fanger says it runs on a 1-225 system of some freaky nature though.

Posted: 25 May 2006, 15:00
by SJ
The exact conversion is

float3 CWeaponDefHandler::hs2rgb(float h, float s)
{
if(h>0.5)
h+=0.1f;
if(h>1)
h-=1;

s=1;
float invSat=1-s;
float3 col(invSat/2,invSat/2,invSat/2);

if(h<1/6.0){
col.x+=s;
col.y+=s*(h*6);
} else if(h<1/3.0){
col.y+=s;
col.x+=s*((1/3.0-h)*6);

} else if(h<1/2.0){
col.y+=s;
col.z+=s*((h-1/3.0)*6);

} else if(h<2/3.0){
col.z+=s;
col.y+=s*((2/3.0-h)*6);

} else if(h<5/6.0){
col.z+=s;
col.x+=s*((h-2/3.0)*6);

} else {
col.x+=s;
col.z+=s*((3/3.0-h)*6);
}
return col;
}

h=color1,s=color2

As can be seen we set the s to 1 always. So why does it look like this ? Well it dates back to the 3d recorder when we tried to figure out how those colors worked and didnt know that there was a secondary pallette or whatever the correct solution is.

Anyway the best thing to do now is probably to introduce a new value that gives color directly in rgb instead and that overrides this whole mess if set, since we dont want to break old stuff.

Posted: 25 May 2006, 15:24
by TradeMark
Caydr wrote:Fanger says it runs on a 1-225 system of some freaky nature though.
He wrote it wrong, its 0-255

Posted: 25 May 2006, 15:48
by Fanger
no its not 255, its 225..

Posted: 25 May 2006, 16:15
by patmo98
SVN wrote:In rev 1351 isokron adds weapon tag for setting color as rgb value

Posted: 25 May 2006, 16:26
by Fanger
Which now makes this whole discussion moot..

Posted: 25 May 2006, 17:56
by TradeMark
Hmm... 225 gave me red instead of purple, i dont understand why they uses 225 :?

But i think it starts from 0, instead of 1. Everything starts from 0 in programming.

Posted: 25 May 2006, 19:35
by Caydr
patmo98 wrote:
SVN wrote:In rev 1351 isokron adds weapon tag for setting color as rgb value
KICK ASSSSSSSSSSSSSSSS

Re: How is weapon colour determined

Posted: 13 Nov 2013, 20:57
by PepeAmpere
just to make easier to find this thread for "search" i write what is clear after some digging now :mrgreen:

in old Spring notation color=144; (some blue laser)

144/225 = 0.64 (Spring hue has max 225 :)
0.64*360 => 230,4 in hue notation

230,4 hue is ~ 64,185,91 in RGB

64/256
185/256
91/256

which is rgbColor=0.25 0.722 0.355; in new Spring weapons color notation

just example to help other people upgrading their weapons def files

Re: How is weapon colour determined

Posted: 13 Nov 2013, 21:36
by PepeAmpere
lua code which makes the work for you (tested on SciTe Lua commrade)

Code: Select all

local function trueHue(SpringHue)
	return (SpringHue/225)*360
end

local function HSL(hue, saturation, lightness, alpha)
    if hue < 0 or hue > 360 then
        return 0, 0, 0, alpha
    end
    if saturation < 0 or saturation > 1 then
        return 0, 0, 0, alpha
    end
    if lightness < 0 or lightness > 1 then
        return 0, 0, 0, alpha
    end
    local chroma = (1 - math.abs(2 * lightness - 1)) * saturation
    local h = hue/60
    local x =(1 - math.abs(h % 2 - 1)) * chroma
    local r, g, b = 0, 0, 0
    if h < 1 then
        r,g,b=chroma,x,0
    elseif h < 2 then
        r,b,g=x,chroma,0
    elseif h < 3 then
        r,g,b=0,chroma,x
    elseif h < 4 then
        r,g,b=0,x,chroma
    elseif h < 5 then
        r,g,b=x,0,chroma
    else
        r,g,b=chroma,0,x
    end
    local m = lightness - chroma/2
    return {r+m,g+m,b+m,alpha}
end

local oldieSpringHue = 144
local result = HSL(trueHue(oldieSpringHue),0.5,0.5)
print("rgbColor=" .. result[1] .. " " .. result[2] .. " " .. result[3] .. ";","which is RGB:",result[1]*256 .. "," .. result[2]*256 .. "," .. result[3]*256)
just copy, save as file.lua (or dowload below) and run with your needed oldieSpringHue

of course maybe you have to play with default S, L values for transition a bit

Re: How is weapon colour determined

Posted: 14 Nov 2013, 00:41
by PepeAmpere
ok, my prev solution is useless, because we dont know S,L of that magic colors. so - use this, just let spring to write you all weapons colors in log