Created
September 1, 2015 14:27
-
-
Save voxelbustersold/3b7c5fb6cd866dcc560b to your computer and use it in GitHub Desktop.
Selective Rendering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
//Ideally can use Layers but want to avoid as, max layers avaialble isn't a big number. | |
public class SelectiveRendering : MonoBehaviour | |
{ | |
//Working version - Can expect as transform values are required for rendering. But not sure if this is optimal way. | |
[SerializeField] | |
private GameObject[] m_targetObjects; | |
void OnPreCull() | |
{ | |
foreach(GameObject _each in m_targetObjects) | |
{ | |
_each.transform.localScale = Vector3.one; | |
} | |
} | |
void OnPostRender() | |
{ | |
foreach(GameObject _each in m_targetObjects) | |
{ | |
_each.transform.localScale = Vector3.zero; | |
} | |
} | |
/* Not working - Ideally, this approach is cleaner but not getting the expected result. | |
[SerializeField] | |
private Renderer[] m_targetObjects; | |
//Enable the renderers required for this camera. | |
void OnPreCull() | |
{ | |
foreach(Renderer _each in m_targetObjects) | |
{ | |
_each.renderer.enabled = true; | |
} | |
} | |
//Disabling them so that the target renderers won't be rendered anywhere else. | |
void OnPostRender() | |
{ | |
foreach(Renderer _each in m_targetObjects) | |
{ | |
_each.renderer.enabled = false; | |
} | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment