1 / 35

CS361

Week 3 - Wednesday. CS361. Last time. What did we talk about last time? Project 1 Graphics processing unit Programmable shading. Questions?. Project 1. Assignment 1. XNA Practice. Vertex Shading. Vertex shader. Supported in hardware by all modern GPUs

Download Presentation

CS361

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 3 - Wednesday CS361

  2. Last time • What did we talk about last time? • Project 1 • Graphics processing unit • Programmable shading

  3. Questions?

  4. Project 1

  5. Assignment 1

  6. XNA Practice

  7. Vertex Shading

  8. Vertex shader • Supported in hardware by all modern GPUs • For each vertex, it modifies, creates, or ignores: • Color • Normal • Texture coordinates • Position • It must also transform vertices from model space to homogeneous clip space • Vertices cannot be created or destroyed, and results cannot be passed from vertex to vertex • Massive parallelism is possible

  9. Vertex shader effects • Lens effects for distortion • Novel perspective correction • Object definition • Creating a mesh and having the vertex shader form its shape • Object twist, bend, and taper • Procedural deformations • Flags • Cloth • Water

  10. More vertex shading effects • Primitive creation • Degenerate 2D meshes given a third dimension by the shader • Page curls, heat haze, water ripples • Make a mesh of the screen and distort it • Vertex texture fetch • Apply a texture to vertices, making ocean surfaces or terrain in hardware

  11. Geometry Shading

  12. Geometry shader • Newest shader added to the family, and optional • Comes right after the vertex shader • Input is a single primitive • Output is zero or more primitives • The geometry shader can be used to: • Tessellate simple meshes into more complex ones • Make limited copies of primitives

  13. Stream output • The geometry shader is guaranteed to return output in the same order as the input was received • In Shader Model 4.0 and later, the output of the GS can be put into a stream (an ordered array) • This stream can be rasterized or it can be sent back through the pipeline for multi-step effects • For computational purposes, the stream could simply be output non-graphically

  14. Pixel Shading

  15. Pixel shader • Clipping and triangle set up is fixed in function • Everything else in determining the final color of the fragment is done here • Because we aren't actually shading a full pixel, just a particular fragment of a triangle that covers a pixel • So much goes on that we'll have to put it off until later • Various lighting models are a lot of it • The pixel shader is limited in that it cannot look at neighboring pixels • Except that some information about gradient can be given • Multiple render targets means that many different colors for a single fragment can be made and stored in different buffers

  16. Merging Stage

  17. Merging stage • Fragment colors are combined into the frame buffer • This is where stencil and Z-buffer operations happen • It's not fully programmable, but there are a number of settings that can be used • Multiplication • Addition • Subtraction • Min/max

  18. Effects

  19. All this programming gets complicated… • So, people in the industry have tried to collect useful programs for rendering things • A collection of shaders to achieve a particular rendering effect can be stored in an effect file (commonly with extension .fx) • The syntax of the effects language allows your application to set specific arguments

  20. Tools to generate effects • You can download existing .fx files or write your own • There are also tools like NVIDIA's FX Composer 2.5 that allow you to create effects with a GUI • Now, let's examine the book's example effect file for Gooch shading

  21. Standard variables • Camera parameters are supplied automatically • Syntax is type id : semantic • type is a system defined type or a user defined struct • id is whatever identifier the user wants • semantic is a system defined use float4x4 WorldXf : World; float4x4 WorldITXf : WorldInverseTranspose; float4x4 WvpXf : WorldViewProjection;

  22. User variables • Default values are given for these variables • The annotations given inside angle brackets allow the outside program to set them float3 Lamp0Ps : Position < string Object = "PointLight0"; string UIName = "Lamp 0 Position"; string Space = "World"; > = {-0.5f, 2.0f, 1.25f}; float3 WarmColor < string UIName = "Gooch Warm Tone"; string UIWidget = "Color"; > = {1.0f, 0.9f, 0.15f}; float3 CoolColor < string UIName = "Gooch Cool Tone"; string UIWidget = "Color"; > = {0.05f, 0.05f, 0.6f};

  23. User defined structs • Input and output types are usually defined by the user • The TEXCOORD1 and TEXCOORD2 semantics are used for historical reasons structappdata { float3 Position : POSITION; float3 Normal : NORMAL; } structvertexOutput { float4 HPosition : POSITION; float3 LightVec : TEXCOORD1; float3 WorldNormal : TEXCOORD2; };

  24. Vertex shader vertexOutputstd_VS(appdata IN) { vertexOutput OUT; float4 No = float4(IN.Normal,0); OUT.WorldNormal = mul(No,WorldITXf).xyz; float4 Po = float4(IN.Position,1); float4 Pw = mul(Po,WorldXf); OUT.LightVec = (Lamp0Pos – Pw.xyz); OUT.HPosition = mul(Po,WvpXf); return OUT; }

  25. Pixel shader • We linearly interpolate between cool and warm colors based on the dot product float4 gooch_PS(vertexOutput IN) : COLOR { float3 Ln = normalize(IN.LightVec); float3 Nn = normalize(IN.WorldNormal); float ldn = dot(Ln,Nn); float mixer = 0.5 * (ldn + 1.0); float4 result = lerp(CoolColor, WarmColor, mixer); return result; }

  26. Putting it all together • Z-buffer configuration is done here • technique Gooch < string Script = "Pass=p0;"; > • { • pass p0 < string Script = "Draw=geometry;"; > • { • VertexShader = compile vs_2_0 std_VS(); • PixelShader = compile ps_2_a gooch_PS(); • ZEnable = true; • ZWriteEnable = true; • ZFunc = LessEqual; • AlphaBlendEnable = false; • } • }

  27. Shader output • The result of the shader given before applied to a teapot:

  28. All kinds of different effects

  29. Why a teapot? • The Utah teapot was modeled in 1975 by graphics pioneer Martin Newell at the University of Utah • It's actually taller than it looks • They distorted the model so that it would look right on their non-square pixel displays

  30. Original vs. modern • Original • Modern

  31. There's a Stanford Bunny too…

  32. Quiz

  33. Upcoming

  34. Next time… • Linear algebra review • Vectors and matrices

  35. Reminders • Read Appendix A • Finish Assignment 1, due Friday by 11:59 • Keep working on Project 1, due Friday, February 8 by 11:59

More Related