Difference between revisions of "Category:LSL Color"

From Second Life Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
{{LSL Header}}
{{LSL Header
Color is specified in LSL as a vector of the red, green and blue values between 0.0 and 1.0.
}}{{#vardefine:header_title|Color in LSL
}}{{#vardefine:header_text|LSL has it's own special format for color. LSL uses a [[vector]] to store color. Unlike traditional RGB where each channel is 0 -&gt; 255, LSL's color channels are 0 -&gt; 1.<br/>
===Format: {{LSL VR|'''R'''|'''G'''|'''B'''}}===
{{{!}}
{{LSL DefineRow|float|x|Red value|[0, 1]}}
{{LSL DefineRow|float|y|Green value|[0, 1]}}
{{LSL DefineRow|float|z|Blue value|[0, 1]}}
{{!}}}


'''Example'''
}}{{#vardefine:helpers|
<lsl>
===Useful functions for storing/retrieving color and alpha values to/from integers===
vector myColor = <1.0,0.1,0.7>;
<pre>
</lsl>
integer ColorAlphatoRGBA(vector color, float alpha) {
would be 100% red scale, 10% green, and 70% blue combined to make a single color.
return (((integer)(alpha * 255.0) & 0xFF) << 24) |
(((integer)(color.x * 255.0) & 0xFF) << 16) |
(((integer)(color.y * 255.0) & 0xFF) << 8) |
((integer)(color.z * 255.0) & 0xFF);
}
 
vector RGBAtoColor(integer rgba) {
return < ((rgba >> 16) & 0xFF) / 255.0, ((rgba >> 8) & 0xFF) / 255.0, (rgba & 0xFF) / 255.0 >;
}
 
float RGBAtoAlpha(integer rgba) {
return ((rgba >> 24) & 0xFF) / 255.0;
}</pre>
}}{{#vardefine:examples|
<pre>
vector white = <1.0, 1.0, 1.0>;
vector red = <1.0, 0.0, 0.0>;
vector green = <0.0, 1.0, 0.0>;
vector blue = <0.0, 0.0, 1.0>;
vector grey = <0.5, 0.5, 0.5>;
vector black = <0.0, 0.0, 0.0>;
</pre>
}}{{LSL Generic}}

Revision as of 07:03, 1 March 2007

Color in LSL

Color in LSL

LSL has it's own special format for color. LSL uses a vector to store color. Unlike traditional RGB where each channel is 0 -> 255, LSL's color channels are 0 -> 1.

Format: <R, G, B>

• float x Red value [0, 1]
• float y Green value [0, 1]
• float z Blue value [0, 1]

Examples

vector white = <1.0, 1.0, 1.0>;
vector red = <1.0, 0.0, 0.0>;
vector green = <0.0, 1.0, 0.0>;
vector blue = <0.0, 0.0, 1.0>;
vector grey = <0.5, 0.5, 0.5>;
vector black = <0.0, 0.0, 0.0>;

Useful Snippets

Useful functions for storing/retrieving color and alpha values to/from integers

integer ColorAlphatoRGBA(vector color, float alpha) {
	return (((integer)(alpha * 255.0) & 0xFF) << 24) |
		(((integer)(color.x * 255.0) & 0xFF) << 16) |
		(((integer)(color.y * 255.0) & 0xFF) << 8) |
		((integer)(color.z * 255.0) & 0xFF);
}

vector RGBAtoColor(integer rgba) {
	return < ((rgba >> 16) & 0xFF) / 255.0, ((rgba >> 8) & 0xFF) / 255.0, (rgba & 0xFF) / 255.0 >;
}

float RGBAtoAlpha(integer rgba) {
	return ((rgba >> 24) & 0xFF) / 255.0;
}