Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2004
    Location
    Århus, Denmark
    Posts
    159

    Cubicfalloff soft edge Brush (Lees brush challenge)

    Someone had to step up to the challenge

    The smooth function was totally and utterly ripped off from the interwebs (I hate reinventing the spoon again and again )

    Like this one a lot more than the linear soft edge brush as it has a more natural look to it. Am definitely going to create more of this type of brushes, had one that lowered the outer edge of the brush and raised the inner edge, which gave some interesting results.

    Next one will be a crater like brush, i.e raising by a lot at the edges and then having a cubic falloff lowering near the center

    Anyways, here comes the code
    SoftCubicEdgeBrush:
    Code:
    using UnityEngine;
    
    namespace _CodeBase.Demos.Brushes {
        class SoftCubicEdgeBrush : Brush {
            public SoftCubicEdgeBrush() {
                Icon = Resources.Load("testPattern") as Texture2D;
            }
    
            public override float sample(UnityEngine.Vector2 samplePoint, float brushSize) {
                var sample = 0f;
    
                if (samplePoint.magnitude <= brushSize / 2f) {
                    var start = 0;
                    var end = brushSize / 2f;
    
                    // sample at current distance.
                    var val = 1f - samplePoint.magnitude / end;                
                    // smooth the sample
                    sample = Smooth(start, end, val);
                    
                    // get the sample back into proper range.
                    sample = sample / (brushSize / 2f);                
                }
                return sample * Opacity;
            }
    
            public float Smooth(float start, float end, float amount) {
                // Clamp to 0-1;
                amount = (amount > 1f) ? 1f : amount;
                amount = (amount < 0f) ? 0f : amount;
    
                // Cubicly adjust the amount value.
                amount = (amount * amount) * (3f - (2f * amount));
    
                return (start + ((end - start) * amount));
            }
        }
    }
    Edit:
    Well the crater one was easier than I thought, just had to change
    Code:
     
    // sample at current distance.
    var val = 1f - samplePoint.magnitude / end;
    to

    Code:
     
    // sample at current distance.
    var val = samplePoint.magnitude / end;
    Last edited by mhylle; 04-20-2011 at 11:01 AM.
    What is the colour of a chameleon standing on a mirror?

  2. #2
    Join Date
    Jun 2008
    Posts
    1,088
    This looks fun... Can't wait till I catch up! Thanks for creating brushes and sharing.

    -Dane
    You know you want to!

  3. #3
    Join Date
    Jan 2011
    Posts
    72
    This is awsome, I didn't expect this to happen with terrain brushes but with ingame spells. Thank you for posting !
    ''A person who never made a mistake never tried anything new.'' - Albert Einstein
    "The expression of what you are in space-time creates the pattern of space time." - Bachir Boumaaza

  4. #4
    Join Date
    Sep 2008
    Location
    Salisbury, UK
    Posts
    2,812
    I took a different approach & skipped up to a 5th order polynomial... our noisy friend 6t^5 - 15t^4 + 10t^3

    I put an enum of FalloffTypes and matching property in TerrainSculptor.cs, along with the following method:
    Code:
            private static void SelectFalloff()
            {
                if (Input.GetKeyDown(KeyCode.Keypad1) && Falloff != FalloffType.Linear)
                    Falloff = FalloffType.Linear;
                if (Input.GetKeyDown(KeyCode.Keypad2) && Falloff != FalloffType.Mound)
                    Falloff = FalloffType.Mound;
                if (Input.GetKeyDown(KeyCode.Keypad3) && Falloff != FalloffType.FifthOrder)
                    Falloff = FalloffType.FifthOrder;
            }
    which is called from Update() before SelectBrush() & SelectSculptTool().

    Then I just did a switch in BrushSoftEdge.cs ...here's my new BrushSoftEdge.Sample() method:
    Code:
            public override float Sample(Vector2 samplePoint, float brushSize)
            {
                var sample = 0f;
                if (samplePoint.magnitude <= brushSize / 2f)
                {
                    var t = samplePoint.magnitude/(brushSize/2f);
    
                    switch (TerrainSculptor.Falloff)
                    {
                        case TerrainSculptor.FalloffType.Linear:
                            sample = 1f - t;
                            break;
                        case TerrainSculptor.FalloffType.Mound:
                            sample = 1f - t*t;
                            break;
                        case TerrainSculptor.FalloffType.FifthOrder:
                            sample = 1f - t*t*t*(t*(t*6 - 15) + 10);
                            break;
                    }
                }
    
                return sample*Opacity;
            }
    EDIT: Here's the result of the hard-edged brush & the 3 different curves for the soft-edged brush:
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	curves.png 
Views:	112 
Size:	314.5 KB 
ID:	71581  
    Last edited by fatgav; 04-21-2011 at 03:02 PM. Reason: Added image

    I found
    my current avatar on google, so props to THIS GUY who created the original...

  5. #5
    Join Date
    Sep 2004
    Location
    Århus, Denmark
    Posts
    159
    Nice one gav. looks cool
    Great idea with the select falloff method, helps a lot when adding new falloffs. So far I have had my cubic falloff on the 5 key and the crater on the 6 key

    Here's mine.



    So much fun to play with, especially combining the crate with a noise brush, gets to look really natural
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	crater.png 
Views:	93 
Size:	317.6 KB 
ID:	71587   Click image for larger version. 

Name:	cubic.png 
Views:	91 
Size:	201.0 KB 
ID:	71588  
    Last edited by mhylle; 04-23-2011 at 04:32 AM.
    What is the colour of a chameleon standing on a mirror?

  6. #6
    Join Date
    May 2008
    Location
    Ely, UK
    Posts
    2,547
    Can't wait to get my hands on this system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •