EsProgram / InkPainter

Texture-Paint on Unity.
https://esprogram.github.io/InkPainterDocument/
MIT License
1.21k stars 171 forks source link

Modifying the alpha of brush at runtime causes abnormal paint behavior #54

Open vizkidd opened 6 years ago

vizkidd commented 6 years ago

bug

When changing the brush's alpha at runtime causes only the last or the latest painted brush to simulate fluidic effects (see screenshot) (Modifying scale works fine)

(Note: How can I change the width and height in scale separately?) (Note2: Changing the alpha in HeightFluid changes the alpha of all the painted brushes ☹️ )

This is how I change alpha in the Update() function

//vars
public InkCanvas inkCanvas; //set in inspector
private static readonly System.Random random = new System.Random();
float dampedAlpha;

//functions
private void Update()
{
    if(Input.GetMouseButton(0))
    {
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;
        if(Physics.Raycast(ray, out hitInfo))
        {
                    dampedAlpha = Mathf.SmoothDamp(dampedAlpha, (float)RandomNumberBetween(0f,1f), ref vel, Time.fixedDeltaTime);
                    Brush tempBrush = brush; 
                    tempBrush.Color = new Color(brush.Color.r,brush.Color.g,brush.Color.b,dampedAlpha); 
                    inkCanvas.Paint(tempBrush, hitInfo);
                  }
          }
}

private static double RandomNumberBetween(double minValue, double maxValue)
{
    var next = random.NextDouble();
    return minValue + (next * (maxValue - minValue));
}

Steps to Reproduce:

  1. Attach "InkCanvas" Component to plane.
  2. Attach "HeightFluid" script to the plane.
  3. Uncheck "Performance Optimize" in HeightFluid script
  4. Change Properties of brush to:
    Color Blend Type = Alpha Only
    Normal Blend Type = Add
    Height Blend Type = Use Brush
  5. Create a custom script, modify the alpha values in Update() and paint.
EsProgram commented 6 years ago

Thanks for the report! currently investigating, so please be patient. I'm sorry for contact late.