SDK Android XR hiện đã có trong Bản dùng thử cho nhà phát triển. Chúng tôi rất mong nhận được ý kiến phản hồi của bạn! Hãy truy cập vào trang hỗ trợ của chúng tôi để liên hệ.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Kể từ bản phát hành alpha04 của thư viện Jetpack XR, có một số nội dung cập nhật quan trọng về cách bạn nên cung cấp các thành phần môi trường không gian để đạt được hiệu suất và chất lượng hình ảnh tối ưu. Những thay đổi này ảnh hưởng đến khả năng tương thích và yêu cầu cập nhật các ứng dụng hiện có đặt môi trường không gian.
Để cung cấp môi trường không gian, bạn cần có hai thành phần chính:
Tệp .glb hoặc .gltf cho hình học của môi trường (ví dụ: mặt phẳng mặt đất, các đối tượng lân cận) và kết cấu hộp ảo chính mà người dùng nhìn thấy.
Một tệp ZIP riêng chứa thông tin về Ánh sáng dựa trên hình ảnh (IBL) được tạo từ hình ảnh EXR có dải động cao bằng công cụ cmgen. Tệp ZIP được dùng để tính toán ánh sáng, chẳng hạn như phản chiếu trên các đối tượng, chứ không phải cho chính hoạ tiết hộp trăng.
Tại sao lại sử dụng phương pháp này?
Cấu trúc thành phần mới cập nhật này mang lại những lợi ích sau:
Kích thước tệp nhỏ hơn: So với các phương pháp trước đây, chẳng hạn như sử dụng một tệp hộp ảo HDR có độ phân giải cao cho cả thông tin hiển thị hình ảnh và thông tin chiếu sáng, phương pháp này giúp giảm kích thước tệp.
Cải thiện hiệu suất: Việc tách riêng hoạ tiết hộp ảo (được tích hợp vào glb) khỏi dữ liệu IBL (trong tệp ZIP) cho phép bạn tối ưu hoá từng thành phần một cách độc lập. Điều này làm giảm băng thông đọc bộ nhớ kết cấu và giảm mức tiêu thụ điện năng.
Ánh sáng được tối ưu hoá: Việc sử dụng tài nguyên hộp ảo có độ phân giải thấp hơn dành riêng cho bản đồ ánh sáng sẽ có lợi cho hiệu suất mà không ảnh hưởng đáng kể đến kết quả hình ảnh của ánh sáng trên các đối tượng.
Để tìm hiểu thêm về cách thêm Môi trường không gian vào ứng dụng, hãy xem hướng dẫn của chúng tôi về cách thêm môi trường vào ứng dụng.
Tối ưu hoá glb
glb của bạn thể hiện hình học xung quanh người dùng và bạn bao gồm cả hoạ tiết hình ảnh của hộp trời. Đối với hình học, bạn nên cố gắng duy trì kích thước tệp bằng hoặc nhỏ hơn 80 MB.
Để làm được điều này, có một số cơ hội để giúp môi trường của bạn hoạt động hiệu quả hơn mà vẫn duy trì chất lượng cao. Ví dụ: mật độ của lưới phải dày nhất ở gần người dùng và bạn có thể giảm mật độ cho các lưới ở xa người dùng hơn.
Khoảng cách xem: Khoảng cách xem cho các môi trường trong Android XR là 200m từ điểm của người dùng và hoạ tiết hộp trời phải tuân thủ quy tắc ràng buộc này. Điều này mang lại trải nghiệm tối ưu vì hiệu ứng thị sai trở nên không thể phân biệt được ở khoảng cách đó.
Chiều cao của người dùng: Vị trí địa lý có thể khác nhau, nhưng hãy đặt người dùng trên một gò đất có chiều cao khoảng 1,5 mét để tránh bị cắt bớt với các thành phần giao diện người dùng lớn hơn trong ứng dụng.
Số đa giác: Hãy chú ý đến số đa giác trong tệp glb, vì số đa giác cao có thể dẫn đến mức tiêu thụ điện năng không cần thiết. Mỗi bản vá hình học không được vượt quá 10.000 đỉnh.
Nén KTX: Tối ưu hoá hiệu suất GPU của tệp glb bằng cách đảm bảo rằng glb sử dụng mipmap và hoạ tiết ktx2.
Tìm tệp .tgz chứa phiên bản cmgen tạo sẵn cho nền tảng của bạn và giải nén tệp đó.
Công cụ tạo sẵn nằm trong thư mục /bin của tệp .tgz đã giải nén.
Các thành phần cần chuẩn bị để tạo tệp .zip cho IBL:
Tệp EXR có độ phân giải thấp khớp với hoạ tiết hộp trời của bạn
Đầu vào kết cấu hộp ảo của bạn phải là tệp EXR. Mặc dù cmgen hỗ trợ các định dạng khác, nhưng bạn nên sử dụng EXR vì chúng cung cấp thông tin về dải động cao rất quan trọng để cung cấp IBL chất lượng cao.
Việc sử dụng các định dạng khác như PNG sẽ khiến ánh sáng kém chính xác hơn.
Hình ảnh nguồn (EXR) cần có tỷ lệ 2:1 và kích thước là luỹ thừa của 2. Sử dụng tệp EXR có kích thước 1024 x 512 pixel. Lưu ý: Có vẻ như độ phân giải 1024 x 512 quá thấp, nhưng điều này lại có lợi cho hiệu suất. Đối với IBL, kết quả hình ảnh cho người dùng rất giống với các thành phần có độ phân giải IBL cao hơn nhiều.
Tệp png màu đen đồng nhất
Thành phần này cũng phải có tỷ lệ 2:1. Sử dụng kích thước 100 x 50 pixel.
Đây là một hoạ tiết được tối ưu hoá để đi kèm với IBL. Người dùng sẽ không xem xét thành phần này, vì vậy, chúng ta tập trung vào việc tối ưu hoá thành phần này để đạt được hiệu suất.
Sau đây là ví dụ về cách sử dụng cmgen để tạo tệp .zip cho IBL.
Trong ví dụ này, chúng ta sử dụng các tệp đầu vào có tên my_360_skybox_1024_x_512.exr và
black_skybox.png, đồng thời tạo một tệp .zip có tên my_ibl.zip
# Produce black cubemaps for the texture of the IBL asset.
./cmgen--format=rgb32f--size=128--extract=./skybox_ibl./black_skybox.png
# Produce lighting cubemaps and a Spherical Harmonics from EXR
./cmgen--format=rgb32f--size=128--deploy=./skybox_ibl--ibl-ld=.--ibl-samples=1024--extract-blur=0.0--sh-irradiance--sh-shader--sh-output=./skybox_ibl/sh.txt./my_360_skybox_1024_x_512.exr
# Copy all of the black cubemaps into the other folder.
cp-rf./skybox_ibl/black_skybox/*./skybox_ibl/my_360_skybox_1024_x_512
# Rename the directory to reflect that these are old assets.
mv./skybox_ibl/black_skybox./skybox_ibl/black_skybox_old
# Rename the directory to reflect that these are your cubemap assets.
mv./skybox_ibl/my_360_skybox_1024_x_512./skybox_ibl/black_skybox
# Change into the child directory.cd./skybox_ibl
# Zip all of the cubemap and the Spherical Harmonics assets together.
zip-qmy_ibl.zipblack_skybox/*
# Return to the directory you started in.cd..
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Optimize environment assets\n\nBeginning with the alpha04 release of the Jetpack XR libraries, there are\nimportant updates to how you should provide spatial environment assets for\noptimal performance and visual quality. These changes are a compatibility impact\nand require updating existing apps that set spatial environments.\n\nTo provide spatial environments, you need two main components:\n\n- A .glb or .gltf file for the environment's geometry (for example, the ground plane, nearby objects) and the primary visual skybox texture that users see.\n- A separate ZIP file containing Image Based Lighting (IBL) information generated from a high dynamic range EXR image using the cmgen tool. The ZIP file is used for lighting calculations, such as reflections on objects, and not for the visual skybox texture itself.\n\nWhy this approach?\n------------------\n\nThis updated asset structure provides these advantages:\n\n- **Smaller file sizes:** Compared to previous methods, such as using a single high-resolution HDR skybox file for both visual display and lighting information, this approach reduces file sizes.\n- **Improved performance:** Separating the visual skybox texture (built into the glb) from the IBL data (in the ZIP file) lets you optimize each component independently. This results in lower texture memory read bandwidth and lower power consumption.\n- **Optimized lighting:** Using a lower resolution skybox resource specifically for the lighting map is beneficial for performance without significantly impacting the visual results of the lighting on objects.\n\nTo learn more about adding a spatial Environment in your app, see our guide on\n[adding environments to your app](/develop/xr/jetpack-xr-sdk/add-environment).\n| **Note:** It's important to provide an IBL asset if your app sets a custom environment, especially if your app has any 3D objects. This is because, if your app provides a glb/glTF but no IBL ZIP file, the 3D objects in the user's environment appear with incorrect lighting (for example, too bright or dim, reflecting objects that the user can't otherwise see).\n\nOptimize your glb\n-----------------\n\nYour glb represents the geometry around the user, and you include the visual\ntexture of your skybox. For your geometry, you should try to maintain file sizes\nat or smaller than 80MB.\n\nTo do this, there are a number of opportunities to make your environment more\nefficient while maintaining high quality. For example, the density of your mesh\nshould be the most dense near the user, and you can decrease the density for\nmeshes that are farther from the user.\n\n- **View distance:** The view distance for environments in Android XR is 200m from the point of the user, and your skybox texture should adhere to this constraint. This provides an optimal experience because parallax becomes indiscernible at that distance.\n- **User height:** Geography can vary, but position the user on a mound at\n around 1.5 meters of height to avoid clipping with larger UI elements in\n apps.\n\n- **Polycount:** Be sensitive to the polycount in your glb files, as a high\n polycount can lead to unnecessary power consumption. Each patch of geometry\n shouldn't exceed 10,000 vertices.\n\n- **KTX compression:** Optimize the GPU performance of your glb file by\n ensuring that your glb uses mipmaps and ktx2 textures.\n\nWhat you'll need to optimize your IBL\n-------------------------------------\n\nDownload the cmgen command line utility:\n\n- You can find the latest release in [the Filament repository](https://github.com/google/filament/releases/).\n- Find the .tgz containing the prebuilt version of cmgen for your platform and extract it.\n- The prebuilt tool is under the /bin directory of the extracted .tgz file.\n\nAssets to prepare to generate the .zip file for IBL:\n\n- A low-resolution EXR that matches your skybox texture\n - Your skybox texture input should be an EXR file. Although cmgen supports other formats, EXRs are recommended because they provide the high dynamic range information that's critical to provide high quality IBL. Using other formats like PNG results in less precise lighting.\n - The source image (EXR) needs to have a 2:1 ratio and dimensions that are a power of 2. Use an EXR that's 1024 x 512 pixels. Note: It may seem that 1024 x 512 is too low of a resolution, but this is beneficial for performance. For IBL, the visual results for the user are very similar to much higher IBL resolution assets.\n- A solid black png\n - This asset must also be a 2:1 ratio. Use a size of 100 x 50 pixels.\n - This serves as an optimized texture to accompany the IBL. Users won't look at this, so we focus the asset on optimizing for performance.\n\nThe following shows an example of using cmgen to create the .zip file for IBL.\nIn this example we use input files named my_360_skybox_1024_x_512.exr and\nblack_skybox.png, and we create a .zip file named my_ibl.zip \n\n # Produce black cubemaps for the texture of the IBL asset.\n ./cmgen --format=rgb32f --size=128 --extract=./skybox_ibl ./black_skybox.png\n\n # Produce lighting cubemaps and a Spherical Harmonics from EXR\n ./cmgen --format=rgb32f --size=128 --deploy=./skybox_ibl --ibl-ld=. --ibl-samples=1024 --extract-blur=0.0 --sh-irradiance --sh-shader --sh-output=./skybox_ibl/sh.txt ./my_360_skybox_1024_x_512.exr\n\n # Copy all of the black cubemaps into the other folder.\n cp -rf ./skybox_ibl/black_skybox/* ./skybox_ibl/my_360_skybox_1024_x_512\n\n # Rename the directory to reflect that these are old assets.\n mv ./skybox_ibl/black_skybox ./skybox_ibl/black_skybox_old\n\n # Rename the directory to reflect that these are your cubemap assets.\n mv ./skybox_ibl/my_360_skybox_1024_x_512 ./skybox_ibl/black_skybox\n\n # Change into the child directory.\n cd ./skybox_ibl\n\n # Zip all of the cubemap and the Spherical Harmonics assets together.\n zip -q my_ibl.zip black_skybox/*\n\n # Return to the directory you started in.\n cd .."]]