Locking render textures to current dimension layer

This commit is contained in:
misabiko 2022-05-15 11:03:25 -04:00
parent 686e543b56
commit f6fd5798b2
2 changed files with 3108 additions and 18395 deletions

File diff suppressed because it is too large Load Diff

View File

@ -108,10 +108,11 @@ public class WorldSwitcher : MonoBehaviour {
void ResetQuadPositions() {
Camera currCam = worldInfos[currentWorldIndex].camera;
LayerMask currLayer = worldInfos[currentWorldIndex].layer;
for (int i = 0; i < worldInfos.Length; ++i) {
bool usingRenderTexture = i != currentWorldIndex;
worldInfos[i].SetUsingRenderTexture(usingRenderTexture);
worldInfos[i].SetUsingRenderTexture(usingRenderTexture, currLayer);
if (usingRenderTexture) {
bool fromRight = i - currentWorldIndex > 0;
@ -128,12 +129,14 @@ struct WorldInfo {
[HideInInspector] public RenderTexture texture;
public Transform renderQuad;
[HideInInspector] public Material material;
public int layer;
static readonly int CameraTexture = Shader.PropertyToID("_CameraTexture");
public void SetUsingRenderTexture(bool usingTexture) {
public void SetUsingRenderTexture(bool usingTexture, int layer) {
if (usingTexture) {
camera.targetTexture = texture;
renderQuad.gameObject.SetActive(true);
renderQuad.gameObject.layer = layer;
}else {
camera.targetTexture = null;
renderQuad.gameObject.SetActive(false);
@ -145,8 +148,8 @@ struct WorldInfo {
if (usingTexture)
camera.targetTexture = null;
//float height = 2f * Mathf.Atan(Mathf.Deg2Rad * camera.fieldOfView) * quadOffset;
renderQuad.localScale = new Vector3(camera.aspect, 1f, 1f);
float height = 2f * Mathf.Atan(Mathf.Deg2Rad * camera.fieldOfView) * quadOffset;
renderQuad.localScale = new Vector3(camera.aspect * height, height, 1f);
texture = new RenderTexture(Screen.width, Screen.height, 32);
material.SetTexture(CameraTexture, texture);