/* * cubic_displacement_mapping(): Displace the surface of a box with the alpha channel of a repeatable background texture. */ displacement cubic_displacement_mapping( float Km = 0.03, u_repeat = 1.0, v_repeat = 1.0; string bkgrnd_texturename = "wood_panel1.tif"; string foregrnd1_texturename = ""; string foregrnd2_texturename = ""; string foregrnd3_texturename = ""; string foregrnd4_texturename = ""; string foregrnd5_texturename = ""; point foregrnd1_P; point foregrnd2_P; point foregrnd3_P; point foregrnd4_P; point foregrnd5_P) { float u_offset, v_offset, scale, s_new, t_new; point foregrnd1_P = point (.1, .1, .6); point foregrnd2_P = point (.1, .1, 1.3); point foregrnd3_P = point (.1, .1, 1.3); point foregrnd4_P = point (.1, .1, 1.3); point foregrnd5_P = point (.1, .1, 1.3); u_offset = xcomp(foregrnd1_P); v_offset = ycomp(foregrnd1_P); scale = zcomp(foregrnd1_P); /*displacement mapping using background textures' 1st alpha channel*/ if((foregrnd1_texturename != "") && (u >= u_offset) && (v >= v_offset) && (u <= u_offset + scale) && (v <= v_offset + scale)){ } else P += (-Km * texture(bkgrnd_texturename [3], u*u_repeat, v*v_repeat)) * normalize(N); N = calculatenormal(P); }