Practical Course – Shader Gallery C# / DirectX WS 06/07

20
Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & computer graphics & visualization visualization Practical Course – Shader Practical Course – Shader Gallery C# / DirectX WS 06/07 Gallery C# / DirectX WS 06/07 Assignment 3 Assignment 3

description

Practical Course – Shader Gallery C# / DirectX WS 06/07. Assignment 3. Move. Create. Reset. Lost. Destroy. Render. Important DirectX “Methods”. private void OnCreateDevice( object sender, DeviceEventArgs e); private void OnResetDevice( object sender, DeviceEventArgs e); - PowerPoint PPT Presentation

Transcript of Practical Course – Shader Gallery C# / DirectX WS 06/07

Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupKai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group

computer graphics & computer graphics & visualizationvisualization

Practical Course – Shader Gallery C# Practical Course – Shader Gallery C# / DirectX WS 06/07/ DirectX WS 06/07

Assignment 3Assignment 3

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Important DirectX “Methods”Important DirectX “Methods”

private void OnCreateDevice(object sender, DeviceEventArgs e);

private void OnResetDevice(object sender, DeviceEventArgs e);

public void OnFrameMove(Device device, double appTime, float elapsedTime)

public void OnFrameRender(Device device, double appTime, float elapsedTime)

private void OnLostDevice(object sender, EventArgs e);

private void OnDestroyDevice(object sender, EventArgs e);

Create Reset

Move

Render

Lost Destroy

DefaultDefault DefaultDefault Managed/SysmemManaged/SysmemManaged/SysmemManaged/Sysmem

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Pixel Stage

Vertex Stage

User / Driver

PipelinePipeline

Transform & LightingTransform & Lighting Rasterizer

TexturingTexturingBlending/Ops

Texture 3Texture 2Texture 1Texture 0

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Rendering pipelineRendering pipeline

Geometrysubsystem

Rastersubsystem

Objects in3D world

Colorimage

2D primitives

2D

Objectcoordinates

Worldcoordinates

Eyecoordinates

Modellingtransform

Viewingtransform

Normalizingtransform

Normalized(Clip-)coord.

clipping

affine

affine

Model-View-Transformation

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Lighting - Light sourcesLighting - Light sources

- Directional (parallel) lightsDirectional (parallel) lights- E.g. sunE.g. sun

- One homogeneous vectorOne homogeneous vector

- Point lightsPoint lights- Same intensity in all directionsSame intensity in all directions

- One homogeneous pointOne homogeneous point

- Spot lightsSpot lights- Limited set of directionsLimited set of directions

- Point + direction + cutoff anglePoint + direction + cutoff angle

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Light sourcesLight sources

- Area lightsArea lights- Light sources with a finite areaLight sources with a finite area

- Can be considered a continuum of point lightsCan be considered a continuum of point lights

- Not available in interactive rendering systemsNot available in interactive rendering systems

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Light sourcesLight sources

- GeometryGeometry

- Positions and directions need to be specified in Positions and directions need to be specified in the same coordinate system as the scene the same coordinate system as the scene geometrygeometry

- Choose camera space coordinates for Choose camera space coordinates for illumination calculationsillumination calculations

- Points and directions undergo normal Points and directions undergo normal model/view transformationsmodel/view transformations

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Ambient lightAmbient light

- Incoming light component that is identical Incoming light component that is identical everywhere in the sceneeverywhere in the scene

- No directionNo direction

- Hack for replacing true global illumination, Hack for replacing true global illumination, i.e. light bouncing off from other objectsi.e. light bouncing off from other objects

