Professional Documents
Culture Documents
DirectX Tutorial 01
DirectX Tutorial 01
Programming
HLSL (High Level Shader Language)
Introduction to DirectX / HLSL
- Tutorial01
-
Today
Introduction to DirectX / HLSL
Tutorial01
- Fixed pipeline version
- Programmable pipeline (shader) version
DirectX / HLSL
DirectX (1/2)
1994 WinG
2D sprite
bitmap API API
5 (KOEI)
DOS Windows
DirectX (2/2)
Assembler Shader
HLSL
Geometry shader
DirectX
object
object
E.g. Direct3D object Direct3DDevice object
2D graphics
3D graphics
Audio
Game input
Not Recommended
Direct3D
Direct3D
Immediate Mode
Direct3D Device
Reference (emulator)
Direct3D
Preprocessor
#define
#elif
#else
#endif
#error
#if
#include
#line
#undef
Types (1/2)
Basic types
float
Int
bool
double
Half
Texture .
Types (2/2)
Variables
Local/ global
Global
Uniform
Const
Static
Texture
Direct3DTexture9
Sampler : filtering
sampler texture mapping
H/W shader version
HLSL 3.0 16
Filtering, address mode sampler
SetSamplerState
Operators
Despite temptation
No bitwise operators
Statement Syntax
{ [statements] }
[expression] ;
return [expression] ;
if ( expression ) statement [else statement]
for ( [expression | variable_declaration] ;
[expression] ; [expression] ) statement
Explanation
Syntax
sqrt
value sqrt(value a)
Square root
exp2
value exp2(value a)
Base 2 Exp
log2
value log2(value a)
Base 2 Log
min
Maximum
max
Minimum
abs
Absolute value
len
float len(value a)
Vector length
det
float det(value a)
Matrix determinant
dot
float dot(value a)
Dot product
mul
Matrix multiplication
any
float any(value a)
all
float all(value a)
User Functions
Have no statcks
Functions (cont.)
Differences from C
No pointers
No recursion
Limitation of loop count and nesting
HLSL Summary
Ease of Use
Consistency of Implementation
Management of Evolution
Shader Model
HLSL version
Under 1_1
2_a
( )
DirectX SDK
( unrolling)
Dynamic branching
(jump)
dynamic 1
256 (loop counter register , 8bit)
Direct3D
Scene rendering
Direct3D
Direct3D
1) application window
2) Direct3D object
3) Direct3DDevice object
4) objects
5) Rendering
Windows
RegisterClassEx()
CreateWindow()
ShowWindow(), UpdateWindow()
Message Loop
GetMessage()
TranslateMessage()
DispatchMessage()
Message loop
GetMessage()
TranslateMessage()
DispatchMessage()
Render() Direct3D
Message loop Direct3D
Message
// full screen
// double buffering
// windows
// full screen
// double buffering
// windows
Depth/ stencil
buffer
Graphic H/w
Screen
Color buffer :
Depth/ stencil buffer : color buffer masking
, color buffer
1:1 .
Depth/ stencil
buffer
Graphic H/w
Screen
Color buffer :
Depth/ stencil buffer : color buffer masking
, color buffer
1:1 .
Direct3DDevice
CreateDevice()
,
D3DDEVTYPE_HAL : H/W rendering
D3DADAPTER_DEFAULT : adapter
Device flag
D3DCREATE_SOFTWARE_VERTEXPROCESSING
D3DCREATE_HARDWARE_VERTEXPROCESSING
&d3dpp
Device
rendering
render() rendering
Back buffer
rendering
OpenGL glBegin(),
glEnd()
, 0, NULL
NULL ( )
Technique setting
Pass setting
( CreateEffectFromFile() )
D3DXCreateEffectFromFile() : 4 parameters
- LPDIRECT3DDEVICE9 pDevice
- LPCTSTR pSrcFile
- DWORD Flags
- LPD3DXEFFECT *ppEffect)
Effect file
struct VS_Input
{
float3 Pos
float4 Color
};
struct PS_Input
{
float4 Pos
float4 Color
};
No Input
D3DXCreateEffectFromFile()
0 1
15
Effect
Stream
Technique_Basic
VS_Basic()
: POSITION;
: COLOR0;
return Out;
}
float4 PS_Basic(PS_Input In) : COLOR0
{
return In.Color;
}
SetTechnique("Technique_Basic)
Vertex
Processing
: POSITION;
: COLOR0;
Begin(&Passes, 0)
BeginPass(0)
Rasterizer
pass0
Fragment
Processing
pass pass1
{
VertexShader = compile vs_3_0 VS_01();
PixelShader = compile ps_3_0 VS_01();
}
PS_Basic()
}
No Drawing
Output Merging
Pixels
Technique Technique_Basic
{
pass pass0
{
VertexShader = compile vs_3_0 VS_Basic();
PixelShader = compile ps_3_0 PS_Basic();
}
Technique Technique02
{
pass pass0
{
VertexShader = compile vs_3_0 VS_02();
PixelShader = compile ps_3_0 PS_02();
}
pass pass1 { }
}
Technique Technique03
{
pass pass0 { }
pass pass1 { }
}
Technique Technique03 { }
Tomorrow
Tutorial02
- Fixed pipeline version
- Programmable pipeline (shader) version