DOC PREVIEW
OSU CS 519 - Using Shaders for Lighting

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1mjb -- January 18, 2013Oregon State UniversityComputer GraphicsUsing Shaders for LightingMike [email protected] State Universitymjb -- January 18, 2013Oregon State UniversityComputer GraphicsLighting DefinitionsN = NormalL = Light vectorE = Eye vectorR = Light reflection vectorER = Eye reflection vectorColor = LightColor * MaterialColorAmbient = Light intensity that is “everywhere”Diffuse = Light intensity proportional to cos(Θ)Specular = Light intensity proportional to cosS(Φ)A-D-S = Lighting model that includes Ambient, Diffuse, and SpecularFlat Interpolation = Use a single polygon normal to compute one A-D-S for the entire polygonPer-vertex lighting= Compute A-D-S using each vertex normal and then interpolate the sum over the entire polygonPer-fragment lightinglation = Interpolate the vertex normals across the entire polygon and compute A-D-S at each fragmentCubeMap Reflection = Using the Eye Reflection Vector (ER) to look-up the reflection of a “wall texture”EΘΘΘΘΘΘΘΘΦΦΦΦNRERL2mjb -- January 18, 2013Oregon State UniversityComputer GraphicsLRLGLBEREGEBWhat the light can produceWhat the eye seesER= LR * MREG= LG * MGEB= LB * MBWhite LightGreen LightMRMGMBWhat the material can reflectWhat you see depends on the light color and the material colormjb -- January 18, 2013Oregon State UniversityComputer GraphicsA-D-S Lighting with Flat Interpolationgl_FragColor.rgb = Ka*ambient + Kd*diffuse + Ks*spec;Note: Each facet has a single lighting value applied to every pixel within it.N = NormalL = Light vectorE = Eye vectorR = Light reflection vectorER = Eye reflection vectorColor = LightColor * MaterialColorvec3 ambient = Color.rgb;diffuse = max( dot(L,N), 0. ) * Color.rgb;vec3 R = normalize( reflect( -L, N ) );vec3 spec = LightColor * pow( max( dot( R, E), 0. ), Shininess );Vertex ShaderFragment ShaderFlat Rasterize ambient, diffuse, spec3mjb -- January 18, 2013Oregon State UniversityComputer GraphicsA-D-S Lighting with Smooth InterpolationNote: The light intensity is computed at each vertex and interpolated throughout the facet. This creates artifacts such Mach Banding and the fact that the bright spot is not circular.You can do this in stock OpenGL or in a shader.N = NormalL = Light vectorE = Eye vectorR = Light reflection vectorER = Eye reflection vectorColor = LightColor * MaterialColorgl_FragColor.rgb = Ka*ambient + Kd*diffuse + Ks*spec;vec3 ambient = Color.rgb;diffuse = max( dot(L,N), 0. ) * Color.rgb;vec3 R = normalize( reflect( -L, N ) );vec3 spec = LightColor * pow( max( dot( R, E), 0. ), Shininess );Vertex ShaderFragment ShaderSmooth Rasterize ambient, diffuse, specmjb -- January 18, 2013Oregon State UniversityComputer GraphicsA-D-S Lighting with Normal Interpolationvec3 ambient = Color.rgb;diffuse = max( dot(L,N), 0. ) * Color.rgb;vec3 R = normalize( reflect( -L, N ) );vec3 spec = LightColor * pow( max( dot( R, E ), 0. ), Shininess );gl_FragColor.rgb = Ka*ambient + Kd*diffuse + Ks*spec;Note: The normal is interpolated throughout the facet. The light intensity is computed at each fragment. This avoids Mach Banding and makes the bright spot circular.You can only do this in a shader.N = NormalL = Light vectorE = Eye vectorR = Light reflection vectorER = Eye reflection vectorColor = LightColor * MaterialColorSmooth Rasterize N, L, EFragment Shader4mjb -- January 18, 2013Oregon State UniversityComputer GraphicsA-D-S Lighting with Normal Interpolation and a CubeMap Reflectionvec3 ambient = Color.rgb;diffuse = max( dot(L,N), 0. ) * Color.rgb;vec3 R = normalize( reflect( -L, N ) );vec3 spec = LightColor * pow( max( dot( R, E ), 0. ), Shininess );vec3 reflcolor = textureCube( ReflectUnit, R ).rgb;gl_FragColor.rgb = Ka*ambient + Kd*diffuse + Ks*spec + Kr*reflcolor.rgb;Note: A cube map reflection is blended in, given a stronger impression that the surface is shiny.N = NormalL = Light vectorE = Eye vectorR = Light reflection vectorER = Eye reflection vectorColor = LightColor * MaterialColorSmooth Rasterize N, L, EFragment Shadermjb -- January 18, 2013Oregon State UniversityComputer GraphicsA-D-S Anisotropic Lighting with Normal Interpolationvec3 ambient = Color.rgb;float dl = dot( T, L );vec3 diffuse = sqrt( 1. - dl*dl ) * Color.rgb;float de = dot( T, E );vec3 spec = LightColor * pow( dl * de + sqrt( 1. - dl*dl ) * sqrt( 1. - de*de ), Shininess );gl_FragColor.rgb = Ka*ambient + Kd*diffuse + Ks*spec;James Kajiya and Timothy Kay, “Rendering Fur with Three Dimensional Textures”, Proceedings of SIGGRAPH 1989, Volume 23, Number 3, July 1989, pp. 271-280.Note: The bright spot is not circular because the material has different properties in different directions. Materials such as fur, hair, and brushed metal behave this way.N = NormalL = Light vectorE = Eye vectorR = Light reflection vectorER = Eye reflection vectorColor = LightColor * MaterialColorFragment Shader5mjb -- January 18, 2013Oregon State UniversityComputer GraphicsSummaryFlatSmoothNormalReflectionAnisotropicmjb -- January 18, 2013Oregon State UniversityComputer GraphicsAmbient-only Diffuse-only Specular-onlyADS – Shininess=50 ADS – Shininess=1000 ADS – Shininess=1000 -- Flat6mjb -- January 18, 2013Oregon State UniversityComputer Graphics#version 330 compatibilityuniform float uLightX, uLightY, uLightZ;flat out vec3 vNf;out vec3 vNs;flat out vec3 vLf;out vec3 vLs;flat out vec3 vEf;out vec3 vEs;vec3 eyeLightPosition = vec3( uLightX, uLightY, uLightZ );voidmain( ){ vec4 ECposition = uModelViewMatrix * aVertex;Nf = normalize( uNormalMatrix * aNormal ); // surface normal vectorNs = Nf;Lf = eyeLightPosition - ECposition.xyz; // vector from the pointLs = Lf; // to the light positionEf = vec3( 0., 0., 0. ) - ECposition.xyz; // vector from the pointEs = Ef ; // to the eye position gl_Position = uModelViewProjectionMatrix * aVertex;}mjb -- January 18, 2013Oregon State UniversityComputer Graphics#version 330 compatibilityuniform float uKa, uKd, uKs;uniform vec4 uColor;uniform vec4 uSpecularColor;uniform float uShininess;uniform bool uFlat, uHalf;flat in vec3 vNf;in vec3v Ns;flat in vec3 vLf;in vec3v Ls;flat in vec3 vEf;in vec3 vEs;out vec4 fFragColor;voidmain( ){vec3 Normal;vec3 Light;vec3 Eye;if( uFlat ){Normal = normalize(vNf);Light = normalize(vLf);Eye = normalize(vEf);}else{Normal = normalize(vNs);Light = normalize(vLs);Eye = normalize(vEs);}7mjb -- January 18, 2013Oregon State UniversityComputer Graphicsvec4 ambient = uKa * uColor;float d = max(


View Full Document

OSU CS 519 - Using Shaders for Lighting

Download Using Shaders for Lighting
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Using Shaders for Lighting and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Using Shaders for Lighting 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?