Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, 7th_zorro, VoroneTZ, Quad), 901 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Voronoi Cell Position #441839
06/04/14 14:42
06/04/14 14:42
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
Hi,
I converted this shader from glsl into hlsl.
It gives the distance and a gradient from the input coordinates to the cell center in relation to the voronoi cell to which it belongs to.
Don't ask me how the math works here. I saw this shader had a basic understanding and converted it. It works great.
I have only added the id to the original to color the cells differently.

Code:
float2 hash2(float2 p)
{
	return tex2D(permSampler2d, (p + 0.5) / 256.0).rg;
}

float4 voronoi( in float2 x)
{
	float2 n = floor(x);
	float2 f = frac(x);

	//----------------------------------
	// first pass: regular voronoi
	//----------------------------------
	float2 mg;
	float2 mr;
	
	float id;

	float md = 8.0;
	
	for( int j = -1; j < 2; j++ )
	{
		for( int i = -1; i < 2; i++ )
		{
			float2 g = float2(i, j);
			float2 o = hash2( n + g );
			
			float2 r = g + o - f;
			float d = dot(r, r);

			if( d < md )
			{
				md = d;
				mr = r;
				mg = g;
				id = length(o);
			}
		}
	}

	//----------------------------------
	// second pass: distance to borders
	//----------------------------------
	
	md = 8.0;
	for( int j=-2; j<=2; j++ )
	{
		for( int i=-2; i<=2; i++ )
		{
			float2 g = mg + float2(i, j);
			float2 o = hash2( n + g );
			
			float2 r = g + o - f;

			if( dot(mr - r, mr - r) > 0.00001 )
			md = min( md, dot( 0.5 * ( mr + r ), normalize( r - mr ) ) );
		}
	}

	return float4( md, mr, id);
}


float4 postprocessing_noise( float2 Tex : TEXCOORD0 ) : COLOR0 
{	
	float2 p;
	p.x = Tex.x + vecSkill1[0]; // vecSkill - offset_x
	p.y = Tex.y + vecSkill1[1]; // vecSkill - offset_y
	float4 c = voronoi( vecSkill1[2] * p ); // vecSkill frequency

[...]



What I need:
I need the distance of the cell core or the cell middle to the middle of the image. I have some trouble to bring the voronoi point into the 0.0 - 1.0 space.
why?
I want to create an island generator. The cells outside the defined range should be black and the rest white (don't worry randomness can be achieved through a second permutation map). The color should be changed by cell, not by pixel coordinate.

Re: Voronoi Cell Position [Re: jenGs] #442116
06/12/14 00:38
06/12/14 00:38
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
ha, finally I solved this.
So stupid.
n + g is the grid id.
a quick distance check to any point (0 .. 1) multiplicated with the frequency/scaling factor gives me the desired results.


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1