Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 3 - Friday.  What did we talk about last time?  Vertex shaders  Geometry shaders  Pixel shaders.

Similar presentations


Presentation on theme: "Week 3 - Friday.  What did we talk about last time?  Vertex shaders  Geometry shaders  Pixel shaders."— Presentation transcript:

1 Week 3 - Friday

2  What did we talk about last time?  Vertex shaders  Geometry shaders  Pixel shaders

3

4

5

6  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

7  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

8  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; float4x4 WorldXf : World; float4x4 WorldITXf: WorldInverseTranspose; float4x4 WvpXf: WorldViewProjection;

9  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}; 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};

10  Input and output types are usually defined by the user  The TEXCOORD1 and TEXCOORD2 semantics are used for historical reasons struct appdata { float3 Position: POSITION; float3 Normal : NORMAL; } struct vertexOutput { float4 HPosition: POSITION; float3 LightVec: TEXCOORD1; float3 WorldNormal: TEXCOORD2; }; struct appdata { float3 Position: POSITION; float3 Normal : NORMAL; } struct vertexOutput { float4 HPosition: POSITION; float3 LightVec: TEXCOORD1; float3 WorldNormal: TEXCOORD2; };

11 vertexOutput std_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; } vertexOutput std_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; }

12  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; } 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; }

13  Z-buffer configuration is done here technique Gooch { pass p0 { VertexShader = compile vs_2_0 std_VS(); PixelShader = compile ps_2_a gooch_PS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; } technique Gooch { pass p0 { VertexShader = compile vs_2_0 std_VS(); PixelShader = compile ps_2_a gooch_PS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; }

14  The result of the shader given before applied to a teapot:

15

16  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

17  Original  Modern

18

19 Yeah… just what do you know about vectors?

20

21  We refer to n-dimensional real Euclidean space as R n  A vector v in this space is an n-tuple, an ordered list of n real numbers  To match the book (and because we are computer scientists), we'll index these from 0 to n – 1  We will generally write our vectors as column vectors rather than row vectors

22  We will be interested in a number of operations on vectors, including:  Addition  Scalar multiplication  Dot product  Norm

23  Addition of two vectors is just element-by- element addition

24  Vector addition is associative:  Vector addition is commutative:

25  There is a unique vector for R n which is 0 = (0,0,…,0) with a total of n zeroes  o is additive identity:  For vector v, there is a unique inverse –v = (-v 0, -v 1, … -v n-1 )  -v is the additive inverse:

26  Multiplication by a scalar is just element-by- element multiplication of that scalar

27  Rules for scalar multiplication can easily be inferred from the normal properties of reals under addition and multiplication:

28  The dot product is a form of multiplication between two vectors that produces a scalar

29

30

31

32

33  Mathematical rules are one thing  Understanding how they are interpreted in geometry is something else  Unfortunately, this means getting more math to link up the existing math with geometry

34  A set of vectors u 0, u 1, … u n-1 is linearly independent if the only scalars that satisfy the following identity are v 0 = v 1 = … = v n-1 = 0  In other words, you can't make any one vector out of any of the others

35  A set of vectors u 0, u 1, … u n-1 spans R n if any vector v  R n can be written:  In addition, if v 0, v 1, …, v n-1 are uniquely determined for all v  R n, then u 0, u 1, … u n-1 form a basis of R n

36  To properly describe R n, the vectors we give are actually scalar multiplied by each of the basis vectors u i  By convention, we leave off the basis vectors u i, because it would be cumbersome to show them  Also, they are often boring: (1,0,0), (0,1,0), and (0,0,1)

37  A vector can either be a point in space or an arrow (direction and distance)  The norm of a vector is its distance from the origin (or the length of the arrow)  In R 2 and R 3, the dot product is: where  is the smallest angle between u and v

38  A basis is orthogonal if every vector in the basis is orthogonal to every other (has dot product 0)  An orthogonal basis is orthonormal if every vector in it has length 1  The standard basis is orthonormal and made up of vectors e i which are all 0's except a 1 at location i

39  We can find the orthogonal projection w of vector u onto vector v  Essentially, this means the part of u that's in v

40  The cross product of two vectors finds a vector that is orthogonal to both  For 3D vectors u and v in an orthonormal basis, the cross product w is:

41

42

43  More linear algebra  Matrices  Homogeneous notation  Geometric techniques

44  Keep reading Appendix A  Assignment 1 due tonight by midnight!  Keep working on Project 1, due next Friday, February 6 by 11:59


Download ppt "Week 3 - Friday.  What did we talk about last time?  Vertex shaders  Geometry shaders  Pixel shaders."

Similar presentations


Ads by Google