Skip to content

Fractal – Shader

February 18, 2007

Je met à dispo dans la suite de ce poste, le code d’un shader HLSL pour afficher des fractals simples en temps réel en utilisant une carte graphique avec des pixels shaders 2.0b. Pour le visualiser facilement (si vous n’avez pas les outils pour), je conseille l’outil de nVidia : FX Composer

// Fractal Shader
// (C) 2006 Twinside
#define MANDEL_ITERATION 57
#define JULIA_ITERATION 56
#define SHEEP_ITERATION 51
#define SHEEJ_ITERATION 50

float	scale = 3.0f;
float2	origin = (0.65, 0.50);
float2	juliaConf = (0.3 , 0.3);

float2 ComplexMul( float2 op1, float2 op2 )
{
	return float2( op1.x * op2.x - op1.y * op2.y ,
					op1.x * op2.y + op1.y * op2.x );
}

float MandelBroot( float2 pos )
{
	float2 z = (1,0);
	float	ret = 10000;
	for (int i = 0; i  (2*2) )
			ret = min(ret,i);
	}
	return ret / MANDEL_ITERATION;
}

float Julia( float2 pos )
{
	float	ret = 100000;
	for (int i = 0; i  (2*2) )
			ret = min(ret,i);
	}
	return ret / JULIA_ITERATION;
}

float BurningSheep( float2 pos )
{
	float2 z = (1,0);
	float ret = 10000;
	for (int i = 0; i  (2*2) )
			ret = min(ret,i);
	}
	return ret / SHEEP_ITERATION;
}

float BurningSheepJulia( float2 pos )
{
	float ret = 10000;
	for (int i = 0; i  (2*2) )
			ret = min(ret,i);
	}
	return ret / SHEEJ_ITERATION;
}

float4 mandelBrootPS( float2 PixPos : TEXCOORD0 ) : COLOR
	{ return MandelBroot( (PixPos - origin) * scale ); }

float4 juliaPS( float2 PixPos : TEXCOORD0 ) : COLOR
	{ return Julia( (PixPos - origin) * scale ); }

float4 burningSheepPS( float2 PixPos : TEXCOORD0 ) : COLOR
	{ return BurningSheep( (PixPos - origin) * scale ); }

float4 burningSheepJPS( float2 PixPos : TEXCOORD0 ) : COLOR
	{ return BurningSheepJulia( (PixPos - origin) * scale ); }

technique mandelBrootDisplay
{
	pass P0 { PixelShader = compile ps_2_b mandelBrootPS(); }
}

technique juliaDisplay
{
	pass P0 { PixelShader = compile ps_2_b juliaPS(); }
}

technique burningSheepDisplay
{
	pass P0 { PixelShader = compile ps_2_b burningSheepPS(); }
}

technique burningSheelpJuliaDisplay
{
	pass P0 { PixelShader = compile ps_2_b burningSheepJPS(); }
}
Advertisements

From → Technique

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: