OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Creating SonarGauge by GLSL


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
?mit Uzun
Guest





PostPosted: Tue Nov 04, 2008 8:17 am    Post subject:
Creating SonarGauge by GLSL
Reply with quote

Hi Folks,

I have already created SonarGauge by using GLSL to create sweeping line on the texture. It almost takes my half day. But I think there would be much stable algorithm in condition controls or full logical creation. In this GLSL code I have used texture coordinates which is changing in [ 0.0, 0.0 ] and [ 1.0, 1.0 ]. I assume the center point of new created coordinate system is [ 0.5, 0.5 ]. So all calculations were created by this reference system.

If you are thinking more optimized code of create same operation, you can share with me your thinking.

Download Link for SonarGauge in RenderMonkey executable file : http://www.fileden.com/files/2007/9/10/1423182/SonarGauge.rar

Best Regards.

--
?mit Uzun,
Environmental Tectonics Corporation Turkey
ODTU Teknokent
Gumus Bloklar A Blok
Zemin Kat Bati Cephe Suit 1
06531 ODTU
Ankara, Turkey
Tel: 90 (312) 210 17 80
Fax: 90 (312) 210 17 84
E-Mail: umituzun84<at>gmail<dot>com
Website: http://www.etc-turkey.com

/----------------------------SonarGauge-VertexShader-------------------------/
//
// Vertex shader for sonar gauge
//
// Authors: ?mit Uzun
//
// Copyright (c) General Public Licence
//

void main(void)
{
gl_TexCoord[ 0 ] = gl_MultiTexCoord0;

gl_Position = ftransform();
}
/----------------------------SonarGauge-VertexShader-------------------------/

/----------------------------SonarGauge-FragmentShader-------------------------/
//
// Fragment shader for sonar gauge
//
// Authors: ?mit Uzun
//
// Copyright (c) General Public Licence
//

uniform sampler2D SonarTexture;
uniform float SonarAngle;

// For rotating the sweeping line around the center
// we will use Texture Coordinates ( coordinates are
// changing between [ 0, 0 ] - [ 1, 1 ] and center
// point is [ 0.5, 0.5 ] )

void main(void)
{
// Pixel's gradient value for center point of texture coordinates
float gradient = ( gl_TexCoord[ 0 ].y - 0.5 ) / ( gl_TexCoord[ 0 ].x - 0.5 );

// Calculate pixel's gradient value to degree for the +X axes
float Q = degrees( atan( gradient ) );

// Clip SonarAngle to the 360.0 degree
float angle1 = float( mod( SonarAngle, 360.0 ) );

// atan( gradient ) operation gives us value in [ PI / 2, -PI / 2 ]
// and we have to use texture coordinate to find out this pixel's portion
// in coordinate system ( [ 0 - 90 ], [ 90 - 180 ], [ 180 - 270 ], [ 270 - 360 ] )
// and then we add some angle to calculate expected value.
if( gl_TexCoord[ 0 ].x < 0.5 )
Q += 180.0;
else if( Q < 0.0 )
Q += 360.0;

// Calculating distance to center for every pixel to sweep circumcircle around the texture
float dist1 = distance( gl_TexCoord[ 0 ].xy, vec2( 0.5, 0.5 ) );
float dist2 = 0.4;
float glow = 0.0;

vec4 tex = texture2D( SonarTexture, gl_TexCoord[ 0 ].xy );

// angle2 is representing trialer which follows the sweeping line
float angle2 = mod ( ( angle1 + 300.0 ), 360.0 );

if( ( angle1 > angle2 && angle1 > Q && angle2 < Q ) && ( dist1 <= dist2 ) )
{
glow = clamp( ( Q - angle2 ) / 60.0, 0.0, 1.0 );
gl_FragColor = mix( tex, vec4( 0.2, 1.0, 0.2, 1.0 ), glow );
}
else if( ( angle1 < angle2 ) && ( dist1 <= dist2 ) )
{
if( ( angle1 > Q && angle2 > Q ) )
{
glow = clamp( ( Q + ( 360.0 - angle2 ) ) / 60.0, 0.0, 1.0 );
gl_FragColor = mix( tex, vec4( 0.2, 1.0, 0.2, 1.0 ), glow );
}
else if( ( angle1 < Q && angle2 < Q ) )
{
glow = clamp( mod( ( 360 - angle2 + Q ), 360.0 ) / 60.0, 0.0, 1.0 );
gl_FragColor = mix( tex, vec4( 0.2, 1.0, 0.2, 1.0 ), glow );
}
else gl_FragColor = tex;
}
else gl_FragColor = tex;
}
/----------------------------SonarGauge-FragmentShader-------------------------/

------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Happy New Year to all OSG Users Chris Hanson General 0 Mon Jan 07, 2019 10:17 am View latest post
No new posts osg-users Digest, Vol 138, Issue 27 Zachary1234 General 0 Tue Jan 01, 2019 1:16 am View latest post
No new posts pass mat4 as attribute for glsl sirian_ye General 4 Tue Nov 27, 2018 4:58 am View latest post
No new posts osg-users Digest, Vol 137, Issue 14 poweruserm@live.com.au General 0 Fri Nov 16, 2018 11:16 pm View latest post
No new posts General Users starting questions in O... A Z General 1 Mon Oct 15, 2018 3:59 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP