How is weapon colour determined - Page 2

How is weapon colour determined

Various things about Spring that do not fit in any of the other forums listed below, including forum rules.

Moderator: Moderators

User avatar
Cheesecan
Posts: 1571
Joined: 07 Feb 2005, 21:30

Post 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.
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Post 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.
User avatar
Caydr
Omnidouche
Posts: 7179
Joined: 16 Oct 2004, 19:40

Post by Caydr »

Fanger says it runs on a 1-225 system of some freaky nature though.
SJ
Posts: 618
Joined: 13 Aug 2004, 17:13

Post 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.
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Post 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
User avatar
Fanger
Expand & Exterminate Developer
Posts: 1509
Joined: 22 Nov 2005, 22:58

Post by Fanger »

no its not 255, its 225..
patmo98
Posts: 188
Joined: 09 Jan 2006, 17:51

Post by patmo98 »

SVN wrote:In rev 1351 isokron adds weapon tag for setting color as rgb value
User avatar
Fanger
Expand & Exterminate Developer
Posts: 1509
Joined: 22 Nov 2005, 22:58

Post by Fanger »

Which now makes this whole discussion moot..
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Post 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.
User avatar
Caydr
Omnidouche
Posts: 7179
Joined: 16 Oct 2004, 19:40

Post by Caydr »

patmo98 wrote:
SVN wrote:In rev 1351 isokron adds weapon tag for setting color as rgb value
KICK ASSSSSSSSSSSSSSSS
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: How is weapon colour determined

Post 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
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: How is weapon colour determined

Post 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
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
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: How is weapon colour determined

Post 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
Attachments
weapons_colors.lua
just write colors
(667 Bytes) Downloaded 2 times
Post Reply

Return to “General Discussion”