You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity URP通过脚本设置Decal Base Map无效果的问题

问题:动态生成笔刷纹理无法更新Decal材质

问题场景

我编写了生成笔刷纹理的脚本,但运行后无法让Decal材质的纹理达到预期更新效果。

生成纹理的脚本代码

private void GenerateBrushTexture()
{
    int textureSize = Mathf.CeilToInt(radius * 2);
    brushTexture = new Texture2D(textureSize, textureSize);

    for (int x = 0; x < textureSize; x++)
    {
        for (int y = 0; y < textureSize; y++)
        {
            // Calculate the distance from the center of the texture
            float distance = Vector2.Distance(new Vector2(x, y), new Vector2(textureSize / 2, textureSize / 2));

            // Normalize the distance
            float normalizedDistance = Mathf.Clamp01(distance / radius);

            // Calculate the falloff using a power function to smooth the edges
            float falloffValue = Mathf.Pow(1 - normalizedDistance, falloff);

            // Set the pixel color based on the falloff value
            brushTexture.SetPixel(x, y, new Color(falloffValue, falloffValue, falloffValue, falloffValue));
        }
    }
    Debug.Log("set texture !");
//UPDATE : I forgot          brushTexture.Apply();
//So there it is :
    brushTexture.Apply();
    brushMaterial.SetTexture("_BaseMap", brushTexture);
}

已尝试的无效操作

  • 替换纹理引用名称,尝试brushMaterial.SetTexture("Base Map", brushTexture)和brushMaterial.SetTexture("_Base Map", brushTexture),均无效果
  • 查看Shader Graph编辑器节点设置,未找到有效线索
  • 在Shader编辑器中确认Base Map的显示名称为Base Map、引用名为Base_Map,使用该名称尝试后仍无效果

内容的提问来源于stack exchange,提问作者Dandjix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 11:57:08