glsl shader slides

27
GPU Shading Announcements GPU Shading Overview Example 1: Shadow Maps Example 2: Algebraic Surfaces

Upload: others

Post on 12-Feb-2022

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GLSL Shader Slides

GPU Shading

• Announcements

• GPU Shading Overview

• Example 1: Shadow Maps

• Example 2: Algebraic Surfaces

Page 2: GLSL Shader Slides

GPU Shading

• Announcements

• GPU Shading Overview

• Example 1: Shadow Maps

• Example 2: Algebraic Surfaces

Page 3: GLSL Shader Slides

Announcements

• Homework 2 Due

• Project 3 Released

• Project 3 Vote

• Midterm Exam Next Week!

Page 4: GLSL Shader Slides

GPU Shading

• Announcements

• GPU Shading Overview

• Example 1: Shadow Maps

• Example 2: Algebraic Surfaces

Page 5: GLSL Shader Slides

GPU Shading

• Announcements

• GPU Shading Overview

• Example 1: Shadow Maps

• Example 2: Algebraic Surfaces

Page 6: GLSL Shader Slides

OpenGL Pipeline! !"#$"%&&%'()*!+,)(+-)

! .)"/)0*,"#1)22#"2

! 3"%$&)-/*,"#1)22#"2

Page 7: GLSL Shader Slides

Simplified OpenGL Pipeline

VertexOperation

Rasterization(Interpolation)

FragmentOperation

Vertex Data

Framebuffer

Page 8: GLSL Shader Slides

More Detail

VertexOperation

Rasterization(Interpolation)

FragmentOperation

Posit

ions

Framebuffer

Nor

mals

Color

s

Eye Positions

Eye Normals

Colors

Position

Normal

Color

(Interpolated)

Page 9: GLSL Shader Slides

Programmability

VertexOperation

Rasterization(Interpolation)

FragmentOperation

Posit

ions

Framebuffer

Nor

mals

Color

s

Eye Positions

Eye Normals

Colors

Position

Normal

Color

(Interpolated)Programmable Programmable

Page 10: GLSL Shader Slides

Variable Types• const - The declaration is of a compile time constant

• attribute - Global variables that may change per vertex, that are passed from the OpenGL application to vertex shaders. This qualifier can only be used in vertex shaders. For the shader this is a read-only variable.

• varying - used for interpolated data between a vertex shader and a fragment shader. Available for writing in the vertex shader, and read-only in a fragment shader.

• uniform - Global variables that may change per primitive (may not be set inside glBegin,/glEnd), that are passed from the OpenGL application to the shaders. This qualifier can be used in both vertex and fragment shaders. For the shaders this is a read-only variable.

Page 11: GLSL Shader Slides

Attribute Variables

VertexOperation

Rasterization(Interpolation)

FragmentOperation

Posit

ions

Framebuffer

Nor

mals

Color

sAttr

ibute

sEye Positions

Eye Normals

Colors

Position

Normal

Color

(Interpolated)Programmable Programmable

Page 12: GLSL Shader Slides

Varying Variables

VertexOperation

Rasterization(Interpolation)

FragmentOperation

Posit

ions

Framebuffer

Nor

mals

Color

sAttr

ibute

sEye Positions

Eye Normals

Colors

Varying

Position

Normal

Color

Varying

(Interpolated)Programmable Programmable

Page 13: GLSL Shader Slides

Uniform Variables

VertexOperation

Rasterization(Interpolation)

FragmentOperation

Posit

ions

Framebuffer

Nor

mals

Color

sAttr

ibute

s

Eye Normals

Colors

Varying

Position

Normal

Color

Varying

(Interpolated)Programmable Programmable

Uniform

Eye Positions

Page 14: GLSL Shader Slides

Why So Fast?

VertexOperation

Rasterization(Interpolation)

FragmentOperation

Posit

ions

Framebuffer

Nor

mals

Color

sAttr

ibute

s

Eye Normals

Colors

Varying

Position

Normal

Color

Varying

(Interpolated)Programmable Programmable

Uniform

Eye Positions

~4 Vertex Shaders

~16 Fragment Shaders

Page 15: GLSL Shader Slides

