160 likes | 237 Views
Learn the basics of HLSL - High Level Shader Language - to enhance your games with stunning lighting effects. Understand shaders’ role in graphics, from vertex to pixel shaders. Discover the rendering pipeline, point lights, surface illumination, attenuation, materials, and more, with practical examples and code demos. Elevate your gaming experience by mastering HLSL shaders today!
E N D
Lighten Up!Lighting a 3D World with HLSL Matt Christian http://www.insidegamer.org matt@insidegamer.org
Who am I? • Current Student • University of Wisconsin – Stout • Applied Mathematics and Computer Science: Software Development • Associate Degree in Computer Programming • Northcentral Technical College • Avid Gamer / Game Programmer • Gamer since age 5 • Worked with XNA, DirectX, VB (yes I wrote a game in VB 6.0)
Microsoft HLSL • High Level Shader Language (HLSL) • Developed for DirectX but used in all traditional graphical APIs • DirectX 8.0 • C-style language used to manipulate graphics • Vertex Shaders • Pixel Shaders • Geometry Shaders (not covered)
Why Use Shaders? • Make things pretty! • More Realistic • Shaders make use of graphics hardware and allow the CPU to be free of the majority of graphical calculations done on the GPU • “Fixed” pipeline (lighting without shaders) is being phased out • XNA’s BasicEffect
Vertex Shaders • Manipulate vertices • Position, color, etc…
Pixel Shaders • Manipulate each pixel • Lighting, bump mapping, post-processing
Rendering Pipeline • How are shaders processed?
3D Transformations • World Transformation • Transform from model coordinates to 3D world coordinates (position, rotation, scale) • View Transformation • Transform the world to align with the camera or ‘eye’ viewing the world • Projection Transformation • Convert 3D objects to 2D screen space • World*View*Projection Transformation Matrix
The Point Light - Basics • A point light is a light source sending light out from the center • 2D: Circle • 3D: Sphere • Examples • Sun • Light bulb • Almost any light
Steps for Our Shader • Determine all transformations • Have light travel in a specific direction • Light contacts surface • Light surface based on distance and brightness • Blend light color with surface color/ material
Light - Brightness • Brightness of a surface is determined by the angle of the light versus the normal of the surface (note:Surface Normal ) • Direct light (light directed at normal) yields a brighter surface • Perpendicular light and normal yields no light applied • Illumination = cos(theta) * brightness • Where theta is the angle between the surface normal and direction of the light • Cos(90) = 0
Light – Attenuation & Falloff • Attenuation is the speed at which a light’s intensity decreases (further away receives less intense light) • While Attenuation deals with distance, a light’s falloff is the loss of intensity from the center of a light source (this slide has a falloff)
DirectX and Materials • General Idea of a Material • Clear layer sitting on top of an object (may be colored) defining how a surface reflects light • Light on Surface = Illumination * Material Info * Attenuation • Material Info includes: • Diffuse – Non-shiny, reflective light (concrete) • Ambient – Reflective ambient light (all-world light) • Specular – Shiny, reflective light (apple) • Emissive – Light the object emits (crystal)
Code & Demo • Effect File (.fx) • DirectX 9.0c
Questions? • HLSL • DirectX • Gaming
More Information • http://freespace.virgin.net/hugo.elias/graphics/x_main.htm • Very helpful site on light and perceiving light • http://msdn2.microsoft.com/en-us/library/bb509561(VS.85).aspx • MSDN HLSL Documentation • http://www.insidegamer.org/projects.aspx • My projects website, contains some shader writings • http://www.geekswithblogs.net/CodeBlog • My blog