Browse Source

Fixed marshaling of multi-dimensional arrays of QGLTextures, and add a second unlit material layer with additive blending for models that use fullbright textures

console
Nico de Poel 5 years ago
parent
commit
4a7155bb1b
  1. 4
      Assets/Scripts/Data/QModel.cs
  2. 4
      Assets/Scripts/Modules/RenderModule.Interop.cs
  3. 21
      Assets/Scripts/Modules/RenderModule.cs

4
Assets/Scripts/Data/QModel.cs

@ -117,8 +117,8 @@ public class QAliasHeader
public int poseVerts;
public int poseData;
public int commands;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = QConstants.MaxSkins)] public IntPtr[] glTextures;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = QConstants.MaxSkins)] public IntPtr[] fbTextures;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = QConstants.MaxSkins * 4)] public IntPtr[] glTextures;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = QConstants.MaxSkins * 4)] public IntPtr[] fbTextures;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = QConstants.MaxSkins)] public int[] texels;
// Actually variable sized, but we receive an additional pointer to the first element so we can manually marshal the entire array

4
Assets/Scripts/Modules/RenderModule.Interop.cs

@ -72,8 +72,8 @@ public partial class RenderModule: CallbackHandler<RenderModule>
var fbTextures = new QGLTexture[QConstants.MaxSkins][];
for (int i = 0; i < QConstants.MaxSkins; ++i)
{
glTextures[i] = header.glTextures[i].ToStructArray<QGLTexture>(4);
fbTextures[i] = header.fbTextures[i].ToStructArray<QGLTexture>(4);
glTextures[i] = header.glTextures[i * 4].ToStructArray<QGLTexture>(4);
fbTextures[i] = header.fbTextures[i * 4].ToStructArray<QGLTexture>(4);
}
return GetSelf(target).UploadAliasModel(

21
Assets/Scripts/Modules/RenderModule.cs

@ -64,10 +64,27 @@ public partial class RenderModule
material.mainTexture = textures[texNum];
}
Material fbMaterial = null;
if (fbTextures != null && fbTextures[0] != null && fbTextures[0][0] != null)
{
var fbTexNum = fbTextures[0][0].texNum;
if (fbTexNum > 0 && textures.ContainsKey(fbTexNum))
{
fbMaterial = new Material(Shader.Find("Universal Render Pipeline/Unlit"));
fbMaterial.mainTexture = textures[fbTexNum];
fbMaterial.SetFloat("_Surface", 1); // Transparent
fbMaterial.SetFloat("_Blend", 2); // Additive
}
}
if (header.numPoses > 1)
{
var mr = go.AddComponent<SkinnedMeshRenderer>();
if (fbMaterial != null)
mr.materials = new[] { material, fbMaterial };
else
mr.material = material;
mr.sharedMesh = mesh;
mr.shadowCastingMode = ShadowCastingMode.Off;
mr.receiveShadows = false;
@ -82,7 +99,11 @@ public partial class RenderModule
var mf = go.AddComponent<MeshFilter>();
mf.sharedMesh = mesh;
var mr = go.AddComponent<MeshRenderer>();
if (fbMaterial != null)
mr.materials = new[] { material, fbMaterial };
else
mr.material = material;
mr.shadowCastingMode = ShadowCastingMode.Off;
mr.receiveShadows = false;
mr.lightProbeUsage = LightProbeUsage.Off;

Loading…
Cancel
Save