1
我正在修改一個叫做Mount的遊戲&刀片,目前試圖通過自定義着色器實現光照貼圖。Un/pack一組UV座標到一個32bit RGBA字段
由於遊戲中的格式不允許每個模型有多個UV貼圖,並且我需要在某處攜帶第二個非重疊參數化的信息,所以我們需要一個四個字段(RGBA,頂點着色)是我唯一的可能性。
首先想到只使用U,V=R,G
但精度不夠好。 現在我試圖用可用的最大精度對它們進行編碼,每個座標使用兩個字段(16位)。我的Python出口商剪斷:
def decompose(a):
a=int(a*0xffff) #fill the entire range to get the maximum precision
aa =(a&0xff00)>>8 #decompose the first half and save it as an 8bit uint
ab =(a&0x00ff) #decompose the second half
return aa,ab
def compose(na,nb):
return (na<<8|nb)/0xffff
我想知道怎麼做的第二部分(作曲,或拆封)在HLSL(DX9,支持Shader Model 2.0)。這是我的嘗試,關閉,但不起作用:
//compose UV from n=(na<<8|nb)/0xffff
float2 thingie = float2(
float(((In.Color.r*255.f)*256.f)+
(In.Color.g*255.f) )/65535.f,
float(((In.Color.b*255.f)*256.f)+
(In.Color.w*255.f) )/65535.f
);
//sample the lightmap at that position
Output.RGBColor = tex2D(MeshTextureSamplerHQ, thingie);
任何建議或巧妙的選擇是值得歡迎的。
它使用編輯器的預覽工作正常的在OpenGL。看起來問題來自遊戲引擎伽馬修正值或什麼。無論如何,謝謝你的答覆,我真的很感激。已經在這個問題上工作了幾個星期了。我想我會從另一個角度來看待它; GPU蒙皮。看起來更有希望,儘管有一些額外的開銷。 – Swyter 2013-03-22 18:20:44