10.11.2014 Views

Master's Thesis - Studierstube Augmented Reality Project - Graz ...

Master's Thesis - Studierstube Augmented Reality Project - Graz ...

Master's Thesis - Studierstube Augmented Reality Project - Graz ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.4 Visualization Framework<br />

3 void main ( void )<br />

4 {<br />

5 // Texture coordinate of the vertex<br />

6 gl_TexCoord [0] = gl_MultiTexCoord0 ;<br />

7 // Position of the vertex<br />

8 gl_Position = gl_ModelView<strong>Project</strong>ionMatrix * gl_Vertex ;<br />

9 }<br />

10<br />

11<br />

12 [ Fragment shader ]<br />

13 uniform sampler2D aTexture ; // an arbitrary input texture<br />

14<br />

15 void main ( void )<br />

16 {<br />

17 // read the RGBA color of the texture ’s pixel<br />

18 // at an interpolated texture position<br />

19 vec4 texVec = texture2D ( aTexture , vec2 ( gl_TexCoord [0]));<br />

20 // set the color of the rendered fragment<br />

21 gl_FragColor = texVec ;<br />

22 }<br />

Available data-types<br />

• Standard types: Besides bool, int and float, also vector types like vec2, vec3<br />

or vec4 and matrix types like mat2, mat3 or mat4 and similar are available.<br />

• Textures: defined with sampler1D, sampler2D or sampler3D (and even some<br />

more for cube- or shadow maps) and accessed via the built-in functions texture1D, texture2D<br />

or texture3D...<br />

• Arrays: defined in the same way as in C with square brackets.<br />

• Type qualifiers: Referring to the two most frequently used, uniform defines a<br />

variable set by the OpenGL API and varying a variable which is interpolated<br />

between vertex and fragment shader and therefore accessible in both.<br />

built-in functions and values<br />

• Vector and matrix types can be accessed element wise via a swizzle operator.<br />

For example a four dimensional vector accessed with vector.xyz or vector.rgb<br />

will result in the first three elements. (w or a refers to the fourth component).<br />

75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!