Browse Source

Added layer masks to separate game and view model, and added a secondary overlay camera to render the view model separately after the main pass. Fixes gun view model clipping into walls.

console
Nico de Poel 5 years ago
parent
commit
4adc71eca8
  1. 127
      Assets/Scenes/Default.unity
  2. 9
      Assets/Scripts/Bootstrap.cs
  3. 5
      Assets/Scripts/Game/Entity.cs
  4. 8
      Assets/Scripts/Game/GameState.cs
  5. 13
      Assets/Scripts/Layers.cs
  6. 4
      ProjectSettings/TagManager.asset

127
Assets/Scenes/Default.unity

@ -153,6 +153,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 941b1c44c09860d4fa2547fa7c914d55, type: 3} m_Script: {fileID: 11500000, guid: 941b1c44c09860d4fa2547fa7c914d55, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
mainCamera: {fileID: 963194227}
visualStyles: visualStyles:
- {fileID: 11400000, guid: d187fe54fb9a3e047bf4cec083877e72, type: 2} - {fileID: 11400000, guid: d187fe54fb9a3e047bf4cec083877e72, type: 2}
--- !u!4 &157597865 --- !u!4 &157597865
@ -169,6 +170,122 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 2 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &567286279
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 567286283}
- component: {fileID: 567286282}
- component: {fileID: 567286281}
- component: {fileID: 567286280}
m_Layer: 0
m_Name: View Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &567286280
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 567286279}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 1
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
--- !u!81 &567286281
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 567286279}
m_Enabled: 1
--- !u!20 &567286282
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 567286279}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 4
far clip plane: 16384
field of view: 70
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 128
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 0
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &567286283
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 567286279}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 963194228}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &705507993 --- !u!1 &705507993
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -314,13 +431,13 @@ Camera:
height: 1 height: 1
near clip plane: 4 near clip plane: 4
far clip plane: 16384 far clip plane: 16384
field of view: 60
field of view: 70
orthographic: 0 orthographic: 0
orthographic size: 5 orthographic size: 5
m_Depth: -1 m_Depth: -1
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295
m_Bits: 64
m_RenderingPath: -1 m_RenderingPath: -1
m_TargetTexture: {fileID: 0} m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0 m_TargetDisplay: 0
@ -342,7 +459,8 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 250, z: -2500} m_LocalPosition: {x: 0, y: 250, z: -2500}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 567286283}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -362,7 +480,8 @@ MonoBehaviour:
m_RequiresDepthTextureOption: 2 m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2 m_RequiresOpaqueTextureOption: 2
m_CameraType: 0 m_CameraType: 0
m_Cameras: []
m_Cameras:
- {fileID: 567286282}
m_RendererIndex: -1 m_RendererIndex: -1
m_VolumeLayerMask: m_VolumeLayerMask:
serializedVersion: 2 serializedVersion: 2

9
Assets/Scripts/Bootstrap.cs

@ -10,6 +10,9 @@ public class Bootstrap : MonoBehaviour
private UniQuake uq; private UniQuake uq;
[SerializeField]
private Camera mainCamera;
[SerializeField] [SerializeField]
private List<VisualStyle> visualStyles = new List<VisualStyle>(); private List<VisualStyle> visualStyles = new List<VisualStyle>();
@ -26,7 +29,7 @@ public class Bootstrap : MonoBehaviour
uq.BaseGame = MissionPack.Quake; uq.BaseGame = MissionPack.Quake;
uq.ModDirectory = mod; uq.ModDirectory = mod;
uq.AdditionalArguments = ParseArgs(); uq.AdditionalArguments = ParseArgs();
uq.Camera = Camera.main; // This can be any one of four cameras for split-screen, each with its own culling layer
uq.Camera = mainCamera; // This can be any one of four cameras for split-screen, each with its own culling layer
uq.SetVisualStyle(visualStyles[0]); uq.SetVisualStyle(visualStyles[0]);
} }
@ -36,7 +39,7 @@ public class Bootstrap : MonoBehaviour
uq.BaseGame = MissionPack.Hipnotic; uq.BaseGame = MissionPack.Hipnotic;
uq.ModDirectory = mod; uq.ModDirectory = mod;
uq.AdditionalArguments = ParseArgs(); uq.AdditionalArguments = ParseArgs();
uq.Camera = Camera.main;
uq.Camera = mainCamera;
uq.SetVisualStyle(visualStyles[0]); uq.SetVisualStyle(visualStyles[0]);
} }
@ -46,7 +49,7 @@ public class Bootstrap : MonoBehaviour
uq.BaseGame = MissionPack.Rogue; uq.BaseGame = MissionPack.Rogue;
uq.ModDirectory = mod; uq.ModDirectory = mod;
uq.AdditionalArguments = ParseArgs(); uq.AdditionalArguments = ParseArgs();
uq.Camera = Camera.main;
uq.Camera = mainCamera;
uq.SetVisualStyle(visualStyles[0]); uq.SetVisualStyle(visualStyles[0]);
} }

