public override bool OnPaint(Terrain terrain, IOnPaint editContext) { BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, 0.0f); Rect rect = brushXform.GetBrushXYBounds(); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, rect); Material mat = GetPaintMaterial(); PaintContext maskContext = null; if (m_TextureMask || m_TextureStencil) { TerrainLayer maskTerrainLayer = terrain.terrainData.terrainLayers[m_TextureMask ? m_maskIndex : m_stencilIndex]; maskContext = TerrainPaintUtility.BeginPaintTexture(terrain, rect, maskTerrainLayer); if (maskContext == null) { return(false); } mat.SetTexture("_MaskTex", maskContext.sourceRenderTexture); } mat.SetInt("_MaskStencil", m_TextureMask ? 1 : (m_TextureStencil ? 2 : 0)); ApplyBrushInternal(paintContext, editContext.brushStrength, editContext.brushTexture, brushXform, mat); if (maskContext != null) { TerrainPaintUtility.ReleaseContextResources(maskContext); } TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Masked Terrace Erosion"); return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { if (Event.current.type == EventType.MouseDrag) { return(true); } Material mat = TerrainPaintUtility.GetBuiltinPaintMaterial(); Rect brushRect = TerrainPaintUtility.CalculateBrushRectInTerrainUnits(terrain, editContext.uv, editContext.brushSize); TerrainPaintUtility.PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushRect); Vector4 brushParams = new Vector4(editContext.brushStrength * 0.01f, 0.0f, m_StampHeight, 0.0f); if (Event.current.shift) { brushParams.x = -brushParams.x; } mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, (int)TerrainPaintUtility.BuiltinPaintMaterialPasses.StampHeight); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Stamp"); return(true); }
private bool Smudge(Terrain terrain, IOnPaint editContext, Vector2 currUV, Vector2 prevUV) { // the brush size is relative to the main brush size float brushSize = editContext.brushSize * ridgeErodeBrushSize / 100f; BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, currUV, brushSize, 0.0f); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds(), 1); Vector2 smudgeDir = editContext.uv - prevUV; paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; Material mat = GetMaterial(); float brushStrength = ridgeErodeBrushStrength / 100f; // editContext.brushStrength; Vector4 brushParams = new Vector4(brushStrength, erosionStrength, mixStrength, 0); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, 0); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Ridge Erode"); return(true); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { commonUI.OnPaint(terrain, editContext); if (commonUI.allowPaint) { Texture brushTexture = editContext.brushTexture; using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "PaintHoles", brushTexture)) { Vector2 halfTexelOffset = new Vector2(0.5f / terrain.terrainData.holesResolution, 0.5f / terrain.terrainData.holesResolution); BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv - halfTexelOffset, commonUI.brushSize, commonUI.brushRotation); PaintContext paintContext = brushRender.AquireHolesTexture(true, brushXform.GetBrushXYBounds()); PaintContext paintContextHeight = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds()); // filter stack Material mat = Utility.GetPaintHeightMaterial(); var brushMask = RTUtils.GetTempHandle(paintContextHeight.sourceRenderTexture.width, paintContextHeight.sourceRenderTexture.height, 0, FilterUtility.defaultFormat); Utility.SetFilterRT(commonUI, paintContextHeight.sourceRenderTexture, brushMask, mat); // hold control key to erase float brushStrength = Event.current.control ? commonUI.brushStrength : -commonUI.brushStrength; Vector4 brushParams = new Vector4(brushStrength, 0.0f, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); brushRender.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); brushRender.RenderBrush(paintContext, mat, (int)TerrainBuiltinPaintMaterialPasses.PaintHoles); TerrainPaintUtility.EndPaintHoles(paintContext, "Terrain Paint - Paint Holes"); RTUtils.Release(brushMask); } } return(true); }
public virtual void OnPaint(Terrain terrain, IOnPaint editContext) { // Manage brush capture history for playback in tests if (isRecording) { OnPaintOccurrence.history.Add(new OnPaintOccurrence(editContext.brushTexture, brushSize, brushStrength, brushRotation, editContext.uv.x, editContext.uv.y)); } m_Controllers.ForEach((controller) => controller.OnPaint(terrain, editContext)); if (m_BrushSmoothController != null) { Vector2 uv = editContext.uv; if (ScatterBrushStamp(ref terrain, ref uv)) { m_BrushSmoothController.kernelSize = 0.03f * m_BrushSizeController.brushSize; m_BrushSmoothController.OnPaint(terrain, editContext, brushSize, brushRotation, brushStrength, uv); } } /// Ensure that we re-randomize where the next scatter operation will place the brush, /// that way we can render the preview in a representative manner. m_BrushScatterController?.RequestRandomisation(); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { Texture brushTexture = editContext.brushTexture; commonUI.OnPaint(terrain, editContext); if (!commonUI.allowPaint) { return(true); } using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "ContrastTool", brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext paintContext = brushRender.AcquireHeightmap(true, brushXform.GetBrushXYBounds(), 1); Material mat = GetPaintMaterial(); Vector3 brushPos = new Vector3(commonUI.raycastHitUnderCursor.point.x, 0, commonUI.raycastHitUnderCursor.point.z); FilterContext fc = new FilterContext(terrain, brushPos, commonUI.brushSize, commonUI.brushRotation); fc.renderTextureCollection.GatherRenderTextures(paintContext.sourceRenderTexture.width, paintContext.sourceRenderTexture.height); RenderTexture filterMaskRT = commonUI.GetBrushMask(fc, paintContext.sourceRenderTexture); mat.SetTexture("_FilterTex", filterMaskRT); paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; ApplyBrushInternal(brushRender, paintContext, commonUI.brushStrength, editContext.brushTexture, brushXform); } } return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { if (!m_isPainting || m_SampleLocation.terrain == null) { return(true); } // grab brush transforms for the sample location (where we are cloning from) // and target location (where we are cloning to) Vector2 sampleUV = TerrainUVFromBrushLocation(m_SampleLocation.terrain, m_SampleLocation.pos); BrushTransform sampleBrushXform = TerrainPaintUtility.CalculateBrushTransform(m_SampleLocation.terrain, sampleUV, editContext.brushSize, 1); BrushTransform targetBrushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, 1); // set material props that will be used for both heightmap and alphamap painting Material mat = GetPaintMaterial(); Vector4 brushParams = new Vector4(editContext.brushStrength, m_StampingOffsetFromClone * 0.5f, terrain.terrainData.size.y, 0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); // apply texture modifications to terrain if (m_PaintAlphamap) { PaintAlphamap(m_SampleLocation.terrain, terrain, sampleBrushXform, targetBrushXform, mat); } if (m_PaintHeightmap) { PaintHeightmap(m_SampleLocation.terrain, terrain, sampleBrushXform, targetBrushXform, editContext, mat); } return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { BrushTransform targetBrushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, 1); Material mat = GetPaintMaterial(); Vector4 brushParams = new Vector4(editContext.brushStrength, 0, 0, 0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); Rect targetRect = targetBrushXform.GetBrushXYBounds(); int numSampleTerrainLayers = terrain.terrainData.terrainLayers.Length; for (int i = 0; i < numSampleTerrainLayers; ++i) { TerrainLayer layer = terrain.terrainData.terrainLayers[i]; if (layer == null) { continue; } int layerIndex = TerrainPaintUtility.FindTerrainLayerIndex(terrain, layer); Texture2D layerTexture = TerrainPaintUtility.GetTerrainAlphaMapChecked(terrain, layerIndex >> 2); PaintContext targetContext = PaintContext.CreateFromBounds(terrain, targetRect, layerTexture.width, layerTexture.height); targetContext.CreateRenderTargets(RenderTextureFormat.R8); targetContext.GatherAlphamap(layer, true); Graphics.Blit(targetContext.sourceRenderTexture, targetContext.destinationRenderTexture, mat, 0); TerrainPaintUtility.EndPaintTexture(targetContext, "Terrain Paint - Smooth Splatmaps"); } return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, 0.0f); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds(), 1); float finalPinchAmount = m_PinchAmount * 0.005f; //scale to a reasonable value and negate so default mode is clockwise if (Event.current.shift) { finalPinchAmount *= -1.0f; } paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; Material mat = GetPaintMaterial(); Vector4 brushParams = new Vector4(editContext.brushStrength, 0.0f, finalPinchAmount, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, 0); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Pinch Height"); return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { commonUI.OnPaint(terrain, editContext); if (!commonUI.allowPaint) { return(true); } using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "SharpenPeak", editContext.brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext paintContext = brushRender.AcquireHeightmap(true, brushXform.GetBrushXYBounds(), 1); Material mat = GetPaintMaterial(); // apply brush Vector4 brushParams = new Vector4( commonUI.brushStrength, m_ErosionStrength, m_MixStrength, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); brushRender.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); brushRender.RenderBrush(paintContext, mat, 0); } } return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { Vector2 uv = editContext.uv; if (Event.current.shift) { height = terrain.terrainData.GetInterpolatedHeight(uv.x, uv.y) / terrain.terrainData.size.y; return(true); } BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, 0.0f); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds(), 1); paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; Material mat = GetPaintMaterial(); int currentMode = (int)mode; if (Event.current.control) { currentMode *= -1; } float modeValue = Mathf.Clamp01(currentMode); Vector4 brushParams = new Vector4(editContext.brushStrength, 0.5f * height, modeValue, 0); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, 0); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Directional Flatten Height"); return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { commonUI.OnPaint(terrain, editContext); if (!commonUI.allowPaint) { return(true); } using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "HydroErosion", editContext.brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext paintContext = brushRender.AcquireHeightmap(true, brushXform.GetBrushXYBounds(), 1); paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; m_Eroder.inputTextures["Height"] = paintContext.sourceRenderTexture; Vector2 texelSize = new Vector2(terrain.terrainData.size.x / terrain.terrainData.heightmapResolution, terrain.terrainData.size.z / terrain.terrainData.heightmapResolution); m_Eroder.ErodeHeightmap(terrain.terrainData.size, brushXform.GetBrushXYBounds(), texelSize, Event.current.control); Material mat = GetPaintMaterial(); Vector4 brushParams = new Vector4(commonUI.brushStrength, 0.0f, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetTexture("_NewHeightTex", m_Eroder.outputTextures["Height"]); mat.SetVector("_BrushParams", brushParams); brushRender.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); brushRender.RenderBrush(paintContext, mat, 0); } } return(true); }
public virtual void OnPaint(Terrain terrain, IOnPaint editContext) { filterContext.ReleaseRTHandles(); // Manage brush capture history for playback in tests if (isRecording) { OnPaintOccurrence.history.Add(new OnPaintOccurrence(editContext.brushTexture, brushSize, brushStrength, brushRotation, editContext.uv.x, editContext.uv.y)); } m_Controllers.ForEach((controller) => controller.OnPaint(terrain, editContext)); if (isSmoothing) { Vector2 uv = editContext.uv; m_BrushSmoothController.kernelSize = (int)Mathf.Max(1, 0.1f * m_BrushSizeController.brushSize); m_BrushSmoothController.OnPaint(terrain, editContext, brushSize, brushRotation, brushStrength, uv); } /// Ensure that we re-randomize where the next scatter operation will place the brush, /// that way we can render the preview in a representative manner. m_BrushScatterController?.RequestRandomisation(); TerrainToolsAnalytics.UpdateAnalytics(this, m_analyticsCallback); filterContext.ReleaseRTHandles(); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { if (splatPaintRules == null) { return(false); } Material mat = GetPaintMaterial(); mat.SetTexture("_BrushTex", editContext.brushTexture); // gathering heightmap BrushTransform brushXformForGatheringHeightmap = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, 0.0f); PaintContext paintContextForGatheringHeightmap = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXformForGatheringHeightmap.GetBrushXYBounds(), 1); if (paintContextForGatheringHeightmap == null) { return(false); } RenderTexture gatheredHeightmap = RenderTexture.GetTemporary(terrain.terrainData.heightmapTexture.descriptor); Graphics.Blit(paintContextForGatheringHeightmap.sourceRenderTexture, gatheredHeightmap); //, TerrainPaintUtility.GetBlitMaterial(), 0); TerrainPaintUtility.ReleaseContextResources(paintContextForGatheringHeightmap); // painting alphamap BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, 0.0f); PaintContext paintContext = TerrainPaintUtility.BeginPaintTexture(terrain, brushXform.GetBrushXYBounds(), m_SelectedTerrainLayer); if (paintContext == null) { return(false); } float targetAlpha = 1.0f; // always 1.0 now -- no subtractive painting (we assume this in the ScatterAlphaMap) Vector4 brushParams = new Vector4(editContext.brushStrength, targetAlpha, splatPaintRules.useHeightTransition ? 1f : 0f, splatPaintRules.useAngleTransition ? 1f : 0f); Vector4 paintRulesParametersHeight = new Vector4(splatPaintRules.minHeightStart, splatPaintRules.minHeightEnd, splatPaintRules.maxHeightStart, splatPaintRules.maxHeightEnd); Vector4 paintRulesParametersAngle = new Vector4(splatPaintRules.minAngleStart, splatPaintRules.minAngleEnd, splatPaintRules.maxAngleStart, splatPaintRules.maxAngleEnd); Vector4 paintRulesInversionAndUsage = new Vector4(splatPaintRules.inverseHeightRule ? 1f : 0f, splatPaintRules.inverseAngleRule ? 1f : 0f, splatPaintRules.applyHeightRule ? 1f : 0f, splatPaintRules.applyAngleRule ? 1f : 0f); mat.SetVector("_BrushParams", brushParams); mat.SetVector("_TerrainSize", (Vector4)terrain.terrainData.size); mat.SetVector("_PaintRulesParametersHeight", paintRulesParametersHeight); mat.SetVector("_PaintRulesParametersAngle", paintRulesParametersAngle); mat.SetVector("_PaintRulesInversionAndUsage", paintRulesInversionAndUsage); mat.SetTexture("_Heightmap", gatheredHeightmap); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, 0); TerrainPaintUtility.EndPaintTexture(paintContext, "Terrain Paint - Texture"); RenderTexture.ReleaseTemporary(gatheredHeightmap); return(true); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { if (Event.current.type == EventType.MouseDown) { m_PrevBrushPos = editContext.uv; return(false); } if (Event.current.type == EventType.MouseDrag && m_PreviousEvent == EventType.MouseDrag) { Rect brushRect = TerrainPaintUtility.CalculateBrushRectInTerrainUnits(terrain, editContext.uv, editContext.brushSize); TerrainPaintUtility.PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushRect); Vector2 smudgeDir = editContext.uv - m_PrevBrushPos; Material mat = GetPaintMaterial(); Vector4 brushParams = new Vector4(editContext.brushStrength, smudgeDir.x, smudgeDir.y, 0); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, 0); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Smudge Height"); m_PrevBrushPos = editContext.uv; } m_PreviousEvent = Event.current.type; return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { Init(); commonUI.OnPaint(terrain, editContext); if (commonUI.allowPaint) { Vector2 uv = editContext.uv; if (commonUI.ScatterBrushStamp(ref terrain, ref uv)) { BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, uv, commonUI.brushSize, commonUI.brushRotation); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds()); float brushStrength = Event.current.control ? -commonUI.brushStrength : commonUI.brushStrength; Vector3 brushPosWS = WSPosFromTerrainUV(terrain, uv); ApplyBrushInternal(paintContext, brushXform, brushPosWS, commonUI.brushRotation, brushStrength, commonUI.brushSize, editContext.brushTexture); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Noise"); } } editContext.Repaint(RepaintFlags.UI); return(true); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { Texture brushTexture = editContext.brushTexture; commonUI.OnPaint(terrain, editContext); if (!commonUI.allowPaint) { return(true); } using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "ContrastTool", brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext paintContext = brushRender.AcquireHeightmap(true, brushXform.GetBrushXYBounds(), 1); Material mat = GetPaintMaterial(); var brushMask = RTUtils.GetTempHandle(paintContext.sourceRenderTexture.width, paintContext.sourceRenderTexture.height, 0, FilterUtility.defaultFormat); Utility.SetFilterRT(commonUI, paintContext.sourceRenderTexture, brushMask, mat); paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; ApplyBrushInternal(brushRender, paintContext, commonUI.brushStrength, editContext.brushTexture, brushXform); RTUtils.Release(brushMask); } } return(false); }
private void PaintSplatMap(Terrain terrain, IOnPaint editContext, RenderTexture sedimentRT) { using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "ThermalErosion", editContext.brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext paintContext = brushRender.AcquireTexture(true, brushXform.GetBrushXYBounds(), m_SelectedTerrainLayer); if (paintContext == null) { return; } Material mat = GetSplatMaterial(); // apply brush float splatStrength = Mathf.Lerp(-1000.0f, 1000.0f, 0.005f * (float)(m_MaterialPaintStrength + 100)); Vector4 brushParams = new Vector4(commonUI.brushStrength, splatStrength, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetTexture("_MaskTex", sedimentRT); mat.SetVector("_BrushParams", brushParams); brushRender.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); brushRender.RenderBrush(paintContext, mat, 0); } } }
private void AddHeight(Terrain terrain, IOnPaint editContext) { using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "ThermalErosion", editContext.brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext paintContext = brushRender.AcquireHeightmap(true, brushXform.GetBrushXYBounds(), 1); paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; Material mat = TerrainPaintUtility.GetBuiltinPaintMaterial(); float brushStrength = Event.current.shift ? -m_Eroder.m_AddHeightAmt : m_Eroder.m_AddHeightAmt; brushStrength *= (commonUI.brushStrength); if (Event.current.control) { brushStrength = 0.0f; } Vector4 brushParams = new Vector4(0.0001f * brushStrength, 0.0f, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); brushRender.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); brushRender.RenderBrush(paintContext, mat, (int)TerrainBuiltinPaintMaterialPasses.RaiseLowerHeight); } } }
private bool Height(Terrain terrain, IOnPaint editContext, Vector2 currUV, Vector2 prevUV) { // the brush size is relative to the main brush size float brushSize = editContext.brushSize * heightBrushSize / 100f; BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, currUV, brushSize, 0.0f); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds(), 1); paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; Material mat = TerrainPaintUtility.GetBuiltinPaintMaterial(); float brushStrength = heightBrushStrength / 100f; brushStrength = Event.current.shift ? -brushStrength : brushStrength; brushStrength *= 0.001f; // magic number ... Vector4 brushParams = new Vector4(brushStrength, 0.0f, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, 0); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Raise or Lower Height"); return(true); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { commonUI.OnPaint(terrain, editContext); Vector2 uv = editContext.uv; if (Event.current.shift) { return(true); } //grab the starting position & height if (Event.current.control) { TerrainData terrainData = terrain.terrainData; float height = terrainData.GetInterpolatedHeight(uv.x, uv.y) / terrainData.size.y; m_StartPoint = new Vector3(uv.x, uv.y, height); m_StartTerrain = terrain; return(true); } else if (!m_StartTerrain || (Event.current.type == EventType.MouseDrag)) { return(true); } else { ApplyBrushInternal(terrain, uv, editContext.brushTexture, commonUI.brushSpacing); return(false); } }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { commonUI.OnPaint(terrain, editContext); if (commonUI.allowPaint) { using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "SlopeFlatten", editContext.brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext paintContext = brushRender.AcquireHeightmap(true, brushXform.GetBrushXYBounds(), 1); Material mat = GetPaintMaterial(); var brushMask = RTUtils.GetTempHandle(paintContext.sourceRenderTexture.width, paintContext.sourceRenderTexture.height, 0, FilterUtility.defaultFormat); Utility.SetFilterRT(commonUI, paintContext.sourceRenderTexture, brushMask, mat); paintContext.sourceRenderTexture.filterMode = FilterMode.Bilinear; Vector4 brushParams = new Vector4(commonUI.brushStrength, 0.0f, commonUI.brushSize, 0); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); brushRender.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); brushRender.RenderBrush(paintContext, mat, 0); RTUtils.Release(brushMask); } } } return(false); }
private void RemoveTrees(Terrain terrain, IOnPaint editContext, bool clearSelectedOnly) { PaintTreesDetailsContext ctx = PaintTreesDetailsContext.Create(terrain, editContext.uv); for (int i = 0; i < ctx.terrains.Length; ++i) { Terrain ctxTerrain = ctx.terrains[i]; if (ctxTerrain != null) { Vector2 ctxUV = ctx.uvs[i]; float radius = 0.5f * brushSize / ctxTerrain.terrainData.size.x; int treePrototype = kInvalidTree; if (clearSelectedOnly && selectedTree != kInvalidTree) { treePrototype = PaintTreesUtils.FindTreePrototype(ctxTerrain, m_TargetTerrain, selectedTree); } if (!clearSelectedOnly || treePrototype != kInvalidTree) { TerrainPaintUtilityEditor.UpdateTerrainDataUndo(ctxTerrain.terrainData, "Terrain - Remove Trees"); ctxTerrain.RemoveTrees(ctxUV, radius, treePrototype); } } } }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { Init(); if (activeMesh == null || Event.current.type != EventType.MouseDown || Event.current.shift == true || m_editTransform) { return(false); } brushUI.OnPaint(terrain, editContext); if (brushUI.allowPaint) { Texture brushTexture = editContext.brushTexture; BrushTransform brushTransform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, brushUI.brushSize, brushUI.brushRotation); PaintContext ctx = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushTransform.GetBrushXYBounds()); ApplyBrushInternal(terrain, ctx, brushTransform); TerrainPaintUtility.EndPaintHeightmap(ctx, "Mesh Stamp - Stamp Mesh"); } return(true); }
public bool OnPaint(Terrain terrain, IOnPaint editContext, float brushSize, float brushRotation, float brushStrength, Vector2 uv) { if (Event.current != null && Event.current.shift) { BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, uv, brushSize, brushRotation); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds()); Material mat = GetMaterial(); //TerrainPaintUtility.GetBuiltinPaintMaterial(); float m_direction = 0.0f; //TODO: UI for this Vector4 brushParams = new Vector4(brushStrength, 0.0f, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); Vector4 smoothWeights = new Vector4( Mathf.Clamp01(1.0f - Mathf.Abs(m_direction)), // centered Mathf.Clamp01(-m_direction), // min Mathf.Clamp01(m_direction), // max kernelSize); // blur kernel size mat.SetVector("_SmoothWeights", smoothWeights); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); RenderTexture temp = RenderTexture.GetTemporary(paintContext.destinationRenderTexture.descriptor); Graphics.Blit(paintContext.sourceRenderTexture, temp, mat, 0); Graphics.Blit(temp, paintContext.destinationRenderTexture, mat, 1); RenderTexture.ReleaseTemporary(temp); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Smooth Height"); return(true); } return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { commonUI.OnPaint(terrain, editContext); if (commonUI.allowPaint) { if (Event.current.control) { Terrain currentTerrain = commonUI.terrainUnderCursor; m_TargetHeight = currentTerrain.terrainData.GetInterpolatedHeight(editContext.uv.x, editContext.uv.y) + currentTerrain.GetPosition().y; editContext.Repaint(); SaveSetting(); return(true); } else { Texture brushTexture = editContext.brushTexture; using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "SetHeightTool", brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushTransform)) { Rect brushBounds = brushTransform.GetBrushXYBounds(); PaintContext paintContext = brushRender.AcquireHeightmap(true, brushBounds); ApplyBrushInternal(paintContext, brushRender, commonUI.brushStrength, brushTexture, brushTransform, terrain); } } } } return(true); }
private bool PaintTexture(Terrain terrain, IOnPaint editContext, Vector2 currUV) { // the brush size is relative to the main brush size float brushSize = editContext.brushSize * paintBrushSize / 100f; BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, currUV, brushSize, 0.0f); PaintContext paintContext = TerrainPaintUtility.BeginPaintTexture(terrain, brushXform.GetBrushXYBounds(), m_SelectedInnerTerrainLayer); if (paintContext == null) { return(false); } Material mat = TerrainPaintUtility.GetBuiltinPaintMaterial(); float targetAlpha = 1.0f; // always 1.0 now -- no subtractive painting (we assume this in the ScatterAlphaMap) float brushStrength = paintBrushStrength / 100f; // editContext.brushStrength // apply brush Vector4 brushParams = new Vector4(brushStrength, targetAlpha, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, (int)TerrainPaintUtility.BuiltinPaintMaterialPasses.PaintTexture); TerrainPaintUtility.EndPaintTexture(paintContext, "Terrain Paint - Texture"); return(true); }
private bool Smooth(Terrain terrain, IOnPaint editContext, Vector2 currUV, BrushSettings brushSettings) { // the brush size is relative to the main brush size float brushSize = brushSettings.brushSize * this.smoothBrushSize / 100f; BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, brushSize, brushSettings.brushRotationDegrees); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds()); Material mat = TerrainPaintUtility.GetBuiltinPaintMaterial(); float brushStrength = smoothBrushStrength / 100f; // editContext.brushStrength; // brushStrength = Event.current.shift ? -brushStrength : brushStrength; Vector4 brushParams = new Vector4(brushStrength, 0.0f, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, (int)TerrainPaintUtility.BuiltinPaintMaterialPasses.SmoothHeights); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Smooth Height"); return(true); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, 0.0f); PaintContext paintContext = TerrainPaintUtility.BeginPaintTexture(terrain, brushXform.GetBrushXYBounds(), m_SelectedTerrainLayer); if (paintContext == null) { return(false); } Material mat = TerrainPaintUtility.GetBuiltinPaintMaterial(); // apply brush float targetAlpha = 1.0f; // always 1.0 now -- no subtractive painting (we assume this in the ScatterAlphaMap) Vector4 brushParams = new Vector4(editContext.brushStrength, targetAlpha, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, (int)TerrainPaintUtility.BuiltinPaintMaterialPasses.PaintTexture); TerrainPaintUtility.EndPaintTexture(paintContext, "Terrain Paint - Texture"); return(true); }
private bool Bridge(Terrain terrain, IOnPaint editContext, Vector2 currUV, float pct, Vector3 stroke, Vector3 startPoint) { float heightOffset = heightProfile.Evaluate(pct) / terrain.terrainData.size.y; float strengthScale = strengthProfile.Evaluate(pct); float widthScale = widthProfile.Evaluate(pct); float finalHeight = (startPoint + pct * stroke).z + heightOffset; int finalBrushSize = (int)(widthScale * (float)editContext.brushSize); BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, currUV, finalBrushSize, 0.0f); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds()); Material mat = GetMaterial(); Vector4 brushParams = new Vector4(); mat.SetTexture("_BrushTex", editContext.brushTexture); brushParams.x = editContext.brushStrength * strengthScale; brushParams.y = 0.5f * finalHeight; mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, 0); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - Bridge"); return(true); }