theory on shader (unity)
TRANSCRIPT
-
8/12/2019 Theory on Shader (Unity)
1/15
Shader
OVERVIEW
-
8/12/2019 Theory on Shader (Unity)
2/15
RENDER PIPELINE
-
8/12/2019 Theory on Shader (Unity)
3/15
WEBGL RENDER PIPELINE
-
8/12/2019 Theory on Shader (Unity)
4/15
Shader Pipeline
-
8/12/2019 Theory on Shader (Unity)
5/15
Shader Pipeline
-
8/12/2019 Theory on Shader (Unity)
6/15
Unity 3D Shader Structure
Shader "MyShaderName" {
Prpertie! {
### prpertie! here ###
$
Su%Shader {
### !u%!hader &r 'raphic! hard(are ) ###
Pa!! {
### pa!! cmmand! ###
$
### mre pa!!e! i& needed ###
$
Su%Shader { ### !u%!hader &r 'raphic! hard(are B ###
$
### *ptinal &all%ac+ ###
,allBac+ "-erte.Lit"
$
-
8/12/2019 Theory on Shader (Unity)
7/15
-ER/E0 E INDE0
-
8/12/2019 Theory on Shader (Unity)
8/15
-ER/E0 )ND INDE0
-
8/12/2019 Theory on Shader (Unity)
9/15
)//RIBU/ES1 UNI,*RMS )ND
-)R2INGS
Attributes are input 4aria%le! u!ed in the 4erte.!hader# ,r e.ample1 4erte. crdinate!1 4erte. clr!1
and ! n# Due t the &act that the 4erte. !hader i!
called n each 4erte.1 the attri%ute! (ill %e different
e4ery time the 4erte. !hader i! in4+ed#
Uniforms are input 4aria%le! a4aila%le &r %th the
4erte. !hader and &ra'ment !hader# Unli+e attri%ute!1
uniforms are constant during a rendering cycle# ,r
e.ample1 li'ht! p!itin#
Varyings are u!ed &rpassing data &rm the 4erte.
!hader t the &ra'ment !hader#
-
8/12/2019 Theory on Shader (Unity)
10/15
-ER/E0 S5)DER
/he 4erte. !hader i! called on each
vertex# /hi! !hader manipulate!per-
vertex data !uch a! vertex coordinates,
normals, colors, and texturecoordinates# /hi! data i! repre!ented %y
attri%ute! in!ide the 4erte. !hader# Each
attri%utepoints to a VBO &rm (here itread! 4erte. data#
-
8/12/2019 Theory on Shader (Unity)
11/15
,R)GMEN/ S5)DER
E4ery !et & three 4ertice! de&ine! a trian'leand each element n the !ur&ace & that
trian'le need! t %e a!!i'ned a clr#
*ther(i!e ur !ur&ace! (uld %e tran!parent#
Each !ur&ace element i! called a fragment#
Since (e are dealin' (ith !ur&ace! that are
'in' t %e di!played n yur !creen1 the!eelement! are mre cmmnly +n(n a!
pixels#
-
8/12/2019 Theory on Shader (Unity)
12/15
,R)GMEN/ S5)DER
/he main 'al & the &ra'ment !hader i! tcalculate the clr & individual pixels#
-
8/12/2019 Theory on Shader (Unity)
13/15
,*RW)RD RENDERING P)/5 6 UNI/2 3D
,r(ard Renderin' path render! each %7ect in ne r mre pa!!e!1dependin' n li'ht! that a&&ect the %7ect8
Up t 9 pint li'ht! are calculated per:4erte.# /he ther li'ht! are
cmputed a! Spherical 5armnic! ;S5unt
?uality Settin'1 then mre li'ht! are rendered per:pi.el1 in rder &
decrea!in' %ri'htne!!#
-
8/12/2019 Theory on Shader (Unity)
14/15
-
8/12/2019 Theory on Shader (Unity)
15/15
Di&&u!e Re&lectin
)l! called Lam%ertian re&lectin8 Li'ht i! re&lected int all directin! (ithut !pecular hi'hli'ht!8 In the ca!e & per&ect di&&u!e re&lectin1 the inten!ity & the %!er4ed
re&lected li'ht depend! n the c!ine & the an'le %et(een the !ur&ace
nrmal 4ectr and the ray & the incmin' li'ht#
Where N L=