160 likes | 466 Views
3D Game Programming Lab6- Bump Mapping. Goal. 了解 bump mapping 的原理 懂得如何使用 GLSL 實作 bump mapping 自行製作 bump map. The Perception. Bump Mapping. add bump map textures to models. model. bump map. result. GLSL. Vertex shaders change or get the information of vertices Fragment shaders
E N D
Goal • 了解bump mapping的原理 • 懂得如何使用GLSL實作bump mapping • 自行製作bump map
Bump Mapping • add bump map textures to models model bump map result
GLSL • Vertex shaders • change or get the information of vertices • Fragment shaders • mostly compute the color to be applied to a fragment
Bump Mapping in GLSL MCVertex MCNormal MCTangent TexCoord0 What you see on the pixelFragColor LightDir EyeDir TexCoord Vertex Shader Fragment Shader
Vertex Shader • compute the informaion of vertices gl_Position = MVPMatrix * MCVertex; EyeDir = vec3(MVMatrix * MCVertex); TexCoord = TexCoord0.st; vec3 n = normalize(NormalMatrix * MCNormal); vec3 t = normalize(NormalMatrix * MCTangent); vec3 b = cross(n, t); vec3 v; v.x = dot(LightPosition, t); v.y = dot(LightPosition, b); v.z = dot(LightPosition, n); LightDir = normalize(v); v.x = dot(EyeDir, t); v.y = dot(EyeDir, b); v.z = dot(EyeDir, n); EyeDir = normalize(v);
Fragment Shader • calculate the color to be perceived vec3 litColor; vec2 c = BumpDensity * TexCoord.st; vec2 p = fract(c) - vec2(0.5); float d, f; d = dot(p,p); f = inversesqrt(d + 1.0); if (d >= BumpSize) { p = vec2(0.0); f = 1.0; } vec3 normDelta = vec3(p.x, p.y, 1.0) * f; litColor = SurfaceColor.rgb * max(dot(normDelta, LightDir), 0.0); vec3 reflectDir = reflect(LightDir, normDelta); float spec = max(dot(EyeDir, reflectDir), 0.0); spec = pow(spec, 6.0); spec *= SpecularFactor; litColor = min(litColor+spec,vec3(1.0)); FragColor = vec4(litColor, SurfaceColor.a);
Bump Map • height map • normal map • displacement map height / normal displacement
Create Bump Map • Image Editing Software • Photoshop • PhotoImpact • GIMP • CrazyBump http://www.crazybump.com/
Create Bump Map • get a image of the texture • take a photo by yourself • find images on the Internet http://www.cgtextures.com/
Create Bump Map • select bumps or dents
Create Bump Map • adjust parameters and save 1. 2.
Create Bump Map Normal Grayscale of Normal convert by other software Occlusion Specularity
Create Bump Map Without Bump Map Specularityas Height Map