VividGL3D 2D_Example2

Miscellaneous Forums/Blitz Showcase/VividGL3D 2D_Example2

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This one shows Pixel shaded 2d.


Requires a card capable of pixel shaders2.0.

http://www.excess.eclipse.co.uk/2D_Example2.rar

This one shows full screen image blurring. You can move the mouse left/right to make the image appear more shape/out of focus.

You can change the image in the media folder, if you wish.

Also, in the shaders folder is the cg file used(Just a pixel shader) in english script form. SO, you can actually edit play around with the shader and rerun.

If the shader is not compatible you'll get a error.

Here's the blitz source

Include "Includes\VividGL_Lite.bb"
Graphics_Init(640,480,16)
glSetbuffer Graphics_Back()
;-

smokeTex=glLoadTexture("Media\full.jpg",glMipMap)
blurSkin=Skin_BlurTexture() ;Blur texture is a built in skin, using pixel shaders2.0


While Not KeyDown(1)
	glCls(False)

	skin_blurFactor(blurSkin,blurFactor#)
      blurFactor#=(MouseX()/640.)*0.02
	fxSkinOn(blurSkin) ;activate pixel shader fx for all following ops. (For meshes, you can set fx on a per surface basis or use this method. both have their advantages)
      Lock2D()
	      activate_Texture(smokeTex,0)
		Render_Quad(0,0,640,480)
	Unlock2D()
	fxSkinOff() ;Turn off shader
	
	glText 1,1,"Move mouse Left/Right to change blur factor"
	glFlip(False)
Wend



Here's the actual pixel shader used. The blur happens in one pass.

struct vertout
{
	float4 position : POSITION;
	float3 texcoord0 : TEXCOORD0;
};

struct pixel
{
	float4 color : COLOR;
};

pixel main(vertout IN,
	   uniform sampler2D Texture: TEXUNIT0,
	   uniform float4 blur)
{
pixel OUT;
float3 comb,final;
float2 tempUV1=IN.texcoord0.xy;
float2 tempUV2;
float blurFactor=blur.x;
	tempUV2.x=tempUV1.x-blurFactor;
	tempUV2.y=tempUV1.y-blurFactor;
	comb=tex2D(Texture,tempUV2);
	tempUV2.x+=blurFactor;
	comb+=tex2D(Texture,tempUV2);
	tempUV2.y+=blurFactor;
	comb+=tex2D(Texture,tempUV2);
	tempUV2.y+=blurFactor;
	comb+=tex2D(Texture,tempUV2);
	tempUV2.x+=blurFactor;
	comb+=tex2D(Texture,tempUV2);
	tempUV2.y-=blurFactor;
	comb+=tex2D(Texture,tempUV2);
	tempUV2.x-=blurFactor*2;
	comb+=tex2D(Texture,tempUV2);
	tempUV2.y+=blurFactor;
	comb+=tex2D(Texture,tempUV2);
	tempUV2.x+=blurFactor*2;
	tempUV2.y-=blurFactor*2;
	comb+=tex2D(Texture,tempUV2);
	OUT.color.rgb=comb/9;
	OUT.color.a=1;
	return OUT;
}