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