Vector4 shader slider script

Hi everybody,

I create a shader with vector4 parameters.
I need to associate the x,y,z,w values to 4 different horizontal slider.
The code below Can’t handle this, maybe could someone help me or give me a hint to solve?

Any help would be very appreciated :slight_smile:

shader slider script

var slider : float = 3.0;





 function Update ()
{
gameObject.renderer.material.SetVector("_shaderpropriety", Vector4(0,0,0,4)* 0.2 *slider);


}

function OnGUI () {

   slider = GUI.HorizontalSlider( Rect(20,135,175,30), slider, 1.0, 0);
   

   

}

It works, but how can i have 4 slider for each value of vector4(x,y,z,w)? Something like this code below works only with ONE of the four vectors :((

/////The (x,y,z,w) vector4 variables///

private var sliderX : float = 3.0;

private var sliderY : float = 3.0;

private var sliderZ : float = 3.0;

private var sliderW : float = 3.0;


//Trying to attach each of them to a GUI.horizontalslider//


 function Update()
{
renderer.material.SetVector("section_depth", Vector4(4,0,0,0)* 0.2 *sliderX);
renderer.material.SetVector("section_depth", Vector4(0,4,0,0)* 0.2 *sliderY);
renderer.material.SetVector("section_depth", Vector4(0,0,4,0)* 0.2 *sliderZ);
renderer.material.SetVector("section_depth", Vector4(0,0,0,4)* 0.2 *sliderW);


}

function OnGUI () {

   sliderX = GUI.HorizontalSlider( Rect(20,135,175,30), slider, 1.0, 0);
   sliderY = GUI.HorizontalSlider( Rect(20,335,175,30), slider2, 1.0, 0);
   sliderZ = GUI.HorizontalSlider( Rect(20,335,175,30), slider2, 1.0, 0);
   sliderW = GUI.HorizontalSlider( Rect(20,335,175,30), slider2, 1.0, 0);
   

}

Ah…so this question isn’t really about shaders or sliders. It’s about how to write a Vector4. Clearly, using SetVector several times in a row won’t work. Like using regular =, the last one overwrites the others. The trick is to put all the sliders into a single Vector4:

Vector4(sliderX, sliderY, sliderZ, sliderW)

I’m not sure why you have a 4 in the positions, then an extra 0.2 outside. It’s the same thing as just writing 0.8. You can, just like anything else, toss in all the extra math you want: Vector4(sliderX*0.8, sliderY*5-9, 0.5, 12);

There’s an extra fancy shortcut, that if you take a whole Vector4 times 6, it will take every slot times 6. So, to be super cute, you could write Vector4(sliderX, sliderY, ...)*0.8; which is the same as putting *0.8 in each slot.