mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-17 04:22:54 +08:00
Replace Dec3N vertex format with RGBA8 SNorm
The game uses DXGI_FORMAT_R8G8B8A8_SNORM when building the D3D11 input-layout for what CW called Dec3N. Updated XML import/export to correctly read these values.
This commit is contained in:
parent
3d22e9b2a4
commit
43c3567803
@ -3779,7 +3779,7 @@ namespace CodeWalker.GameFiles
|
|||||||
case VertexComponentType.Float2: SetVector2(v, c, new Vector2(f(0), f(1))); break;
|
case VertexComponentType.Float2: SetVector2(v, c, new Vector2(f(0), f(1))); break;
|
||||||
case VertexComponentType.Float3: SetVector3(v, c, new Vector3(f(0), f(1), f(2))); break;
|
case VertexComponentType.Float3: SetVector3(v, c, new Vector3(f(0), f(1), f(2))); break;
|
||||||
case VertexComponentType.Float4: SetVector4(v, c, new Vector4(f(0), f(1), f(2), f(3))); break;
|
case VertexComponentType.Float4: SetVector4(v, c, new Vector4(f(0), f(1), f(2), f(3))); break;
|
||||||
case VertexComponentType.Dec3N: SetDec3N(v, c, new Vector4(f(0), f(1), f(2), f(3))); break;
|
case VertexComponentType.RGBA8SNorm: SetRGBA8SNorm(v, c, new Vector4(f(0), f(1), f(2), f(3))); break;
|
||||||
case VertexComponentType.Half2: SetHalf2(v, c, new Half2(f(0), f(1))); break;
|
case VertexComponentType.Half2: SetHalf2(v, c, new Half2(f(0), f(1))); break;
|
||||||
case VertexComponentType.Half4: SetHalf4(v, c, new Half4(f(0), f(1), f(2), f(3))); break;
|
case VertexComponentType.Half4: SetHalf4(v, c, new Half4(f(0), f(1), f(2), f(3))); break;
|
||||||
case VertexComponentType.Colour: SetColour(v, c, new Color(b(0), b(1), b(2), b(3))); break;
|
case VertexComponentType.Colour: SetColour(v, c, new Color(b(0), b(1), b(2), b(3))); break;
|
||||||
@ -3862,30 +3862,22 @@ namespace CodeWalker.GameFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void SetDec3N(int v, int c, Vector4 val)
|
public void SetRGBA8SNorm(int v, int c, Vector4 val)
|
||||||
{
|
{
|
||||||
//see https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb322868(v%3Dvs.85)
|
// Equivalent to DXGI_FORMAT_R8G8B8A8_SNORM
|
||||||
if ((Info != null) && (VertexBytes != null))
|
if ((Info != null) && (VertexBytes != null))
|
||||||
{
|
{
|
||||||
var s = Info.Stride;
|
var s = Info.Stride;
|
||||||
var co = Info.GetComponentOffset(c);
|
var co = Info.GetComponentOffset(c);
|
||||||
var o = (v * s) + co;
|
var o = (v * s) + co;
|
||||||
var e = o + 4;//sizeof(Dec3N)
|
var e = o + 4;//sizeof(RGBA8SNorm)
|
||||||
if (e <= VertexBytes.Length)
|
if (e <= VertexBytes.Length)
|
||||||
{
|
{
|
||||||
var sx = (val.X >= 0.0f);
|
var x = (byte)Math.Max(-127.0f, Math.Min(val.X * 127.0f, 127.0f));
|
||||||
var sy = (val.Y >= 0.0f);
|
var y = (byte)Math.Max(-127.0f, Math.Min(val.Y * 127.0f, 127.0f));
|
||||||
var sz = (val.Z >= 0.0f);
|
var z = (byte)Math.Max(-127.0f, Math.Min(val.Z * 127.0f, 127.0f));
|
||||||
var sw = (val.W >= 0.0f);
|
var w = (byte)Math.Max(-127.0f, Math.Min(val.W * 127.0f, 127.0f));
|
||||||
var x = Math.Min((uint)(Math.Abs(val.X) * 511.0f), 511);
|
var u = x | (y << 8) | (z << 16) | (w << 24);
|
||||||
var y = Math.Min((uint)(Math.Abs(val.Y) * 511.0f), 511);
|
|
||||||
var z = Math.Min((uint)(Math.Abs(val.Z) * 511.0f), 511);
|
|
||||||
var w = Math.Min((uint)(val.W), 2);
|
|
||||||
var ux = ((sx ? x : ~x) & 0x1FF) + (sx ? 0x200 : 0);
|
|
||||||
var uy = ((sy ? y : ~y) & 0x1FF) + (sy ? 0x200 : 0);
|
|
||||||
var uz = ((sz ? z : ~z) & 0x1FF) + (sz ? 0x200 : 0);
|
|
||||||
var uw = sw ? w : 3;//(0,1,2)=>(0,1,2); (-1)=>(3)
|
|
||||||
var u = ux + (uy << 10) + (uz << 20) + (uw << 30);
|
|
||||||
var b = BitConverter.GetBytes(u);
|
var b = BitConverter.GetBytes(u);
|
||||||
Buffer.BlockCopy(b, 0, VertexBytes, o, 4);
|
Buffer.BlockCopy(b, 0, VertexBytes, o, 4);
|
||||||
}
|
}
|
||||||
@ -3973,7 +3965,7 @@ namespace CodeWalker.GameFiles
|
|||||||
case VertexComponentType.Float2: return FloatUtil.GetVector2String(GetVector2(v, c), d);
|
case VertexComponentType.Float2: return FloatUtil.GetVector2String(GetVector2(v, c), d);
|
||||||
case VertexComponentType.Float3: return FloatUtil.GetVector3String(GetVector3(v, c), d);
|
case VertexComponentType.Float3: return FloatUtil.GetVector3String(GetVector3(v, c), d);
|
||||||
case VertexComponentType.Float4: return FloatUtil.GetVector4String(GetVector4(v, c), d);
|
case VertexComponentType.Float4: return FloatUtil.GetVector4String(GetVector4(v, c), d);
|
||||||
case VertexComponentType.Dec3N: return FloatUtil.GetVector4String(GetDec3N(v, c), d);
|
case VertexComponentType.RGBA8SNorm: return FloatUtil.GetVector4String(GetRGBA8SNorm(v, c), d);
|
||||||
case VertexComponentType.Half2: return FloatUtil.GetHalf2String(GetHalf2(v, c), d);
|
case VertexComponentType.Half2: return FloatUtil.GetHalf2String(GetHalf2(v, c), d);
|
||||||
case VertexComponentType.Half4: return FloatUtil.GetHalf4String(GetHalf4(v, c), d);
|
case VertexComponentType.Half4: return FloatUtil.GetHalf4String(GetHalf4(v, c), d);
|
||||||
case VertexComponentType.Colour: return FloatUtil.GetColourString(GetColour(v, c), d);
|
case VertexComponentType.Colour: return FloatUtil.GetColourString(GetColour(v, c), d);
|
||||||
@ -4054,29 +4046,22 @@ namespace CodeWalker.GameFiles
|
|||||||
}
|
}
|
||||||
return Vector4.Zero;
|
return Vector4.Zero;
|
||||||
}
|
}
|
||||||
public Vector4 GetDec3N(int v, int c)
|
public Vector4 GetRGBA8SNorm(int v, int c)
|
||||||
{
|
{
|
||||||
//see https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb322868(v%3Dvs.85)
|
// Equivalent to DXGI_FORMAT_R8G8B8A8_SNORM
|
||||||
if ((Info != null) && (VertexBytes != null))
|
if ((Info != null) && (VertexBytes != null))
|
||||||
{
|
{
|
||||||
var s = Info.Stride;
|
var s = Info.Stride;
|
||||||
var co = Info.GetComponentOffset(c);
|
var co = Info.GetComponentOffset(c);
|
||||||
var o = (v * s) + co;
|
var o = (v * s) + co;
|
||||||
var e = o + 4;//sizeof(Dec3N)
|
var e = o + 4;//sizeof(RGBA8SNorm)
|
||||||
if (e <= VertexBytes.Length)
|
if (e <= VertexBytes.Length)
|
||||||
{
|
{
|
||||||
var u = BitConverter.ToUInt32(VertexBytes, o);
|
var xyzw = BitConverter.ToUInt32(VertexBytes, o);
|
||||||
var ux = (u >> 0) & 0x3FF;
|
var x = (sbyte)(xyzw & 0xFF) / 127.0f;
|
||||||
var uy = (u >> 10) & 0x3FF;
|
var y = (sbyte)((xyzw >> 8) & 0xFF) / 127.0f;
|
||||||
var uz = (u >> 20) & 0x3FF;
|
var z = (sbyte)((xyzw >> 16) & 0xFF) / 127.0f;
|
||||||
var uw = (u >> 30) & 0x3;
|
var w = (sbyte)((xyzw >> 24) & 0xFF) / 127.0f;
|
||||||
var sx = (ux & 0x200) > 0;
|
|
||||||
var sy = (uy & 0x200) > 0;
|
|
||||||
var sz = (uz & 0x200) > 0;
|
|
||||||
var x = ((sx ? ux : ~ux) & 0x1FF) / (sx ? 511.0f : -511.0f);
|
|
||||||
var y = ((sy ? uy : ~uy) & 0x1FF) / (sy ? 511.0f : -511.0f);
|
|
||||||
var z = ((sz ? uz : ~uz) & 0x1FF) / (sz ? 511.0f : -511.0f);
|
|
||||||
var w = (uw == 3) ? -1.0f : uw;//(0,1,2)=>(0,1,2); (3)=>(-1)
|
|
||||||
return new Vector4(x, y, z, w);
|
return new Vector4(x, y, z, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace CodeWalker.GameFiles
|
|||||||
Float4 = 7,
|
Float4 = 7,
|
||||||
UByte4 = 8,
|
UByte4 = 8,
|
||||||
Colour = 9,
|
Colour = 9,
|
||||||
Dec3N = 10,
|
RGBA8SNorm = 10,
|
||||||
Unk1 = 11,
|
Unk1 = 11,
|
||||||
Unk2 = 12,
|
Unk2 = 12,
|
||||||
Unk3 = 13,
|
Unk3 = 13,
|
||||||
@ -43,7 +43,7 @@ namespace CodeWalker.GameFiles
|
|||||||
case VertexComponentType.Float4: return 16;
|
case VertexComponentType.Float4: return 16;
|
||||||
case VertexComponentType.UByte4: return 4;
|
case VertexComponentType.UByte4: return 4;
|
||||||
case VertexComponentType.Colour: return 4;
|
case VertexComponentType.Colour: return 4;
|
||||||
case VertexComponentType.Dec3N: return 4;
|
case VertexComponentType.RGBA8SNorm: return 4;
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ namespace CodeWalker.GameFiles
|
|||||||
case VertexComponentType.Float4: return 4;
|
case VertexComponentType.Float4: return 4;
|
||||||
case VertexComponentType.UByte4: return 4;
|
case VertexComponentType.UByte4: return 4;
|
||||||
case VertexComponentType.Colour: return 4;
|
case VertexComponentType.Colour: return 4;
|
||||||
case VertexComponentType.Dec3N: return 4;
|
case VertexComponentType.RGBA8SNorm: return 4;
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ namespace CodeWalker.Rendering
|
|||||||
case VertexComponentType.Float4: return Format.R32G32B32A32_Float;
|
case VertexComponentType.Float4: return Format.R32G32B32A32_Float;
|
||||||
case VertexComponentType.UByte4: return Format.R8G8B8A8_UInt;
|
case VertexComponentType.UByte4: return Format.R8G8B8A8_UInt;
|
||||||
case VertexComponentType.Colour: return Format.R8G8B8A8_UNorm;
|
case VertexComponentType.Colour: return Format.R8G8B8A8_UNorm;
|
||||||
case VertexComponentType.Dec3N: return Format.R10G10B10A2_UNorm;
|
case VertexComponentType.RGBA8SNorm: return Format.R8G8B8A8_SNorm;
|
||||||
default: return Format.Unknown;
|
default: return Format.Unknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user