DOC PREVIEW
UCSD CSE 125 - Advanced Lighting

This preview shows page 1-2-16-17-18-33-34 out of 34 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 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 34 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 34 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 34 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 34 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 34 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 34 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

SKYBOXES, ADVANCED LIGHTING, AND NORMAL MAPPINGAlex GoldbergSpring 2008Skyboxes Skyboxes add a great deal of character to a game, and are great for outdoor environment background detail Skyboxes are really only useful for distant features Typically, the player will always be at the center of the skybox, regardless of movement They lack parallax effects – mountains in the same skybox won‟t move relative to each other Modern games will have several layers of background scenery: Unreachable medium detail geometric mountains with billboarded trees Several layers of billboarded mountains that shift relative to each other Finally, a skybox for really distant featuresSkybox Implementation Adding skyboxes to your shader-based game is extremely simple On the application side:1. Load a .dds cube texture at program start See D3DXCreateCubeTextureFromFile()2. Create a box model (only vertex positions required)3. Draw your scene as usual4. Draw a giant box around your world using a custom skybox shader. Note: The box should be centered at the origin. The shader will transform it to be centered at the camera  Note that the skybox is drawn last to reduce unnecessary texture lookups. It would look the same if drawn first…Skybox Implementation Contd. The shader is also quite simple – it only samples a texture and outputs the result. The only catch is that we‟re now sampling a cube texture using the HLSL texcube() function. Cube maps are sampled using three texture coordinates Imagine a cube centered at the origin (0,0,0). The three texture coordinates represent the 3D vector at the origin that points towards at the point on the cube that we want to lookup. Note that this vector does not need to be normalizedShader Codematrix g_mView; //Camera View matrixmatrix g_mProj; //Camera Projection matrix//Skybox texture and texture samplertexture g_skyBoxTexture;sampler g_cubeSampler = sampler_state {Texture = g_skyBoxTexture;MipFilter = LINEAR;MinFilter = LINEAR;MagFilter = LINEAR;ADDRESSU = Clamp;ADDRESSV = Clamp;};//Vertex shader output structurestruct VS_OUTPUT {float4 Position : POSITION;float3 TextureUV : TEXCOORD0;};Shader Code Contd.//Vertex ShaderVS_OUTPUT VS(float4 vPos : POSITION) {VS_OUTPUT Out;// Strip any translation from the view matrixfloat3x3 mViewNoTrans = (float3x3)g_mView;// Output the positionOut.Position = mul(vPos.xyz, mul(mViewNoTrans, g_mProj));// Calculate the cube map texture coordinates// Because this is a cube map, the 3-D texture coordinates are calculated// from the world-position of the skybox vertex.// They skybox should be drawn centered at the origin, and it will appear centered at// the cameraOut.TextureUV = vPos.xyz;return Out;}//Pixel Shader//NOTE: A real shader would likely do much more here (diffuse & specular lighting, color// texture sampling, normal mapping, etc.)Float4 PS(VS_OUTPUT In) {// The skybox texture is pre-lit, so simply output the sampled cube texture colorreturn texCUBE(g_cubeSampler, In.TextureUV);}Creating Skyboxes DirectX directly supports loading cubemaps saved in the .ddsformat. Skyboxes can be created by manually painting each cube face as a separate texture and then packing them into a cubemap texture There are also many free skyboxes online in various formats To create and manipulate cubemaps, you should be familiar with a few simple tools:1. DirectX Texture Tool: Installed with the DirectX SDK2. ATI CubeMapGen: Free program downloaded at http://ati.amd.com/developer/cubemapgen/index.html3. HDRShop: Free program downloaded at www.hdrshop.comDirectX Texture Tool The DirectX Texture Tool allows you to preview .dds textures, view different faces of cube textures, add alpha channels, and visualize texture mip levels Faces in a cube map .dds texture can be viewed separately using the keys x, y, z, and X, Y, Z Textures can be loaded onto cubemap faces using the “Open Onto This Cubemap Face…” command ATI‟s CubeMapGen may be more useful for this purpose…ATI CubeMapGen CubeMapGen has several useful capabilities, but the biggest one is the ability to convert between the „cross‟ layout and .dds cube map files.  It also enables you to load separate images onto each face, and flip individual faces across various axes CubeMapGen is also really useful for identifying alignment issues between faces Tip: Zoom inside the default sphere to get an idea of what your skybox will look like from the inside NOTE: CubeMapGen requires images to be power-of-two sized, and only supports a few image formats (ARGB, for instance) Cross format images must also have width 3*res and height 4*res, where res is the power-of-two resolution of each cube faceHDRShop HDRShop is an extremely robust program that can convert between many different environment texture layouts, change exposure and contrast settings, convert between High Dynamic Range and LDR images, and perform image convolution. Very useful for converting between the various formats found on the internetCommon Environment Map LayoutsCross LayoutLatitude/Longitude (Panorama) LayoutLight Probe LayoutSkybox Resources I have uploaded quite a few cube maps in .dds format, including several UCSD cubes donated by Mark Rotenberg, to the server at http://pisa.ucsd.edu/cse125/2008/Resources.html More resources: Paul Debevec‟s Light Probes: Very high quality panoramic layout images (http://gl.ict.usc.edu/Data/HighResProbes/) – use HDRShop & CubeMapGen to convert Planet Pixel Emporium: Great color, bump, and detail maps in panoramic layout for various planets (http://planetpixelemporium.com/planets.html)  Hazel Skybox Texture packs: Pretty decent 6-image skyboxes (http://www.hazelwhorley.com/textures.html) – use CubeMapGen or the DirectX Texture Tool to load onto each cube faceThe Basic Lighting Equation The canonical simplified lighting equation for a single light is:Pixel Color = Ambient Color + Visibility * (Diffuse term + Specular term) Ambient Color: Often just a constant color value (eg. (.2,.2,.2)) Visibility: Shadow component. 0 when a pixel is entirely in shadow, and 1 when the light source is entirely visible Diffuse term = Material Color * Light Color * N dot L * Attenuation Material Color: Usually a color texture lookup or solid color, but could have a number of other components Light Color: Usually a single color specific to the light source


View Full Document

UCSD CSE 125 - Advanced Lighting

Download Advanced 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 Advanced 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 Advanced 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?