Professional Documents
Culture Documents
GPU CG
kang_yu_zhi@yahoo.cn
2009 9
GPU CG
kang_yu_zhi@yahoo.cn
2009 9
3
26
4
7
17
IT
5
5
GPU
Cg NVIDIA CgUsersManual
7
1 ............................................................................................................13
1.1 Programmable Graphics Processing Unit ....................................13
1.2 GPU VS CPU..................................................................................................15
1.3 ...........................................................................................18
1.4 ...................................................................................18
2 GPU .......................................................................................21
2.1 .......................................................................................................22
2.1.1 object space world space............................................................23
2.1.2 world space eye space................................................................24
2.1.3 eye space project and clip space ................................................25
2.2 Primitive Assembly && Triangle setup .........................................................26
2.3 ...................................................................................................27
2.3.1 Rasterization .........................................................................................27
2.3.2 Pixel Operation .....................................................................................28
2.4 .......................................................................................................30
2.4.1 GPU .....................................................................................30
2.4.2 Z Buffer Z ...................................................................................31
2.4.3 Stencil Buffer ........................................................................................33
2.4.4 Frame Buffer .........................................................................................34
2.5 ........................................................................................................35
3 Shader Language............................................................................................36
3.1 Shader Language ..................................................................................37
3.2 Vertex Shader Program.................................................................................39
3.3 Fragment Shader Program ............................................................................40
3.4 CG VS GLSL VS HLSL.................................................................................41
3.5 .......................................................................................................43
4 Cg ..................................................................................................44
4.1 Cg ................................................................................................44
4.2 CG ........................................................................................................45
8
4.3 CG .......................................................................................................45
4.3.1 CG ........................................................................................45
4.3.1 CGC .....................................................................................47
4.4 CG Profiles....................................................................................................50
5 CG ................................................................................................53
5.1 ...............................................................................................53
5.2 .......................................................................................................55
5.3 .......................................................................................................56
5.4 Interfaces...............................................................................58
5.5 .......................................................................................................58
6 CG ................................................................................60
6.1 Comparison Operators ......................................................60
6.2 Logical Operators..............................................................61
6.3 Math Operators .................................................................62
6.4 ...................................................................................................62
6.5 Swizzle ............................................................................................63
6.6 Conditional Operators........................................................64
6.7 ...........................................................................................65
6.8 Control Flow Statement .....................................................66
7 \..................................................................................67
7.1 Cg .....................................................................................................67
7.2 uniform..........................................................................................................68
7.3 const ..............................................................................................................69
7.4 \in\out\inout..............................................................69
7.5 SemanticBinding Semantics ..........................70
7.5.1 ...............................................................71
7.5.2 ...................................................................72
7.5.3 ...................................................................73
7.5.4 ...................................................................75
9
7.5.5 .......................................................................................75
8 ............................................................................................79
8.1 ...............................................................................................................79
8.1.1 ...............................................................................................80
8.2 ........................................................................................................81
8.3 .......................................................................................................82
8.4 CG ............................................................................................83
8.4.1 Mathematical Functions................................................84
8.4.2 Geometric Functions.....................................................87
8.4.3 Texture Map Functions .........................................88
8.4.4 Derivative Functions.....................................................91
8.4.5 Debugging Function......................................................94
8.5 ................................................................................94
...............................................................................................................96
9 illumination model .........................................................97
9.1 ...............................................................................................................97
9.2 Lambert ...............................................................................98
9.2.1 ..........................................................................................99
9.3 Phong .............................................................................102
9.3.1 phong ..................................................................................103
9.4 Blinn-Phong ...............................................................................107
9.5 Rendering Equation ........................................................109
9.6 .....................................................................................................110
10 ............................................................................................ 111
10.1 Cook-Torrance .........................................................................112
10.1.1 Cook-Torrance .................................................116
10.2 BRDF .......................................................................................118
10.2.1 BRDF ...............................................................118
10.2.2 ............................................................................119
10
10.3 Bank BRDF ................................................................................120
10.4 ...................................................................................................123
11 ........................................................................124
11.1 Snell Fresnel ........................................................................125
11.1.1 Snell ......................................................................125
11.1.2 ................................................................................................126
11.1.3 Fresnel ...................................................................................127
11.2 ....................................................................................................128
11.3 ...................................................................................132
11.4 ...........................................................136
12 Projective Texture Mapping.......................................137
12.1 ...............................................................................137
12.2 Homogeneous Texture Coordinates..........................139
12.3 ........................................................................................139
12.4 ...................................................................................................143
13 Shadow Map ..............................................................................................144
13.1 depth map.....................................................................................144
13.2 Shadow map shadow texture ..................................................145
13.3 Shadow map .................................................................146
14 Volume Rendering .........................................................152
14.1 ...............................................................................153
14.2 .......................................................................................153
14.3 ...................................................................................154
14.4 Volume Data .........................................................................155
14.4.2 Voxel ................................................................................156
14.4.1 Volume Texture ............................................................157
14.5 ...............................................................................................159
15 Ray Casting................................................................160
15.1 ...................................................................................160
11
15.1.1 ...........................................................................................161
15.2 ...................................................................161
15.2.1 ......................................................................161
15.2.2 ..................................................................................163
15.2.3 ..............................................................................164
15.2.2 ..........................................................166
15.3 ...................................................................................................168
15.4 ...................................................................................169
15.5 ...................................................................................................172
A ................................................................................................173
B.............................................................................175
CStencil Shadow ............................................................178
....................................................................................................................182
Alice
Alice
Alice
12
1
GPU 20 70 80
monolithic GPU
20 80 90
digital signal processor chip GPU
1991
S3 Graphics 2D 1995 PC
2D
fixed-function Windows accelerators
PC
13
3 2 302 million
workstation GPU
cube mapNVIDIA GeForce256
GeForce MAXATI Radeon 7500
14
programmability fragment programmability DirectX OpenGL
API vertex programmability fragment programmability 2003
DirectX OpenGL
GPU GeForce
ATI
DirectX OpenGL
2. IEEE32
3. 4 4
4.
5. >27.1GB/s
6. 1D2D3D
7. Render to TextureRTT
15
complex algorithms.
GPU highly parallel structure
GPU CPU 1 GPU VS
CPU GPU CPU CPU
CPU
OS GPU
ALU ALU
Cache
DRAM DRAM
GPU CPU
1 GPU VS CPU
GPU
1
2 2D
CPU C++ GPU
16
2 CPU GPU
GPU CPU
GPU CPU GPU CPU
GPU CPU
GPU
GPU CPU
GPU CPUGPU
CPU
OpenGL fp2.0fp3.0
DirectX ps_4_0 profile
GPU
GPU
4-6
2012 GPU
GPU API
GPU
GPU
Shader language GPU
17
1.3
CT CPU
GPU
CPU
GPU GPU
GPUGPGPU
General-Purpose Computing on Graphics Processing Units,GPGP
GP 2 GPU
linear algebra
kruger and westermann 2003
physical simulation
Harris et al. 2003ray tracer
Purcell et
al.2002 Carr et al. 2002GPU
GPU29GPGPU
http://gpgpu.org/
GPU GPU
2004 BROOKGPU
C
BROOK GPU BROOKGPU AMD
30
1.4
GPU GPU
GPU bank BRDF
ray-casting GPU
18
GPU
GPU
Cg
NVIDIA The Cg Tutorial The Definitive Guide to
Programmable Real-Time Graphics Cg ToolKit Users Manual
The Cg Tutorial The Definitive Guide to
Programmable Real-Time Graphics Cg _
Cg ToolKit
Users Manual
GPU
Cg BRDF
BRDF
19
GPU
20
2 GPU
GPU
GPU
GPU
GPU
GPU
CC++JAVA
CPU
b/s
Accelerated Graphic Port,AGP
387
234 GPU
10
Pixel
21
2.1
T<&L Transform & Lighting
GPU
GPU
GPU
Object spaceWorld spaceEye space
Clip and Project space 3 GPU
22
3 GPU
The object space for one object may have no relationship to the object space of
another object.3
23
world space coordinate object space coordinate
world space coordinate world
matrix
3D
11
GPU
world space eye space
Frustum Culling
24
4
Once positions are in eye space, the next step is to determine what positions are
actually viewable in the image you eventually intend trend.3
eye space
viewing frustum
Frustum Culling
clip
viewing frustum
CVV
screen coordinate space
25
1. CVV
2. CVV
3.
viewing frustum
CVV
Twinsen
12 3
CVV
12
5
1 Twinsen
2 GPU C\C++
CPU
GPU
GPU
GPU C++ OGRE
Object-Oriented Graphics Rendering Engine
26
Back-face Culling
OpenGL
enable disable
2.2 2.3
Triangle Setup
Rasterizing
2.3
2.3.1 Rasterization
27
2 3
10.4820.511021
52
DDA Bresenham
3
(vertex)
(pixel)
Pixel operation
2Texture operation
3Blending
28
Alpha
alpha
RGB Z
alpha
alpha 1.0 0
RGBA over
a alpha ca cs
cd Over
compositingOGRE
compositor
z buffer
4.5 59
4Filtering Filtering
5 21.2.3
29
5 OpenGL Direct3D Raster Operations
2.4
GPU
z bufferstencil buffer
frame buffer color buffer
2.4.1 GPU
cpu gpu
cpu gpu
Shader
GPU glsl hlsl
GPU
30
6 GPU
2.4.2 Z Buffer Z
Z Euclidean distance
az +b
z _ buffer _ value = (1 << N )
z
f
a=
f n
31
f n
b=
n f
f n
z N Z
z buffer z
Z
3D
7 AE
1 5 234
BCD BCD
Z Z
Z
1000
32
7 Z
16 Z buffer 24 Z buffer
32 32 Z buffer Z
Z-precision
Z Z
flimmeringZ-fighting
A stencil buffer is an extra buffer, in addition to the color buffer and depth buffer
found on modern computer graphics hardware. The buffer is per pixel, and works on
integer values, usually with a depth of one byte per pixel. The depth buffer and stencil
buffer often share the same area in the RAM of the graphics hardware.
33
stencil buffer( Z buffer) Z buffer stencil buffer
Stencil buffer
buffer stencil buffer 1
shadow volume
Frame buffer: The portion of memory reserved for holding the complete
bit-mapped image that is sent to the monitor. Typically the frame buffer is stored in
the memory chips on the video adapter. In some instances, however, the video chipset
is integrated into the motherboard design, and the frame buffer is stored in general
main memory.
34
2.5
GPU
GPU
openGPU
2 3 Blinn A Trip
Down the Graphics Pineline
35
3 Shader Language
In the last year I have never had to write a single HLSL/GLSL shader. Bottom
line, I cant think of any reason NOT to use CG.
shader languageshade
Wikipedia shader language The job of a surface shading procedure is
to choose a color for each pixel on a surface, incorporating any variations in color of
the surface itself and the effects of lights that shine on the surface(Marc Olano)
shader language
GPU shader
language
shader language
Shader language
3 OpenGL GLSL Direct3D HLSL NVIDIA
Cg
shader language
Programmable Vertex Processor
36
Programmable Fragment Processor
vertex program fragment program
GLSLHLSL Cg
The vertex and Fragment processing broken out into programmable units. The
Programmable vertex processor is the hardware unit that runs your Cg Vertex
programs, whereas the programmable fragment processor is the unit that runs your Cg
fragment programs.
GPU 8
37
8
3 GPU
9 \
buffer
38
9 \
GPU
10
vertex buffer
texture buffer
39
phong
Gourand
phong
phong Gourand
GPU shader
10
40
GPU
41
HLSL windows
HLSL HLSL
Shader language HLSL
NVIDIA AMD ATI
GPU GeForce
Cg NVIDIA
GPU
GPU Cg
NVIDIA Cg
Cg
Cg OpenGL Direct3D
Cg OpenGLDirectX OpenGL DirectX
Cg OpenGL DirectX
Cg Microsoft NVIDIA
[1] 1.3.1 Microsoft and NVIDIAs
Collaboration to Develop Cg and HLSLHLSL Cg
Cg _ 29
HLSL Cg cg
Microsoft NVIDIA cg
GPU CG
Microsoft NVIDIA Cg
42
GLSL
Cg C for graphics C
C
C++ Java C cg C
CC++Java Cg
Cg C
Cg cg
NVIDIA Cg
CgGLSLHLSL Cg
2007 12 OSG CgGLSLHLSL
Cg GLSL
3D Cg
2009 Cg
OGRE Cg GLSL
In the last year I have never had to write a single HLSL/GLSL shader. Bottom
line, I cant think of any reason NOT to use CG.
3.5
CgGLSLHLSL
Cg GLSL
43
4 Cg
Cg C Cg
*. Cg
4.1 Cg
NVIDIA http://developer.nvidia.com/object/cg_toolkit.html Cg
Toolkit 2009 10 Cg 2.2
bin cgc.exe NVIDIA Cg
Cg NVIDIA Cg
IDE
.cg NShader
http://nshader.codeplex.com/ Visual Studio2008
11
44
11 NShader
4.2 CG
4.3 CG
4.3.1 CG
01
C C++
.exe GPU
static
coompilation
dynamic compilation
Cg Cg ( Cg
45
Runtime library) Cg Cg
OGRE
[2] 1.4.2 Cg
Cg
Cg Cg APIOpenGL Direct3D
OpenGL Direct3D Cg
OpenGL Direct3D
NVIDIA Cg cgc.exe
Cg
Cg
GPU Cg
AIP Cg
Cg Profiles profile profile
profile
Cg Profiles Cg Cg
Cg Profile
46
4.3.1 CGC
12 cgc -h
Cg
[options]file Cg
profile
47
1. profile profile
profile
profile
profile profile fp20
profile
2. profile
profile
tex2D(sampler2D tex , float3 sz ,float2 dsdx , float2 dsdy ) fp20
48
fp30
while loops may only be used if the compiler can fully unroll them (that is, if the
compiler can determine the iteration count at compile time)
profilesforwhile
profilesfor,while
profiles
3. .cg
4. cgc Cg
GLSL HLSL
test.cg main_v
glsl direct.glsl
5.
49
GPU
C++\JAVA
4.4 CG Profiles
Cg compiler profiles
z OpenGL ARB vertex programs
Runtime profile: CG_PROFILE_ARBVP1
Compiler option: _profile arbvp1
z OpenGL ARB fragment programs
Runtime profile: CG_PROFILE_ARBFP1
Compiler option: _profile arbfp1
50
z OpenGL NV40 vertex programs
Runtime profile: CG_PROFILE_VP40
Compiler option: _profile vp40
z OpenGL NV40 fragment programs
Runtime profile: CG_PROFILE_FP40
Compiler option: _profile fp40
z OpenGL NV30 vertex programs
Runtime profile: CG_PROFILE_VP30
Compiler option: _profile vp30
z OpenGL NV30 fragment programs
Runtime profile: CG_PROFILE_FP30
Compiler option: _profile fp30
z OpenGL NV2X vertex programs
Runtime profile: CG_PROFILE_VP20
Compiler option: _profile vp20
z OpenGL NV2X fragment programs
Runtime profile: CG_PROFILE_FP20
Compiler option: _profile fp20
z DirectX 9 vertex shaders
Runtime profiles: CG_PROFILE_VS_2_X
CG_PROFILE_VS_2_0
Compiler options:-profile vs_2_x
-profile vs_2_0
z DirectX 9 pixel shaders
Runtime profiles: CG_PROFILE_PS_2_X
CG_PROFILE_PS_2_0
Compiler options: -profile ps_2_x
-profile ps_2_0
z DirectX 8 vertex shaders
Runtime profiles: CG_PROFILE_VS_1_1
51
Compiler options:-profile vs_1_1
z DirectX 8 pixel shaders
Runtime profiles: CG_PROFILE_PS_1_3
CG_PROFILE_PS_1_2
CG_PROFILE_PS_1_1
Compiler options: -profile ps_1_3
-profile ps_1_2
-profile ps_1_2
-profile ps_1_1
2009 10 profile
DirectX 11 profile
52
5 CG
Cgbuilt inprimitive
5.1
Cg 7
1. float32 profile
DirectX8 pixel profiles
2. half16
5. bool, if ?:
profiles
7. string profile
Cg Cg runtime API
Cg
53
6 Wikipedia Cg
6 string Cg
(built-in vector data types)
float4 float 4 bool4 bool
4
4 Cg float1float2float3
float4 4
float5 array;//
Cg 4*4
54
Cg
C\C++ C\C++
Cg
5.2
Cg
Cg
Cg C
.length
float a[10]; //
int length = a.length;//
55
float b[2][3] = {{0.0, 0.0, 0.0},{1.0, 1.0, 1.0}};
4*4
float M[4][4];4 float4x4 M 16
float 4 float4x4 M[4]
4 4
profiles
8 8.1
5.3
Cg structure Cg C++
Cg
C++
public private shader
Cg
56
struct
myAdd
struct myAdd
{
float val;
float add(float x)
{
return val + x;
}
};
myAdd s;
float a = s.value;
float b = s.add(a);
profile
,Cg
C
( Binding Semantics)
57
Cg POSTION )COLOR()NORMAL(
)Texcoord()
5.4 Interfaces
Cg
Cg
GPU
3
Interfaces
5.5
Cg C C
Cg
float a = 1.0;
half b = 2.0;
float c = a+b; // float c = a + (float)b;
float a = 1.0;
float b = a + 2.0; //2.0 float
Cg
58
float a = 1.0;
float b = a + 2.0h; //2.0h half
type suffix 3
z f float;
z h: half;
z x: fixed
59
6 CG
Cg7
Cg
operatoroperand
CgCC
CgSwizzle
CCg
>Cg
C
Cg6
1, bool
!= expr != expr
== expr == expr
60
Cgbool
boolean operator
Cgboolean operator
bool
Cg3(boolean Operators) 2
bool
|| expr || expr
! !expr
2
bool
Cg&&||C
short-circuitingbool
bool
61
6.3 Math Operators
CgCg*
/-+%++*=/=+=-=
23.3Math Expressions
++
Cg
%int
error C1021: operands to % must be integral.
void function()
{
float2 a = float2(1.0, 1.0);
float b = 2.0;
f *= d;
f *= 2.0;
}
6.4
CgC
int
62
int2 a = int2(0.0,0.0);
int2 b = a>>1;
float2 a = int2(0.0,0.0);
float2 b = a>>1;
6.5 Swizzle
Cgswizzle.
swizzleGPUswizzlexyzw
swizzle
rgba
swizzlergba
Cgfloat a float1 a
floatboolhalfswizzle
float a = 1.0;
float4 b = a.xxxx;
swizzle
swizzleerror C1010: expression left of .x is
63
not a struct or arrayarrayvector
[]
expr1trueflasetrue,expr2expr3
if-else
Cgexpr1
boolexpr2expr3expr1
64
float3 h = float3(-1.0,1.0,1.0);
float3 i = float3(1.0,0.0,0.0);
float3 g = float3(1.0,1.0,0.0);
float3 k;
k = (h < float3(0.0,0.0,0.0))?(i):(g);
6.7
Cg 3
Cg_
3.3.1
() [] -> .
! ~ ++ - + - * &
(type) sizeof
*/%
+-
<< >>
< >= > >=
== !=
&
^
|
&&
||
?:
= += -= *= /= %=
&= ^= != <<= >>=
,
65
3
statement
Cifif-else
switchwhiledo-whileforCg
Cifif-elsewhileforbreak
for
Cgbool
CC01
vs_2_x, vp30vp40profilebranch
instruction
forwhileprofile3
In other profiles, for and while loops may only be used if the compiler can
fully unroll them (that is, if the compiler can determine the iteration count at compile
time)
profilesforwhile
fp40ps_3_0
profilesfor, whileerror c6003instruction
limit of exceededprofiles
returnrecursion
CgSwitch casedefaultCg
profile
66
7 \
GPU
Cg
1. GPUGPU
GPU
2. GPU
3.
7.1 Cg
67
intfloat structCg
C\C++ Cg
Semanticsbinding semantics
Cg inoutinout
\
in out
Cg uniformconst
C\C++
Cg
7.2 uniform
1. Varying inputs,
GPU
Cg
2. Uniform inputs
Uniform
68
uniform float brightness,
uniform float4x4 modleWorldProject
float 4
OpenGL DirectX
Uniform
uniform Cg
uniform
uniform
7.3 const
const uniform
const uniform
7.4 \in\out\inout
C\C++
69
pass-by-value
pass-by-reference
C\C++
Cg
GPU Cg
1. in:
2. out:
3. inout:
return out \
70
Varying inputs
binding semantics
7.5.1
GPU
C/C++
Cg
Cg
binding semantics\
OpenGL Cg profiles
DirectX-based Cg profiles
\
POSITION
Shader POSITION
71
POSITION
POSITION
POSITION
OpenGL Cg profiles \
DirectX Cg profiles 3
25
In the OpenGL Cg profiles, binding semantics implicitly specify the mapping of varying
inputs to particular hardware registers. However, in DirectX based Cg profiles there is no
such implied mapping.
3 260
Often, these predefined names correspond to the names of hardware registers or API
resources
7.5.2
13 Cg vertex profile ,
profile
POSITION BLENDWEIGHT
NORMAL TANGENT
BINORMAL PSIZE
BLENDINDICES TEXCOORD0---TEXCOORD7
13
POSITION0 POSITION
POSITION OpenGL
72
NORMAL OpenGL
A
1
0
7.5.3
POSITION
POSITION
POSITION
73
void main_v(float4 position: POSITION,
//out float4 oposition : POSITION,
uniform float4x4 modelViewProj)
{
//oposition = mul(modelViewProj,position);
}
struct
struct VertexIn
{
float4 position : POSITION;
float4 normal : NORMAL;
};
struct VertexScreen
{
float4 oPosition : POSITION;
float4 objectPos : TEXCOORD0;
float4 objectNormal : TEXCOORD1;
};
struct
POSITION
TEXCOORD
TEXCOORD
74
struct
vertex programPOSITION
fragment program
7.5.4
COLOR
GPU out
COLOR
color.xyz = float3(1.0,1.0,1.0);
color.w = 1.0;
}
fragment profileDEPTH
multiple
render targets , MRTs
COLOR
7.5.5
\ 4 3 260
75
1.
const inoutinout
type identifier
3
2. struct
struct <struct-tag>
{
<type><identifier> [:<binding-semantic >];
};
C2E1v_Outpu 2 POSITION
COLOR C2E1v_green C2E1v_Outpu
76
struct C2E1v_Output {
float4 position : POSITION;
float3 color : COLOR;
};
return OUT;
}
3.
return ocolor;
}
4.
77
<type> <identifier> [:<binding-semantic>][=<initializer>];
78
8
5 7 5
6 \ 7
Cg
\ C\C++ main() Cg
8.1
Cg
C\C++return typeparameter list
void
void
7.4 \
79
C\C++ Cg
8.1.1
C\C++
stephen C.Dewhurst C++
Cg
Cg [3]Array
The most important difference from C is that arrays are first-class types. That
means array assignments actually copy the entire array, and arrays that are passed as
parameters are passed by value, rather than by reference.
Cg first-class types
first-class
Unsized Array
80
myFunc
float
void main()
{
float a[2] = {0.0, 1.0};
float b[3] = {0.0, 1.0, 2.0};
myFunc(a); //
myFunc(b); //
}
8.2
81
bool function(float a, float b) {return ( a == b);}
bool function(boo a, bool b) {return ( a == b);}
Cg
8.3
C\C++ main()
4.4 CG main
Cg
7.5
C2E1v_green
return CgNVIDIA
Corporation\Cg\examples\OpenGL\basic\ 01_vertex_program\C2E1v_green.cg
82
struct C2E1v_Output {
float4 position : POSITION;
float3 color : COLOR;
};
OUT.position = float4(position,0,1);
OUT.color = float3(0,1,0);
return OUT;
}
8.4 CG
C Cg
reflect
refract mul
GPU
Cg GPU
GPU
Cg
1. Mathematical Functions;
2. (Geometric Functions)
3. (Texture Map Functions)
4. (Derivative Functions)
83
5. (Debugging Function)
4 Cg
abs(x)
acos(x) [-1,1]
[ 0, ]
all(x) 0 ture
flase&&
any(x) 0
true||
asin(x)
, [ 1,1]
,
2 2
atan(x)
,
2 2
atan2(y,x) y/x atan(x)
atan(x) =
atan2(x, float(1))
ceil(x) ceil(float(1.3))
2.0
clamp(x,a,b) x a a x b
b x
cos(x)
x [ 1,1]
84
determinant(m)
dot(A,B) A B (dot product)
A B
exp(x)
e x e= 2.71828182845904523536
exp2(x)
2 x
floor(x) floor(float(1.3))
1.0 floor(float(-1.3))
-2.0 ceil(x)
fmod(x,y) x/y y 0
frac(x) Returns the fractional portion of a scalar or
each vector component
frexp(x, out x
exp) x = m* 2^exp m exp
x 0 0
isfinite(x)
true false;
(not-a-number NaN)
isinf(x)
true false;
isnan(x)
(not-a-number NaN) true
false;
ldexp(x, n)
x 2n
lerp(a, b, f)
(1 f ) a + b f a + f ( b a )
a b f
a b f
lit(NdotL, N L H
NdotH, m) m
4
X 1.0
Y N L < 0
0 N L
Z N L < 0
N H < 0 0 ( N H ) m
W 1.0
85
log(x)
ln ( x ) x 0
log2(x)
log (2x ) x 0
log10(x) ( x)
log10 x 0
max(a, b)
min(a,b)
modf(x, out ip) Cg Reference Manual
mul(M, N) M AxB
N BxC AxC
mul(M, v)
mul(v, M)
noise( x) 01
pow(x, y) y
x
radians(x)
round(x) Round-to-nearest closest integer to x
rsqrt(x) X x 0
saturate(x) x 0 0 x 1
1 x
sign(x) x 0 1 x 0
01 0
sin(x)
[ 1,1]
86
tan(x)
tanh(x)
transpose(M) M
4 Cg
5
Cg
3 normalize reflect
refract
1.
2. reflect refract
distance( pt1, pt2) Euclidean
distance
faceforward(N,I,Ng)
Ng I < 0 N-N
length(v) sqrt(dot(v,v))
normalize( v)
reflect(I, N) I
N I N
I
refract(I,N,eta) I N
eta I N
I N
000
I
87
5 Cg
Cg ps_2_0ps_2_x
arbfp1fp30 fp40 profiles fully supported
tex1D(sampler1D tex, float s)
tex1D(sampler1D tex, float s, float dsdx, float dsdy)
derivatives
Tex1D(sampler1D tex, float2 sz)
Tex1D(sampler1D tex, float2 sz, float dsdx,float dsdy)
derivatives
Tex1Dproj(sampler1D tex, float2 sq)
Tex1Dproj(sampler1D tex, float3 szq)
Tex2D(sampler2D tex, float2 s)
Tex2D(sampler2D tex, float2 s, float2 dsdx, float2 dsdy)
derivatives
Tex2D(sampler2D tex, float3 sz)
Tex2D(sampler2D tex, float3 sz, float2 dsdx,float2 dsdy)
derivatives
Tex2Dproj(sampler2D tex, float3 sq)
Tex2Dproj(sampler2D tex, float4 szq)
texRECT(samplerRECT tex, float2 s)
88
texRECT proj(samplerRECT tex, float3 sq)
texRECT proj(samplerRECT tex, float3 szq)
Tex3D(sampler3D tex, float s)
Tex3D(sampler3D tex, float3 s, float3 dsdx, float3 dsdy)
derivatives
Tex3Dproj(sampler3D tex, float4 szq)
texCUBE(samplerCUBE tex, float3 s)
texCUBE (samplerCUBE tex, float3 s, float3 dsdx, float3 dsdy)
derivatives
texCUBEproj (samplerCUBE tex, float4 sq)
6 Cg
s z depth comparison
q perspective value,
S
0 1
1D
2D 3D TexREC
3D Volume Texture
14
15 16
89
14
proj
float4
uvproj
tex2Dproj(texture,uvproj);
90
8.4.4 Derivative Functions
ddx(a) a
X
ddy(a) a
X
7 Cg
ddx x
ddy y
Cg Refernece
Manual ddx (ddy )returns
approximate partial derivative with respect to window-space X
\
1. ddx ddy
2. ddx ddy
3. ddx ddy
If you evaluate ddx (myVar), the GPU will give you the difference between the
value of myVar at the current pixel and its value at the pixel next door. It's a straight
linear difference, made efficient by the nature of GPU SIMD architectures
(neighboring pixels will be calculated simultaneously).The derivative of any uniform
value will always be zero.Because these derivatives are always linear, the second
derivativesfor example, ddx(ddx(myVar))will always be zero.
ddx myVar
p ( i, j ) ddx(myVar) p ( i + 1, j ) myVar
91
ddy(myVar) p ( i, j + 1) myVar ddx ddy
p ( i + 1, j ) myVar
1. ddx ddy
2. ddx ddy
3. ddx ddy
Complex filtering depends on knowing just how much of the texture (or shading)
we need to filter. Modern GPUs such as the GeForce FX provide partial derivative
functions to help us. For any value used in shading, we can ask the GPU: "How much
does this value change from pixel to pixel, in either the screen-x or the screen-y
direction?"
These functions are ddx() and ddy(). Although they are little used, they can be
very helpful for filtering and antialiasing operations.
92
ddx X ddy Y
ddx ddy
A B
A B
GeForce GPU
15
15
93
16
void debug(float4 x) DEBUG
x
COLOR
8 Cg
8.5
94
IDE
GPU
95
913
1415
illumination model
ward BRDF
IMopenGPU
96
9 illumination model
---
CG
CG
9.1
(Ambient Light):
389
97
9.2 Lambert
diffuse reflection
Lambert
(9-1)
I ambdiff = kd I a (9-1)
I a kd 0< kd <1
I ambdiff
Lambert
98
Lambert Lambert
Il
(0 90) I ldiff
90
N L
cos N L (9-2)
(9-3)
I ldiff = kd I l ( N L) (9-3)
Lambert
9.2.1
Hello Cg World
Cg
99
1
//
float3 L = lightPosition - worldPos;
L = normalize(L);
//
float3 diffuseColor = Kd*lightColor*max(dot(N, L), 0);
//
float3 ambientColor = Kd*globalAmbient;
color.xyz = diffuseColor+ambientColor;
color.w = 1;
}
17
17
100
2
struct VertexIn
{
float4 position : POSITION;
float4 normal : NORMAL;
};
struct VertexScreen
{
float4 oPosition : POSITION;
float4 color : COLOR;
};
void main_v(VertexIn posIn,
out VertexScreen posOut,
//
float3 L = lightPosition - worldPos;
L = normalize(L);
//
float3 diffuseColor = Kd*lightColor*max(dot(N, L), 0);
//
float3 ambientColor = Kd*globalAmbient;
posOut.color.xyz = diffuseColor+ambientColor;
posOut.color.w = 1;
}
101
9.3 Phong
Lambert
(9-5)
I spec = k s I l (V R ) ns (9-5)
k s ns V
ns
ns
R L N
R + L = (2 N L) N (9-6)
102
R = (2 N L) N L (9-7)
Cg 8.3.2
VS
9.3.1 phong
Phong 3 18
phong
18 phong
18 phong
18
phong
103
3 phong
struct VertexIn
{
float4 position : POSITION; // Vertex in object-space
float4 normal : NORMAL;
};
struct VertexScreen
{
float4 oPosition : POSITION;
float4 color : COLOR;
};
void main_v( VertexIn posIn,
out VertexScreen posOut,
uniform float4x4 modelViewProj,
uniform float4x4 worldMatrix,
uniform float4x4 worldMatrix_IT,
uniform float3 globalAmbient,
uniform float3 eyePosition,
uniform float3 lightPosition,
uniform float3 lightColor,
uniform float3 Kd,
uniform float3 Ks,
uniform float shininess)
{
posOut.oPosition = mul(modelViewProj, posIn.position);
//
float3 L = normalize(lightPosition - worldPos);
float3 V = normalize(eyePosition - worldPos);
float3 R = 2*max(dot(N, L), 0)*N-L;
R = normalize(R);
//
float3 diffuseColor = Kd * globalAmbient+Kd*lightColor*max(dot(N, L), 0);
//
float3 specularColor = Ks * lightColor*pow(max(dot(V, R), 0), shininess);
104
phong
4 3 VertexScreen
TEXCOORD objectPos objectNormal
4 phong
struct VertexIn
{
float4 position : POSITION;
float4 normal : NORMAL;
};
struct VertexScreen
{
float4 oPosition : POSITION;
float4 objectPos : TEXCOORD0;
float4 objectNormal : TEXCOORD1;
};
TEXCOORD
5 phong
105
6 phong
6 phong
//
float3 L = normalize(lightPosition - worldPos);
float3 V = normalize(eyePosition - worldPos);
float3 R = 2*max(dot(N, L), 0)*N-L;
R = normalize(R);
//
float3 diffuseColor = Kd * globalAmbient+Kd*lightColor*max(dot(N, L), 0);
//
float3 specularColor = Ks * lightColor*pow(max(dot(V, R), 0), shininess);
19 phong
106
19 phong
9.4 Blinn-Phong
phong V R R
V Blinn-phong N H
V R Blinn-phong
I spec = ks I l ( N H ) ns
9-8
N H L V
107
L +V
H= 9-9
| L +V |
Blinn-phong phong
phong blinn-phong
Blinn-phong Blinn-phong
Blinn-phong
phong
Blinn-phong
7 Blinn-phong
//\\
float3 L = normalize(lightPosition - worldPos);
float3 V = normalize(eyePosition - worldPos);
float3 H = normalize(L + V);
//
float3 diffuseColor = Kd * globalAmbient+Kd*lightColor*max(dot(N, L), 0);
//
float3 specularColor = Ks * lightColor*pow(max(dot(N, H), 0), shininess);
108
Blinn-phong
20 Blinn-phong
19 20
phong blinn-phong
phong blinn-phong
x Lo ( x, wo ) x wo
Le ( x, wo ) x wo
f r ( x, wi , wo ) wi x wo
BRDF Li ( x, wi ) wi x n x
phong BRDF
109
Lo ( x, wo ) = f r ( x, wi , wo ) Li ( x, wi )(n wi ) 9-11
BRDF
112
I diff f rs ( x, wi , wo ) BRDF
Phong
ks (nih) ns
f rs ( x, wi , wo ) = 9-13
ni wi
10 BRDF f rs ( x, wi , wo )
9.6
GPU
110
10
21
21
BRDF
111
Cook-TorranceGPU
BRDFBRDFBidirectional Reflectance Distribution
FunctionBRDF
10.1 Cook-Torrance
phong blinn-phong
Cook-Torrance
10-1
I diff k s I l Rs
cook-Torrance phong
blinn-phong Rs cook-Torrancephong
blinn-phong Rs
Rs specular term
Cook-Torrance Rs Wikipedia
112
specular highlight 10-2
F D G
Rs = 10-2
V N
3D 117 D3DBook (Lighting)
Cook-Torrance 10-3
F D G
Rs = 10-3
( N iV ) ( N i L )
A Reflectance Model For Computer Graphics
10-3
term N V L
schlick Fresnel 11 1%
10-4
F = f 0 + (1 f 0 )(1 V i H )
5
10-4
f 0 0 Fresnel V
H
Backmann
tan 2
1
D= 2 e m2
10-5
m cos 4
m m m
113
N H
1 cos 2
tan 2
cos 2
cos 2 1 ( N i H )2 1
= = 2 = 10-6
m2 m2 m cos 2 m 2 ( N i H ) 2
Backmann 10-7
( N i H ) 2 1 ( N i H ) 2 1
1 2 2 1 2 2
D= 2 e m ( N i H ) = 2 e m ( N i H ) 10-7
m cos
4
m (N iH ) 4
G = min(1, G1 , G2 ) 10-8
2( N i H )( N i L)
G1 = 10-9
V iH
2( N i H )( N iV )
G2 = 10-10
V iH
= kd Il ( NiL) +ksIl
( f0 +(1 f0 )(1ViH)
5
) 1
m cos
2 4
em2(NiH)2
min(1,
2(NiH)(NiL) 2(NiH)(NiV)
ViH
,
ViH
)
ViN
10-11
119 beckmann
Backmann beckmann 10-12
114
( N i H ) 2 1
1 2 2
D= e m ( N i H ) 10-12
4 m ( N i H )
2 4
Cook-Torrance
beckmann
115
2. Computer graphics: principles and practice, James D. Foley - 1995 -
Computers - 1175
10.1.1 Cook-Torrance
Cook-Torrance 22
22 Cook-Torrance
Cook-Torrance
8 Cook-Torrance
116
9 Cook-Torrance
float nv = dot(N,V);
bool back = (nv>0) && (nl>0);
if(back)
{
float nh = dot(N,H);
float temp = (nh*nh-1)/(m*m*nh*nh);
float roughness = (exp(temp))/(pow(m,2)*pow(nh,4.0)); // beckmann
float vh = dot(V,H);
float a = (2*nh*nv)/vh;
float b = (2*nh*nl)/vh;
float geometric = min(a,b);
geometric = min(1,geometric); //
117
10.2 BRDF
10.2.1 BRDF
BRDF
111 23 wi wo
BRDF wi
wo
23
BRDF
dLr ( wo ) dLr ( wo )
f r ( wi , wo ) = = 10-13
dEi ( wi ) Li ( wi ) cos i dwi
118
Lr ( wo ) Ei ( wi )
wo Radiance
wi Irradiance
d dA
BRDF
10.2.2
(anisotropy)
anisotropic surface
24
24
119
25
1.
2.
3.
25
Bank BRDF
Bank BRDF
10-14
f = k s ( 1 ( L T ) 2 1 (V T ) 2 ( L T )(V T )) ns 10-14
ks ns L V
Bank BRDF 26 27 27
120
26 Bank BRDF 1
27 Bank BRDF 2
Bank BRDF
10 Bank BRDF
121
11 Bank BRDF
//
float3 V = normalize(eyePosition - P);
float3 H = normalize(L + V);
float3 specular = float3(0.0,0.0,0.0);
bool back = (dot(V,N)>0) && (dot(L,N));
if(back)
{
float3 T = normalize(cross(N,V)); //
float a = dot(L,T);
float b = dot(V,T);
float c = sqrt(1-pow(a,2.0))* sqrt(1-pow(b,2.0)) - a*b; // Bank BRDF
float brdf = Ks* pow(c, shininess);
122
10.4
123
11
CPUGPU
CPU
GPU
GPU
GPU
SnellFresnel
GPUGPU
3D
124
11.1 Snell Fresnel
11.1.1 Snell
c v 11-1
1
1
c
n= 11-1
v
\ 1.0\ 1.0003
1.333
1.5-1.7
2.417
1.309
Snell
28 i
ni t nt
snell
125
i
28 Snell
fresnel
fresnel
11.1.2
1672
29
1936
29
126
11.1.3 Fresnel
Fresnel
kr fresnel kt
fresnel
fresnel
3D
117 Fresnel
schlick Fresnel 1%
F = f 0 + (1 f 0 )(1 V i H )
5
11-3
f 0 0 Fresnel V
H 11-3
90 1
127
(n n )
2
f0 = i t 2 11-4
( ni + nt )
fresnel 1
0 fresnel
4n1n2
ft 0 = 1 f 0 = 11-5
( ni + nt )
2
11-311-4
fresnel
(n n )
2
4n1n2
F i t 2+ (1 V H )5 11-6
( ni + nt ) ( ni + nt )
2
11-6 0
fresnel 11-7
fresnel
11-7
F (1 V H ) 4 11-7
4%
11.2
Greece 1986 11
128
6
6
DirectX
.dds 6
29 OGRE 2
30 OGRE 2
2 5.7.4
31
129
31
1.
2.
3.
Cg smaplerCUBE
texCUBE
12
130
12
//
float3 positionW = mul( modelToWorld, position).xyz;
float3 normalW = mul( modelToWorld_IT, normal).xyz;
normalW = normalize( normalW);
float3 I = positionW - eyePosition;
// R.
R = reflect( I, normalW );
}
32
131
32
11.3
33
t A A
ia , ib A
i = (1 t ) ib + t ia 11-8
132
ib
ia
33
ia ib
ib
34
34
133
11-8
Cg lerp
8.3.1
11.2
13
struct VertexIn
{
float4 position : POSITION;
float4 normal : NORMAL;
};
struct VertexScreen
{
float4 oPosition : POSITION;
float4 objectPos : TEXCOORD0;
float4 objectNormal : TEXCOORD1;
};
14
134
15
//\\
float3 L = normalize(lightPosition - worldPos);
float3 V = normalize(eyePosition - worldPos);
float3 H = normalize(L + V);
//
float3 diffuseColor = Kd * globalAmbient+Kd*lightColor*max(dot(N, L), 0);
float3 specularColor = Ks * lightColor*pow(max(dot(N, H), 0), shininess);
float3 reflectColor = diffuseColor+specularColor;
//, refract
float3 I = normalize(worldPos - eyePosition);
float3 T = refract(I, N, etaRatio);
//
float3 refractedColor = texCUBE(environmentMap, T).xyz;
135
11.4
GPU 16
136
12 Projective Texture Mapping
35
35 (12)
12.1
137
13
15
36
gradient
36
138
37
(a) (b)
37
s,t,r,q,(x, y, z,
w) s (s, t) r
q w 1
12.3
139
3D
NDC
POSTION
38
38
140
01 normalMatrix ,
1/21/2
0.5 0 0 0.5
0 0.5 0 0.5
normalMatrix = 12-1
0 0 0.5 0.5
0 0 0 1
Cg
tex2DProjtex2D
q
141
API
16
void main_v(
float4 position : POSITION,
float4 normal : NORMAL,
//
float4 worldPos = mul(worldMatrix, position);
outShadowUV = mul(texViewProj, worldPos);
}
142
17
void main_f(
float4 shadowUV : TEXCOORD0,
out float4 result : COLOR,
uniform sampler2D projectiveMap //
)
{
shadowUV = shadowUV / shadowUV.w;
float4 mapColor ;
// 0-1
shadowUV.x = (shadowUV.x +float(1.0))/float(2.0);
shadowUV.y = (shadowUV.y +float(1.0))/float(2.0);
mapColor = tex2D(projectiveMap, shadowUV.xy);
result = mapColor;
}
12.4
Shadow Map 16
143
13 Shadow Map
Shadows are created by testing whether a pixel is visible from the light source,
by comparing it to a z-buffer or depth image of the light source's view, stored in the
form of a texture.
2D
v v v
144
Shadow texture Depth texture
39
wikipid shadow map depth map
shadow texture
Shadow texture
texture
projective
Shadow map
Shadow map shadow
texture
145
shadow texture
depth map
1.
2. worldViewProjMatrix
Z Z
shadow
01Cg
0-1
depth map
depth map Z Buffer Z
Euclidean distanceZ
2.4.2 GPU
depth map
01
depth map
146
18 depth map
//
depth.x = oPosition.z;
depth.y = oPosition.w;
}
19 depth map
// 0-1
depthNum = (depth.x - pNear) / (pFar - pNear);
depthNum += depthOffset;
result.xyz = depthNum.xxx;
result.w = 1.0;
}
147
19 depthOffset
0.01
depth map
1.
worldViewProjMatrix
13
l enth2
2. depth map
l enth1
3. l enth2 l enth1
20 depth map
//
outShadowUV = mul(texViewProj, worldPos);
}
148
21 depth map
//
float4 depths = float4(
tex2D(shadowMap, shadowUV.xy + float2(-pixelOffset, 0)).x,
tex2D(shadowMap, shadowUV.xy + float2(pixelOffset, 0)).x,
tex2D(shadowMap, shadowUV.xy + float2(0, -pixelOffset)).x,
tex2D(shadowMap, shadowUV.xy + float2(0, pixelOffset)).x);
float centerdepth = tex2D(shadowMap, shadowUV.xy).x;
//
float l_Lit = (lightDistance >= centerdepth? 0 : 1);
l_Lit += (lightDistance >= depths.x? 0 : 1);
l_Lit += (lightDistance >= depths.y? 0 : 1);
l_Lit += (lightDistance >= depths.z? 0 : 1);
l_Lit += (lightDistance >= depths.w? 0 : 1);
l_Lit *= 0.2f;
40 shadow map
149
40 shadow map
Shadow map
Shadow map
depth map
01
z-fighting
Self-shadow Aliasing,
150
Spot light
Point light
cube textureDirectional light
, worldViewProjMatrix
stencil
shadow map C
151
14 Volume Rendering
1982 2
----1.1
M.Levoy
Display of surfaces from volume data(14)volume rendering
describes a wide range of techniques for generating images from three-dimensional
scalar data
CT
,
CT CT
152
80
GPU
openGPU
14.1
14.2
153
server the people,
CT
CT
B
41
41
14.3
,
phong
154
cook-torrance
ray-cast
155
C
H20
XYZ
1.
2. CT MRI
VoxelVolume Texture
14.4.2 Voxel
Wikipediavoxel
156
42
n*m*t
XYZnmt
256*256*256
256
mm
0.412mm0.412
42
volume texture
2d texture3d texturevolume texture
3d texture
23
2d texture3d texture
157
3d texturevolume texture22
2D
2D
1.
2.
x,y
XYvolume
texture
CT
DirectX.dds.raw
.raw
.raw.raw
158
.raw 43
University of TbingenGermanyViatronix Inc.(USA)Walter Reed Army Medical
Center (USA)
43
http://wwwvis.informatik.uni-stuttgart.de/~engel/pre-integrated/data.html
http://www9.informatik.uni-erlangen.de/External/vollib/
http://www.volren.org/
14.5
Ray-casting-
Shear-warp Frequency Domain
Splatting
GPU
15
159
15 Ray Casting
15.1
CPU
GPU
16.1.2
160
15.1.1
Optical Models
Optical Model
15
1. Absorption only
2. Emission only
3. Absorption plus emission
5. Multiple Scattering
15.2
15.2.1
161
OpenGL Direct3D
44
162
44
OpenGL 8
GPU 6 GPU
11
15.2.2
alpha
alpha over Alpha
c0 = as cs + (1 as )cd 15-1
as cs cd
c0
163
Ci Ai
Ci Ai
Ci = (1 Ai )Ci+1 + Ci
15-3
Ai = (1 Ai ) Ai+1 + Ai
15.2.3
45
45 F L
164
m F nn<m
tstart d delta
n t
n>m 1
OpenGL DirectX
profile
Cg OpenGL DirectX
165
15.2.2
m
n n>=m
n
CPU m
GPU
GPU
GPU
OpenGL Direct
1. frontDepth
14 frontDepth
2. backDepthbackDepth
166
3. m
14 shadow Map
\
46
46
frontDepth backDepth
rgba
a
01
167
15.3
front face
back face
47
47
168
48
48
15.4
169
22
struct VertexIn
{
float4 position : POSITION;
float4 texCoord: TEXCOORD;
};
struct VertexScreen
{
float4 position : POSITION;
float4 worldPos : TEXCOORD0;
float4 projPos : TEXCOORD1;
float4 texCoord : TEXCOORD2;
};
23
return posOut;
}
170
24
//
float3 tex = posIn.texCoord.xyz;
float2 uvDelta;
uvDelta.x = 0.0;//ddx( tex ).x;
uvDelta.y = 0.0;//ddy( tex ).y;
//,
float2 uv= posIn.projPos.xy/posIn.projPos.w;
float frontDis = tex2D(frontDepthTex,uv).x;
float backDis = tex2D(backDepthTex,uv).x;
float len = backDis-frontDis;
//
float3 norm_dir = normalize(dir);
float stepsize = 0.01;
float delta = stepsize;
float3 delta_dir = norm_dir * delta;
float delta_dir_len = length(delta_dir);
float3 vec = posIn.texCoord.xyz;
float4 col_acc = float4(0,0,0,0);
float alpha_acc = 0;
float length_acc = 0;
float4 color_sample;
float alpha_sample;
171
15.5
1415
Object-Order Empty Space
Skipping
Markus Hadwiger
Advanced Illumination Techniques for GPU-Based Volume
Raycasting SIGGRAPH ASIA2008
166
172
A
----F.S.Hill,JR
( a, b, c )
Z 317
1
0
v v1 v 2 v3
A-2
v = a v1 + b v 2 + c v3 A-2
p p1 p 2 p3 po
A-3
173
p = a p1 + b p 2 + c p3 + po A-3
A-2A-3 2
A-4A-5
v = ( a b c 0 ) ( v1 v 2 v3 p0 ) A-4
p = ( a b c 1) ( p1 p 2 p3 p0 ) A-5
1 0 1
p ( x p yp z p ) ( t x ty t z )
(x '
p y' p z' p ) = ( xp yp z p ) + (tx ty tz ) A-6
x ' p 1 0 0 tx x p
'
y p = 0 1 0 t y y p
A-7
z ' p 0 0 1 tz z p
1 0 0 0 1 1
174
B
1CT
X
XX
X
1963X
CT1967
XCT
19719
104
X
X
19724
CTCT
X
1979CT
CTXX
1895XX
X70
175
30CT
CT
CTXX
XX
x
CTXCTX
CT
X XCT2000
X20
2CT
CTX
CTXX
CT
X
176
CT
1~10
CT
CT
CT
3CT
CTX
X/
analog/digital converter
voxel
X
digital matrix/
digital/analog converter
pixelCTCT
X
I0 X , d X
X I
177
I = I 0 e ud B-1
()
, X
CT
CT X
X
123 d
I ,
CT CT
CT
u uwater
CT = *1000 B-3
uwater
CStencil Shadow
Stencil Shadowstencil
buffer
shadow map
178
OGRE
shadow volume
stencil buffer
2.4.3
B
A
C
D
E
49
1
2
179
3D
50
50
501 502
503
Z Pass stencil
stencil stencil
stencil
stencil
stencil stencil
2.4.3
180
Z Pass z buffer
stencil buffer
1Z Enable z buffer
2Z Disable z buffer
stencil
stencil
3
stencil
4
stencil stencil buffer
Z Pass stencil
shadow volume
1
2
stencil
3
181
stencil
4 stencil
stencil
Z Fail
51
Doom3
object
Outlining
1 Feng Liu, Platform Independent Real-time X3D Shaders and Their Applications
in Bioinformatics Visualization, Georgia State University, 2005, ISBN:
0-542-56173-5, Order Number: AAI3207182.
182
2 Randima Fernando, Mark J. Kilgard, The Cg Tutorial The Definitive Guide to
Programmable Real-Time Graphics, Addison-Wdsley Professional, March 8, 2003,
ISBN-10: 0321194969.
3 Cg Toolkit Users Manual A Developers Guide to Programmable Graphics.
Release 1.4, September 2005.
4 Kr uger, J., and Westermann, R. 2003. Linear algebra operators for GPU
implementation of numerical algorithms. ACM Trans. Graph. 22, 3, 908-916.
5 Harris, M. J., Baxter, W. V., Scheuermann, T., and Lastra, A. 2003. Simulation of
cloud dynamics on graphics hardware. In Proceedings of Graphics hardware,
Eurographics Association, 92-101.
6 Purcell, T. J., Buck, I., Mark, W. R., and Hanrahan, P. 2002. Ray tracing on
programmable graphics hardware. ACM Trans. Graph., 703-712.
7 Alexander J.Faaborg, A Psychophysical Study of BRDF-Based Lighting, May 10,
2001.
8 Wynn, C. (2000). An Introduction to BRDF-Based Lighting. nVIDIA
Corporation.
9 Michael Ashikhmin, Peter Shirley, An Anisotropic Phong BRDF Model. August
13, 2000.
10 Blinn, J.F., and M.E. Newell, Texture and reflection in computer generated
images, Communications of the ACM, vol.19, no. 10, pp.542-547, October 1976.
11 Greene, Ned, Environment Mapping and Other Applications of World
Projections, IEEE Computer Graphics and Application, vol, 6, no, 11, pp21-29,
November 1986.
12 Cass Everitt, Projective Texture Mapping, 04/24/2001
13 Lance Williams, Casting curved shadows on curved surfaces, 1978,
ISSN:0097-8930, page: 270-274.
14 Levoy,M. Display of surfaces from volume data. May, 1988, Computer Graphics
and Applications, IEEE, Volume: 8, Issue: 3.
15 Nelson Max. Optical models for direct volume rendering. IEEE
183
19 Crow,Franklin C:Shadow Algorithms for Computer Graphics, Computer
Graphics (SIGGRAPH 77 Proceedings), vol. 11, no. 2, 242-248.
20 http://nshader.codeplex.com/
21 http://www.opengpu.org/
22 www.tech-faq.com3d-texture.shtml#
23 http://wwwvis.informatik.uni-stuttgart.de/~engel/pre-integrated/data.html
24 http://www9.informatik.uni-erlangen.de/External/vollib/
25 http://www.volren.org/
26 Randima Fernando, Mark J.Kilgard, Cg
_ 2004 9 ISBN:
711512430
27 Tomes Akenine-Moller, Eric-Haines,
2004-8-18 7301071051
28 Stephen C.DewhurstC++2005 12 16
7115141010
29 GPU 2006 4
30 2004 2
31 Frangois X.Sillion, James R.Arvo, A Global Illumination Solution for General
Reflectance Distributions. ACM O-89791-436-8/91/007/0187, 1991.
32 Robert L. Cook, A Reflectance Model For Computer Graphics, ACM
O-8971-045-I/81-0800-0370. 1981.
33 Xin Sun, Kun Zhou, Yanyun Chen, Interactive Relighting with Dynamic BRDFs.
34 Wolfgang Heidrich , Hans-Peter Seidel. Efficient Rendering of Anisotropic
Surfaces Using Computer Graphics Hardware.
35 David C.Banks. Illumination In Diverse Codimensions.
36 Zhao Dong, Jan Kautz, Christian Theobalt. Interactive Global Illumination Using
Implicit Visibility.
37 Daniel Reiter Horn, Jeremy Sugerman, Mike Houston. Interactive k-D Tree GPU
Raytracing.
38 Benthin,C., Wald,I., Scherbaum, M., And Friedrich,H. 2006. Ray Tracing on the
Cell Processor. In Proceedings of the 2006 IEEE Symposium on Interactive Ray
Tracing.
39 Buck, I., Foley, T., Horn, D., Sugerman, J., Fatahalian, K., Houston, M., And
Hanrahan, P. 2004. Brook for GPUs: Stream computing on graphics hardware. In
184
Proceedings of ACM SIGGRAPH 2004.
40 Xin Sun, Kun Zhou, Eric Stollnitz. Interactive Relighting of Dynamic Refractive
Objects.
41 Timothy J.Purcell, Ian Buck, William R.Mark. Ray Tracing on Programmable
Graphics Hardware.
42 Ziyad S.Hakura, John M.Snyder. Realistic Reflections and Refractions on
Graphics Hardware With Hybrid Rendering and Layered Environment Maps.
43 Turner Whitted, An Improved Illumination Model for Shaded Display. 1980 ACM
0001-0782/80/0600-0343.
44 Mark Segal, carl Korobkin, Rolf van Widenfelt. Fast Shadows and Lighting
Effects Using Texture Mapping. 1992 ACM-0-89791-479-1/92/007/0249.
45 Mark J.Kilgard. Improving Shadows and Reflections via the Stencil Buffer.
NVIDIA Corporation.
46 Randima Fernando. Percentage-Closer Soft Shadows. NVIDIA Corporation.
47 Fan Zhang, Hanqiu Sun, Leilei Xu. Parallel-Split Shadow Maps for Large-scale
Virtual Environments.
48 Uwe Behrens, Ralf Rastering. Adding shadows to a texture-based volume renderer.
In VVS98: Proceedings of the 1998 IEEE symposium on Volume visualization,
pages 39-46. ACM Press, 1998.
49 Johanna Beyer, Markus Hadwiger. Smooth Mixed-Resolution GPU Volume
Rendering. In IEEE/EG International Symposium on Volume and Point-Based
Graphics, pages 163-170, 2008.
50 Praveen Bhaniramka, Yves Demange. OpenGL Volumizer: A Toolkit for High
Quality Volume Rendering of Large Data Sets. In Proceedings IEEE Visualization
2002, pages 45-53, 2002.
51 Imma Boada, Isabel Navazo, Roberto Scopigno. Multiresolution volume
visualization with a texture-based octree. The Visual Computer, 17:185-197, 2001.
52 N. Carr, J.Hall, J.Hart. GPU Algorithms for Radiosity and Subsurface Scattering.
In proc. Graphics Hardware, 2003.
53 Nathan A. Carr, Jesse D.hall, and John C.Hart. GPU algorithms for radiosity and
subsurface scattering. In HWWS03: Proceedings of the conference on Graphics
Hardware 03, pages 51-59. Eurographics Association, 2003.
54 R.A.Drebin, L.Carpenter, and P. Hanrahan. Volume rendering. In Proceedings of
SIGGRAPH 88, pages 65-74, 1988.
185