Pull request #36: Much better color format for render textures

Merge in CEGJ/creative-jam-20 from jason to main

* commit '90207c5b47b8af9ba824b32ee1f9ca10d73fff25':
  Much better color format for render textures
This commit is contained in:
Jason Durand 01 2022-05-15 20:04:53 +00:00
commit 2f7c894a93

View File

@ -31,6 +31,7 @@ public class WorldSwitcher : MonoBehaviour {
int lastWorldIndex;
int currentWorldIndex;
Coroutine transition;
bool supportHDR;
static readonly int UVOffset = Shader.PropertyToID("_UVOffset");
//static readonly int Opacity = Shader.PropertyToID("_Opacity");
@ -46,10 +47,12 @@ public class WorldSwitcher : MonoBehaviour {
currentWorldIndex = 1;
lastWorldIndex = 0;
supportHDR = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.DefaultHDR);
for (int i = 0; i < worldInfos.Length; i++) {
worldInfos[i].material = worldInfos[i].renderQuad.GetComponent<Renderer>().material;
worldInfos[i].GenerateRenderTexture(quadOffset);
worldInfos[i].GenerateRenderTexture(quadOffset, supportHDR);
}
ResetQuadPositions();
@ -65,7 +68,7 @@ public class WorldSwitcher : MonoBehaviour {
//TODO Block window resize during transition?
foreach (WorldInfo worldInfo in worldInfos) {
if (Screen.width != worldInfo.texture.width || Screen.height != worldInfo.texture.height)
worldInfo.GenerateRenderTexture(quadOffset);
worldInfo.GenerateRenderTexture(quadOffset, supportHDR);
}
lastWorldIndex = currentWorldIndex;
@ -228,7 +231,7 @@ struct WorldInfo {
}
}
public void GenerateRenderTexture(float quadOffset) {
public void GenerateRenderTexture(float quadOffset, bool supportHDR) {
bool usingTexture = !ReferenceEquals(camera.targetTexture, null);
if (usingTexture)
camera.targetTexture = null;
@ -236,6 +239,8 @@ struct WorldInfo {
float height = 2f * Mathf.Tan(Mathf.Deg2Rad * camera.fieldOfView / 2f) * quadOffset;
renderQuad.localScale = new Vector3(camera.aspect * height, height, 1f);
texture = new RenderTexture(Screen.width, Screen.height, 32);
if (supportHDR)
texture.format = RenderTextureFormat.DefaultHDR;
material.SetTexture(CameraTexture, texture);