【问题标题】:Un/pack additional set of UV coordinates into a 32bit RGBA field将一组额外的 UV 坐标解包/打包到 32 位 RGBA 字段中
【发布时间】:2013-03-17 18:58:36
【问题描述】:

我正在修改一款名为 Mount&Blade 的游戏,目前正在尝试通过自定义着色器实现光照贴图。

由于游戏中的格式不允许每个模型超过一个 UV 贴图,我需要在某处携带第二个非重叠参数化的信息,即四个 uints 的字段(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,着色器模型 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);

欢迎任何建议或巧妙的替代方案。

【问题讨论】:

    标签: graphics shader blender hlsl directx-9


    【解决方案1】:

    记得在分解 a 之后对 aa 和 ab 进行归一化。 像这样的:

    (u1, u2) = decompose(u)
    (v1, v2) = decompose(v)
    color.r = float(u1) / 255.f
    color.g = float(u2) / 255.f
    color.b = float(v1) / 255.f
    color.a = float(v2) / 255.f
    

    像素着色器:

    float2 texc;
    texc.x = (In.Color.r * 256.f + In.Color.g) / 257.f;
    texc.y = (In.Color.b * 256.f + In.Color.a) / 257.f;
    

    【讨论】:

    • 它在 OpenGL 中使用编辑器的预览可以正常工作。看起来问题来自游戏引擎伽玛校正值或其他东西。无论如何,谢谢,回复是正确的,我很感激,真的。已经在这个问题上工作了几个星期。我想我会从另一个角度来处理它; GPU蒙皮。似乎更有希望,尽管有一些额外的开销。
    猜你喜欢
    • 2020-03-08
    • 2020-09-22
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2015-05-31
    • 1970-01-01
    相关资源
    最近更新 更多