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. 25
      Assets/Scripts/Modules/RenderModule.cs

4
Assets/Scripts/Data/QModel.cs

@ -117,8 +117,8 @@ public class QAliasHeader
public int poseVerts; public int poseVerts;
public int poseData; public int poseData;
public int commands; 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; [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 // 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][]; var fbTextures = new QGLTexture[QConstants.MaxSkins][];
for (int i = 0; i < QConstants.MaxSkins; ++i) 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( return GetSelf(target).UploadAliasModel(

25
Assets/Scripts/Modules/RenderModule.cs

@ -64,10 +64,27 @@ public partial class RenderModule
material.mainTexture = textures[texNum]; 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) if (header.numPoses > 1)
{ {
var mr = go.AddComponent<SkinnedMeshRenderer>(); var mr = go.AddComponent<SkinnedMeshRenderer>();
mr.material = material;
if (fbMaterial != null)
mr.materials = new[] { material, fbMaterial };
else
mr.material = material;
mr.sharedMesh = mesh; mr.sharedMesh = mesh;
mr.shadowCastingMode = ShadowCastingMode.Off; mr.shadowCastingMode = ShadowCastingMode.Off;
mr.receiveShadows = false; mr.receiveShadows = false;
@ -82,7 +99,11 @@ public partial class RenderModule
var mf = go.AddComponent<MeshFilter>(); var mf = go.AddComponent<MeshFilter>();
mf.sharedMesh = mesh; mf.sharedMesh = mesh;
var mr = go.AddComponent<MeshRenderer>(); var mr = go.AddComponent<MeshRenderer>();
mr.material = material;
if (fbMaterial != null)
mr.materials = new[] { material, fbMaterial };
else
mr.material = material;
mr.shadowCastingMode = ShadowCastingMode.Off; mr.shadowCastingMode = ShadowCastingMode.Off;
mr.receiveShadows = false; mr.receiveShadows = false;
mr.lightProbeUsage = LightProbeUsage.Off; mr.lightProbeUsage = LightProbeUsage.Off;

Loading…
Cancel
Save