5
Assets/Scripts/Game/Entity.cs

@ -28,7 +28,10 @@ public class Entity
private void CreateGameObject() private void CreateGameObject()
{ {
gameObject = new GameObject($"Entity_{entityNum}");
gameObject = new GameObject($"Entity_{entityNum}")
{
layer = entityNum == 0 ? (int)Layers.View1 : (int)Layers.Game1
};
skinnedMeshRenderer = gameObject.AddComponent<SkinnedMeshRenderer>(); skinnedMeshRenderer = gameObject.AddComponent<SkinnedMeshRenderer>();
skinnedMeshRenderer.enabled = false; skinnedMeshRenderer.enabled = false;

8
Assets/Scripts/Game/GameState.cs

@ -27,7 +27,7 @@ public class GameState
Destroy(); Destroy();
Resources.UnloadUnusedAssets(); Resources.UnloadUnusedAssets();
worldGameObject = new GameObject(worldModel.Name);
worldGameObject = new GameObject(worldModel.Name) { layer = (int)Layers.Game1 };
// The first sub-model contains all of the static geometry // The first sub-model contains all of the static geometry
var subModel = worldModel.GetSubModel(0); var subModel = worldModel.GetSubModel(0);
@ -37,11 +37,11 @@ public class GameState
private GameObject CreateBrushGameObject(BrushModel.SubModel subModel) private GameObject CreateBrushGameObject(BrushModel.SubModel subModel)
{ {
var subModelGO = new GameObject(subModel.Name);
var subModelGO = new GameObject(subModel.Name) { layer = (int)Layers.Game1 };
foreach (var surfaceMesh in subModel.SurfaceMeshes) foreach (var surfaceMesh in subModel.SurfaceMeshes)
{ {
var meshGO = new GameObject(surfaceMesh.Mesh.name);
var meshGO = new GameObject(surfaceMesh.Mesh.name) { layer = (int)Layers.Game1 };
meshGO.transform.SetParent(subModelGO.transform); meshGO.transform.SetParent(subModelGO.transform);
var mf = meshGO.AddComponent<MeshFilter>(); var mf = meshGO.AddComponent<MeshFilter>();
@ -107,7 +107,7 @@ public class GameState
return; return;
} }
var brushModelGO = new GameObject(brushModel.Name);
var brushModelGO = new GameObject(brushModel.Name) { layer = (int)Layers.Game1 };
for (int i = 0; i < brushModel.SubModelCount; ++i) for (int i = 0; i < brushModel.SubModelCount; ++i)
{ {
var subModelGO = CreateBrushGameObject(brushModel.GetSubModel(i)); var subModelGO = CreateBrushGameObject(brushModel.GetSubModel(i));

13
Assets/Scripts/Layers.cs

@ -0,0 +1,13 @@
public enum Layers
{
Game1 = 6,
View1 = 7,
}
public static class LayerExtensions
{
public static int ToLayerMask(this Layers layer)
{
return 1 << (int)layer;
}
}

4
ProjectSettings/TagManager.asset

@ -11,8 +11,8 @@ TagManager:
- -
- Water - Water
- UI - UI
-
-
- Game1
- ViewModel1
- -
- -
- -

Loading…
Cancel
Save