技術筆記(7)Unity導入人物和場景資源,出現(xiàn)的材質(zhì)顯示問題
一,如果兩個人物擁有同名但內(nèi)容不同的的材質(zhì)shader
-
error:
Unity在導入的時候,識別到近似內(nèi)容時,會用新的內(nèi)容去替換同名shader的內(nèi)容,而不是重新創(chuàng)建一個。這樣就會導致第一個人物的材質(zhì)顯示異常,其本質(zhì)是shader內(nèi)容被替換了。
-
解決方案:
嘗試了多次各種導入資源的方式,最終選擇了一個妥協(xié)折中的方法。
在導入完第一個人物之后,就將所有沖突重名的shader重命名,且shader內(nèi)部也需要重命名。前者是為了導入資源時,Unity能做出區(qū)分;后者是為了避免人物材質(zhì)引用shader時出現(xiàn)錯誤。
?文章來源地址http://www.zghlxwxcb.cn/news/detail-838746.html
二,shader引用的.cginc文件找不到或無法打開
-
error:
報錯信息如下:
Couldn't open include file 'CharaMain.cginc'
?即shader中引用到的include文件無法打開
出現(xiàn)的契機是我修改了shader名,并轉移到其他文件夾中。有時這樣不會出錯,甚至有時是在我再次導入其他資源時,這個報錯才出現(xiàn)。
-
解決方案:
主要原因是include 文件的時候,使用的相對路徑,所以引用到的那個文件必須與shader放在同一個目錄之下才能找到。
將所有引用到的文件復制一份,放到shader同一個目錄之后,人物材質(zhì)shader的顯示恢復了正常。
解決幫助來源:
Make sure your shader file if it includes other files has the right folder structure. I ran into this also after I moved my files around into different folders. It is basically breaking the connection between the custom files.
IE: In my shader file I include a resource file. I used to just have it here in the root like this.
#include "/CustomShaderFile.cginc"
So when I moved my custom shader into a new folder I had to change the structure so it looked in the right folder.
#include "../ShadersFolder/CustomShaderFile.cginc"
Hope this helps.文章來源:http://www.zghlxwxcb.cn/news/detail-838746.html
?
到了這里,關于技術筆記(7)Unity導入人物和場景資源,出現(xiàn)的材質(zhì)顯示問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!