class in UnityEngine.TerrainTools
/
Implemented in:UnityEngine.TerrainModule
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseThe context for a paint operation that may span multiple connected Terrain tiles.
This class is used to apply an edit operation to an area of Terrain that may span multiple Terrain tiles.
A PaintContext may be used to edit heightmap or splatmap data, and may also be used to gather normal data in read-only mode (you cannot write to normals, because they are derived from the heightmap).
A PaintContext will calculate the relevant regions on each Terrain, and collect the original data into a single sourceRenderTarget.
Your edit operation can then read from sourcerenderTarget, and write the modified data to destinationRenderTarget.
Once you have applied your edit operation, the PaintContext can also write the modified data in destinationRenderTarget back to each Terrain, ensuring no seams between them.
The simplest way to use a PaintContext is through the helper functions in TerrainPaintUtility:
TerrainPaintUtility.BeginPaintHeightmap, TerrainPaintUtility.EndPaintHeightmap, TerrainPaintUtility.BeginPaintTexture, TerrainPaintUtility.EndPaintTexture, TerrainPaintUtility.CollectNormals and TerrainPaintUtility.ReleaseContextResources.
You can also use PaintContext more directly through its member functions. In general, they are used in the following order:
1) Constructor, PaintContext.CreateFromBounds - Construct a PaintContext with a target Terrain and a region to edit
2) PaintContext.CreateRenderTargets - Create the source and destination RenderTargets
3) PaintContext.GatherHeightmap, PaintContext.GatherAlphamap, PaintContext.GatherNormals - Read from Terrain tiles into sourceRenderTarget
4) Apply editing operations, reading from sourceRenderTarget, and writing to destinationRenderTarget
5) PaintContext.ScatterHeightmap, PaintContext.ScatterAlphamap - Write from destinationRenderTarget into Terrain tiles (optional)
6) PaintContext.Cleanup - Destroy RenderTarget resources (required if you call CreateRenderTargets)
7) PaintContext.ApplyDelayedActions - Apply any delayed actions that perform expensive updates
Additional resources: TerrainPaintTool<T0>
kNormalizedHeightScale | Unity uses this value internally to transform a [0, 1] height value to a texel value, which is stored in TerrainData.heightmapTexture. |
destinationRenderTexture | (Read Only) RenderTexture that an edit operation writes to modify the data. |
heightWorldSpaceMin | The minimum height of all Terrain tiles that this PaintContext touches in world space. |
heightWorldSpaceSize | The height range (from Min to Max) of all Terrain tiles that this PaintContext touches in world space. |
oldRenderTexture | (Read Only) The value of RenderTexture.active at the time CreateRenderTargets is called. |
originTerrain | (Read Only) The Terrain used to build the PaintContext. |
pixelRect | (Read Only) The pixel rectangle that this PaintContext represents. |
pixelSize | (Read Only) The size of a PaintContext pixel in terrain units (as defined by originTerrain.) |
sourceRenderTexture | (Read Only) Render target that stores the original data from the Terrain tiles. |
targetTextureHeight | (Read Only) The height of the target terrain texture. This is the resolution for a single Terrain. |
targetTextureWidth | (Read Only) The width of the target terrain texture. This is the resolution for a single Terrain. |
terrainCount | (Read Only) The number of Terrain tiles in this PaintContext. |
PaintContext | Creates a new PaintContext, to edit a target texture on a Terrain, in a region defined by pixelRect. |
Cleanup | Releases the allocated resources of this PaintContext. |
CreateRenderTargets | Creates the sourceRenderTexture and destinationRenderTexture. |
Gather | Gathers user-specified Texture data into sourceRenderTexture. |
GatherAlphamap | Gathers the alphamap information into sourceRenderTexture. |
GatherHeightmap | Gathers the heightmap information into sourceRenderTexture. |
GatherHoles | Gathers the Terrain holes information into sourceRenderTexture. |
GatherNormals | Gathers the normal information into sourceRenderTexture. |
GetClippedPixelRectInRenderTexturePixels | Retrieves the clipped pixel rectangle for a Terrain, relative to the PaintContext render textures. |
GetClippedPixelRectInTerrainPixels | Retrieves the clipped pixel rectangle for a Terrain. |
GetTerrain | Retrieves a Terrain from the PaintContext. |
Scatter | Applies an edited PaintContext by copying modifications back to user-specified RenderTextures for the source Terrain tiles. |
ScatterAlphamap | Applies an edited alphamap PaintContext by copying modifications back to the source Terrain tiles. |
ScatterHeightmap | Applies an edited heightmap PaintContext by copying modifications back to the source Terrain tiles. |
ScatterHoles | Applies an edited Terrain holes PaintContext by copying modifications back to the source Terrain tiles. |
ApplyDelayedActions | Flushes the delayed actions created by PaintContext heightmap and alphamap modifications. |
CreateFromBounds | Constructs a PaintContext that you can use to edit a texture on a Terrain, in the region defined by boundsInTerrainSpace and extraBorderPixels. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.