wiki.sine.space | sinespace

Difference between revisions of "Scripting/SMaterial"

From wiki.sine.space
Jump to: navigation, search
(Members)
(Added SetFloat, GetFloat, SetColor x2, SetColor32, SetInt, GetInt)
(3 intermediate revisions by one other user not shown)
Line 2: Line 2:
  
 
==Members==
 
==Members==
{{ScriptFunction|void|SetFloat|(string name, float value);|Sets a shader property to value}}
+
{{ScriptFunction|void|SetFloat|(string name, float value);|Sets a shader property to value|5=
{{ScriptFunction|void|SetColor|(string name, float r, float g, float b, float a);|Sets a shader colour to value (HDR variant, 0..1 values)}}
+
''-- Let's set the Metallic property to 0.75:''<br>
{{ScriptFunction|void|SetColor32|(string name, byte r, byte g, byte b, byte a);|Sets a shader colour to value (32-bit, 0..255 values)}}
+
local obj = Space.Host.ExecutingObject;<br>
{{ScriptFunction|void|SetInt|(string name, int value);|Sets a shader property to value}}
+
obj.Renderer.Material.SetFloat("_Metallic", 0.75);}}
{{ScriptFunction|void|SetTexture|(string name, SResource texture);|Sets a object's specified texture map (specified in parameter 1) to the texture provided as a resource in parameter #2|5 = function hithere()<br>
+
 
 +
{{ScriptFunction|float|GetFloat|(string name);|Gets the current value of a shader property.|5=
 +
''-- Let's find out the current Glosiness level''<br>
 +
local obj = Space.Host.ExecutingObject;<br>
 +
Space.Log(obj.Renderer.Material.GetFloat("_Glossiness"));<br>
 +
''-- prints "0.5" (by default) to the console.''}}
 +
 
 +
{{ScriptFunction|void|SetColor|(string name, SColor color);|Sets a shader colour to the required one.|5=
 +
''-- Let's change the Color to red:''<br>
 +
local obj = Space.Host.ExecutingObject;<br>
 +
local newColor = Color.New(1, 0, 0, 1);<br>
 +
obj.Renderer.Material.SetColor("_Color", newColor);}}
 +
 
 +
{{ScriptFunction|void|SetColor|(string name, float r, float g, float b, float a);|Sets a shader colour to value (HDR variant, 0..1 values)|5=
 +
''-- Let's change the Color to purple:''<br>
 +
local obj = Space.Host.ExecutingObject;<br>
 +
obj.Renderer.Material.SetColor("_Color", 0.5,0,0.5,1);}}
 +
 
 +
{{ScriptFunction|void|SetColor32|(string name, byte r, byte g, byte b, byte a);|Sets a shader colour to value (32-bit, 0..255 values)|5=
 +
''-- Let's change the Color to light blue:''<br>
 +
local obj = Space.Host.ExecutingObject;<br>
 +
obj.Renderer.Material.SetColor32("_Color", 53,172,232,255);}}
 +
 
 +
{{ScriptFunction|void|SetInt|(string name, int value);|Sets a shader property to value. This can be a convenient way to work with Boolean values.|5=
 +
''-- For example, let's disable Specular Highlights (enabled by default in the Standard shader):''<br>
 +
local obj = Space.Host.ExecutingObject;<br>
 +
obj.Renderer.Material.SetInt("_SpecularHighlights", 0);}}
 +
 
 +
{{ScriptFunction|int|GetInt|(string name);|Gets the current value of a shader property. This can be a convenient way to work with Boolean values.|5=
 +
''-- Let's find out if the Reflections property is enabled:''<br>
 +
local obj = Space.Host.ExecutingObject;<br>
 +
Space.Log(obj.Renderer.Material.GetInt("_GlossyReflections"));<br>
 +
''-- prints "1" (by default) to the console, which means that the Reflections property is indeed enabled.''}}
 +
 
 +
{{ScriptFunction|void|SetTexture|(string name, SResource texture);|Sets a object's specified texture map (specified in parameter 1) to the texture provided as a resource in parameter #2. The example script must be in a object with a '_MainTex' map, and that object should be set as a resource on the scripting runtime. Additionally, that object should be called 'dispobj'.<br><br>note also that this function can be used to set any of the texture maps by varying the value of the first parameter accordingly.|5 = function hithere()<br>
 
   image = "mrlee.jpg"<br>
 
   image = "mrlee.jpg"<br>
 
   server = "https://middleware.systems/"<br>
 
   server = "https://middleware.systems/"<br>
 
   obj = Space.Host.GetReference("dispobj")<br>
 
   obj = Space.Host.GetReference("dispobj")<br>
   resrc = Space.WebServices.GetImage(server .. "mrlee.jpg")<br>
+
   resrc = Space.WebServices.GetImage(server .. image)<br>
 
   obj.Renderer.Material.SetTexture("_MainTex", resrc)<br>
 
   obj.Renderer.Material.SetTexture("_MainTex", resrc)<br>
 
end<br>
 
end<br>

Revision as of 15:23, 24 July 2017

The SMaterial class provides a wrapper around Materials used for rendering

Members

SetFloat

void SetFloat (string name, float value);

Sets a shader property to value

-- Let's set the Metallic property to 0.75:

local obj = Space.Host.ExecutingObject;

obj.Renderer.Material.SetFloat("_Metallic", 0.75);


GetFloat

float GetFloat (string name);

Gets the current value of a shader property.

-- Let's find out the current Glosiness level

local obj = Space.Host.ExecutingObject;
Space.Log(obj.Renderer.Material.GetFloat("_Glossiness"));

-- prints "0.5" (by default) to the console.


SetColor

void SetColor (string name, SColor color);

Sets a shader colour to the required one.

-- Let's change the Color to red:

local obj = Space.Host.ExecutingObject;
local newColor = Color.New(1, 0, 0, 1);

obj.Renderer.Material.SetColor("_Color", newColor);


SetColor

void SetColor (string name, float r, float g, float b, float a);

Sets a shader colour to value (HDR variant, 0..1 values)

-- Let's change the Color to purple:

local obj = Space.Host.ExecutingObject;

obj.Renderer.Material.SetColor("_Color", 0.5,0,0.5,1);


SetColor32

void SetColor32 (string name, byte r, byte g, byte b, byte a);

Sets a shader colour to value (32-bit, 0..255 values)

-- Let's change the Color to light blue:

local obj = Space.Host.ExecutingObject;

obj.Renderer.Material.SetColor32("_Color", 53,172,232,255);


SetInt

void SetInt (string name, int value);

Sets a shader property to value. This can be a convenient way to work with Boolean values.

-- For example, let's disable Specular Highlights (enabled by default in the Standard shader):

local obj = Space.Host.ExecutingObject;

obj.Renderer.Material.SetInt("_SpecularHighlights", 0);


GetInt

int GetInt (string name);

Gets the current value of a shader property. This can be a convenient way to work with Boolean values.

-- Let's find out if the Reflections property is enabled:

local obj = Space.Host.ExecutingObject;
Space.Log(obj.Renderer.Material.GetInt("_GlossyReflections"));

-- prints "1" (by default) to the console, which means that the Reflections property is indeed enabled.


SetTexture

void SetTexture (string name, SResource texture);

Sets a object's specified texture map (specified in parameter 1) to the texture provided as a resource in parameter #2. The example script must be in a object with a '_MainTex' map, and that object should be set as a resource on the scripting runtime. Additionally, that object should be called 'dispobj'.

note also that this function can be used to set any of the texture maps by varying the value of the first parameter accordingly.

function hithere()
  image = "mrlee.jpg"
server = "https://middleware.systems/"
obj = Space.Host.GetReference("dispobj")
resrc = Space.WebServices.GetImage(server .. image)
obj.Renderer.Material.SetTexture("_MainTex", resrc)
end


SetTextureOffset

void SetTextureOffset (string name, float x, float y);

Sets a texture offset to a value. IF USING FOR SCROLLING ANIMATION PLEASE US A ANIMATION NOT A SCRIPT

No example provided yet


SetTextureScale

void SetTextureScale (string name, float x, float y);

Sets a texture scale to a value. IF USING FOR SCROLLING ANIMATION PLEASE US A ANIMATION NOT A SCRIPT

No example provided yet


SetVector

void SetVector (string name, SVector value);

Sets a shader property to value

No example provided yet