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, "Twist", brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { float finalTwistAmount = m_TwistAmount * -0.001f; //scale to a reasonable value and negate so default mode is clockwise if (Event.current.shift) { finalTwistAmount *= -1.0f; } Material mat = GetPaintMaterial(); Vector4 brushParams = new Vector4(commonUI.brushStrength, 0.0f, finalTwistAmount, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); //twist splat map if (m_AffectMaterials) { for (int i = 0; i < terrain.terrainData.terrainLayers.Length; i++) { TerrainLayer layer = terrain.terrainData.terrainLayers[i]; PaintContext paintContext = brushRender.AcquireTexture(true, brushXform.GetBrushXYBounds(), layer); 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; brushRender.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); brushRender.RenderBrush(paintContext, mat, 0); brushRender.Release(paintContext); RTUtils.Release(brushMask); } } //twist height map if (m_AffectHeight) { PaintContext paintContext = brushRender.AcquireHeightmap(true, brushXform.GetBrushXYBounds(), 1); 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, finalTwistAmount, brushTexture, brushXform); brushRender.Release(paintContext); RTUtils.Release(brushMask); } } } } return(false); }
public override bool OnPaint(Terrain terrain, IOnPaint editContext) { #if UNITY_2019_1_OR_NEWER if (m_EyedropperSelected && m_LayerList != null) { Texture2D[] splatmaps = terrain.terrainData.alphamapTextures; int splatOffset = 0; foreach (Texture2D splatmap in splatmaps) { Color pixel = splatmap.GetPixelBilinear(editContext.uv.x, editContext.uv.y); if (pixel.r > .5f) { SelectEyedroppedLayer(terrain, splatOffset); break; } else if (pixel.g > .5f) { SelectEyedroppedLayer(terrain, 1 + splatOffset); break; } else if (pixel.b > .5f) { SelectEyedroppedLayer(terrain, 2 + splatOffset); break; } else if (pixel.a > .5f) { SelectEyedroppedLayer(terrain, 3 + splatOffset); break; } splatOffset += 4; } return(true); } #endif commonUI.OnPaint(terrain, editContext); if (commonUI.allowPaint) { Texture brushTexture = editContext.brushTexture; using (IBrushRenderUnderCursor brushRender = new BrushRenderUIGroupUnderCursor(commonUI, "PaintTextureTool", brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushTransform)) { Rect brushRect = brushTransform.GetBrushXYBounds(); PaintContext paintContext = brushRender.AcquireTexture(true, brushRect, m_SelectedTerrainLayer); if (paintContext != null) { PaintContext heightContext = brushRender.AcquireHeightmap(false, brushRect); // Evaluate the brush mask filter stack Material mat = GetPaintMaterial(); var brushMask = RTUtils.GetTempHandle(heightContext.sourceRenderTexture.width, heightContext.sourceRenderTexture.height, 0, FilterUtility.defaultFormat); Utility.SetFilterRT(commonUI, heightContext.sourceRenderTexture, brushMask, mat); // apply brush float targetAlpha = m_TargetStrength; float s = commonUI.InvertStrength ? -commonUI.brushStrength : commonUI.brushStrength; Vector4 brushParams = new Vector4(s, targetAlpha, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); brushRender.SetupTerrainToolMaterialProperties(paintContext, brushTransform, mat); brushRender.RenderBrush(paintContext, mat, 0); RTUtils.Release(brushMask); } } } } return(true); }