How is weapon colour determined
Moderator: Moderators
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.
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.
Ya, i understanded that, but it doesnt work. The color doesnt change when i change color2.Fanger wrote:color=x; is the hue
color2=x; is the saturation
Edit:
Oh, so i was right! only one color affects?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.
Edit2:
I think the right values are 128 and 255 (not much difference), means: only hue value affects.Fanger wrote:you have leave lum at about 120, and sat at 240 to get the color roughly you will end up with.
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.
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.
- PepeAmpere
- Posts: 591
- Joined: 03 Jun 2010, 01:28
Re: How is weapon colour determined
just to make easier to find this thread for "search" i write what is clear after some digging now
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

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
- PepeAmpere
- Posts: 591
- Joined: 03 Jun 2010, 01:28
Re: How is weapon colour determined
lua code which makes the work for you (tested on SciTe Lua commrade)
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
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)
of course maybe you have to play with default S, L values for transition a bit
- Attachments
-
- springColorsConvertor.lua
- just short code for fixing fast transfer for LUA-dudes
(autohor of main function is here http://stackoverflow.com/questions/10393134/converting-hsl-to-rgb , i did just the junk around) - (1.11 KiB) Downloaded 1 time
- PepeAmpere
- Posts: 591
- Joined: 03 Jun 2010, 01:28
Re: How is weapon colour determined
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
- Attachments
-
- weapons_colors.lua
- just write colors
- (667 Bytes) Downloaded 2 times