Monthly Archives: February 2012

Doxygen and GLSL shader

As I’ve finished the documentation-madness I stumbled over my GLSL shader. Doxygen, _the_ documentation tool of choice, reads them (as they are very c-like) but dumps them rather unfancy. Doxygen is not only very flexible – it is also extensible with filters to process other languages.

Idea

Write a small filter, that pads every shader into a class and set a namespace that acts kinda like a category (e.g. class Gauss in namespace GLSL::FILTER::BLUR). The result is my glslfilter.py python-script.

Usage
  1. Make Doxygen aware of the filter and the newly supported file extensions. To do this, edit your Doxyfile:
    • Add FILE_PATTERNS: *.frag, *.vert
    • Add FILTER_PATTERNS: "*.frag=./glslfilter.py", "*.vert=./glslfilter.py"
  2. If you want, add annotations to your shader:
    • Use @class to set the class name
    • Use @namespace to set the namespace – a category

    If you set no name, the script will use the bare filename and the default namespace is “GLSL”.

    Of course you can further document your shader with doxytags – they are fully processed by Doxygen. The only limitation here (blame my lazyness or my thought it just wasn’t worth it) is that you have to put the “class” comment (= the shader information) at the very beginning in one big blockcomment starting with /* or /**. But seriously – why would you comment it in any other way? ;-)

To better illustrate the procedure here’s a little GLSL fragment shader:

Example
/**
 * A simple 3x3 gaussian convolution filter, non-separated version
 * @author Sebastian Schaefer
 * @date 2012
 * @namespace GLSL::FILTER::BLUR
 * @class Gauss3x3
 */
#version 150 core

uniform sampler2D image; ///< the input image

in vec2 tex;	///< texture coordinated
out vec4 color; ///< the color output

/**
 * The main routine: read the 3x3 neighbours and multiply with kernel
 */
void main()
{
    ...
}

Click here to see how the above example can look like.

Download

Grab the filter at my github-repository github.com/numb3r23/glslAdditions
This page might get updated so please link to this page only, not the direct download. thank you!


edit: moved source to github

Mac: Automator Service for a Google popup

As I was documenting a big amount of source-code today, I ran into the problem of looking up some stuff in the web (OpenGL-SDK docs to be specific) while inside XCode. There may be better ways to do this, but I ended up seeing that service entry in the context-menu and thought – hey, why not make a service to look up that stuff?

Here’s what I found out:

  1. Create a new Automator Service
  2. On the top right, set “Service recieves selected text” in “any application
  3. Drop a “Run AppleScript” from the Actions Library
  4. Add the following text:
    	on run {input, parameters}
    		set theURL to ("http://www.google.com/search?btnI=I%27m+Feeling+Lucky&q=" & input & "&go=Go")
    		return theURL
    	end run
    	
  5. Drop a “Website Popup” from the Actions Library and configure it as desired

    I choose size & agent “iPhone” so it’s not too big but readable.

The selected text is searched by google and the first hit is opened (a.k.a. I’m feeling lucky). Good enough for my documentation problems as the service can be mapped to a global shortcut.

Integrating FXAA

Revently I’ve integrated Timothy Lottes extreme powerful Anti-Alising filter Fast Approximate Anti-Aliasing into my ph.d.-project (might be introduced later on…).¬† It didn’t really take a long time as the filter source is documented quite well.

As I already have a class CPostProcessor that takes a base image and filters it using a generic vertex- and a custom fragment-shader I’ve created a class CPPFXAA that applies the FXAA filter.

1. Setup

Before integrating the FXAA shader you have to set it up, meaning going through the first part of the downloadable header-file and choose the defines to what you need/want.

2. Texture to RGBL

This step is not really necessary, but I somehow ended up integrating it anyway. Instead of an alpha value the alpha channel stores the luminace: (for me: color.a = dot(color.rgb, vec3(0.299, 0.587, 0.114));).

3. FXAA filter

Disable blending (if it was enabled) and apply the filter: render a screen-aligned quad with a fxaa as a fragment-shader. Set the input image as your “BaseImage” and set the correct viewport dimensions (“screenwidth” and “screenheight”).

4. done.

That’s it.

 

I hope it works as good for you as it does for me:)