MP3D Engine Alpha 33

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Sveinung
Enthusiast
Enthusiast
Posts: 142
Joined: Tue Oct 07, 2003 11:03 am
Location: Bergen, Norway

Re: MP3D Engine Alpha 32

Post by Sveinung »

A little something...

Code: Select all

;Motion trailing
;By Sveinung

Procedure paintImg(col.i,sz.i)
  StartDrawing(ImageOutput(0))
  Box(0,0,256,256,col)
  Box(sz,sz,256-(2*sz),256-(2*sz),0)
  StopDrawing()
EndProcedure

MP_Graphics3DWindow(0,0,640,480,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)

cam=MP_CreateCamera()
MP_PositionCamera(cam,0,0,-3)

lig=MP_CreateLight(2)
MP_PositionEntity(lig,0,5,-5)
MP_LightSetRange(lig,7)

;Texture
CreateImage(0,256,256)
paintImg(RGB(255,255,255),1)
tx1=MP_ImageToTexture(0)
paintImg(RGB(200,200,200),1)
tx2=MP_ImageToTexture(0)
paintImg(RGB(150,150,150),1)
tx3=MP_ImageToTexture(0)
paintImg(RGB(100,100,100),1)
tx4=MP_ImageToTexture(0)
paintImg(RGB(50,50,50),1)
tx5=MP_ImageToTexture(0)
FreeImage(0)

;cubes
cube1=MP_CreateCube()
MP_EntitySetTexture(cube1,tx1,0)
MP_MeshSetAlpha (cube1,1)
cube2=MP_CreateCube()
MP_EntitySetTexture(cube2,tx2,0)
MP_MeshSetAlpha (cube2,1)
cube3=MP_CreateCube()
MP_EntitySetTexture(cube3,tx3,0)
MP_MeshSetAlpha (cube3,1)
cube4=MP_CreateCube()
MP_EntitySetTexture(cube4,tx4,0)
MP_MeshSetAlpha (cube4,1)
cube5=MP_CreateCube()
MP_EntitySetTexture(cube5,tx5,0)
MP_MeshSetAlpha (cube5,1)

;loop
Repeat
  WindowEvent()
  ang.f+1
  xrot.f=ang*1.3
  yrot.f=ang*1.4
  zrot.f=ang*1.8
  MP_RotateEntity(cube1,MP_LimitTo360(xrot),MP_LimitTo360(yrot),MP_LimitTo360(zrot))
  MP_RotateEntity(cube2,MP_LimitTo360(xrot-5),MP_LimitTo360(yrot-5),MP_LimitTo360(zrot-5))
  MP_RotateEntity(cube3,MP_LimitTo360(xrot-10),MP_LimitTo360(yrot-10),MP_LimitTo360(zrot-10))
  MP_RotateEntity(cube4,MP_LimitTo360(xrot-15),MP_LimitTo360(yrot-15),MP_LimitTo360(zrot-15))
  MP_RotateEntity(cube5,MP_LimitTo360(xrot-20),MP_LimitTo360(yrot-20),MP_LimitTo360(zrot-20))
  MP_RenderWorld()
  MP_Flip()
