| 38 | } |
| 39 | |
| 40 | cpp::Group MipMapTextures::buildGroup() const |
| 41 | { |
| 42 | std::vector<vec3f> v_position = {{-2.5f, -1.5f, -4.f}, |
| 43 | {2.5f, -1.5f, -4.f}, |
| 44 | {2.5f, 1.5f, 0.f}, |
| 45 | {-2.5f, 1.5f, 0.f}, |
| 46 | {-1.25f, 1.5f, -2.f}, |
| 47 | {1.25f, 1.5f, -2.f}, |
| 48 | {1.25f, 3.5f, -0.5f}, |
| 49 | {-1.25f, 3.5f, -0.5f}}; |
| 50 | std::vector<vec2f> v_texcoord = {{0.f, 0.f}, |
| 51 | {scale, 0.f}, |
| 52 | {scale, scale}, |
| 53 | {0.f, scale}, |
| 54 | {0.f, 0.f}, |
| 55 | {scale, 0.f}, |
| 56 | {scale, scale}, |
| 57 | {0.f, scale}}; |
| 58 | |
| 59 | cpp::Geometry planeGeometry("mesh"); |
| 60 | planeGeometry.setParam("vertex.position", cpp::CopiedData(v_position)); |
| 61 | planeGeometry.setParam("vertex.texcoord", cpp::CopiedData(v_texcoord)); |
| 62 | planeGeometry.setParam("quadSoup", true); |
| 63 | planeGeometry.commit(); |
| 64 | |
| 65 | vec2ul texSize(500, 500); |
| 66 | std::vector<uint8_t> texData(texSize.product()); |
| 67 | uint8_t grayTexel{50}; |
| 68 | uint8_t lightTexel{200}; |
| 69 | for (size_t i = 0; i < texSize.x; i++) { |
| 70 | const int sz = 1 + i * 4 / texSize.x; |
| 71 | for (size_t j = 0; j < texSize.y; j++) { |
| 72 | texData[j * texSize.x + i] = |
| 73 | (i / sz + j / sz) % 2 ? lightTexel : grayTexel; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | cpp::Texture procTex("texture2d"); |
| 78 | procTex.setParam("format", OSP_TEXTURE_L8); |
| 79 | procTex.setParam("filter", filter); |
| 80 | procTex.setParam("data", cpp::CopiedData(texData.data(), texSize)); |
| 81 | procTex.commit(); |
| 82 | |
| 83 | cpp::GeometricModel plane(planeGeometry); |
| 84 | |
| 85 | cpp::Material material("obj"); |
| 86 | material.setParam("map_kd", procTex); |
| 87 | material.setParam("map_kd.scale", vec2f(scale)); |
| 88 | material.setParam("map_kd.translation", vec2f(0.5f - 0.5f / scale)); |
| 89 | material.commit(); |
| 90 | |
| 91 | plane.setParam("material", material); |
| 92 | plane.commit(); |
| 93 | |
| 94 | cpp::Group planeGroup; |
| 95 | planeGroup.setParam("geometry", cpp::CopiedData(plane)); |
| 96 | planeGroup.commit(); |
| 97 | |