Types and Functions!"#$%&#'()"'*%#+',(

-./012()345/1647(89:;(<;;=(!"#$$!"#%&'()!*+,-#.$!"#/$!"#$0$(>?5/60(@?A./164.A()345/1647(89:B(<;;=(1))-$$"--.$1234$0$1))-$$"56.$1234$0$1234$$37,"-.$234/$234$0$1234$$37,"-.$&234/$&234$0$1234$$37,"-.$1234/$1234$0$1234$$8%3"#3%9:"5.$234/$234$0$1234$$8%3"#3%9:"5.$&234/$&234$0$1234$$8%3"#3%9:"5;7,"-.$234/$234$0$1234$$8%3"#3%9:"5;7,"-.$&234/$&234$0$1234$$-3<<9:"5.$234/$234$0$1234$$-3<<9:"5.$&234/$&234$0$1234$$-3<<9:"5;7,"-.$234/$234$0$1234$$-3<<9:"5;7,"-.$&234/$&234$0$1234$$5)#.$1234$0$1234$$5)#;7,"-.$234/$234$0$1234$$5)#;7,"-.$&234/$&234$0$1234$$5)#;7,"-.$1234/$1234$0$$

C?DE(234$=$234>$?$234@$?$234A$!"#$=$!"#>$?$!"#@$?$!"#A$&234$=$&234>$?$&234@$?$&234A$1234$=$1234>$?$1234@$?$1234A$83596*3$=$B-)"#$?$234>$?$234@$?$234A$

F?6G?/015()345/1647(89:H(<;H=(234A$$ B#%"5<B)%!.0$$$$$$$$$$$!"#$"%&'()*$234@$$ 4%)<<.$234@/$234@$0$B-)"#$$ C&<#"543.$83596*3/$83596*3$0$B-)"#$$$ C)#.$83596*3/$83596*3$0$83596*3$$ B"43B)%D"%C.$83596*3$!/$83596*3&+/$83596*3$($0$B-)"#$$$ -358#:.$83596*3$0$83596*3$$ 5)%!"-&E3.$83596*3$0$83596*3$$ %3B-34#.$83596*3&+/$83596*3$($0$83596*3$$ %3B%"4#.$83596*3&+/$83596*3$(/$B-)"#$"$,$0$

I4JA?(.4K(%01J646G?/0D()345/1647(89:L(<;L=(83596*3$$<&5.$83596*3$0$83596*3$$4)<.$83596*3$0$83596*3$$#"5.$83596*3$0$$83596*3$$"<&5.$83596*3$0$83596*3$$"4)<.$83596*3$0$83596*3$$"#"5.$83596*3/$83596*3$0$83596*3$$"#"5.$83596*3$0$$83596*3$$%"C&"5<.$83596*3$0 83596*3$$C38%33<.$83596*3$0$$

*6GG64()345/1647(89:M(<;N=(83596*3$$"1<.$83596*3$0$83596*3$$43&-.$83596*3$0$83596*3$$4-"!*.$83596*3/$83596*3/$83596*3$0$83596*3$$4-"!*.$83596*3/$B-)"#/$B-)"#$0$83596*3$$B-))%.$83596*3$0$83596*3$$B%"4#.$83596*3$0$83596*3$$!"'.$83596*3/$83596*3$0$83596*3$$!"'.$83596*3/$B-)"#$0$83596*3$$!&5.$83596*3/$83596*3$0$83596*3$$!&5.$83596*3/$B-)"#$0$83596*3$$!&'.$83596*3/$83596*3/$83596*3$0$83596*3$$!&'.$83596*3/$83596*3/$B-)"#$0$83596*3$$!)C.$83596*3/$83596*3$0$83596*3$$!)C.$83596*3/$B-)"#$0$83596*3$$<&85.$83596*3$0$83596*3$$<!))#:<#3*.$83596*3/$83596*3/$83596*3$0$83596*3$$<!))#:<#3*.$B-)"#/$B-)"#/$83596*3$0$83596*3$$<#3*.$83596*3/$83596*3$0$83596*3$$<#3*.$B-)"#/$83596*3$0$$

O2<64?4/1.A()345/1647(89:N(<;N=(83596*3$$*)D.$83596*3/$83596*3$0$83596*3$$3'*.$83596*3$0$83596*3$$-)8.$83596*3$0$83596*3$$3'*>.$83596*3$0$83596*3$$-)8>.$83596*3$0$83596*3$$<7%#.$83596*3$0$83596*3$$&523%<3<7%#.$83596*3$0$

)0.JG?4/(P065?7714J()345/1647(89:9(<;9=($&-#,./"0$&'()*$83596*3$$CFC'.$83596*3$0$83596*3$$CFC6.$83596*3$0$83596*3$$BD&C#:.$83596*3$0

%?2/30?($66Q3<()345/1647(89:R(<;B=$$$'1$230,4&52,6&$"#/&26&-#,./"0$&'()*&234A$$#3'#,%3GH.$<"!*-3%GH/$B-)"#$I/B-)"#$52,6J$0$234A$$#3'#,%3GHK%)L.$<"!*-3%GH/$234>$I/B-)"#$52,6J$0$234A$$#3'#,%3GHK%)L.$<"!*-3%GH/$234A$I/B-)"#$52,6J$0$$234A$$#3'#,%3>H.$<"!*-3%>H/$234>$I/B-)"#$52,6J$0$234A$$#3'#,%3>HK%)L.$<"!*-3%>H/$234@$I/B-)"#$52,6J$0$234A$$#3'#,%3>HK%)L.$<"!*-3%>H/$234A$I/B-)"#$52,6J$0$$234A$$#3'#,%3@H.$<"!*-3%@H/$234@$I/B-)"#$52,6J$0$234A$$#3'#,%3@HK%)L.$<"!*-3%@H/$234A$I/B-)"#$52,6J$0$$234A$$#3'#,%3(,13.$<"!*-3%(,13/$234@$I/B-)"#$52,6J$0$$234A$$<:"C)DGH.$<"!*-3%GHM:"C)D/$234@$I/B-)"#$52,6J$0$234A$$<:"C)D>H.$<"!*-3%>HM:"C)D/$234@$I/B-)"#$52,6J$0$234A$$<:"C)DGHK%)L.$<"!*-3%GHM:"C)D/$234A$I/B-)"#$52,6J$0$234A$$<:"C)D>HK%)L.$<"!*-3%>HM:"C)D/$234A$I/B-)"#$52,6J$0$

%?2/30?($66Q3<()345/1647(S1/T($+U(89:R(<;B=$$!"#$"%&'()*7&"068#"&9):;<=:!>?@>=:@>=@A?>:+;<9>:A(+@B&C&D$234A$$#3'#,%3GHN)C.$<"!*-3%GH/$B-)"#/$B-)"#&43E$0$234A$$#3'#,%3GHK%)LN)C.$<"!*-3%GH/$234>/$B-)"#&43E$0$234A$$#3'#,%3GHK%)LN)C.$<"!*-3%GH/$234A/$B-)"#&43E$0$$234A$$#3'#,%3>HN)C.$<"!*-3%>H/$234>/$B-)"#&43E$0$234A$$#3'#,%3>HK%)LN)C.$<"!*-3%>H/$234@/$B-)"#&43E$0$234A$$#3'#,%3>HK%)LN)C.$<"!*-3%>H/$234A/$B-)"#&43E$0$234A$$#3'#,%3@HK%)LN)C.$<"!*-3%@H/$234A/$B-)"#&43E$0$$234A$$#3'#,%3(,13N)C.$<"!*-3%(,13/$234@/$B-)"#$43E&0$$234A$$<:"C)DGHN)C.$<"!*-3%GHM:"C)D/$234@/$B-)"#&43E&0$234A$$<:"C)D>HN)C.$<"!*-3%>HM:"C)D/$234@/$B-)"#&43E$0$234A$$<:"C)DGHK%)LN)C.$<"!*-3%GHM:"C)D/$234A/$B-)"#&43E$0$234A$$<:"C)D>HK%)LN)C.$<"!*-3%>HM:"C)D/$234A/$B-)"#&43E&0

'617?()345/1647(89:V(<BW=(B-)"#$$5)&<3G.$83596*3$0$234>$$5)&<3>.$83596*3$0$234@$$5)&<3@.$83596*3$0$234A$$5)&<3A.$83596*3$0$

+<?4F$X(,T.K14J($.4J3.J?(8F$,$=(Y315Q(@?Z?0?45?(F31K?$

$H3<4%&13<$ONMN$23%<&)5$GPGQ/$"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Z345/164(<.0.G?/?07E(&5$$ 2"-,3$&5&#&"-&E3C$)5$35#%6/$5)#$4)*&3C$)5$%3#,%5$.C3B",-#0$),#$$ 4)*&3C$),#$)5$%3#,%5/$1,#$5)#$&5&#&"-&E3C$&5),#$$ 2"-,3$&5&#&"-&E3C$)5$35#%6/$"5C$4)*&3C$),#$)5$%3#,%5$4)5<#$$ 4)5<#"5#$B,54#&)5$&5*,#$

>O*%+@(*+-P+'O'%,(8;:;(<(MW=$$

F3/130"0$&0,/"6&/,G&03$&5"&/2%"E&,F#366&6"$6&&$$$$$$$$'/$6/$E/$D$$$$$$$$$%/$8/$1/$"$$$$$$$$$</$#/$*/$7$

Page 16: GLSL Shader Slides

Type Properties

• Matrix / vector / integer / floating point types.

• Strict casting requirements.

• Const / attribute / varying / uniform variables.

Page 17: GLSL Shader Slides

Control Loops in GLSL

for (int i=0 ; i<10 ; i++) {statements;

}

if (condition) {statements;

} else {statements;

}

while (condition) {statements;

}

Beware:If Statement

Implementation

Page 18: GLSL Shader Slides

Builtins!"#$"%&'()*"#&!)#+),-"'&

.#)/0"1$&'()*"#&!)#+),-"'&!

!'234567&89:29:&!6;56<73=&>?@A&2BCD&!"##$%%&'(!"#$%!!&'()*+&,-'-*.!"#$%!!&'()*+&/+0+1&'(2+3/*+45677#*89.!7'-+0!!&'()*+&/#:0;.!!!!!!!!)*+,-./&01+2"03442567!

'234567&+E29:&!6;56<73=&>?@A&2BCD&!"##$%%&'8!"#$%!!&'()*+&,--*<.!!!!!!!!!!!!!!!!9:;$1!#4425:<"=$%!=--'!!&'()*->0)+$?>&.!

,F+-$G+1&F1+.8#0=&>?@H&2BHD&&"##$%%&'8!!6>?7-*@!@+0%!!&'(2-<#'A?#42+0*?3.!6>?7-*@!@+0%!!&'(2-<#'A?#4B*-C#$0?->2+0*?3.!6>?7-*@!@+0%!!&'(B*-C#$0?->2+0*?3.!6>?7-*@!@+0%!!&'(D#306*#2+0*?31&'(2+3D#306*#,--*<89.!!6>?7-*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$->80!?>0!&'(2+3/*+45677#*8.!!$->80!?>0!&'(2+3D#306*#,--*<8.!!$->80!?>0!&'(2+3D#306*#T>?08.!$->80!?>0!&'(2+3D#306*#E@+&#T>?08.!!$->80!?>0!&'(2+3A#*0#3D#306*#E@+&#T>?08.!$->80!?>0!&'(2+3,-@=?>#<D#306*#E@+&#T>?08.!$->80!?>0!&'(2+3M?&;08.!$->80!?>0!&'(2+3,'?:B'+>#8.!!

.5E3&2;5E:&T&U5=4765R3;&,-:L*?&;0!ZYY[!2?Q#!^#?='#>!!;00:_``@#4a$3`!B'#+8#!8#><!7##<=+$Q`$-**#$0?->8`$-@@#>08!0-!&'8'b@#4a$3!X:#>cM!?8!+!*#&?80#*#<!0*+<#@+*Q!-7!H?'?$->!c*+:;?$8!E>$a!N3$#:0!+8!>-0#<!=#'-4d!?7!<?8$*#:+>$?#8!=#04##>!0;?8!&6?<#!+><!0;#!cMHM!8:#$?7?$+0?->d!=#'?#"#!0;#!8:#$e!I#"?8#<!ZYY[fVVfZ\!!1Q:3=!Va!,-**#$08!+!0L:-!?>!0;#!X:#>cM!ZaY!8:#$?7?$+0?->a!

Page 19: GLSL Shader Slides

GPU Shading

• Announcements

• GPU Shading Overview

• Example 1: Shadow Maps

• Example 2: Algebraic Surfaces

Page 20: GLSL Shader Slides

GPU Shading

• Announcements

• GPU Shading Overview

• Example 1: Shadow Maps

• Example 2: Algebraic Surfaces

Page 21: GLSL Shader Slides

Soft Shadows

• Why? How?

Page 22: GLSL Shader Slides

Hard Shadows

Page 23: GLSL Shader Slides

43Computer Graphics 15-462

!"#$%&'!"#$%&'(%))*+(&",+,(%-.,)/'(#+,("0$$,1(2+%3(#(405"/('%*+),

%30/(#16(01/,1'0/6()%1/+0-*/0%1(2+%3("0$$,1(405"/('%*+),'

7%+8015(%*/(&"#/(0/("0$$,1(0'('03946(#(:0'0-040/6(9+%-4,3

)#1(/",(405"/('%*+),(',,(/",(%-.,)/;

*',(/",(<=-*22,+('"#$%&(#45%+0/"3>

+*1(/",(#45%+0/"3(2+%3(/",(405"/('%*+),?'(:0,&9%01/

'#:,(/",(<=-*22,+(#'(/",('"#$%&(-*22,+

+*1(/",(+,#4(<=-*22,+(#45%+0/"3@(/+#1'2%+3015(,#)"(9%01/(01/%(/",(405"/('%*+),?'()%%+$01#/,'(#1$()%39#+015(/",(<(:#4*,(#5#01'/(/",('"#$%&(-*22,+

How does the z-buffer work?How can we use the z-buffer to compute shadows?

Page 24: GLSL Shader Slides

GPU Shading

• Announcements

• GPU Shading Overview

• Example 1: Shadow Maps

• Example 2: Algebraic Surfaces

Page 25: GLSL Shader Slides

GPU Shading

• Announcements

• GPU Shading Overview

• Example 1: Shadow Maps

• Example 2: Algebraic Surfaces

Page 26: GLSL Shader Slides
Page 27: GLSL Shader Slides

Happy GPU Coding!