Reflection probes unity что это
Reflection probes
CG films and animations commonly feature highly realistic reflections, which are important for giving a sense of “connectedness” among the objects in the scene. However, the accuracy of these reflections comes with a high cost in processor time and while this is not a problem for films, it severely limits the use of reflective objects in realtime games.
Traditionally, games have used a technique called reflection mapping to simulate reflections from objects while keeping the processing overhead to an acceptable level. This technique assumes that all reflective objects in the scene can “see” (and therefore reflect) the exact same surroundings. This works quite well for the game’s main character (a shiny car, say) if it is in open space but is unconvincing when the character passes into different surroundings; it looks strange if a car drives into a tunnel but the sky is still visibly reflected in its windows.
Unity improves on basic reflection mapping through the use of Reflection Probes, which allow the visual environment to be sampled at strategic points in the scene. You should generally place them at every point where the appearance of a reflective object would change noticeably (eg, tunnels, areas near buildings and places where the ground colour changes). When a reflective object passes near to a probe, the reflection sampled by the probe can be used for the object’s reflection map. Furthermore, when several probes are nearby, Unity can interpolate between them to allow for gradual changes in reflections. Thus, the use of reflection probes can create quite convincing reflections with an acceptable processing overhead.
How Reflection Probes Work
The visual environment for a point in the scene can be represented by a cubemap. This is conceptually like a box with flat images of the view from six directions (up, down, left, right, forward and backward) painted on its interior surfaces.
Inside surfaces of a skybox cubemap (front face removed)
For an object to show the reflections, its shader must have access to the images representing the cubemap. Each point of the object’s surface can “see” a small area of cubemap in the direction the surface faces (ie, the direction of the surface normal vector). The shader uses the colour of the cubemap at this point in calculating what colour the object’s surface should be; a mirror material might reflect the colour exactly while a shiny car might fade and tint it somewhat.
As mentioned above, traditional reflection mapping makes use of only a single cubemap to represent the surroundings for the whole scene. The cubemap can be painted by an artist or it can be obtained by taking six “snapshots” from a point in the scene, with one shot for each cube face. Reflection probes improve on this by allowing you to set up many predefined points in the scene where cubemap snapshots can be taken. You can therefore record the surrounding view at any point in the scene where the reflections differ noticeably.
In addition to its view point, a probe also has a zone of effect defined by an invisible box shape in the scene. A reflective object that passes within a probe’s zone has its reflection cubemap supplied temporarily by that probe. As the object moves from one zone to another, the cubemap changes accordingly.
Продвинутые возможности Reflection Probes
Две дополнительные возможности, позволяющие улучшить визуальный реализм отражений Reflection Probes, описаны ниже: Interreflections (взаимоотражения) и Box Projection (кубическая проекция).
Взаимоотражения
Возможно, вы наблюдали ситуацию, в которой два зеркала расположены довольно близко друг к другу. Оба зеркала отражают не только друг друга, но также свои отражения. В результате, получаем бесконечную последовательность отражений двух зеркал. Подобные отражения между объектами называются Interreflections.
Отражение создает кубмап, делая снимок со своей позиции. Однако, имея один снимок, невозможно показать взаимоотражения, так что необходимо сделать дополнительные снимки для каждого этапа в последовательности взаимоотражений.
Количество раз, которое отражение может “отскочить” туда и обратно между двумя объектами, контролируется свойством свойством Reflection Bounces в Lighting window (это задается не для каждой пробы, а глобально для всех проб). Если задать количество отскоков равное 1, то отражающие объекты будут показаны черными. Со значением равным 2, будет виден первый уровень взаимоотражений, со значением 3 будут видны первые два уровня, и так далее.
Обратите внимание, что счетчик отскоков также равен количеству раз, которое проба должна быть просчитана с соответствующим увеличением во времени, требуемым для завершения полного просчета. Поэтому, устанавливать счетчик в значение большее одного, следует только если вы уверены, что отражающие объекты будут хорошо видны в одной или более проб.
Кубическая проекция
Как правило, предполагается, что кубмап с отражениями находится на бесконечном расстоянии от любого заданного объекта. Различные углы кубмапа будут видны при повороте объекта, но объект не может приблизиться или отдалиться от отраженного окружения. Это часто очень хорошо работает для открытых пространств, но его ограничения проявляются в помещениях; внутренние стены комнаты находятся не на бесконечном расстоянии и отражение на стене должно увеличиваться, при приближении к ней объекта.
The Box Projection option (available on platforms supporting Shader Model 3 or better) allows you to create a reflection cubemap at a finite distance from the probe, thus allowing objects to show different-sized reflections according to their distance from the cubemap’s walls. The size of the surrounding cubemap is determined by the probes zone of effect, as determined by its Size property. For example, with a probe that reflects the interior of a room, you should set the size to match the dimensions of the room.
Reflection Probe
A Reflection Probe is rather like a camera A component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary that captures a spherical view of its surroundings in all directions. The captured image is then stored as a Cubemap that can be used by objects with reflective materials. Several reflection probes can be used in a given scene A Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary and objects can be set to use the cubemap produced by the nearest probe. The result is that the reflections on the object can change convincingly according to its environment.
A Reflection Probe showing reflections from a nearby object
Properties
Details
There are two buttons at the top of the Reflection Probe Inspector A Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary window that are used for editing the Size and Probe Origin properties directly within the Scene. With the leftmost button (Size) selected, the probe’s zone of effect is shown in the scene as a yellow box shape with handles to adjust the box’s size.
The other button (Origin) allows you to drag the probe’s origin relative to the box. Note that the origin handle resembles the Transform position handle but the two positions are not the same. Also, the rotation and scale operations are not available for the probe box.
The probe’s Type property determines how the reflection data is created and updated:
To make use of the reflection cubemap, an object must have the Reflection Probes option enabled on its Mesh Renderer A mesh component that takes the geometry from the Mesh Filter and renders it at the position defined by the object’s Transform component. More info
See in Glossary and also be using a shader that supports reflection probes. When the object passes within the volume set by the probe’s Size and Probe Origin properties, the probe’s cubemap will be applied to the object.
You can also manually set which reflection probe to use for a particular object using the settings on the object’s Mesh Renderer. To do this, select one of the options for the Mesh The main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary Renderer’s Reflection Probes property (Simple, Blend Probes or Blend Probes and Skybox) and drag the chosen probe onto its Anchor Override property.
See the Reflection Probes section in the manual for further details about principles and usage.
Using Reflection Probes
The Reflection Probe component can be added to any object in the scene but you will typically want to add each probe to a separate empty GameObject. The usual workflow is:
To see the reflections, you will also need at least one reflective object in the scene. A simple test object can be created as follows:
The sphere can now show the reflections obtained from the probes. A simple arrangement with a single probe is enough to see the basic effect of the reflections.
Finally, the probes must be baked before the reflections become visible. If you have the Auto option enabled in the Lighting window (this is the default setting) then the reflections will update as you position or change objects in the scene, although the response is not instantaneous. If you disable auto baking then you must click the Bake button in the Reflection Probe inspector to update the probes. The main reason for disabling auto baking is that the baking process can take quite some time for a complicated scene with many probes.
Positioning Probes
The position of a probe is primarily determined by the position of its GameObject and so you can simply drag the object to the desired location. Having done this, you should set the probe’s zone of effect; this is an axis-aligned box shape whose dimensions are set by the Size property. You can set the size values directly or enable the size editing mode in the inspector and drag the sides of the box in the Scene view (see the Reflection Probe component page for details). The zones of the full set of probes should collectively cover all areas of the scene where a reflective object might pass.
You should place probes close to any large objects in the scene that would be reflected noticeably. Areas around the centres and corners of walls are good candidate locations for probes. Smaller objects might require probes close by if they have a strong visual effect. For example, you would probably want the flames of a campfire to be reflected even if the object itself is small and otherwise insignificant.
When you have probes in all the appropriate places, you then need to define the zone of effect for each probe, which you can do using the Size property as mentioned above. A wall might need just a single probe zone along most of its length (at least if it has a fairly uniform appearance) but the zone might be relatively narrow in the direction perpendicular to the wall; this would imply that the wall is only reflected by objects that are fairly close to it. An open space whose appearance varies little from place to place can often be covered by a single probe. Note that a probe’s zone is aligned to the main world axes (X, Y and Z) and can’t be rotated. This means that sometimes a group of probes might be needed along a uniform wall if it is not axis-aligned.
By default, a probe’s zone of effect is centred on its view point but this may not be the ideal position for capturing the reflection cubemap. For example, the probe zone for a very high wall might extend some distance from the wall but you might want the reflection to be captured from a point close to it rather than the zone’s centre. You can optionally add an offset to view point using the Probe Origin property (ie, the origin is the position in the GameObject’s local space that the probe’s cubemap view is generated from). Using this, you can easily place the view point anywhere within the zone of effect or indeed outside the zone altogether.
Overlapping Probe Zones
It would be very difficult to position the zones of neighbouring reflection probes without them overlapping and fortunately, it is not necessary to do so. However, this leaves the issue of choosing which probe to use in the overlap areas. By default, Unity calculates the intersection between the reflective object’s bounding box and each of the overlapping probe zones; the zone which has the largest volume of intersection with the bounding box is the one that will be selected.
Probe A is selected since its intersection with the object is larger
You can modify the calculation using the probes’ Importance properties. Probes with a higher importance value have priority over those of lower importance within overlap zones. This is useful, say, if you have a small probe zone that is contained completely inside a larger zone (ie, the intersection of the character’s bounding box with the enclosing zone might always be larger and so the small zone would never be used).
Blending
If your target platform uses Shader Model 3 or better then you have the option of blending between probes in the areas where their zones overlap. With blending enabled, Unity will gradually fade out one probe’s cubemap while fading in the other’s as the reflective object passes from one zone to the other. This gradual transition avoids the situation where a distinctive object suddenly “pops” into the reflection as an object crosses the zone boundary.
Blending is controlled using the Reflection Probes property of the Mesh Renderer component. Two blending options are available:
When probes have equal Importance values, the blending weight for a given probe zone is calculated by dividing its intersection (volume) with the object’s bounding box by the sum of all probes’ intersections with the box. For example, if the box intersects probe A’s zone by 1.0 cubic units and intersects probe B’s zone by 2.0 cubic units then the blending values will be:
In other words, the blend will incorporate 33% of probe A’s reflection and 67% of probe B’s reflection.
The calculation must be handled slightly differently in the case where one probe is entirely contained within the other, since the inner zone overlaps entirely with the outer. If the object’s bounding box is entirely within the inner zone then that zone’s blending weight is 1.0 (ie, the outer zone is not used at all). When the object is partially outside the inner zone, the intersection volume of its bounding box with the inner zone is divided by the total volume of the box. For example, if the intersection volume is 1.0 cubic units and the bounding box’s volume is 4.0 cubic units, then the blending weight of the inner probe will be 1.0 / 4.0 = 0.25. This value is then subtracted from 1.0 to get the weight for the outer probe which in this case will be 0.75.
When one probe involved in the blend has a higher Importance value than another, the more important probe overrides the other in the usual way.
Reflection Probe
A Reflection Probe is rather like a camera that captures a spherical view of its surroundings in all directions. The captured image is then stored as a Cubemap that can be used by objects with reflective materials. Several reflection probes can be used in a given scene and objects can be set to use the cubemap produced by the nearest probe. The result is that the reflections on the object can change convincingly according to its environment.
A Reflection Probe showing reflections from a nearby object
Свойства
Свойство: | Функция: |
---|---|
Type | Is the probe for a Baked, Custom or Realtime setup? |
Dynamic Objects | (Custom type only) Forces objects not marked as Static to be baked in to the reflection. |
Cubemap | (Custom type only) Sets a custom cubemap for the probe. |
Refresh Mode | (Realtime type only) Selects if and how the probe will refresh at runtime. The On Awake option renders the probe only once when it first becomes active. Every Frame renders the probe every frame update, optionally using Time Slicing (see below). The Via Scripting option refreshes the probe from a user script command rather than an automatic update. |
Time Slicing | (Realtime type only) How should the probe distribute its updates over time? The options are All Faces At Once (spreads update over nine frames), Individual Faces (updates over fourteen frames) and No Time Slicing (the update happens entirely within one frame). See below for further details. |
Runtime Settings | |
Importance | The degree of “importance” of this probe compared to its neighbours. Higher values indicate greater importance; more important probes will have priority over less important one in cases where an object is within range of two or more probes. This setting also affects the Blending, explained below. |
Intensity | The intensity modifier that is applied to the texture of this probe in its shader. |
Box Projection | Should box projection be enabled for reflection UV mappings? |
Size | The size of the zone within which objects will be affected by this probe’s reflection cubemap. Also used by Box Projection. |
Probe Origin | The centre point of the probe’s zone of effect which is also used while baking the probe. Also used by Box Projection. |
Cubemap Capture settings | |
Resolution | The resolution of the captured reflection image. |
HDR | Should High Dynamic Range rendering be enabled for the cubemap? This also determines whether probe data is saved in OpenEXR or PNG format. |
Shadow Distance | Distance at which shadows are drawn when rendering the probe. |
Clear Flags | Option to specify how empty background areas of the cubemap will be filled. The options are Skybox and Solid Color. |
Background | Background colour to which the reflection cubemap is cleared before rendering. |
Culling Mask | Allows objects on specified layers to be included or excluded in the reflection. See the section about the Camera’s culling mask on the Layers page. |
Use Occlusion Culling | Should occlusion culling be used when baking the probe? |
Clipping Planes | Near and far clipping planes of the probe’s “camera”. |
Детали
At the top of the Reflection Probe inspector are two buttons that are used for editing the Size and Probe Origin properties directly within the scene. With the leftmost button (Size) selected, the probe’s zone of effect is shown in the scene as a yellow box shape with handles to adjust the box’s size.
The other button (Origin) allows you to drag the probe’s origin relative to the box. Note that the origin handle resembles the Transform position handle but the two positions are not the same. Also, the rotation and scale operations are not available for the probe box.
The probe’s Type property determines how the reflection data is created and updated:
To make use of the reflection cubemap, an object must have the Reflection Probes option enabled on its Mesh Renderer and also be using a shader that supports reflection probes. When the object passes within the volume set by the probe’s Size and Probe Origin properties, the probe’s cubemap will be applied to the object.
You can also manually set which reflection probe to use for a particular object using the settings on the object’s Mesh Renderer. To do this, select one of the options for the Mesh Renderer’s Reflection Probes property (Simple, Blend Probes or Blend Probes and Skybox) and drag the chosen probe onto its Anchor Override property.
See the Reflection Probes section in the manual for further details about principles and usage.