aaout IkxI )(

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Diffuse Light - Lambert’s Cosine LawDiffuse Light - Lambert’s Cosine Law

- The reflected luminous intensity in any direction from a The reflected luminous intensity in any direction from a perfectly diffusing surface varies as the cosine of the angle perfectly diffusing surface varies as the cosine of the angle between the direction of incident light and the normal vector between the direction of incident light and the normal vector of the surface.of the surface.

- Intuitively: cross-sectional area of Intuitively: cross-sectional area of the “beam” intersecting an elementthe “beam” intersecting an elementof surface area is smaller for greater of surface area is smaller for greater angles with the normal.angles with the normal.

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Lambert’s Cosine LawLambert’s Cosine Law

- Ideally diffuse surfaces obey cosine law.Ideally diffuse surfaces obey cosine law.- Often called Often called LambertianLambertian surfaces. surfaces.

- IIdd = = kkd d IIincidentincident cos cos = = kkd d IIincident incident ((NN··LL).).

- kkdd is the diffuse reflectance is the diffuse reflectanceof the material.of the material.

- Wavelength dependent, so usually specified as a color.Wavelength dependent, so usually specified as a color.

IN

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Specular Light - Phong Lighting ModelSpecular Light - Phong Lighting Model

- Phong adds specular highlights.Phong adds specular highlights.

- His original formula for the specular term:His original formula for the specular term:- WW((ii)[cos )[cos s s ]]n n

- s s is the angle between the view and specular reflection directions.is the angle between the view and specular reflection directions.- ““WW((ii) is a function which gives the ratio of the specular reflected ) is a function which gives the ratio of the specular reflected

light and the incident light as a function of the the incident angle light and the incident light as a function of the the incident angle ii..””- Ranges from 10 to 80 percent.Ranges from 10 to 80 percent.

- ““n n is a power which models the specular reflected light for each is a power which models the specular reflected light for each material.”material.”

- Ranges from 1 to 10.Ranges from 1 to 10.

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Phong Lighting ModelPhong Lighting Model

- More recent formulations are slightly different.More recent formulations are slightly different.- Replace Replace WW((ii) with a constant ) with a constant kkss, independent of the , independent of the

incident direction.incident direction.- What do we lose when we do this?What do we lose when we do this?

- IIss= = kks s IIincidentincident coscosnn= = kks s IIincidentincident ( (VV··RR))nn..

- VV is the view direction. is the view direction.- R R is the specular reflection direction.is the specular reflection direction.

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

The Phong modelThe Phong model

Phong Bui-Tuong (1975):Phong Bui-Tuong (1975):Use cosine power as heuristicUse cosine power as heuristic

)()()( xIrvkxI inn

lsout

nn vvrrllll

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

MaterialsMaterials

- Computing the reflection direction rComputing the reflection direction rll of l of l

- n and l are unit lengthn and l are unit length

nn

(n▪l)▪n(n▪l)▪nll

-l-l

rrll=2(n▪l)▪n-l=2(n▪l)▪n-l

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Phong lightingPhong lighting

- For specular componentFor specular component

- Extended highlightsExtended highlights

- Perfect mirroring only in Perfect mirroring only in direction rdirection rll

- Rapid decayRapid decay- Model using cosModel using cosnn (perfect n (perfect n ))

ninsout xIkxI cos)()(

n

lrl

v

eye

cosn

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

- Using the halfway vectorUsing the halfway vectorvl

vlh

iins

iinsout

xIk

nhxIkxI

cos)(

)()(

The Blinn-Phong modelThe Blinn-Phong model

h n

l

rl

v

eye

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

ShadingShading

Ka = 0.1

Kd = 0.5

Ks = 0.4

Ambient Diffuse Specular

Phong

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

One application for alpha blendingOne application for alpha blending

TransparencyTransparency

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Transparency with alphaTransparency with alpha

Idea:Idea:

1122

3344

Over Operator:

Colordst := (1-Alphasrc)*Colordst+ Alphasrc*Colorsrc

computer graphics & computer graphics & visualizationvisualization

Kai Bürger & Polina Kondratieva – Computer Graphics and Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization GroupVisualization Group

Depth Peeling …Depth Peeling …You‘ll need (for the minimum version):You‘ll need (for the minimum version):

CullMode CullMode = CW; = CW; // = Clockwise;// = Clockwise;

CullMode CullMode = CCW; = CCW; // = Counterclockwise;// = Counterclockwise;

You‘ll need (for the cool version):You‘ll need (for the cool version):

ColorWriteEnable ColorWriteEnable = 0; = 0; // ColorWriteEnable ColorWriteEnable = 15; = 15; // = all// = all

ZFuncZFunc = GreaterEqual; = GreaterEqual; / / ZFuncZFunc = Less; = Less; / / ZFuncZFunc = Equal; = Equal;

device.Clear(device.Clear(ClearFlags.ZBuffer, Color.Black, 0.0f, 0);ClearFlags.ZBuffer, Color.Black, 0.0f, 0);