Search Unity

Drawing mutiple circles at different locations using shader

Discussion in 'Shaders' started by johndoe123, Jul 22, 2016.

  1. johndoe123

    johndoe123

    Joined:
    Jul 22, 2016
    Posts:
    2
    Hey,
    I'm new to unity and shaders and I really need some help.
    I need to have some circles at different locations of different radius. I want to provide radius and location programmatically by C#.

    The color of entire shader will be the same but the alpha will be different, circle will have zero alpha(would be better it has some drop-off).
    I have added an image with single circle(background was kind of blue, the inner side of circle is having alpha lesser then outside of circle) but all I need is multiple circles.

    Thanks for the help.
    Sorry if repeated the question
     

    Attached Files:

    Last edited: Jul 22, 2016
  2. johndoe123

    johndoe123

    Joined:
    Jul 22, 2016
    Posts:
    2
    Is it possible to pass arrays from unity to shaders?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    It is. In 5.3 and earlier you have to pass each element of the array using the name of the array and a number, i.e.:

    C#:
    for (int i=0; i < myVectorArrayValues.Count; ++i)
    myMaterial.SetVector("_myVectorArray" + i, myVectorArrayValues[0]);

    ShaderLab:
    uniform float4 _myVectorArray[50];

    In 5.4 they added SetVectorArray so you can just do:
    myMaterial.SetVectorArray("_myVectorArray", myVectorArrayValues);

    Note that the arrays in the shader are a constant size. If you'll either want to always pass an array from C# that matches the size of the array in the shader and fill the unneeded entries with valid data you can test against to skip, or you can set another property to let the shader know how many elements to iterate over.