circular s-curve function [HLSL]

Posted By: Hummel

circular s-curve function [HLSL] - 02/08/11 20:49

Hi,
just wanted to share this function I developed for fun.
Converting to any other language shouldnt be the problem.

Lets take a look at the func itself first:
Click to reveal..
Code:
static const float sqrt2_05=sqrt(2.f)*0.5f;
static const float smi=1e-4;

#define floatn float

floatn circular_sCurve(floatn x,float tau)
{
	x-=smi;
	
	float st=sign(sign(-tau)+1);
	floatn p2=step(0.5,x);
	floatn p3=abs(st-p2);
	
	x=fmod(x*2,1);
	x=abs(p3-x);
	
	tau=(1-abs(tau))*sqrt2_05;
	tau=min(tau,sqrt2_05-smi);
	
	float tau2=tau*tau;
	
	float remap0=tau-sqrt(1-2*tau2+tau2);
	float remap1=1-sqrt(1-tau2);
	
	x=-x*remap0+tau;
	
	floatn X=1-sqrt(1-x*x);
	X=(X-remap1)/((1-tau)-remap1);
	
	return (abs(p3-saturate(X))+p2)*0.5;		
}



Input values have to be in the range 0..1 for x and -1..1 for tau.
Output lies also between 0 and 1.

Visualized function with different values for tau:


So,why do I call it 'circular'?
Imagine a simple linear function with a rise of 1 which gets 'deformed' by two 'circles' from the left and the right side of the function, respectively.
The amount of 'deformation' depends on tau. For tau=0 you get a linear function. I hope that is understandable. laugh

You can download a small Demo here where the function is drawn with a dynamic changing tau value.

And eventually the big question:
You: "What the heck is this thing good for?!"
Me: "Well, actually...I´ve no clue^^"
You: "..."
Me: " laugh "

Have fun!

Posted By: Rondidon

Re: circular s-curve function [HLSL] - 02/08/11 20:51

What the heck is this thing good for?!
Posted By: Joozey

Re: circular s-curve function [HLSL] - 02/08/11 20:54

LINERIDER!
Posted By: Quad

Re: circular s-curve function [HLSL] - 02/08/11 21:29

movement of particle effects, nice looking spells etc.

also you could use the graph you get for alot of other stuff, speed, volume, area etc.
Posted By: Clemens

Re: circular s-curve function [HLSL] - 02/08/11 21:41

ant not to forget: learning (to program with) mathematics ... laugh
Posted By: fogman

Re: circular s-curve function [HLSL] - 02/08/11 22:09

add: Doing fancy procedural texture stuff just for the sake of it. wink
Posted By: MrGuest

Re: circular s-curve function [HLSL] - 02/09/11 13:11

Originally Posted By: Rondidon
What the heck is this thing good for?!
People with imagination...
© 2024 lite-C Forums