Horde3D

Next-Generation Graphics Engine
It is currently 28.03.2024, 09:35

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Pong!
PostPosted: 03.02.2009, 08:46 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Image

Download (310KB)

All the graphics are procedural (rendered with GLSL only), distance fields for circles and boxes are easy to calculate :wink:

Controls
Enter to start each round.
A/Z to move player 1's paddle.
Up/Down to move player 2's paddle.
Escape to quit.
F displays frame-rate.


Top
 Profile  
Reply with quote  
 Post subject: Re: Pong!
PostPosted: 03.02.2009, 22:56 
Offline

Joined: 26.03.2008, 02:58
Posts: 160
Ha...

Nice one :mrgreen:


Top
 Profile  
Reply with quote  
 Post subject: Re: Pong!
PostPosted: 04.02.2009, 20:12 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Reminds me of the good old times :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Pong!
PostPosted: 14.02.2009, 07:46 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
Is it possible to use your changes in engine to create a GUI lib? IMHO it's great to have a GUI lib based on shaders to accelerate heavy 2d scenes and adding support for png/mng anims ! Could you explain it a bit more ? It's too interesting for me :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Pong!
PostPosted: 14.02.2009, 11:49 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Siavash wrote:
Is it possible to use your changes in engine to create a GUI lib? IMHO it's great to have a GUI lib based on shaders to accelerate heavy 2d scenes and adding support for png/mng anims ! Could you explain it a bit more ? It's too interesting for me :D
You could use the ideas from my shaders to create a GUI renderer, yes.
These shaders do not use texture data, instead they just use mathematical descriptions of shapes within the fragment shader.

For example, a circle can be expressed mathematically as:
Code:
x^2 + y^2 = radius^2

These variables (x,y and radius) are given to the shader via 2 uniform variables:
Code:
uniform vec4 radius;// vec4(r, 0,0,0);
uniform vec4 offset;// vec4(x, y, 0,0);

The shader utilizes "texCoord" to determine the location of the pixel currently being rendered.

First, the shader measures the distance from the current pixel to the center of the circle:
Code:
distance( texCoord, offset.xy )

If this distance is less than the radius, then this pixel is inside the circle. Otherwise, the pixel is outside the circle.

To make the shaders easier to write, this distance is transformed into a standard distance-field representation.
Code:
float d = distance( texCoord, offset.xy ) - radius.x;

Now, the variable d tells us the distance to the edge of the circle (instead of the distance to the center).
If the distance is less than 0, the current pixel is inside the shape. If it is greater than 0, this pixel is outside the shape.

You can get anti-aliased smooth edges with the smoothstep function:
Code:
float alpha = 1.0-smoothstep( -half_pixel_size, half_pixel_size, distance_field );
gl_FragColor = vec4(color,alpha);


Distance fields can be combined using min and max.
One shape can be subtracted from another with: C = max( A, -1*B )
One shape can be added to another with: C = min( A, B )

E.g. you can cut one circle out of another to make a doughnut:
Code:
float circle_big = distance( texCoord, offset.xy ) - 0.5;
float circle_small = distance( texCoord, offset.xy ) - 0.125;
float doughnut = max( circle_big, -1.0*circle_small );


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group