Logo by Pauldelbrot - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. March 29, 2024, 10:38:46 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: help - round rectangle - for metaballs...  (Read 888 times)
0 Members and 1 Guest are viewing this topic.
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« on: September 12, 2013, 01:45:59 PM »

hello, i know you can help me, for a decent metaball visualisation (just in 2d ) i want to visualise the balls
as rounded rectangles, the standard distance function for the metaballs uses sqrt(distx^2+disty^2) to create
the shape of circles, but i would like to have rounded rectangles instead, anyone has a round rectangle distance function handy for me ?!
  smiley
Logged

---

divide and conquer - iterate and rule - chaos is No random!
lkmitch
Fractal Lover
**
Posts: 238



« Reply #1 on: September 12, 2013, 05:42:52 PM »

Use (distx^n + disty^n)^(1/n) for larger values of n.  4 or 6 may work.
Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #2 on: September 12, 2013, 07:16:57 PM »

Ah right its that simple, will check it out!!
Logged

---

divide and conquer - iterate and rule - chaos is No random!
Roquen
Iterator
*
Posts: 180


« Reply #3 on: September 13, 2013, 11:10:14 AM »

Let me know if you need this explained.

Code:
#ifdef GL_ES
precision mediump float;
#endif

uniform float time;
uniform vec2  mouse;
uniform vec2  resolution;
uniform vec2  surfaceSize;
varying vec2  surfacePosition;

// exterior distance: p = test point, e = extent of rectange
float box(vec2 p, vec2 e)
{
  vec2 d;
 
  p = abs(p);      // fold into Q1
  p = p - e;       // translate corner of rect to origin
  p = max(p, 0.0); // fold into Q1

  // final result is distance to origin
  return length(p);
}

// exterior distance p = test point, e = extent of rectange, r = radius of circle
// which extends 'e'. (move center of circle around perimeter)
float rbox(vec2 p, vec2 e, float r)
{
  p = max(abs(p)-e, 0.0);  // same as above

  // returns '0' inside unextended rect, negative if inside extended, zero on
  // perimeter and positive outside.  Add another clamp if no negative
  // result desired.
  return length(p)-r;
}

void main(void)
{
  vec2 p = 2.0 * surfacePosition - vec2(0.5, 0.0);
  vec2 mousePosition = (mouse - (gl_FragCoord.xy/resolution)) * surfaceSize + surfacePosition;

  vec2 a = vec2(.2);
  vec3 c = rbox(p, a, .1) >= 0.0 ? vec3(1.0) : vec3(0.0);
 
  gl_FragColor.rgb = c;
  gl_FragColor.a   = 1.0;
}
Logged

All code submitted by me is in the public domain. (http://unlicense.org/)
jehovajah
Global Moderator
Fractal Senior
******
Posts: 2749


May a trochoid in the void bring you peace


WWW
« Reply #4 on: October 07, 2013, 09:07:23 AM »

Cool, De Fermat's last theorem applied ! Make sure you use even numbers. If n is very large you may get a perfect square, so play around with the range.
Logged

May a trochoid of ¥h¶h iteratively entrain your Logos Response transforming into iridescent fractals of orgasmic delight and joy, with kindness, peace and gratitude at all scales within your experience. I beg of you to enrich others as you have been enriched, in vorticose pulsations of extravagance!
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Rectangle Spiral Mandelbulb3D Gallery bib 0 654 Last post January 20, 2011, 07:35:35 AM
by bib
Round'n'Round Mandelbulb3D Gallery MarkJayBee 0 862 Last post June 27, 2011, 04:23:41 PM
by MarkJayBee
Folding around a rectangle (new) Theories & Research DarkBeam 0 254 Last post July 23, 2012, 09:21:31 AM
by DarkBeam
Hybrid 02 - rectangle hieroglyphs Mandelbulber Gallery zebastian 0 471 Last post February 06, 2016, 11:19:30 PM
by zebastian
hybrid 02 animation - rectangle hieroglyphs Animations Showcase (Rate My short Animation) zebastian 1 888 Last post April 06, 2016, 10:53:28 PM
by quaz0r

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.17 seconds with 25 queries. (Pretty URLs adds 0.012s, 2q)