31.10.2013 Aufrufe

Download - Benjamin Granzow Portfolio

Download - Benjamin Granzow Portfolio

Download - Benjamin Granzow Portfolio

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

4.3. BELEUCHTUNG 40<br />

varying vec3 textCoord ;<br />

uniform sampler2D t e x t u r e 0 ;<br />

uniform sampler2D t e x t u r e 1 ;<br />

uniform mat3 normalMatrix ;<br />

uniform sampler2D t r a n s f e r F u n c t i o n ;<br />

uniform f l o a t fromIndex ;<br />

uniform f l o a t toIndex ;<br />

void main ( void )<br />

{<br />

f l o a t mixSample , sample0 , sample1 ;<br />

vec4 r e s u l t ;<br />

sample0 = texture2D ( texture0 , textCoord . xy ) . r ;<br />

sample1 = texture2D ( texture1 , textCoord . xy ) . r ;<br />

mixSample = mix ( sample0 , sample1 , textCoord . z ) ;<br />

i f ( mixSample . a < fromIndex ) {<br />

mixSample . a = 0 . 0 ;<br />

} e l s e i f ( mixSample . a > toIndex ) {<br />

mixSample . a = 1 . 0 ;<br />

} e l s e {<br />

mixSample . a −= ( mixSample . a−fromIndex ) /<br />

( toIndex−fromIndex ) ;<br />

}<br />

r e s u l t = texture2D ( t r a n s f e r F u n c t i o n , vec2 ( mixSample , 0 . 5 ) ) ;<br />

// Feste Licht− und Kameraposition<br />

vec3 l i g h t P o s = vec3 ( 0 . 0 , 1 0 . 0 , 0 . 0 ) ;<br />

vec3 eyePos = vec3 ( 0 . 0 , 0 . 0 , 0 . 0 ) ;<br />

// Erweitern und n o r m a l i s i e r e n des Normalen−Vektors<br />

vec3 normal = 2 . 0 * mixSample . rgb−vec3 ( 1 . 0 ) ;<br />

// Korrektur der O r t hogonalit ä t<br />

normal = normalize ( normalMatrix * normal ) ;<br />

// Berechnung der Licht− und B l i c k r i c h t u n g<br />

vec3 viewDir = normalize ( eyePos−p o s i t i o n ) ;<br />

vec3 l i g h t D i r = normalize ( l ightPos −p o s i t i o n ) ;<br />

// Addieren des Beleuchtungswertes zur Emision<br />

r e s u l t . rgb += blinnPhong ( normal , viewDir , l i g h t D i r ) ;<br />

g l F r a g C o l o r = r e s u l t ;<br />

}<br />

\ c l e a r p a g e<br />

Listing 4.9: Fragmentshader mit Transferfunktion und Blinn-Phong<br />

Beleuchtung

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!