| 61 | } |
| 62 | |
| 63 | void GFXCubemap::initNormalize( U32 size ) |
| 64 | { |
| 65 | Point3F axis[6] = |
| 66 | {Point3F(1.0, 0.0, 0.0), Point3F(-1.0, 0.0, 0.0), |
| 67 | Point3F(0.0, 1.0, 0.0), Point3F( 0.0, -1.0, 0.0), |
| 68 | Point3F(0.0, 0.0, 1.0), Point3F( 0.0, 0.0, -1.0),}; |
| 69 | Point3F s[6] = |
| 70 | {Point3F(0.0, 0.0, -1.0), Point3F( 0.0, 0.0, 1.0), |
| 71 | Point3F(1.0, 0.0, 0.0), Point3F( 1.0, 0.0, 0.0), |
| 72 | Point3F(1.0, 0.0, 0.0), Point3F(-1.0, 0.0, 0.0),}; |
| 73 | Point3F t[6] = |
| 74 | {Point3F(0.0, -1.0, 0.0), Point3F(0.0, -1.0, 0.0), |
| 75 | Point3F(0.0, 0.0, 1.0), Point3F(0.0, 0.0, -1.0), |
| 76 | Point3F(0.0, -1.0, 0.0), Point3F(0.0, -1.0, 0.0),}; |
| 77 | |
| 78 | F32 span = 2.0; |
| 79 | F32 start = -1.0; |
| 80 | |
| 81 | F32 stride = span / F32(size - 1); |
| 82 | GFXTexHandle faces[6]; |
| 83 | |
| 84 | for(U32 i=0; i<6; i++) |
| 85 | { |
| 86 | GFXTexHandle &tex = faces[i]; |
| 87 | GBitmap *bitmap = new GBitmap(size, size); |
| 88 | |
| 89 | // fill in... |
| 90 | for(U32 v=0; v<size; v++) |
| 91 | { |
| 92 | for(U32 u=0; u<size; u++) |
| 93 | { |
| 94 | Point3F vector; |
| 95 | vector = axis[i] + |
| 96 | ((F32(u) * stride) + start) * s[i] + |
| 97 | ((F32(v) * stride) + start) * t[i]; |
| 98 | vector.normalizeSafe(); |
| 99 | vector = ((vector * 0.5) + Point3F(0.5, 0.5, 0.5)) * 255.0; |
| 100 | vector.x = mClampF(vector.x, 0.0f, 255.0f); |
| 101 | vector.y = mClampF(vector.y, 0.0f, 255.0f); |
| 102 | vector.z = mClampF(vector.z, 0.0f, 255.0f); |
| 103 | // easy way to avoid knowledge of the format (RGB, RGBA, RGBX, ...)... |
| 104 | U8 *bits = bitmap->getAddress(u, v); |
| 105 | bits[0] = U8(vector.x); |
| 106 | bits[1] = U8(vector.y); |
| 107 | bits[2] = U8(vector.z); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | tex.set(bitmap, &GFXStaticTextureSRGBProfile, true, "Cubemap"); |
| 112 | } |
| 113 | |
| 114 | initStatic(faces); |
| 115 | } |
| 116 | |
| 117 | const String GFXCubemap::describeSelf() const |
| 118 | { |
no test coverage detected