200 likes | 334 Views
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);
E N D
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); 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); Managed/Sysmem Default Default Managed/Sysmem Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
User / Driver Vertex Stage Pixel Stage Texture 0 Texture 1 Texture 2 Texture 3 Pipeline Transform & Lighting Rasterizer Texturing Blending/Ops Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Objects in 3D world Geometry subsystem 2D primitives Raster subsystem Color image Rendering pipeline Object coordinates Modelling transform affine World coordinates Model-View-Transformation Viewing transform affine Eye coordinates Normalizing transform Normalized (Clip-)coord. clipping 2D Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Lighting - Light sources • Directional (parallel) lights • E.g. sun • One homogeneous vector • Point lights • Same intensity in all directions • One homogeneous point • Spot lights • Limited set of directions • Point + direction + cutoff angle Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Light sources • Area lights • Light sources with a finite area • Can be considered a continuum of point lights • Not available in interactive rendering systems Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Light sources • Geometry • Positions and directions need to be specified in the same coordinate system as the scene geometry • Choose camera space coordinates for illumination calculations • Points and directions undergo normal model/view transformations Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Ambient light • Incoming light component that is identical everywhere in the scene • No direction • Hack for replacing true global illumination, i.e. light bouncing off from other objects Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Diffuse Light - Lambert’s Cosine Law • The reflected luminous intensity in any direction from a perfectly diffusing surface varies as the cosine of the angle between the direction of incident light and the normal vector of the surface. • Intuitively: cross-sectional area of the “beam” intersecting an elementof surface area is smaller for greater angles with the normal. Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
N I Lambert’s Cosine Law • Ideally diffuse surfaces obey cosine law. • Often called Lambertian surfaces. • Id = kd Iincidentcos = kd Iincident (N·L). • kd is the diffuse reflectanceof the material. • Wavelength dependent, so usually specified as a color. Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Specular Light - Phong Lighting Model • Phong adds specular highlights. • His original formula for the specular term: • W(i)[cos s]n • s is the angle between the view and specular reflection directions. • “W(i) is a function which gives the ratio of the specular reflected light and the incident light as a function of the the incident angle i.” • Ranges from 10 to 80 percent. • “n is a power which models the specular reflected light for each material.” • Ranges from 1 to 10. Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Phong Lighting Model • More recent formulations are slightly different. • Replace W(i) with a constant ks, independent of the incident direction. • What do we lose when we do this? • Is= ks Iincidentcosn = ks Iincident (V·R)n. • V is the view direction. • R is the specular reflection direction. Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
The Phong model Phong Bui-Tuong (1975):Use cosine power as heuristic n v rl l Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Materials • Computing the reflection direction rl of l • n and l are unit length n (n▪l)▪n l rl=2(n▪l)▪n-l -l Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Phong lighting cosn • For specular component • Extended highlights • Perfect mirroring only in direction rl • Rapid decay • Model using cosna (perfect n ) a n eye rl l v J J a Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
The Blinn-Phong model • Using the halfway vector n h eye rl b l v J J a Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Shading Specular Ambient Diffuse Ka = 0.1 Kd = 0.5 Ks = 0.4 Phong Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
One application for alpha blending Transparency Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Transparency with alpha Idea: 4 3 2 1 Over Operator: Colordst := (1-Alphasrc)*Colordst+ Alphasrc*Colorsrc Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group
Depth Peeling … You‘ll need (for the minimum version): CullMode = CW; // = Clockwise; CullMode = CCW; // = Counterclockwise; You‘ll need (for the cool version): ColorWriteEnable = 0; /ColorWriteEnable = 15; // = all ZFunc = GreaterEqual; / ZFunc = Less; / ZFunc = Equal; device.Clear(ClearFlags.ZBuffer, Color.Black, 0.0f, 0); Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group