2017年5月20日 星期六

Test allow HDR in Main Camera

當這裡設定成linear



主camera的allow  HDR沒勾選的話




預設情況下Unity會對主Camera的color Buffer開啟 sRGB  read  and sRGB  write


///////////////////////////////////////////////////////////////////////////////////////////

把主camera的allow  HDR打開的話



因為使用的buffer是linear的,所以不會開啟sRGB  read  和  sRGB  write



但為了畫面正確,最後會再執行一次sRGB  write

///////////////////////////////////////////////////////////////////////////////////////////

但會把HDR打開,是希望畫面上的亮暗更顯眼

(1)所以會打開bloom(讓最亮的地方有漸層暈光)
(2)因為HDRcolor的範圍會超出(0~1),所以也要打開Color Grading作tonemapping(clamp to 0~1)




右邊平面的貼圖是透過第2個Camra畫到New Render Texture上的
沒有發亮是因為New Render Texture的格式是ARGB32(非HDR格式)


 打它修改成ARGB  Half(HDR格式)後就會看到發亮效果了


///////////////////////////////////////////////////////////////////////////////////////////

如果主camera沒有使用HDR格式,會發現最亮的黃色不見了


因為沒有使用HDR的render buffer,最亮的黃色也被clamp  to 0~1
在bloom的FragPrefilter就無法過慮出最亮的顏色了(所以也就沒那麼亮了)


///////////////////////////////////////////////////////////////////////////////////////////






When using Gamma color space, no conversions are done of any kind, and this setting is not used.
聽起來像是當使用這樣的設定時


對所有的RenderBuffer,都不會作sRGB  read 和sRGB  write
所以自己對外部的貼圖作sRGB  read再畫到 RenderBuffer,最後輸出到畫面時再整個作一次sRGB  write
應該就能達到和Linear color space一樣的畫面!
可是實測後監看frameDebugger發現跟本不是那樣

It's still a mystery.  QQ  

///////////////////////////////////////////////////////////////////////////////////////////


結論:大人的世界真的好麻煩(尤其是身為程式設計師的大人)

Unity Texture sRGB and Render Texture sRGB




在Unity裡,決定shader讀取貼圖要不要開啟sRGB  read可以在這裡設定


////////////////////////////////////////////////////////////////////////////////////////////////////////




對Render Texture如果sRGB打勾了
對這個Render Texture的寫入就會使用sRGB  write
在shader裡讀取這個Render Texture時也會使用  sRGB  read

2017年5月18日 星期四

Why Object having NormalMap material can do mirror in Unity 5



4  case (make 3 real-axis look like match  right hand rule)  
它們都做了奇數次的鏡射(odd times mirror)


3 case (make 3  real-axis still  match left hand rule)
它們都做了偶數次的鏡射(even times mirror)


在奇數次的鏡射的情況(in  odd times  mirror)
要再多改變一次tangent的方向(swap y again)


Unity乘上unity_WorldTransformParams.w應該就是這個原因


但Unity怎麼計算出unity_WorldTransformParams.w?
我猜可能像這樣...

方法(1)
transform  has  LossyScale(the global scale of object)

unity_WorldTransformParams.w=sign(LossyScaleX*LossyScaleY*LossyScaleZ)


方法(2)
transform has   right , up , forward

但是right,up ,forward並不會反應出scale設為負值後的方向改變
所以必須乘上lossyScale
(也就是光看right,up,forward看不出3軸有沒有match right hand rule )

檢查cross(real_right ,real_up)和real_forward 是不是同向,決定[鏡射因子]
Vector3 real_right=LossyScaleX*right;
Vector3 real_up=LossyScaleY*up;
Vector3 real_forward=LossyScaleZ*forward;
unity_WorldTransformParams.w=sign(dot(cross(real_right,real_up),real_forward));

2017年5月16日 星期二

Peek tangent in Unity

Unity use cross(v.Normal,v.tangent)*v.tanget.w
to find biNormal

I guess v.tanget.w=-1 in general situation
and v.tangetw=1 in mirror situation

then I try some test

in 3dsmax (general situation)


in  Unity  w of tangent is  -1
Normal Direction :  red  ball to green ball   
Tangent Direction : red  ball to blue ball   


in 3dsmax (mirror situation)


in  Unity  w of tangent is  1

PS:
set  Absolute  Mode  to  see the UV  coordinate


2017年5月6日 星期六

Local vs Global

Mr = final  rotaion matrix

Local Mode





Mr = My


Mr = My Mx


Mr = My Mx Mz

Global Mode




Mr =Mz

Mr = Mx Mz


Mr = My Mx Mz

備註:對quaternion來說也是這樣(前乘和後乘具有不同的幾何意義)