Until MP_KeyDown(#PB_Key_Escape)

Regards
Sveinung
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

Where is MPZ? I want to know the progress he has made so far.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: MP3D Engine Alpha 32

Post by luis »

Mythros wrote:Where is MPZ? I want to know the progress he has made so far.
Let's make a thread about it!
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: MP3D Engine Alpha 32

Post by Kuron »

Mythros wrote:Where is MPZ? I want to know the progress he has made so far.
He is with TheFool :wink:
Best wishes to the PB community. Thank you for the memories. ♥️
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hello,

i was in holiday and skiing. Before my holiday i work on a new command MP_ParticleAcceleration(Entity, VarVelocity.f) ; Acceleration of particle , a new help file with a nice translation from Peter and some bug fixes.

Here comes 5 shader from the http://glsl.heroku.com/ website (14 000 open gl shader) i have translated them with my new Shaderconverter program. The program translated GLSL to HLSL for mp3d dx9 shader functions. You can test the shader with my shadereditore ...

Greetings Michael

Code: Select all

float4x4 worldViewProjI; float postfx;
#ifdef GL_ES
// precision mediump float;
#endif

uniform float time;
uniform float2 mouse;
uniform float2 resolution = float2(933,511) ; // Screensize;

// drip test --joltz0r

float check (float2 p, float size) {
	float c = float(int(floor(cos(p.x/size)*10000.0)*ceil(cos(p.y/size)*10000.0)))*0.0001;
	return clamp(c, 0.3, 0.7);
}
float4 main(float2 gl_FragCoord: TEXCOORD0, float4 gl_FragColor: COLOR ) : COLOR {
if (postfx == 1) gl_FragCoord.x = gl_FragCoord.x + 0.23;

gl_FragCoord.y = 1 - gl_FragCoord.y; gl_FragCoord = gl_FragCoord * resolution;


	float2 p = (( gl_FragCoord.xy / resolution.xy ) - 0.5) * 2.5;
	p.x *= resolution.x/resolution.y;
	float2 i = p;
	
	float c = 0.0;
        float2 sc = float2(sin(time*0.54), cos(time*0.56));
		
	float d = length(p)*10.0;
	float r = atan2(p.x, p.y);
	float len = (1.0-length(p*0.5));
	float dist = (1.0-sin(pow(d,1.25)+(cos(d-time*2.5)*4.0)));
	float pc = check(p, 0.125);
        i += float2(dist*0.05,dist*0.05);
	float ic = check(i, 0.125);

	c = 1.0/((length(p+sc)*pc)+((length(i+sc)*ic*8.0)));
	gl_FragColor = float4( float3(c,c,c), 1.0 );
            return gl_FragColor;


}
// Vertex Shader
struct VS_INPUT
{
    float3 position	: POSITION;
    float2 texture0     : TEXCOORD0;
};

struct VS_OUTPUT
{
     float4 hposition : POSITION;
     float2 texture0  : TEXCOORD0;
};

VS_OUTPUT myvs( VS_INPUT IN )
{
    VS_OUTPUT OUT;
    if (postfx == 0) {
      OUT.hposition = mul( worldViewProjI, float4(IN.position.x ,IN.position.y ,IN.position.z, 1) ); 
    } else {
      OUT.hposition = float4(IN.position.x ,IN.position.y ,IN.position.z, 1);
    }    
    OUT.texture0 = IN.texture0;
    return OUT;
}
// ---------------------------------------------
technique Start
{
    pass p1  
    {
        VertexShader = compile vs_3_0 myvs();
        PixelShader = compile ps_3_0 main();
    }
}

Code: Select all

float4x4 worldViewProjI; float postfx;
#ifdef GL_ES
// precision mediump float;
#endif

// Rainbow Dash rendered by mapping signs of improper equations of graphic primitives,
// mainly lines, circles, and ellipses.
// (c) mniip 2014

uniform float time;
uniform float2 mouse;
uniform float2 resolution = float2(933,511) ; // Screensize;
static float2 m;

  float3 COLOR_LINE = float3(0x77, 0xB0, 0xE0) / 255.0;
  float3 COLOR_MANELINE = float3(0x1E, 0x98, 0xD3) / 255.0;
  float3 COLOR_BODY = float3(0x9E, 0xDB, 0xF9) / 255.0;
  float3 COLOR_MANE1 = float3(0xEE, 0x41, 0x44) / 255.0;
  float3 COLOR_MANE2 = float3(0xF3, 0x70, 0x33) / 255.0;
  float3 COLOR_MANE3 = float3(0xFD, 0xF6, 0xAF) / 255.0;
  float3 COLOR_MANE4 = float3(0x62, 0xBC, 0x4D) / 255.0;
  float3 COLOR_MANE5 = float3(0x67, 0x2F, 0x89) / 255.0;
  float3 COLOR_EYEBROW = float3(0x00, 0x00, 0x00) / 255.0;
  float3 COLOR_IRIS1 = float3(0xC6, 0x00, 0x6F) / 255.0;
  float3 COLOR_IRIS2 = float3(0x46, 0x00, 0x25) / 255.0;
  float3 COLOR_BLACK = float3(0x00, 0x00, 0x00) / 255.0;
  float3 COLOR_WHITE = float3(0xFF, 0xFF, 0xFF) / 255.0;

bool linee(float2 p, float2 a, float2 b)
{
	return (p.x - a.x) * (a.y - b.y) > (p.y - a.y) * (a.x - b.x);
}

bool circle(float2 p, float2 a, float r)
{
	return (p.x - a.x) * (p.x - a.x) + (p.y - a.y) * (p.y - a .y) > r * r;
}

bool ellipse(float2 p, float2 a, float2 r)
{
	return (p.x - a.x) * (p.x - a.x) / r.x / r.x + (p.y - a.y) * (p.y - a .y) / r.y / r.y > 1.0;
}



bool ear(inout float3 c, float2 p)
{
	bool A = circle(p, float2(638, 664), 362.);
	bool B = circle(p, float2(1075, 641), 323.);
	bool C = circle(p, float2(646, 708), 378.);
	if(!A && !B && !C)
	{
		bool D = circle(p, float2(637, 662), 345.);
		bool E = circle(p, float2(1109, 588), 363.);
		bool F = circle(p, float2(651, 692), 269.);
		bool G = circle(p, float2(395, 732), 516.);
		if(D || E || (!F && G))
			c = COLOR_LINE;
		else
			c = COLOR_BODY;
		return true;
	}
	return false;
}

bool mane(inout float3 c, float2 p)
{
	bool A = circle(p, float2(434, 460), 514.);
	bool B = circle(p, float2(254, 110), 903.);
	bool C = circle(p, float2(384, 228), 668.);
	bool D = circle(p, float2(475, 505), 425.);
	bool E = circle(p, float2(513, 281), 536.);
	bool F = circle(p, float2(777, 435), 360.);
	bool G = circle(p, float2(915, 174), 554.);
	bool H = circle(p, float2(659, 444), 536.);
	bool I = circle(p, float2(-201, 601), 337.);
	bool J = linee(p, float2(-253, 218), float2(176, 590));
	bool K = circle(p, float2(-164, 1212), 882.);
	bool L = circle(p, float2(650, 764), 80.); // lol weird
	if(!A && !B && (C || (!D && E) || (!F && G) || (!H || (I && !J)) && !K) || !L)
	{
		bool M = circle(p, float2(422, 434), 518.);
		bool N = circle(p, float2(372, 261), 647.);
		bool O = circle(p, float2(491, 499), 425.);
		bool P = circle(p, float2(395, 377), 402.);
		bool Q = circle(p, float2(790, 454), 352.);
		bool R = circle(p, float2(891, 216), 527.);
		bool S = circle(p, float2(680, 453), 536.);
		bool T = circle(p, float2(-217, 1332), 992.);
		bool U = circle(p, float2(-150, 586), 305.);
		bool V = linee(p, float2(280, 404), float2(119, 566));
		if((!M && N) || ((!O && P || !Q && !M) && R) || (!S && !M && !T) || (U && !T && V))
		{
			if(circle(p, float2(491, 84), 764.))
				c = COLOR_MANE1;
			else
				if(circle(p, float2(686, 204), 576.))
					c = COLOR_MANE2;
				else
					c = COLOR_MANE3;
		}
		else
			c = COLOR_MANELINE;
		return true;
	}
	return false;
}

bool mane2(inout float3 c, float2 p)
{
	bool A = circle(p, float2(607, 464), 306.);
	bool B = circle(p, float2(777, 485), 339.);
	bool C = circle(p, float2(1181, -127), 463.);
	bool D = circle(p, float2(-433, 198), 1442.);
	bool E = linee(p, float2(554, -80), float2(1055, -80));
	if((A && !B || !C) && !D && E)
	{
		bool F = circle(p, float2(613, 461), 319.);
		bool G = circle(p, float2(769, 486), 323.);
		bool H = circle(p, float2(1195, -123), 454.);
		bool I = circle(p, float2(288, 485), 691.);
		bool J = circle(p, float2(122, 278), 864.);
		if((F && !G || !H) && !I && !J)
			c = COLOR_MANE4;
		else
		{
			bool K = circle(p, float2(388, 235), 607.);
			bool L = circle(p, float2(416, 87), 570.);
			if(K && !L)
				c = COLOR_MANE5;
			else
				c = COLOR_MANELINE;
		}
		return true;
	}
	return false;
}

bool face(inout float3 c, float2 p)
{
	bool A = circle(p, float2(588, 396), 357.);
	bool B = linee(p, float2(325, 74), float2(887, 122));
	bool C = ellipse(p, float2(489, 237), float2(287, 166));
	bool D = circle(p, float2(209, 437), 163.);
	if(!A && B || !C && D)
	{
		bool E = ellipse(p, float2(536, 253), float2(315, 170));
		bool F = circle(p, float2(500, 921), 828.);
		bool G = circle(p, float2(220, 367), 110.);
		bool H = linee(p, float2(201, 454), float2(658, 108));
		bool I = linee(p, float2(237, 115), float2(363, 238));
		bool J = ellipse(p, float2(283, 204), float2(68, 57));
		bool K = ellipse(p, float2(253, 192), float2(102, 70));
		bool L = circle(p, float2(285, 228), 19.);
		bool M = circle(p, float2(281, 236), 19.);
		if((!E && !F && G || H) && (I || !J || K) && (L || !M))
			c = COLOR_BODY;
		else
			c = COLOR_LINE;
		return true;
	}
	return false;
}

bool eye1(inout float3 c, float2 p)
{
	// skewed ellipse please ignore
#define SQR(q) ((q) * (q))
	bool A = SQR((p.x - 590.0) / 150.0 - (p.y - 378.0) / 900.0) + SQR((p.y - 378.0) / 180.0) < 1.0;
	if(A)
	{
		bool B = SQR((p.x - 593.0) / 149.0 - (p.y - 382.0) / 900.0) + SQR((p.y - 361.0) / 180.0) < 1.0;
		if(B)
		{
			float2 d = m - float2(580, 360);
			if(length(d) > 60.0)
			   d = d / length(d) * 60.0;
			bool C = ellipse(p, float2(580, 360) + d, float2(112, 162));
			if(C)
				c = COLOR_WHITE;
			else
			{
				bool D = ellipse(p, float2(551, 305) + d, float2(19, 26));
				bool E = ellipse(p, float2(601, 410) + d, float2(35, 57));
				if(D && E)
				{
					bool F = ellipse(p, float2(580, 360) + d * 1.3, float2(71, 126));
					if(F)
						c = lerp(COLOR_IRIS1, COLOR_IRIS2, SQR((p.y - 360.0 - d.y) / 252.0 + 0.5));
					else
						c = COLOR_BLACK;
				}
				else
					c = COLOR_WHITE;
			}
		}
		else
			c = COLOR_EYEBROW;
		return true;
	}
	// rotating ellipses hacks, nothing to see here
	bool G = ellipse(p, float2(757, 430), float2(40, 5));
	bool H = ellipse(float2(p.x + p.y * 0.3, p.x * -0.3 + p.y), float2(890, 260), float2(40, 6));
	bool I = ellipse(float2(p.x + p.y * 0.5, p.x * -0.5 + p.y), float2(990, 175), float2(40, 7));
	if(!G || !H || !I)
	{
		c = COLOR_BLACK;
		return true;
	}
	return false;
}

bool eye2(inout float3 c, float2 p)
{
	bool A = linee(p, float2(207, 460), float2(323, 265));
	bool B = circle(p, float2(213, 434), 158.);
	bool C = circle(p, float2(739, 417), 500.);
	bool D = ellipse(p, float2(289, 444), float2(50, 144));
	if(!A && !B && !C || !D)
	{
		bool E = ellipse(p, float2(285, 390), float2(47, 184));
		if(!E)
		{
			float2 d = m - float2(290, 360);
			if(length(d) > 60.0)
			   d = d / length(d) * 60.0;
			d *= float2(0.33, 1.0);
			bool F = ellipse(p, float2(290, 360) + d, float2(50, 162));
			if(F)
				c = COLOR_WHITE;
			else
			{
				bool D = ellipse(p, float2(304, 446) + d, float2(17, 41));
				bool E = ellipse(p, float2(278, 354) + d, float2(11, 24));
				if(D && E)
				{
					bool F = ellipse(p, float2(290, 360) + d * 1.3, float2(42, 126));
					if(F)
						c = lerp(COLOR_IRIS1, COLOR_IRIS2, SQR((p.y - 360.0 - d.y) / 252.0 + 0.5));
					else
						c = COLOR_BLACK;
				}
				else
					c = COLOR_WHITE;
			}
		}
		else
			c = COLOR_EYEBROW;
		return true;
	}
	return false;
}

bool neck(inout float3 c, float2 p)
{
	bool A = circle(p, float2(1247, -28), 638.);
	bool B = circle(p, float2(353, 258), 638.);
	bool C = linee(p, float2(554, -80), float2(1055, -80));
	if(!A && !B && C)
	{
		bool D = circle(p, float2(1235, -21), 606.);
		if(D)
			c = COLOR_LINE;
		else
			c = COLOR_BODY;
		return true;
	}
	return false;
}

float2 transform(float2 x)
{
    return (x - resolution / 2.0) / resolution.y * 1000.0 + 500.0;
}

float4 main(float2 gl_FragCoord: TEXCOORD0, float4 gl_FragColor: COLOR ) : COLOR
{
if (postfx == 1) gl_FragCoord.x = gl_FragCoord.x + 0.23;

gl_FragCoord.y = 1 - gl_FragCoord.y; gl_FragCoord = gl_FragCoord * resolution;

	m = transform(mouse * resolution);
	float2 p = transform(gl_FragCoord.xy);
	float3 c = float3(1, 1, 1);
//	ear(c, p) || mane(c, p) || mane2(c, p) || eye1(c, p) || eye2(c, p)  || face(c, p) || neck(c, p);
                neck(c, p) || face(c, p) || eye2(c, p)  ||eye1(c, p) ||mane2(c, p) || mane(c, p) ||ear(c, p);	return  float4(c, 1);
}
// Vertex Shader
struct VS_INPUT
{
    float3 position	: POSITION;
    float2 texture0     : TEXCOORD0;
};

struct VS_OUTPUT
{
     float4 hposition : POSITION;
     float2 texture0  : TEXCOORD0;
};

VS_OUTPUT myvs( VS_INPUT IN )
{
    VS_OUTPUT OUT;
    if (postfx == 0) {
      OUT.hposition = mul( worldViewProjI, float4(IN.position.x ,IN.position.y ,IN.position.z, 1) ); 
    } else {
      OUT.hposition = float4(IN.position.x ,IN.position.y ,IN.position.z, 1);
    }    
    OUT.texture0 = IN.texture0;
    return OUT;
}
// ---------------------------------------------
technique Start
{
    pass p1  
    {
        VertexShader = compile vs_3_0 myvs();
        PixelShader = compile ps_3_0 main();
    }
}

Code: Select all

float4x4 worldViewProjI; float postfx;
// precision highp float;
uniform float2 resolution = float2(933,511) ; // Screensize;
uniform float time;

float4 main(float2 gl_FragCoord: TEXCOORD0, float4 gl_FragColor: COLOR ) : COLOR {
if (postfx == 1) gl_FragCoord.x = gl_FragCoord.x + 0.23;

gl_FragCoord.y = 1 - gl_FragCoord.y; gl_FragCoord = gl_FragCoord * resolution;

    float2 uv = gl_FragCoord.xy / resolution.xy;
    uv = uv * 2.0 - 1.0;
    uv.x *= resolution.x / resolution.y;

    float c = length(float2(0.0, 0.0) - uv) - 0.25;
    float d = c;
    float f = log(sin(atan2(uv.y, uv.x) * 3.0 + time * 3.0) * 2.0);
    c = smoothstep(0.0, 0.3, sin(c * 3.141592 * 10.0 + f));
    c *= (sin(atan2(uv.y, uv.x) * 3.0 + d + time * 3.0));
    float3 col = float3(c,c,c);
    gl_FragColor = float4(col, 1.0);
            return gl_FragColor;

}
// Vertex Shader
struct VS_INPUT
{
    float3 position	: POSITION;
    float2 texture0     : TEXCOORD0;
};

struct VS_OUTPUT
{
     float4 hposition : POSITION;
     float2 texture0  : TEXCOORD0;
};

VS_OUTPUT myvs( VS_INPUT IN )
{
    VS_OUTPUT OUT;
    if (postfx == 0) {
      OUT.hposition = mul( worldViewProjI, float4(IN.position.x ,IN.position.y ,IN.position.z, 1) ); 
    } else {
      OUT.hposition = float4(IN.position.x ,IN.position.y ,IN.position.z, 1);
    }    
    OUT.texture0 = IN.texture0;
    return OUT;
}
// ---------------------------------------------
technique Start
{
    pass p1  
    {
        VertexShader = compile vs_3_0 myvs();
        PixelShader = compile ps_3_0 main();
    }
}

Code: Select all

float4x4 worldViewProjI; float postfx;
#ifdef GL_ES
// precision mediump float;
#endif

uniform float time;
uniform float2 mouse;
uniform float2 resolution = float2(933,511) ; // Screensize;

float2 hash( float2 p )
{
	p = float2( dot(p,float2(127.1,311.7)), dot(p,float2(269.5,183.3)));

	return -1.0 + 2.0*frac(sin(p)*43758.5453123);
}

float noise( in float2 p )
{
	float2 i = floor( p );
	float2 f = frac( p );
	float2 u = f*f*f*(6.0*f*f - 15.0*f + 10.0);
	return lerp( lerp( dot( hash( i + float2(0.0,0.0) ), f - float2(0.0,0.0) ), 
		         dot( hash( i + float2(1.0,0.0) ), f - float2(1.0,0.0) ), u.x),
	            lerp( dot( hash( i + float2(0.0,1.0) ), f - float2(0.0,1.0) ), 
		         dot( hash( i + float2(1.0,1.0) ), f - float2(1.0,1.0) ), u.x), u.y) * 0.5 + 0.5;
}

float fbm( in float2 p ) 
{
	float ret = 0.0;
	ret += noise( p * 1.0 ) * 1.0;
	ret += noise( p * 2.0 ) * 0.5;
	ret += noise( p * 4.0 ) * 0.25;
	ret += noise( p * 8.0 ) * 0.125;
	ret *= 0.533333;
	return ret;
}


float4 main(float2 gl_FragCoord: TEXCOORD0, float4 gl_FragColor: COLOR ) : COLOR {
if (postfx == 1) gl_FragCoord.x = gl_FragCoord.x + 0.23;

gl_FragCoord.y = 1 - gl_FragCoord.y; gl_FragCoord = gl_FragCoord * resolution;


	float2 uv = gl_FragCoord.xy / resolution.xy * 2.0 - 1.0;
	uv.x *= resolution.x / resolution.y;
	float2 m = mouse * 2.0 - 1.0;
	m.x *= resolution.x / resolution.y;
	float2 p = floor(uv);
	float2 f = frac(uv);
	float3 normal;
	float offset = 0.0001;
	float mult = 10.0;
	float2 vl = float2(uv.x - offset, uv.y) * mult;
	float2 vr = float2(uv.x + offset, uv.y) * mult;
	float2 vu = float2(uv.x, uv.y - offset) * mult;
	float2 vd = float2(uv.x, uv.y + offset) * mult;
	
	float hl = fbm(vl);
	float hr = fbm(vr);
	float hu = fbm(vu);
	float hd = fbm(vd);
	
	float3 vlh = float3(vl.x, vl.y, hl);
	float3 vrh = float3(vr.x, vr.y, hr);
	float3 vuh = float3(vu.x, vu.y, hu);
	float3 vdh = float3(vd.x, vd.y, hd);
	
	normal = normalize(cross(vlh - vrh, vuh - vdh));
	
	float3 color;
	float3 lightDir = normalize(-float3(uv.x - m.x, uv.y - m.y, -0.4));
	float3 eye = float3(0.0, 0.0, -1.0);
	float3 view = normalize(float3(uv.x, uv.y,  0.0) - eye);
	float3 ref = reflect(view, normal);
	float3 d = max(float3(0,0,0), dot(normal, lightDir));
	float3 s = pow(d, float3(7,7,7));
	color = d*0.5 + s;
	gl_FragColor = float4(float3(pow(color, float3(1.0, 0.8, 0.7))), 1.0);
            return gl_FragColor;

}
// Vertex Shader
struct VS_INPUT
{
    float3 position	: POSITION;
    float2 texture0     : TEXCOORD0;
};

struct VS_OUTPUT
{
     float4 hposition : POSITION;
     float2 texture0  : TEXCOORD0;
};

VS_OUTPUT myvs( VS_INPUT IN )
{
    VS_OUTPUT OUT;
    if (postfx == 0) {
      OUT.hposition = mul( worldViewProjI, float4(IN.position.x ,IN.position.y ,IN.position.z, 1) ); 
    } else {
      OUT.hposition = float4(IN.position.x ,IN.position.y ,IN.position.z, 1);
    }    
    OUT.texture0 = IN.texture0;
    return OUT;
}
// ---------------------------------------------
technique Start
{
    pass p1  
    {
        VertexShader = compile vs_3_0 myvs();
        PixelShader = compile ps_3_0 main();
    }
}

Code: Select all

float4x4 worldViewProjI; float postfx;
uniform float time;

float Pi = 3.14159;

float sinApprox(float x) {
    x = Pi + (2.0 * Pi) * floor(x / (2.0 * Pi)) - x;
    return (4.0 / Pi) * x - (2.0 / Pi / Pi) * x * abs(x);
}

float cosApprox(float x) {
    return sinApprox(x + 0.1 * Pi);
}

float4 main(float2 gl_FragCoord: TEXCOORD0, float4 gl_FragColor: COLOR ) : COLOR
{

if (postfx == 1) gl_FragCoord.x = gl_FragCoord.x + 0.23;

gl_FragCoord.y = 1 - gl_FragCoord.y;

float2 p=gl_FragCoord*.2+.7;

	for(int i=1;i<50;i++)
	{
		float2 newp=p;
		newp.x+=0.6/float(i)*sin(float(i)*p.y+time/40.0+0.3*float(i))+1.0;
		newp.y+=0.6/float(i)*sin(float(i)*p.x+time/40.0+0.3*float(i+10))-1.4;
		p=newp;
	}
	float3 col=float3(0.5*sin(3.0*p.x)+0.5,0.5*sin(3.0*p.y)+0.5,sin(p.x+p.y));
	gl_FragColor=float4(col, 1.0);
            return gl_FragColor;

}
// Vertex Shader
struct VS_INPUT
{
    float3 position	: POSITION;
    float2 texture0     : TEXCOORD0;
};

struct VS_OUTPUT
{
     float4 hposition : POSITION;
     float2 texture0  : TEXCOORD0;
};

VS_OUTPUT myvs( VS_INPUT IN )
{
    VS_OUTPUT OUT;
    if (postfx == 0) {
      OUT.hposition = mul( worldViewProjI, float4(IN.position.x ,IN.position.y ,IN.position.z, 1) ); 
    } else {
      OUT.hposition = float4(IN.position.x ,IN.position.y ,IN.position.z, 1);
    }    
    OUT.texture0 = IN.texture0;
    return OUT;
}
// ---------------------------------------------
technique Start
{
    pass p1  
    {
        VertexShader = compile vs_3_0 myvs();
        PixelShader = compile ps_3_0 main();
    }
}
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: MP3D Engine Alpha 32

Post by dobro »

has about : MP_Graphics3D (800,600,32,0)

he'll be fine, can indicate a WindowID in the parameters ...
so, we will be able to create a 3D window in an existing window of a prg Purebasic ...

ex : MP_Graphics3D (x,y,800,600,32,WindowsId(xxx)) :)

