Unity烘焙材质到单一贴图的脚本

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Unity烘焙材质到单一贴图的脚本

这个脚本由 CocoaChina 版主“四角钱” 分享,可以将复杂的材质(比如有法线贴图的材质)进行"烘焙",转变为单一的贴图。可用来将Unity 的游戏移植到移动平台时候使用。请将脚本放 Editor 文件夹里,使用时选择一个 Material 材质,然后在菜单种"Custom/Bake Material"打开并调整照明和其他参数,点击Bake按钮就会生成一个单一的贴图。

class BakeMaterialSettings

{

private static var kEditorPrefsName = "BakeMaterialSettings";

static var kBakingLayerShouldBeUnusedInScene = 30;

static var kStandardTexNames = new Array ("_MainTex", "_BumpMap", "_Detail", "_ParallaxMap", "_Parallax");

var bakeAlpha = false;

var bakeMainTexAsWhite = false;

var minTextureResolution = 8;

var maxTextureResolution = 2048;

var emptyScene = false;

var useCustomLights = false;

var ambient = Color.black;

static var kLights = 3;

var enableLight = new boolean[kLights];

var colorLight = new Color[kLights];

var dirLight = new Vector2[kLights];

function BakeMaterialSettings ()

{

Load ();

}

function Load ()

{

bakeAlpha = EditorPrefs.GetBool(kEditorPrefsName + ".bakeAlpha");

bakeMainTexAsWhite = EditorPrefs.GetBool(kEditorPrefsName + ".bakeMainTexAsWhite");

minTextureResolution = EditorPrefs.GetInt(kEditorPrefsName + ".minTextureResolution", 8);

maxTextureResolution = EditorPrefs.GetInt(kEditorPrefsName + ".maxTextureResolution", 2048);

emptyScene = EditorPrefs.GetBool(kEditorPrefsName + ".emptyScene");

useCustomLights = EditorPrefs.GetBool(kEditorPrefsName + ".useCustomLights");

ambient.r = EditorPrefs.GetFloat(kEditorPrefsName + ".ambient.r");

ambient.g = EditorPrefs.GetFloat(kEditorPrefsName + ".ambient.g");

ambient.b = EditorPrefs.GetFloat(kEditorPrefsName + ".ambient.b");

ambient.a = EditorPrefs.GetFloat(kEditorPrefsName + ".ambient.a", 1.0f);

for (var q = 0; q < kLights; ++q)

{

enableLight[q] = EditorPrefs.GetBool(kEditorPrefsName + ".enableLight" + q);

colorLight[q].r = EditorPrefs.GetFloat(kEditorPrefsName + ".color.r" + q, 0.5f);

colorLight[q].g = EditorPrefs.GetFloat(kEditorPrefsName + ".color.g" + q, 0.5f);

colorLight[q].b = EditorPrefs.GetFloat(kEditorPrefsName + ".color.b" + q, 0.5f);

colorLight[q].a = EditorPrefs.GetFloat(kEditorPrefsName + ".color.a" + q, 1.0f);

dirLight[q].x = EditorPrefs.GetFloat(kEditorPrefsName + ".dir.x" + q);

dirLight[q].y = EditorPrefs.GetFloat(kEditorPrefsName + ".dir.y" + q);

}

}

function Save ()

{

EditorPrefs.SetBool(kEditorPrefsName + ".bakeAlpha", bakeAlpha); EditorPrefs.SetBool(kEditorPrefsName + ".bakeMainTexAsWhite", bakeMainTexAsWhite);

EditorPrefs.SetInt(kEditorPrefsName + ".minTextureResolution", minTextureResolution);

EditorPrefs.SetInt(kEditorPrefsName + ".maxTextureResolution", maxTextureResolution);

EditorPrefs.GetBool(kEditorPrefsName + ".emptyScene",

相关文档
最新文档