顯示具有 Technical 標籤的文章。 顯示所有文章
顯示具有 Technical 標籤的文章。 顯示所有文章

2013年10月7日 星期一

[Unity] Particle System使用Mesh時,在畫面外不會Render的解決方式

  近日在幫忙解決一個Particle System(Shuriken)的particle消失的問題,遇到的情況是當Particle System的Render Mode使用Mesh,且Particle System的pivot是在畫面外時,mesh不會被render。這是Particle System本身的一個bug,理應要有個Always Render之類的選項來避免off-screen的時候被cull掉。(舊版的particle系統中則是沒有這個問題)

  在經過測試之後,得出兩種解決方式:
  1. Simulation Space - World
    在Particle System的基本設定中,把Simulation Space設定為World。而必須使用Local Space的particle就可使用第二種方式。
  2. Sub Emitters
    啟用Sub Emitters Module,在Birth新增一個sub emitter,這個sub emitter可以是deactive的。



2013年9月6日 星期五

[Unity][Mecanim] 角色處理注意事項


以下為作業上的一些紀錄。

角色輸出與輸入


  • 3ds Max的單位設置為 1 Unit = 1 Centimeters
    • 如此在不改變Asset的Scale Factor狀況下(在Asset的Import Settings中,預設為0.01),Max中的一公尺會與Unity的一公尺相等,這是最符合物理的單位設定,可避免物理運算出現奇怪的現象。
  • 讓角色在DCC Tool中面向Front View(從Front View看到的是角色的正面),如此匯入Unity後,角色的正面會與GameObject的Forward方向一致。
  • 輸出骨架模型FBX檔案時,雖然不會勾選Animation項目,但是其子項目Skins必須要是被勾選著的,否則不會帶出Skin資料(3dsMax 9)。
  • 非Biped-based角色(只由Bone/Dummy...組成的Rig)在輸出動作檔案時,需保留一個Skinned mesh一同輸出,否則會發生輸出的FBX檔沒有Root Node的狀況。
  • 骨架請勿帶有negative scale,因為目前的mechanim並不支援negative scale的blending。
  • 當你的角色的root node不是skeleton而是dummy之類的物件時,在Unity的FBX Import Settings需將Animation設置為Store in Nodes,原因尚未探究(參考
  • 物件的命名不要跟輸出的FBX檔名相同(不是Child的物件),否則會出現flagsCount >= mask.m_Count錯誤訊息,而Rig的Root Node若取名與檔名相同則會出現Look rotation viewing vector is zero錯誤訊息(參考)。
  • Twist bone的父物件必須為該部位的主要骨頭
Mechanim系統
  • 在進行FBX Import Setting的設定時,在Animation的部份要注意Root Transform的設定,勾選的項目將不會對角色產生實際的位移旋轉效果(成為假動作的狀態)。
  • 當角色的動作本身有做位移時,如果動作與動作間的Blending設定吃掉了部份的時間區段,將會喪失那個時間區段內的位移距離,可能會導致位移效果有誤差的狀況。

相關文章

[Unity] 效能上需要注意的事項


在此整理一些有關效能上需要注意的問題,主要資訊來源是Unity的Manual,其中可能有許多地方理解錯誤,請多包涵與指正。
  • Mesh

    • Mesh的渲染是由Renderer Component擔當,一個Renderer會消耗一次運算,當一個角色被拆分成N個Meshes,也就會有N次的運算,因此要儘可能的減少Mesh的數量。
    • GameObject上被Deactive的Renderer Component,依舊會佔用記憶體,只是不會被呈像出來。
    • Mesh的Hard Edge上的點,因為Vert的Normal不一致,所以會被視為多個Verts,而UV Border Edge上的Vert也是一樣,在渲染流程上會被視為多個點。在Unity中所顯示的Verts、Tris就是這個真實的數量(送給OpenGLES的點的數量),所以才會有與DCC Tool中所顯示的數據不同的現象。
參考資料


  • Compression Assets
    • Unity在匯入資源時,會自動進行壓縮,而你可以在Preference中取消這項設定讓編輯時可以省下壓縮的等待時間,但在建立遊戲時是一定會進行壓縮的,不受該項設定影響。
  • Mesh Import Settings
    • Mesh Compression可以減少檔案所佔容量,但不能減少運算時的記憶體消耗。
    • Mesh Optimization會優化點的順序增進GPU運算效能。
  • Textures
    • Normals、Tangents:
      若物件沒有使用到Normal map及Real-time Lighting的話,可以取消Normals。而物件沒有使用到Normal map的話,可以取消Tangents。
    • Anisotropic Filtering:
      是針對當Mesh的面與視角的夾角相當小時會獲得較好的貼圖品質(通常用於地板),但也會增加GPU的運算消耗,在Quality Settings中可以針對所有的貼圖進行設定。
    • 在Unity中貼圖必須為二的冪次方,非二的冪次方貼圖通常只用於GUI。
    • Unity沒有限制貼圖必須為正方形,然而在iOS平台有這項要求,因此製作貼圖時須遵守正方貼圖原則。
參考資料




  • Materials:
    • 在一個GameObject、Renderer上使用的Material是越少越好,最好只使用一個,每個Material都會增加一個Draw call。
  • Skinned Mesh:
    • Unity使用1、2、4根骨頭來計算控制一個頂點,因此在DCC Tool中進行綁定時,一個頂點的權重最多包含4根骨頭即可,在遊戲中實際使用幾根骨頭做運算是依據Quality Settings中的設定。
參考資料




  • Bones:
    • PC遊戲通常的骨頭數量是介議於15~60根間,而行動平台建低於30根。(Blade&Soul的玩家角色使用約130根左右,其中包含臉部、附加骨頭)若人物有使用IK,在匯入Unity後因已經過Bake程序,應把IK清除掉必免占用運算。
  • Animation Compression:
    • Keyframe Reduction
      在匯入時減少Keyframs數量,能夠減少檔案尺寸及記憶體消耗,而Compression只能減少檔案尺寸
  • Combine Children:
    • Combine Children這個Script可以進行combine meshes的動作,而要combine的物件得使用同一張圖,這個處理可以有效降低draw calls(將多個使用同一張貼圖同一個材質的Meshes合併為一個Mesh)。

//

Manual中有優化圖像效能的指引

CPU: optimizing Draw call count
GPU: optimizing Model geometry

http://docs.unity3d.com/Documentation/Manual/OptimizingGraphicsPerformance.html

[Unity] Scroll and Turbulence Shader (流動加擾動效果)

這是我的第二個Fragment Shader,在此作紀錄供參考。
參考文章


此Shader的表現效果:


Inputs
MainTex為一張transparent texture,OffsetTex則是一張noise texture,Shader會以OffsetTex擾動MainTex,擾動的程度由Distortion控制,速度則由TurbulenceSpd控制。另外MainTex本身也會做流動,流動速度由ScrollSpd控制。
Inputs
Fragment Shader (without normals)

 Properties 
 {
  _MainTex("_MainTex", 2D) = "black" {}
  _OffsetTex("_Offset", 2D) = "black" {}
  _Distortion("_Distortion", Float ) = 0.1
  _TurbulenceSpd("_TurbulenceSpd", Float) = -50  
  _ScrollSpd("_ScrollSpd", Float) = 30
 }
 
 SubShader 
 {
  Tags
  {
   "Queue"="Transparent"
   "IgnoreProjector"="True"
   "RenderType"="Transparent"
  }
  
  Cull Off
  ZWrite Off
  Blend SrcAlpha OneMinusSrcAlpha

  Pass {
   CGPROGRAM
   #pragma vertex vert
   #pragma fragment frag
   #include "UnityCG.cginc"
   
   struct appdata {
    fixed4 vertex : POSITION;
    fixed2 texcoord : TEXCOORD0;
   };
   
   struct v2f {
    fixed4 pos : SV_POSITION;
    fixed2 uv : TEXCOORD0;
    fixed2 uv2 : TEXCOORD1;
   };
   
   fixed4 _MainTex_ST;
   fixed4 _OffsetTex_ST;
   fixed _Distortion;
   fixed _TurbulenceSpd;
   fixed _ScrollSpd;
   
   v2f vert (appdata_base v) {
    v2f o;
    
    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    
    // Offset _MainTex uv
    fixed mainTexOffset = _Time * _ScrollSpd;
    //o.uv.x = v.texcoord.x * _MainTex_ST.x + _MainTex_ST.z;
    //o.uv.y = v.texcoord.y * _MainTex_ST.y + _MainTex_ST.w + mainTexOffset;
    o.uv.x = v.texcoord.x;
    o.uv.y = v.texcoord.y + mainTexOffset;
    
    // Offset _OffsetTex uv
    fixed offsetTexOffset = _Time * _TurbulenceSpd;
    //o.uv2.x = v.texcoord.x * _OffsetTex_ST.x + _OffsetTex_ST.z + offsetTexOffset;
    //o.uv2.y = v.texcoord.y * _OffsetTex_ST.y + _OffsetTex_ST.w;
    o.uv2.x = v.texcoord.x + offsetTexOffset;
    o.uv2.y = v.texcoord.y;
    
    return o;
   }
   
   sampler2D _MainTex;
   sampler2D _OffsetTex;
   
   fixed4 frag(v2f i) : COLOR {
    // convert OffsetTex's color to luminance to distort MainTex's uv
    fixed4 offsetTexColor = tex2D(_OffsetTex, i.uv2);
    fixed lum = Luminance(offsetTexColor);
    fixed2 texCord = ( lum, lum );
    
    fixed4 mainTexColor = tex2D( _MainTex, i.uv + texCord * _Distortion );
    
    return mainTexColor;
   }
   
   ENDCG
  }
 }

  • tex2D返回的是color值(r, g, b, a)


Surface Shader ( Need Normals)

  CGPROGRAM
  #pragma surface surf NoLighting 
  #pragma target 2.0
  
  sampler2D _MainTex;
  sampler2D _OffsetTex;
  float _Distortion;
  float _Speed;
  float _MoveSpeed;

  struct EditorSurfaceOutput {
   half3 Albedo;
   half3 Normal;
   half3 Emission;
   half3 Gloss;
   half Specular;
   half Alpha;
  };
  
  fixed4 LightingNoLighting(EditorSurfaceOutput s, fixed3 lightDir, fixed atten)
     {
         fixed4 c;
         c.rgb = s.Albedo; 
         c.a = s.Alpha;
         return c;
     }
   
  struct Input {
   float2 uv_MainTex;
   float2 uv_OffsetTex;
  };

  void surf (Input IN, inout EditorSurfaceOutput o) {
   
   // pan OffsetTex
   fixed time = _Time * _Speed;
   fixed2 UV_PanY = fixed2( IN.uv_OffsetTex.x + time, IN.uv_OffsetTex.y );
   
   // pan MainTex
   fixed moveTime = _Time * _MoveSpeed;
   fixed2 UV_PanMove = fixed2( IN.uv_OffsetTex.x, IN.uv_OffsetTex.y + moveTime );
   
   fixed2 OffsetTex2D = tex2D( _OffsetTex, UV_PanY.xy );
   fixed2 distorted = OffsetTex2D * _Distortion;
   fixed2 Add1 = UV_PanMove + distorted;
   
   fixed4 MainTex2D = tex2D( _MainTex, Add1.xy );
   
   o.Albedo = MainTex2D;
   o.Alpha = MainTex2D.a;
  }
  ENDCG

2013年9月5日 星期四

[Unity] Read/Write Enabled

Unity匯入的Asset中,Texture與Model的Import Settings裡都會有Read/Write Enabled的選項,這個選項的作用是:
  • Texture:
    • Select this to enable access to the texture data from scripts (GetPixels, SetPixels and other Texture2D functions). Note however that a copy of the texture data will be made, doubling the amount of memory required for texture asset. Use only if absolutely necessary. This is only valid for uncompressed and DTX compressed textures, other types of compressed textures cannot be read from. Disabled by default.
    • 當有scripts會從Texture存取texture data時,會需要勾選Read/Write Enabled,但這個選項會使Unity需要一份額外的copy,增加記憶體的消耗。此選項預設是關閉的,也只適用於未壓縮或DXT貼圖格式的貼圖。
  • Model:
    • Enables the mesh to be written at runtime so you can modify the data; it makes a copy in memory. When this option is turned off, it saves memory since Unity can unload a copy of mesh data in the game. However, if you are scaling or instantiating meshes at runtime with a non-uniform scale, you may have to enable "Read/Write Enabled" in their import settings. The reason is that non-uniform scaling requires the mesh data to be kept in memory. Normally this is detected at build time, but when meshes are scaled or instantiated at runtime you need to set this manually. Otherwise they might not be rendered in game builds correctly.
    • 當你需要Runtime修改Model資料時,會需要開啟Read/Write Enabled,同樣會需要一份額外的記憶體消耗,而值得注意的是當Model在Runtime有被做非等比縮放時,也會需要開啟此選項。
    • 使用Mesh Combine...功能時需要開啟Read/Write Enabled。
參考資料
參考文章

2013年9月4日 星期三

[Unity][Mecanim] flagsCount >= mask.m_Count 錯誤訊息的解決方法



  在處理Mecanim的角色時,有時候會遇到上面的錯誤訊息,經過一番搜尋在Unity Answers上找到了錯誤的原因:


  FBX檔案內的物件命名跟FBX檔名命名相同。另外也發現如果Rig Root Node的命名跟FBX檔名相同的話會產生以下的錯誤:


  因此在DCC端處理物件的時候,要注意物件的命名都不可以跟FBX檔名重複,雖然child物件並不會造成這個問題,但還是應該嚴謹一點依照此原則做命名。


  而當要修正此問題時,似乎要把原有有問題的檔案先刪除之後再Import修正過的檔案才能正確運作,若是直接覆蓋錯誤訊息依然會存在。

2013年9月3日 星期二

[Unity] Collider的Physics效能比較

  最近專案在進行效能調校時,為了要減少Physics的效能消耗,查到了freshcut在Unity Community中發表的實驗數據

在只考量Physics效能的時候,Static的Collider無論是哪一類型的Collider消耗都是非常低的,但在dynamic的狀況下,三種Collider對效能的消耗量則有相當的差距:
Box Collider > Capsule Collider >> Sphere Collider
Box Collider稍稍大於Capsule Collider的消耗,而Sphere Collider的消耗則是明顯的少了很多,因此在許可的狀況之下應盡量使用Sphere Collider。

參考文章


2013年8月29日 星期四

[Unity] 更改Asset的Import Settings後,執行ImportAsset以正確更新

  當利用script進行批次的Import Settings設定時,需注意設定參數完成之後得要重新Import Asset才能夠讓Unity成功判讀到你的更改,不然會發生在Inspector中的資訊是對的,但執行Save Project後卻還是沒有正確寫入到Prefab或meta檔案之中。

舉例:
// 設定貼圖檔案的圖片壓縮格式
textureImporter.textureFormat = TextureImporterFormat.PVRTC_RGBA4;
// 設定了Import Settings之後再使用AssetDatabase.ImportAsset進行asset的更新
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate );

參考資料

2013年8月1日 星期四

[Unity] Shader試作 可調整Rim Light效果的Fragment Shader

嘗試撰寫Shader的紀錄。
這是一個帶有類似Rim Light效果及Tint Color,並且可以與原始的Texture做Blending的不受光Fragment Shader,用於角色受擊效果。

Shader "Custom/Unlit Transparent Cutout With Color" {
 Properties {
  _Color ("Color (RGB) Blending (A)", Color) = (1,0,0,0)
  _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
 
 // Fragment shader by Janus Huang
 SubShader {
 
  Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  Blend SrcAlpha OneMinusSrcAlpha
  Lighting Off
  
  Pass {
   CGPROGRAM
   #pragma vertex vert
   #pragma fragment frag
   #include "UnityCG.cginc"
   
   struct appdata {
    fixed4 vertex : POSITION;
    fixed3 normal : NORMAL;
    fixed2 texcoord : TEXCOORD0;
   };
   
   struct v2f {
    fixed4 pos : SV_POSITION;
    fixed2 uv : TEXCOORD0;
    fixed4 color : COLOR;
   };
   
   fixed4 _MainTex_ST;
   fixed4 _Color;
   fixed _Cutoff;
   
   v2f vert (appdata_base v) {
    v2f o;
    
    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    fixed3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
    // 越是面向camera的vertex在dot計算後會獲得越大的計算結果
    fixed dotProduct = dot(v.normal, viewDir);
    // smoothstep用法同lerp, 但其曲線在頭尾都會趨緩
    o.color = smoothstep(0.5, 1, dotProduct);
    o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    
    return o;
   }
   
   sampler2D _MainTex;
   
   fixed4 frag(v2f i) : COLOR {
    fixed4 texcol = tex2D(_MainTex, i.uv);
    // clip同AlphaTest
    clip( texcol.a - _Cutoff );
    // 受擊時的color計算 - 將貼圖加亮1.5倍後乘上dot計算後的黑白色(外黑內白)再加上_Color
    fixed3 hitColor = texcol.rgb * 1.5 * i.color.rgb + _Color.rgb;
    // 以_Color的alpha控制貼圖與受擊時的混合程度
    texcol.rgb = lerp( texcol.rgb, hitColor, _Color.a);

    return texcol;
   }   
   ENDCG
  }
 }
}


參考文章

2013年7月10日 星期三

[Unity] Soft Particles

Soft Particle是能淡化Particle與其他Object交錯的痕跡的技術。

Unity在使用Soft Particle前必須要先設定Quality中的Soft Particles選項,且平台需支援Depth Textures(似乎無法在iOS上運作)。另外也必須使用Deferred Lighting rendering path或是以Script讓Camera去render Depth Textures


相關文章

2013年6月27日 星期四

[Unity] 使用 Mecanim 需要注意的事情

此處紀錄我在使用Mecanim過程中所發現需要注意的一些地方,有些可能不正確或解說錯誤,僅供參考!

  • 骨架檔的root的x,y需要對正至原點
骨架檔的root的x,y需要對正至原點,否則動作blending時會有位移的誤差。
  • (Humanoid Rig)如果想要動作在blending前後不會移動到collider,除了在Import Settings裡把動作位移鎖住之外,要注意若是進行blending的時間區段中有較大的位移會容易造成collider的移動,因為blending時會吃掉一部分的位移量導致發生誤差。
  • Any State可以立即執行動作
想要立刻執行的動作(例如死亡)可以利用Any State,Any State代表任何時機點且在任何State之上,所以只要觸發條件成立就會立即執行,但其conditions必須是一次性的命令發送。詳細內容:[Unity] Mecanim 強制進入某個State的方法
Any State的觸發時機是任何時候,只要觸發條件成立就會立刻執行
  • 骨架由無實體物件組成時,需要給骨架的root綁定一個mesh
如果骨架是由bone, dummy等無實體的物件組成,且採取骨架、動態分離的檔案規則時,骨架的root需要綁定一個mesh,且動態檔內也必須要留著這個mesh,如此骨架檔才能成功套用到動態。
  • Humanoid Rig會消耗較多的效能
角色的Rig選擇Humanoid會比起Generic消耗更多的效能,而Legacy則是依據開發者所撰寫的controller,當角色越簡單時,使用Legacy會比較省效能。詳細內容:Mecanim Performance and Optimization
  • 當不使用IK功能時,Rig選擇Generic可以避免一些問題
角色需求較單純時使用Generic可以避免一些因為Humanoid的IK所造成的表現性上的誤差(如transition時的位移誤差)。當Rig選擇Generic時可看到Clip設定中的Root Transform Position(XZ)的Based Upon可選項目除了Original(依照動作檔中原始所key的位置)外就是Root Node Position,選擇Root Node Position時會以骨架的root對正(0,0),而Humanoid則是Center of Mass,以骨架體積中心點對正(0,0),因此當角色的腳挪動時僅管hip沒有移動仍然會使角色的位置偏移。
  • Humanoid Rig最好只使用在人類角色上
Humanoid是針對人類型骨架角色設計的,例如因Foot IK是針對單關節(人類的膝蓋)所設計,所以當腿部結構有雙關節時(如羊人的腳),就會發生一些不正常的現象(如滑步明顯、腳步抖動...)。
  • Transition的conditions為bool時,無法調整blending timing
當條件為bool時,代表該transition可以在任何時間發生,所以就只能調整duration而無法調整timing,如果去調整它會發現重新點選該transition時,會被自動歸回中央點。
當conditions為bool時是無法設定transition timing的
  • 承上,transition的conditions可以不只一個
譬如已有一個bool的條件再加上一個exit time條件,可以使transition依照bool判斷觸發,但transition發生的timing會是固定的,也就是你在transition的timeline中所調整的timing。 參考文章:


bool搭配exit time可以指定transition的timing

延伸閱讀:

2013年6月21日 星期五

[Unity] 以ARGB4444搭配Dithering進行貼圖減量

  之前一直受ARGB Texture所困擾,在Mobile平台沒有合適的壓縮格式能在品質與容量之間取得較好的平衡,下面列出幾個格式的缺點
  • RGBA PVRTC 4 bits - iOS推薦的壓縮格式,但是4bits對於圖像品質的破壞太大
  • ARGB 32 bit - 雖能保有圖片品質,但所消耗的容量實在太龐大
  • ARGB 16 bit - 雖能降低貼圖容量,但是顏色有明顯的帶狀瑕疵(color banding)
  Android平台由於各家GPU所支援的壓縮格式各有不同,因此ARGB 16 bit也就是降低texture容量最適合的選項,但16 bit所造成的帶狀瑕疵十分明顯,若真的要使用也不太可能,正好前一陣子看到Unity IN上有Cytus開發者之一的syyang所發表的文章



  • 使用 RGBA4444 搭配 Dithering 減少記憶體用量 by syyang @ UNITYIN

  •   這篇文章正好解決了這個問題,利用Dithering在16bit color depth獲得較佳的圖像呈現,消除帶狀瑕疵。進行Dither處理之後,圖片的顏色資訊會被重新處理,檢視圖片可發現變的有顆粒狀感(抖色),當圖片在眼中的呈現越小時,就會發現看起來跟truecolor的圖片品質頗接近。由於是對顏色資訊做了重新的演算,所以並不受到Unity的轉檔所影響,只要在Import Settings中設定Format為16 bit的壓縮,即可省下容量又能保有還能接受的圖片品質。

      此外需要注意的是經過dither處理的texture若又被Unity重新壓縮到不同尺寸的圖片時,會加重顆粒感使圖片品質降低(因為顏色訊息被重新處理過了),因此輸出給Unity的texture asset必須要輸出成遊戲主要使用的texture size。此外,若處理過的貼圖是用於3D模型的話,經過UV的拉扯也會使圖片失真更加明顯。目前Unity本身並不支援dithering,在網上也還沒看到有人做出支援dither處理的script/plug-in,因此得要自行預先處理這些textures。

    經過UV拉扯、尺寸放大後失真變的相當明顯
    但dithering還是有其諸多限制,而最原始的作法當然就是使用RGB444的安全色系來繪製texture,及在各個channel中只使用:0, 15, 31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191, 207, 223, 239, 255。但除了顏色數便少之外,還得少用漸層表現,要犧牲的也是相當多,也許能在不影響美術風格的前提下選擇性使用。

      在以Gimp進行dithering處理時,須先將貼圖縮成最終使用的尺寸,在縮小圖片時三種內插法看起來效果幾乎相同,然後再執行Dither to ARGB,此時會多出一個圖檔視窗就是dithering後的圖檔,進行匯出之後即可。匯出PNG的設定所有選項皆可取消,但當texture需要再alpha邊緣作細緻的過度時,透明像素的色彩是必須要被儲存的。Compression Level 0跟9在色系較單純的圖片上是幾乎沒有差別。


    Gimp在安裝script之後可進行dithering處理
    Gimp匯出PNG時的設定

    參考資料


    延伸閱讀

    2013年5月9日 星期四

    [Unity] Prefab 不會 update 的問題

    近日在作業時遇到一個嚴重的問題!
    當我把一個fbx檔案包成prefab時,就會造成部分內容無法與原始的fbx檔案同步更新。

    目前只知道單純變動fbx檔案內的geometry, uv是會同步更新的,
    而hierarchy完全不會更新,
    skin資訊雖會更新,但是看起來只有更新了權重值,所以依然會有問題發生,
    若fbx檔案變動了material,也不會更新,
    此外相信不會更新的內容有非常多...
    而目前對於此問題沒有找到較好的解決方式...


    相關文章:

    2013年4月2日 星期二

    Unity - Editor Script Coding - 編寫Editor Script之參考資料

    入門站:
    資料:

    參考文章蒐集:
    • http://forum.unity3d.com/threads/92148-need-help-with-texture-import-setting-script

    零散紀錄:
    • 取得Type
      GameObject.GetType().Name
    • 取得某個選擇中的Asset的路徑(亦可作用於目錄)
      AssetDatabase.GetAssetPath(OBJECT)
    • 取得 某個Asset檔案 內的所有元件
      AssetDatabase.LoadAllAssetsAtPath("AssetPath")

    2013年3月12日 星期二

    如何不影響Scale的數值對Bone做到縮放尺寸的效果

    如何不影響Scale的數值對Bone做到縮放尺寸的效果

    例,在對原本Scale值為[1,1,1]的Bone,進行Scale 2倍的動作後,Scale值變為[2,2,2],若想在保持現有尺寸的狀態下把Bone的Scale值歸回[1,1,1],可利用Animation>Bone Tools,方法如下:
    1. 開啟Bone Tools視窗。
    2. 選擇要修改的Bone,執行Reset Scale,此時Scale值已被修正為1,但Bone的顯示有問題,用以下步驟進行修正。
    3. 將Bone On關掉再打開,做個Refresh動作。
    4. 執行Reset Stretch。
    5. 執行Realign。

    另外可用Max Script進行這個手續:
    for o in selection do
    (
        resetScale o
        o.setBoneEnable false currenttime
        o.setBoneEnable true currenttime
        o.resetBoneStretch()
        o.realignBoneToChild()
    )
    

    2013年3月7日 星期四

    Unity3D輸出之圖檔壓縮格式(行動平台)

    要對圖檔壓縮進行優化時,須先了解各圖檔之規格,Unity Manual中有提到各平台可支援的各種圖檔格式,請參考在本文結尾的參考文章中的[1]以及Wiki中的資訊。

    iOS:
    PVRCT
      貼圖尺寸須為二的冪次方之正方貼圖
    Android:
    RGB Compressed ETC 4 bits (ETC1)
     (Ericsson Texture Compression, supported by all OpenGL ES 2.0 GPUs)
     4bits / pixel,無Alpha,Android 2.2(Froyo)以上支援
    RGBA 16bit
     有Alpha,容量是ETC的四倍(請看參考[1])。

    若要減少Alpha對資源的佔用,有一些技巧可以解決(請看參考[3][4])。
     方法1,將Alpha Channel抽出,與Color Map連接拼成一張貼圖。
      優點:一張貼圖、Shader改動較小。
      缺點:貼圖只能二方連續(one direction wrap),提高shader效能消耗
     方法2,將Alpha Channel抽出,單獨存成一個檔案,再從shader進行結合。
      優點:貼圖可四方連續,運用上靈活性較高。
      缺點:shader需要額外多出一個sampler。
    當硬體不支援輸出之壓縮格式時,Unity會將資源以RGBA的方式做Decompress,如此會提高渲染時間、記憶體消耗和Decompress時間(增加讀取階段的時間)。

    下表是檔案容量對照(含MipMaps)

    尺寸 ETC 4bits RGBA 16bit RGBA 32bit
    2048
    2.7 mb
    10.7 mb
    21.3mb
    1024 682.8
    2.7 mb
    5.3mb
    512 170.8 682.7
    1.3mb
    256 42.8 170.7 341.3
    128 10.7 42.8 85.3
    64 2.7 10.7 21.3


    參考文章:
    [1]http://docs.unity3d.com/Documentation/Manual/Textures.html
    [2]http://docs.unity3d.com/Documentation/Manual/android-GettingStarted.html
    [3]http://forum.unity3d.com/threads/73998-DXT-or-PVRTC
    [4]http://malideveloper.arm.com/develop-for-mali/sample-code/etcv1-texture-compression-and-alpha-channels/
    http://gamedev.stackexchange.com/questions/44134/unity-android-truecolor-texture-performance-hit-and-alternatives-for-truecolor
    http://stackoverflow.com/questions/9148795/android-opengl-texture-compression

    http://zh.wikipedia.org/wiki/RGB
    http://en.wikipedia.org/wiki/Ericsson_Texture_Compression
    http://en.wikipedia.org/wiki/PVRTC

    2012年5月25日 星期五

    利用nvidia DDS Utilities - nvDXT進行DDS轉檔



    最近嘗試了幾種dds轉檔的方式,用maxScript的缺陷是在於無法產生alpha,用python透過com操作photoshop則是運行耗時、且我找不到dds的save option,利用nvidia DDS Utilities來進行dds轉檔看來是目前最好的方法。

    nvidia DDS Utilities是什麼?nvidia的說明是:
    included are a set of utilities for manipulating DDS image files, including:
    nvDXT, a command-line binary version of the nvDXT library, 
    detach, a tool that extracts MIP levels from a DDS file,
    stitch, a tool that recombines MIP levels into a single DDS file and
    readDXT, which reads compressed images and writes TGA files.
    Download DDS Utilities >> http://developer.nvidia.com/legacy-texture-tools

    利用nvDXT即可用command-line的方式來輸出.dds檔案,最簡單的命令如下
    nvdxt -profile profile -file file -outdir outdir
    nvdxt -profile profile -file file -outsamedir
    很方便,可以讀取.psd,-file可運用萬用字元,還可指定profile(由photoshop產生)

    ----------以下是nvDXT本身的說明內容----------
    This program
       compresses images
       creates normal maps from color or alpha
       creates DuDv map
       creates cube maps
       writes out .dds file
       does batch processing
       reads .tga, .bmp, .gif, .ppm, .jpg, .tif, .cel, .dds, .png, .psd, .rgb, *.bw and .rgba
       filters MIP maps


    Options:
      -profile : Read a profile created from the Photoshop plugin
      -quick : use fast compression method
      -quality_normal : normal quality compression
      -quality_production : production quality compression
      -quality_highest : highest quality compression (this can be very slow)
      -rms_threshold : quality RMS error. Above this, an extensive search is performed.
      -prescale : rescale image to this size first
      -rescale : rescale image to nearest, next highest or next lowest power of two
      -rel_scale : relative scale of original image. 0.5 is half size Default 1.0, 1.0


    Optional Filtering for rescaling. Default cube filter:
      -RescalePoint
      -RescaleBox
      -RescaleTriangle
      -RescaleQuadratic
      -RescaleCubic
      -RescaleCatrom
      -RescaleMitchell
      -RescaleGaussian
      -RescaleSinc
      -RescaleBessel
      -RescaleHanning
      -RescaleHamming
      -RescaleBlackman
      -RescaleKaiser

      -clamp : maximum image size. image width and height are clamped
      -clampScale : maximum image size. image width and height are scaled
      -window : window of original window to compress
      -nomipmap : don't generate MIP maps
      -nmips : specify the number of MIP maps to generate
      -rgbe : Image is RGBE format
      -dither : add dithering
      -sharpenMethod : sharpen method MIP maps
        is
            None
            Negative
            Lighter
            Darker
            ContrastMore
            ContrastLess
            Smoothen
            SharpenSoft
            SharpenMedium
            SharpenStrong
            FindEdges
            Contour
            EdgeDetect
            EdgeDetectSoft
            Emboss
            MeanRemoval
            UnSharp
            XSharpen
            Custom
      -pause : wait for keyboard on error
      -flip : flip top to bottom
      -timestamp : Update only changed files
      -list : list of files to convert
      -cubeMap : create cube map .
                Cube faces specified with individual files with -list option
                positive x, negative x, positive y, negative y, positive z, negative z
                Use -output option to specify filename
                Cube faces specified in one file.  Use -file to specify input filename
      -volumeMap : create volume texture.
                Volume slices specified with individual files with -list option
                      Use -output option to specify filename
                Volume specified in one file.  Use -file to specify input filename

      -all : all image files in current directory
      -outdir : output directory
      -deep [directory]: include all subdirectories
      -outsamedir : output directory same as input
      -overwrite : if input is .dds file, overwrite old file
      -forcewrite : write over readonly files
      -file : input file to process. Accepts wild cards
      -output : filename to write to [-outfile can also be specified]
      -append : append this string to output filename


      -8    : compress 8 bit images with this format
      -16 : compress 16 bit images with this format
      -24  : compress 24 bit images with this format
      -32  : compress 32 bit images with this format

      -swapRB : swap rb
      -swapRG : swap rg
      -gamma : gamma correcting during filtering
      -outputScale : scale the output by this (r,g,b,a)
      -outputBias : bias the output by this amount (r,g,b,a)
      -outputWrap : wraps overflow values modulo the output format
      -inputScale : scale the inpput by this (r,g,b,a)
      -inputBias : bias the input by this amount (r,g,b,a)
      -binaryalpha : treat alpha as 0 or 1
      -alpha_threshold : [0-255] alpha reference value
      -alphaborder : border images with alpha = 0
      -alphaborderLeft : border images with alpha (left) = 0
      -alphaborderRight : border images with alpha (right)= 0
      -alphaborderTop : border images with alpha (top) = 0
      -alphaborderBottom : border images with alpha (bottom)= 0
      -fadeamount : percentage to fade each MIP level. Default 15
      -fadecolor : fade map (color, normal or DuDv) over MIP levels
      -fadetocolor : color to fade to
      -custom_fade : set custom fade amount.  n is number number of fade amounts. fadeamount are [0,1]
      -fadealpha : fade alpha over MIP levels
      -fadetoalpha : [0-255] alpha to fade to
      -border : border images with color
      -bordercolor : color for border
      -force4 : force DXT1c to use always four colors
      -weight : Compression weightings for R G and B
      -luminance :  convert color values to luminance for L8 formats
      -greyScale : Convert to grey scale
      -greyScaleWeights : override greyscale conversion weights of (0.3086, 0.6094, 0.0820, 0)
      -brightness : per channel brightness. Default 0.0 usual range [0,1]
      -contrast : per channel contrast. Default 1.0  usual range [0.5, 1.5]

    Texture Format  Default DXT3:
      -dxt1c   : DXT1 (color only)
      -dxt1a   : DXT1 (one bit alpha)
      -dxt3    : DXT3
      -dxt5    : DXT5n
      -u1555   : uncompressed 1:5:5:5
      -u4444   : uncompressed 4:4:4:4
      -u565    : uncompressed 5:6:5
      -u8888   : uncompressed 8:8:8:8
      -u888    : uncompressed 0:8:8:8
      -u555    : uncompressed 0:5:5:5
      -p8c     : paletted 8 bit (256 colors)
      -p8a     : paletted 8 bit (256 colors with alpha)
      -p4c     : paletted 4 bit (16 colors)
      -p4a     : paletted 4 bit (16 colors with alpha)
      -a8      : 8 bit alpha channel
      -cxv8u8  : normal map format
      -v8u8    : EMBM format (8, bit two component signed)
      -v16u16  : EMBM format (16 bit, two component signed)
      -A8L8    : 8 bit alpha channel, 8 bit luminance
      -fp32x4  : fp32 four channels (A32B32G32R32F)
      -fp32    : fp32 one channel (R32F)
      -fp16x4  : fp16 four channels (A16B16G16R16F)
      -dxt5nm  : dxt5 style normal map
      -3Dc     : 3DC
      -g16r16  : 16 bit in, two component
      -g16r16f : 16 bit float, two components

    Mip Map Filtering Options. Default box filter:
      -Point
      -Box
      -Triangle
      -Quadratic
      -Cubic
      -Catrom
      -Mitchell
      -Gaussian
      -Sinc
      -Bessel
      -Hanning
      -Hamming
      -Blackman
      -Kaiser

    ***************************
    To make a normal or dudv map, specify one of
      -n4 : normal map 4 sample
      -n3x3 : normal map 3x3 filter
      -n5x5 : normal map 5x5 filter
      -n7x7 : normal map 7x7 filter
      -n9x9 : normal map 9x9 filter
      -dudv : DuDv

    and source of height info:
      -alpha : alpha channel
      -rgb : average rgb
      -biased : average rgb biased
      -red : red channel
      -green : green channel
      -blue : blue channel
      -max : max of (r,g,b)
      -colorspace : mix of r,g,b
      -norm : normalize mip maps (source is a normal map)
      -toHeight : create a height map (source is a normal map)


    Normal/DuDv Map dxt:
      -aheight : store calculated height in alpha field
      -aclear : clear alpha channel
      -awhite : set alpha channel = 1.0
      -scale : scale of height map. Default 1.0
      -wrap : wrap texture around. Default off
      -minz : minimum value for up vector [0-255]. Default 0

    ***************************
    To make a depth sprite, specify:
      -depth

    and source of depth info:
      -alpha  : alpha channel
      -rgb    : average rgb (default)
      -red    : red channel
      -green  : green channel
      -blue   : blue channel
      -max    : max of (r,g,b)
      -colorspace : mix of r,g,b

    Depth Sprite dxt:
      -aheight : store calculated depth in alpha channel
      -aclear : store 0.0 in alpha channel
      -awhite : store 1.0 in alpha channel
      -scale : scale of depth sprite (default 1.0)
      -alpha_modulate : multiplies color by alpha during filtering
      -pre_modulate : multiplies color by alpha before processing


    Examples
      nvdxt -cubeMap -list cubemapfile.lst -output cubemap.dds
      nvdxt -cubeMap -file cubemapfile.tga
      nvdxt -file test.tga -dxt1c
      nvdxt -file *.tga
      nvdxt -file c:\temp\*.tga
      nvdxt -file temp\*.tga
      nvdxt -file height_field_in_alpha.tga -n3x3 -alpha -scale 10 -wrap
      nvdxt -file grey_scale_height_field.tga -n5x5 -rgb -scale 1.3
      nvdxt -file normal_map.tga -norm
      nvdxt -file image.tga -dudv -fade -fadeamount 10
      nvdxt -all -dxt3 -gamma -outdir .\dds_dir -time
      nvdxt -file *.tga -depth -max -scale 0.5

    Send comments, bug fixes and feature requests to texturetools@nvidia.com