mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add culling for offscreen decals
This commit is contained in:
parent
3c5fcedca4
commit
23c309fa9a
Binary file not shown.
Binary file not shown.
@ -51,6 +51,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DecalBoundsBehaviour.cs" />
|
||||
<Compile Include="DecalConfig.cs" />
|
||||
<Compile Include="DecalIconFixer.cs" />
|
||||
<Compile Include="DecalPropertyIDs.cs" />
|
||||
|
12
Source/ConformalDecals/DecalBoundsBehaviour.cs
Normal file
12
Source/ConformalDecals/DecalBoundsBehaviour.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ConformalDecals {
|
||||
public class DecalBoundsBehaviour : MonoBehaviour {
|
||||
public ModuleConformalDecal decalRenderer;
|
||||
|
||||
private void OnWillRenderObject() {
|
||||
decalRenderer._shouldRender = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -48,6 +48,8 @@ namespace ConformalDecals {
|
||||
/// </remarks>
|
||||
[KSPField] public string decalProjector = "Decal-Projector";
|
||||
|
||||
[KSPField] public string decalBounds = "Decal-Bounds";
|
||||
|
||||
// Parameters
|
||||
|
||||
[KSPField] public bool scaleAdjustable = true;
|
||||
@ -124,6 +126,7 @@ namespace ConformalDecals {
|
||||
[KSPField] public Transform decalBackTransform;
|
||||
[KSPField] public Transform decalModelTransform;
|
||||
[KSPField] public Transform decalProjectorTransform;
|
||||
[KSPField] public Transform decalBoundsTransform;
|
||||
|
||||
[KSPField] public Material backMaterial;
|
||||
[KSPField] public Vector2 backTextureBaseScale;
|
||||
@ -140,6 +143,8 @@ namespace ConformalDecals {
|
||||
private Material _decalMaterial;
|
||||
private Material _previewMaterial;
|
||||
|
||||
internal bool _shouldRender;
|
||||
|
||||
private int DecalQueue {
|
||||
get {
|
||||
_decalQueueCounter++;
|
||||
@ -204,6 +209,15 @@ namespace ConformalDecals {
|
||||
if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'.");
|
||||
}
|
||||
|
||||
// find bounds transform
|
||||
if (string.IsNullOrEmpty(decalBounds)) {
|
||||
decalBoundsTransform = part.transform;
|
||||
}
|
||||
else {
|
||||
decalBoundsTransform = part.FindModelTransform(decalBounds);
|
||||
if (decalBoundsTransform == null) throw new FormatException($"Could not find decalBounds transform: '{decalBounds}'.");
|
||||
}
|
||||
|
||||
// get back material if necessary
|
||||
if (updateBackScale) {
|
||||
this.Log("Getting material and base scale for back material");
|
||||
@ -303,6 +317,9 @@ namespace ConformalDecals {
|
||||
|
||||
materialProperties.RenderQueue = DecalQueue;
|
||||
|
||||
var boundsBehaviour = decalBoundsTransform.gameObject.AddComponent<DecalBoundsBehaviour>();
|
||||
boundsBehaviour.decalRenderer = this;
|
||||
|
||||
UpdateMaterials();
|
||||
|
||||
if (HighLogic.LoadedSceneIsGame) {
|
||||
@ -419,6 +436,10 @@ namespace ConformalDecals {
|
||||
UpdateScale();
|
||||
}
|
||||
|
||||
protected void Update() {
|
||||
_shouldRender = false;
|
||||
}
|
||||
|
||||
protected void UpdateScale() {
|
||||
var aspectRatio = materialProperties.AspectRatio;
|
||||
Vector2 size;
|
||||
@ -592,7 +613,7 @@ namespace ConformalDecals {
|
||||
}
|
||||
}
|
||||
|
||||
protected void Render(Camera camera) {
|
||||
public void Render(Camera camera) {
|
||||
if (!_isAttached) return;
|
||||
|
||||
// render on each target object
|
||||
|
Loading…
Reference in New Issue
Block a user