Thank you for your work
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi Dobro,

in MP3D you have two commands for these:

MP_ScreenToHandle(WindowID(0) ) -> get the pb window
MP_UsePB3D(pd3d) -> to get the dx9.IDirect3DDevice9

I hope this help :)

Greetings Michael

example for MP_ScreenToHandle(WindowID(0) )

Code: Select all

If OpenWindow(0, 0, 0, 400, 230, "PBWindow", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  
  ;If OpenWindow(0, 0, 0, 322, 150, "ContainerGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
   ; ContainerGadget(0, 8, 8, 306, 133, #PB_Container_Raised)
   ;   MP_ScreenToHandle( GadgetID(0))
   ; CloseGadgetList()
      
   MP_ScreenToHandle(WindowID(0) )
  
  camera=MP_CreateCamera() ; Kamera erstellen

    light=MP_CreateLight(1) ; Es werde Licht

    Mesh=MP_CreateCube() ; Und jetzt eine Würfel
 
    MP_PositionEntity (Mesh,0,0,3) ; Position des Würfels

    While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen

        MP_TurnEntity (Mesh,0.1,0.1,0.1) ; dreh den Würfel
        MP_RenderWorld() ; Erstelle die Welt
        MP_Flip () ; Stelle Sie dar

    Wend
  EndIf 
example for MP_UsePB3D(pd3d)

Code: Select all

InitSprite()

OpenWindow(0, 0, 0, 800, 600, "Screen", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

Font = FontID(LoadFont(#PB_Any, "Arial", 192))
CreateSprite(1, 256, 256, #PB_Sprite_AlphaBlending )
StartDrawing(SpriteOutput(1))
  DrawingFont(Font) : DrawingMode(1)
  Box(0,0,256,256,$FF0000)
  DrawText(0,0,"F", $0000FF, 0)
StopDrawing()

Define pd3d.IDirect3DDevice9
EnableASM

CompilerIf  #PB_Compiler_Processor = #PB_Processor_x86
  
  !extrn _PB_Screen_Direct3DDevice ; Get the DX9 device of PB 
  !MOV dword EAX, [_PB_Screen_Direct3DDevice]
  !MOV dword [v_pd3d],EAX

CompilerElse
  
  !extrn PB_Screen_Direct3DDevice ; Get the DX9 device of PB 
  !MOV dword EAX, [PB_Screen_Direct3DDevice]
  !MOV dword [v_pd3d],EAX
  
CompilerEndIf

DisableASM

MP_UsePB3D(pd3d)

;MP_SetRenderState(22,1) ; Make the Sprite3D looking from two sizes

Sprite = MP_LoadSprite("c:\Programme\PureBasic\Examples\Sources\Data\Geebee2.bmp")
 
Repeat
  
  wire + 1
  
  If Wire > 100
    MP_Wireframe(1)
  Else
    MP_Wireframe(0)
  EndIf
  If Wire > 200 : Wire = 0 : EndIf 
  
  ClearScreen(0)

  #HalfSize = 150

  a.f = ElapsedMilliseconds()/1000
     
  ZoomSprite(1,200*Sin(a),200)
  DisplaySprite(1, 400-100*Sin(a), 200)
  
  ;- MP3D Sprite Part
  MP_TurnSprite(Sprite, 1)
  MP_DrawSprite(Sprite, 40, 40,$FF)
  MP_RenderSprite()
  ;- 
  
  FlipBuffers()  
  
Until WindowEvent() = #PB_Event_CloseWindow 
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: MP3D Engine Alpha 32

Post by dobro »

Very Thanks :)

why this code bug on mp_Close ??


This is a code pushed to the extreme, but I have a problem of the same kind on my Current Code :)

I have to spend a window of my prg has a fullscreen screen
and to leave to go to the window, and then again at the request

mp_Close() does not seem to release resources ? :)

Code: Select all


for i =1 to 5
	MP_Graphics3D (800,600,32,0) ; Erstelle ein Vollbild 3D Fenster mit 800x600 Punkten und 32 Farben
	
	
	
	While Zaehler < 60 
		Zaehler + 1
		MP_RenderWorld () ; Hier gehts los
		MP_Flip () ; 
	Wend
	
	MP_Close()
	
	
next i; EPB
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi Dobro,

it is a "little" stupid bug. I found the bug an solve them. I will actualize the beta version tonight and inform you here...

Greetings
Michael
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: MP3D Engine Alpha 32

Post by dobro »

cool :)

ps:
a question I ask myself,

there is a very strong resemblance between MP3D and Dreamotion3D (motor deceased) ...

same manner of implementation, and almost the same functions names :)
a link between the two engines? :)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi,

version beta with function 49) is out.

