Skip to content

Commit 66dbd77

Browse files
committed
Optimize neighborhood rendering a bunch
1 parent dc3c2da commit 66dbd77

File tree

8 files changed

+46
-3
lines changed

8 files changed

+46
-3
lines changed

Assets/Scenes/Neighborhood.unity

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/OpenTS2/Content/DBPF/Effects/DecalEffect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public DecalEffect(string textureName, float life, Vector2 textureOffset)
2222
public GameObject CreateGameObject()
2323
{
2424
var gameObject = new GameObject(TextureName, typeof(SwarmDecal), typeof(MeshFilter), typeof(MeshRenderer));
25+
gameObject.layer = Layers.NonReflective;
2526
var swarmDecal = gameObject.GetComponent<SwarmDecal>();
2627
swarmDecal.SetDecal(this);
2728
return gameObject;

Assets/Scripts/OpenTS2/Content/EffectsManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace OpenTS2.Content
1010
{
1111
public class EffectsManager
1212
{
13+
[GameProperty(false)]
14+
public static bool EnableEffects = true;
1315
public static EffectsManager Instance { get; set; }
1416

1517
public EffectsManager()
@@ -44,6 +46,8 @@ public bool HasEffect(string effectName)
4446

4547
public SwarmParticleSystem CreateEffect(string effectName)
4648
{
49+
if (!EnableEffects) return null;
50+
4751
var visualEffect = _effects.GetEffectByName(effectName);
4852

4953
var system = new GameObject("SwarmParticleSystem", typeof(ParticleSystem), typeof(SwarmParticleSystem));
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace OpenTS2.Content
8+
{
9+
public static class Layers
10+
{
11+
public const int Default = 0;
12+
public const int TransparentFX = 1;
13+
public const int IgnoreRaycast = 2;
14+
public const int Terrain = 3;
15+
public const int Water = 4;
16+
public const int UI = 5;
17+
public const int NonReflective = 6;
18+
}
19+
}

Assets/Scripts/OpenTS2/Content/Layers.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/OpenTS2/Rendering/CameraReflection.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
using OpenTS2.Content;
2+
using OpenTS2.Engine;
13
using System.Collections;
24
using System.Collections.Generic;
35
using UnityEngine;
46

57
[RequireComponent(typeof(Camera))]
68
public class CameraReflection : MonoBehaviour
79
{
10+
[GameProperty(false)]
11+
public static float ReflectionResolutionFactor = 0.5f;
812
public Color ReflectionSkyColor;
913
public static CameraReflection Instance;
1014
public Camera reflectionCamera;
@@ -15,11 +19,13 @@ public class CameraReflection : MonoBehaviour
1519
private void Awake()
1620
{
1721
Instance = this;
18-
ReflectionTexture = new RenderTexture(Screen.width, Screen.height, 24);
22+
ReflectionTexture = new RenderTexture((int)(Screen.width * ReflectionResolutionFactor), (int)(Screen.height * ReflectionResolutionFactor), 24);
1923
var reflectionCameraGameObject = new GameObject("Reflection Camera");
2024
reflectionCamera = reflectionCameraGameObject.AddComponent<Camera>();
2125
_camera = GetComponent<Camera>();
2226
reflectionCamera.CopyFrom(_camera);
27+
reflectionCamera.allowMSAA = false;
28+
reflectionCamera.cullingMask = 1 << Layers.Default | 1 << Layers.Terrain;
2329
reflectionCamera.targetTexture = ReflectionTexture;
2430
reflectionCamera.enabled = false;
2531
reflectionCamera.backgroundColor = ReflectionSkyColor;

Assets/Scripts/OpenTS2/Scenes/NeighborhoodDecorations.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace OpenTS2.Scenes
1818
{
1919
public class NeighborhoodDecorations : AssetReferenceComponent
2020
{
21+
[GameProperty(false)]
2122
private static bool EnableBatching = true;
2223
private Dictionary<string, Material> _roadMaterialLookup = new Dictionary<string, Material>();
2324
private Transform _decorationsParent;
@@ -90,6 +91,7 @@ private void RenderRoad(RoadDecoration road)
9091
parent = _roadsParent
9192
}
9293
};
94+
roadObject.layer = Layers.NonReflective;
9395

9496
var roadMesh = new Mesh();
9597
roadMesh.SetVertices(road.RoadCorners);

ProjectSettings/TagManager.asset

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)