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>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="DecalBoundsBehaviour.cs" />
|
||||||
<Compile Include="DecalConfig.cs" />
|
<Compile Include="DecalConfig.cs" />
|
||||||
<Compile Include="DecalIconFixer.cs" />
|
<Compile Include="DecalIconFixer.cs" />
|
||||||
<Compile Include="DecalPropertyIDs.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>
|
/// </remarks>
|
||||||
[KSPField] public string decalProjector = "Decal-Projector";
|
[KSPField] public string decalProjector = "Decal-Projector";
|
||||||
|
|
||||||
|
[KSPField] public string decalBounds = "Decal-Bounds";
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
|
|
||||||
[KSPField] public bool scaleAdjustable = true;
|
[KSPField] public bool scaleAdjustable = true;
|
||||||
@ -124,6 +126,7 @@ namespace ConformalDecals {
|
|||||||
[KSPField] public Transform decalBackTransform;
|
[KSPField] public Transform decalBackTransform;
|
||||||
[KSPField] public Transform decalModelTransform;
|
[KSPField] public Transform decalModelTransform;
|
||||||
[KSPField] public Transform decalProjectorTransform;
|
[KSPField] public Transform decalProjectorTransform;
|
||||||
|
[KSPField] public Transform decalBoundsTransform;
|
||||||
|
|
||||||
[KSPField] public Material backMaterial;
|
[KSPField] public Material backMaterial;
|
||||||
[KSPField] public Vector2 backTextureBaseScale;
|
[KSPField] public Vector2 backTextureBaseScale;
|
||||||
@ -140,6 +143,8 @@ namespace ConformalDecals {
|
|||||||
private Material _decalMaterial;
|
private Material _decalMaterial;
|
||||||
private Material _previewMaterial;
|
private Material _previewMaterial;
|
||||||
|
|
||||||
|
internal bool _shouldRender;
|
||||||
|
|
||||||
private int DecalQueue {
|
private int DecalQueue {
|
||||||
get {
|
get {
|
||||||
_decalQueueCounter++;
|
_decalQueueCounter++;
|
||||||
@ -204,6 +209,15 @@ namespace ConformalDecals {
|
|||||||
if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'.");
|
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
|
// get back material if necessary
|
||||||
if (updateBackScale) {
|
if (updateBackScale) {
|
||||||
this.Log("Getting material and base scale for back material");
|
this.Log("Getting material and base scale for back material");
|
||||||
@ -303,6 +317,9 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
materialProperties.RenderQueue = DecalQueue;
|
materialProperties.RenderQueue = DecalQueue;
|
||||||
|
|
||||||
|
var boundsBehaviour = decalBoundsTransform.gameObject.AddComponent<DecalBoundsBehaviour>();
|
||||||
|
boundsBehaviour.decalRenderer = this;
|
||||||
|
|
||||||
UpdateMaterials();
|
UpdateMaterials();
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
@ -419,6 +436,10 @@ namespace ConformalDecals {
|
|||||||
UpdateScale();
|
UpdateScale();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void Update() {
|
||||||
|
_shouldRender = false;
|
||||||
|
}
|
||||||
|
|
||||||
protected void UpdateScale() {
|
protected void UpdateScale() {
|
||||||
var aspectRatio = materialProperties.AspectRatio;
|
var aspectRatio = materialProperties.AspectRatio;
|
||||||
Vector2 size;
|
Vector2 size;
|
||||||
@ -592,7 +613,7 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Render(Camera camera) {
|
public void Render(Camera camera) {
|
||||||
if (!_isAttached) return;
|
if (!_isAttached) return;
|
||||||
|
|
||||||
// render on each target object
|
// render on each target object
|
||||||
|
Loading…
Reference in New Issue
Block a user