x86 for PB 511 and older
http://www.flasharts.de/mpz/mp33/pb511/MP3D_Library.zip

x86 for pb 520 and newer
http://www.flasharts.de/mpz/mp33/pb520/MP3D_Library.zip

@dobro -> MP_Close() crashed if used two times, problem solved

* there is a very strong resemblance between MP3D and Dreamotion3D (motor deceased) ...
No, the first commands names i got was names from Blitzbasic3d. Then after some month of programming other users helps with ideas of names (thx to DrShrek for much of these names ).

@N_Gnom -> MP_EntityLookAt (Entity,x.f,y.f,z.f[,XGrad.f,YGrad.f]), has now two optional paramteres xgrad and ygrad

@ParnosDias van Boston -> MP_ParticleAcceleration(Entity, VarVelocity.f) ; Acceleration of particle

her comes 2 testcodes:

greetings
Michael

MP_ParticleAcceleration(Entity, VarVelocity.f) ; Acceleration of particle

Code: Select all

MP_Graphics3D (640,480,0,3) ; Erstelle ein WindowsFenster #Window = 0
SetWindowTitle(0, "LookAt Demo, Push Space and the camera is following") 

Camera=MP_CreateCamera() ; Kamera erstellen

light=MP_CreateLight(1) ; Es werde Licht

Max = 30 ; Was der Rechner kann = ?
Dim Cone(Max) 

For n = 0 To Max

  ;Cone(n) = MP_CreateCone (8,2)
  Cone(n) =  MP_CreateTeapot()

    MP_EntitySetColor (Cone(n),RGB(Random(255),Random(255),Random(255)))
    MP_PositionEntity (Cone(n),10-Random(20),10-Random(20),10+Random(20))
    
Next n

Mesh=MP_CreateCube() ; Und jetzt eine Würfel
 
MP_AmbientSetLight (RGB(123,222,204)) 

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen

    count.f + 0.01
    MP_PositionEntity(Mesh,  Sin(count) * 5, Cos(count) * 5, 20)

    For n = 0 To Max
       MP_EntityLookAt(Cone(n),MP_EntityGetX(Mesh),MP_EntityGetY(Mesh),MP_EntityGetZ(Mesh),0,count*100)
    Next n

    If MP_KeyDown(#PB_Key_Space)=1
       MP_CameraLookAt(Camera,MP_EntityGetX(Mesh),MP_EntityGetY(Mesh),MP_EntityGetZ(Mesh))
    EndIf


    MP_TurnEntity (Mesh,1,1,1) 
    MP_RenderWorld() ; Erstelle die Welt
    MP_Flip () ; Stelle Sie dar

Wend
MP_EntityLookAt (Entity,x.f,y.f,z.f[,XGrad.f,YGrad.f]) ; Parameter XGrad/YGrad als float; optionaler Parameter to turn the Entity

Code: Select all

MP_Graphics3D (640,480,0,3) ; Erstelle ein WindowsFenster #Window = 0
SetWindowTitle(0, "LookAt Demo, Push Space and the camera is following") 

Camera=MP_CreateCamera() ; Kamera erstellen

light=MP_CreateLight(1) ; Es werde Licht

Max = 30 ; Was der Rechner kann = ?
Dim Cone(Max) 

For n = 0 To Max

  ;Cone(n) = MP_CreateCone (8,2)
  Cone(n) =  MP_CreateTeapot()

    MP_EntitySetColor (Cone(n),RGB(Random(255),Random(255),Random(255)))
    MP_PositionEntity (Cone(n),10-Random(20),10-Random(20),10+Random(20))
    
Next n

Mesh=MP_CreateCube() ; Und jetzt eine Würfel
 
MP_AmbientSetLight (RGB(123,222,204)) 

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen

    count.f + 0.01
    MP_PositionEntity(Mesh,  Sin(count) * 5, Cos(count) * 5, 20)

    For n = 0 To Max
       MP_EntityLookAt(Cone(n),MP_EntityGetX(Mesh),MP_EntityGetY(Mesh),MP_EntityGetZ(Mesh),0,count*100)
    Next n

    If MP_KeyDown(#PB_Key_Space)=1
       MP_CameraLookAt(Camera,MP_EntityGetX(Mesh),MP_EntityGetY(Mesh),MP_EntityGetZ(Mesh))
    EndIf


    MP_TurnEntity (Mesh,1,1,1) 
    MP_RenderWorld() ; Erstelle die Welt
    MP_Flip () ; Stelle Sie dar

Wend
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: MP3D Engine Alpha 32

Post by dobro »

mpz wrote: @dobro -> MP_Close() crashed if used two times, problem solved

hum .. no really ... (sorry ) :mrgreen:

subject that I installed the library in the right place .. ? (in UserLibrary ) (in 5.20 )

I always have a problem with the screen in window fashion
the screen closes, but the window is displayed

Code: Select all

for i =1 to 2
	MP_Graphics3D (800,600,32,1) ; Erstelle ein Vollbild 3D Fenster mit 800x600 Punkten und 32 Farben
	
	While Zaehler < 60
		Zaehler + 1
		MP_RenderWorld () ; Hier gehts los
		MP_Flip () ;
	Wend
	MP_Close() ; why no close the window ??   <<<<<<<<<<<<<<
	calldebugger
next i
; EPB


and this code will have to display a fullscreen 2 times
but it displays only the first

the first MP_Close () leaves a gray frame ....
and the second screen does not appear ...

the beep () are only there to control


Code: Select all

;********************************************************************************************
MP_Graphics3D (800,600,32,0)
While Zaehler < 60
	Zaehler + 1
	MP_RenderWorld () ; Hier gehts los
	MP_Flip () ;
Wend
MP_Close()
beep(440,1000) ; let a little Square  ??
;********************************************************************************************
delay( 2000) ; wait 2 secondes
MP_Graphics3D (800,600,32,0) ; no Screen Appear !! ????
MP_RenderWorld ()  ;  <<<<<<<<<<<<< Bug here
MP_Flip () ;


While Zaehler < 60
	Zaehler + 1
	MP_RenderWorld () ; Hier gehts los
	MP_Flip () ;
Wend
MP_Close()
beep(440,1000)

; 

; EPB
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Thanks mpz!!
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi Dobro,

i found a second bug and hope i solve them all. Please check these new lib 8)

x86 for PB 511 and older
http://www.flasharts.de/mpz/mp33/pb511/MP3D_Library.zip

x86 for pb 520 and newer
http://www.flasharts.de/mpz/mp33/pb520/MP3D_Library.zip

The command MP_Close() dont close the windows, only mp3d dx9. Please use the command CloseWindow(0) for these. The reason is you can use a window or a gadget or something else with mp3d and so the command can't close the "first" window. Please see scond example, i think this show what i mean...

Greetings Michael

Your example

Code: Select all

For i =1 To 2
   MP_Graphics3D (800,600,32,1) ; Erstelle ein Vollbild 3D Fenster mit 800x600 Punkten und 32 Farben
   
   While Zaehler < 60
      Zaehler + 1
      MP_RenderWorld () ; Hier gehts los
      MP_Flip () ;
   Wend
   MP_Close() ; why no close the window ??   <<<<<<<<<<<<<<
   
   CloseWindow(0)
   
   CallDebugger
Next i
MP_Close() dont close window(0)

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "ContainerGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
    ContainerGadget(0, 8, 8, 306, 133, #PB_Container_Raised)
      MP_ScreenToHandle( GadgetID(0))
    CloseGadgetList()
      
      
    camera=MP_CreateCamera() ; Kamera erstellen

    light=MP_CreateLight(1) ; Es werde Licht

    Mesh=MP_CreateCube() ; Und jetzt eine Würfel
 
    MP_PositionEntity (Mesh,0,0,3) ; Position des Würfels

    While Zaehler < 120
      Zaehler + 1
        MP_TurnEntity (Mesh,0.1,0.1,0.1) ; dreh den Würfel
        MP_RenderWorld() ; Erstelle die Welt
        MP_Flip () ; Stelle Sie dar

    Wend
    
    MP_Close()
    
    Repeat
    Event = WaitWindowEvent()

    If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndIf

  Until Quit = 1
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: MP3D Engine Alpha 32

Post by dobro »

Thanks :)

But the problem is still present in this code: (Read the Comment ) :)

