Re: Shader coders?



Hi,

In one of my lectures I have to learn image filters and GLSL
programming, so I thought this shader could be a good exercise. It's my
first shader ever :-)

It works, but the kernel and the offset can probably be improved. Tested
with a RV770 [Radeon HD 4850] and fglrx driver.

Screen shot:
http://img134.imageshack.us/img134/9493/blurshaderscreenshot.png

There is one bug with the upper edge of the shadow. It is nearly
unblurred and causes an artefact below the marker. This can probably be
fixed with a higher drawing area for shadows.

Cheers,
Simon

Pierre-Luc Beaudoin wrote:
> Hi,
>
> To blur the shadow of markers, I though we could use a shader.  Well, I
> don't have that knowledge or the time to learn how to write them :)
>
> Anyone wants to have a look at the shadow branch on mainline? It
> contains a predrawn shadow (in priv->shadow) that needs to be blured.
> All the code is there, only the working SHADER code is missing.
>
> Also, that branch is buggy because it recompiles the shader constantly..
> Will be fixed before merging hehe
>
> Pierre-Luc
>
> _______________________________________________
> libchamplain-list mailing list
> libchamplain-list gnome org
> http://mail.gnome.org/mailman/listinfo/libchamplain-list
>   


diff --git a/champlain/champlain-marker.c b/champlain/champlain-marker.c
index a168610..0e4ceaf 100644
--- a/champlain/champlain-marker.c
+++ b/champlain/champlain-marker.c
@@ -418,38 +418,22 @@ draw_box (cairo_t *cr,
 
 }
 
-const gchar* SHADER = "#extension GL_ARB_texture_rectangle : enable \
-\
-variables settable by Pd \
-uniform float horizontal; \
-uniform float vertical; \
-\
-// some helper variables \
-float xpos; \
-float ypos; \
-float maxhv; \
-float sum; \
- \
-texture comes from Pd \
-uniform sampler2DRect image; \
- \
-vec2 pos = gl_TexCoord[0].st; \
- \
-void main() \
-{ \
- vec4 color = texture2DRect(image, pos); \
-  sum = 1.; \
-  maxhv = max(horizontal, vertical); \
-  for (float i=0.; i<=horizontal*2.; i++) { \
-    xpos = i-horizontal; \
-    for (float j=0.; j<=vertical*2.; j++) { \
-        ypos = j-vertical; \
-        color += texture2DRect(image, pos+vec2( xpos, ypos)) * ((maxhv+1.)-sqrt(xpos*xpos+ypos*ypos)); \
-        sum+=(maxhv+1.)-sqrt(xpos*xpos+ypos*ypos); \
-      } \
-  } \
-  gl_FragColor = color/sum; \
-}";
+const gchar* SHADER = ""
+"uniform sampler2D rectTexture;"
+"void main (void) {"
+"  mat3 kernel = mat3(1.0/16.0, 2.0/16.0, 1.0/16.0, "
+"                     2.0/16.0, 4.0/16.0, 2.0/16.0, "
+"                     1.0/16.0, 2.0/16.0, 1.0/16.0);"
+"  int i, j; vec2 coord;"
+"  vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);"
+"  for(i = -1; i <= 1; i++) {"
+"    for(j = -1; j <= 1; j++) {"
+"      coord = gl_TexCoord[0].st + vec2(float(i) * 1.0/40.0, float(j) * 1.0/40.0);"
+"      sum += kernel[i+1][j+1] * texture2D(rectTexture, coord.xy);"
+"    }"
+"  }"
+"  gl_FragColor = sum;"
+"}";
 
 static void
 draw_shadow (ChamplainMarker *marker,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]