Code: Select all

;********************************************************************************************

MP_Graphics3D (800,600,32,0)
While Zaehler < 60
	Zaehler + 1
	MP_RenderWorld () ; Hier gehts los
	MP_Flip () ;
Wend
MP_Close()
beep(440,1000) ; let a little Square  ??
;********************************************************************************************
delay( 2000) ; wait 2 secondes
MP_Graphics3D (800,600,32,0) ; no Screen Appear !! ????
MP_RenderWorld ()  ;  <<<<<<<<<<<<< Bug here
MP_Flip () ;


While Zaehler < 60
	Zaehler + 1
	MP_RenderWorld () ; Hier gehts los
	MP_Flip () ;
Wend
MP_Close()
beep(440,1000)

; 



; EPB
or Here : (mode Window)

Code: Select all

;********************************************************************************************

MP_Graphics3D (800,600,32,1)
While Zaehler < 60
	Zaehler + 1
	MP_RenderWorld () ; Hier gehts los
	MP_Flip () ;
Wend
MP_Close()
CloseWindow(0)
beep(440,1000) ; let a little Square  ??
;********************************************************************************************
delay( 2000) ; wait 2 secondes
MP_Graphics3D (800,600,32,1) ; no Screen Appear !! ????
MP_RenderWorld ()  ;  <<<<<<<<<<<<< Bug here
MP_Flip () ;


While Zaehler < 60
	Zaehler + 1
	MP_RenderWorld () ; Hier gehts los
	MP_Flip () ;
Wend
MP_Close()
CloseWindow(0)
beep(440,1000)

; 



; EPB
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Post Reply