Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack of fixes #13

Merged
merged 11 commits into from Sep 25, 2017
Prev Previous commit
Next Next commit
Fix SEGI scene view camera conflicts with the game view
  • Loading branch information
nxrighthere committed Sep 24, 2017
commit ab4380f245b7435c261731585d11d602846b3631
108 changes: 60 additions & 48 deletions SEGI.cs
Expand Up @@ -514,11 +514,12 @@ void Init()

voxelizationShader = Shader.Find("Hidden/SEGIVoxelizeScene");
voxelTracingShader = Shader.Find("Hidden/SEGITraceScene");

material = new Material(Shader.Find("Hidden/SEGI"));
material.hideFlags = HideFlags.HideAndDontSave;



if (!material) {
material = new Material(Shader.Find("Hidden/SEGI"));
material.hideFlags = HideFlags.HideAndDontSave;
}

//Get the camera attached to this game object
attachedCamera = this.GetComponent<Camera>();
attachedCamera.depthTextureMode |= DepthTextureMode.Depth;
Expand Down Expand Up @@ -561,57 +562,67 @@ void Init()

//Create the proxy camera objects responsible for rendering the scene to voxelize the scene. If they already exist, destroy them
GameObject vcgo = GameObject.Find("SEGI_VOXEL_CAMERA");
if (vcgo)
DestroyImmediate(vcgo);

voxelCameraGO = new GameObject("SEGI_VOXEL_CAMERA");
voxelCameraGO.hideFlags = HideFlags.HideAndDontSave;

voxelCamera = voxelCameraGO.AddComponent<Camera>();
voxelCamera.enabled = false;
voxelCamera.orthographic = true;
voxelCamera.orthographicSize = voxelSpaceSize * 0.5f;
voxelCamera.nearClipPlane = 0.0f;
voxelCamera.farClipPlane = voxelSpaceSize;
voxelCamera.depth = -2;
voxelCamera.renderingPath = RenderingPath.Forward;
voxelCamera.clearFlags = CameraClearFlags.Color;
voxelCamera.backgroundColor = Color.black;
voxelCamera.useOcclusionCulling = false;

if (!vcgo) {
voxelCameraGO = new GameObject("SEGI_VOXEL_CAMERA");
voxelCameraGO.hideFlags = HideFlags.HideAndDontSave;

GameObject lvp = GameObject.Find("SEGI_LEFT_VOXEL_VIEW");
if (lvp)
DestroyImmediate(lvp);
voxelCamera = voxelCameraGO.AddComponent<Camera>();
voxelCamera.enabled = false;
voxelCamera.orthographic = true;
voxelCamera.orthographicSize = voxelSpaceSize * 0.5f;
voxelCamera.nearClipPlane = 0.0f;
voxelCamera.farClipPlane = voxelSpaceSize;
voxelCamera.depth = -2;
voxelCamera.renderingPath = RenderingPath.Forward;
voxelCamera.clearFlags = CameraClearFlags.Color;
voxelCamera.backgroundColor = Color.black;
voxelCamera.useOcclusionCulling = false;
}
else
{
voxelCameraGO = vcgo;
voxelCamera = vcgo.GetComponent<Camera>();
}

leftViewPoint = new GameObject("SEGI_LEFT_VOXEL_VIEW");
leftViewPoint.hideFlags = HideFlags.HideAndDontSave;
GameObject lvp = GameObject.Find("SEGI_LEFT_VOXEL_VIEW");

if (!lvp) {
leftViewPoint = new GameObject("SEGI_LEFT_VOXEL_VIEW");
leftViewPoint.hideFlags = HideFlags.HideAndDontSave;
}
else
{
leftViewPoint = lvp;
}

GameObject tvp = GameObject.Find("SEGI_TOP_VOXEL_VIEW");
if (tvp)
DestroyImmediate(tvp);

topViewPoint = new GameObject("SEGI_TOP_VOXEL_VIEW");
topViewPoint.hideFlags = HideFlags.HideAndDontSave;


//Get blue noise textures
blueNoise = null;
blueNoise = new Texture2D[64];
for (int i = 0; i < 64; i++)
{
string fileName = "LDR_RGBA_" + i.ToString();
Texture2D blueNoiseTexture = Resources.Load("Noise Textures/" + fileName) as Texture2D;

if (!tvp) {
topViewPoint = new GameObject("SEGI_TOP_VOXEL_VIEW");
topViewPoint.hideFlags = HideFlags.HideAndDontSave;
}
else
{
topViewPoint = tvp;
}

if (blueNoiseTexture == null)
{
Debug.LogWarning("Unable to find noise texture \"Assets/SEGI/Resources/Noise Textures/" + fileName + "\" for SEGI!");
}
//Get blue noise textures
blueNoise = null;
blueNoise = new Texture2D[64];
for (int i = 0; i < 64; i++)
{
string fileName = "LDR_RGBA_" + i.ToString();
Texture2D blueNoiseTexture = Resources.Load("Noise Textures/" + fileName) as Texture2D;

blueNoise[i] = blueNoiseTexture;
if (blueNoiseTexture == null)
{
Debug.LogWarning("Unable to find noise texture \"Assets/SEGI/Resources/Noise Textures/" + fileName + "\" for SEGI!");
}

}

blueNoise[i] = blueNoiseTexture;

}

//Setup sun depth texture
if (sunDepthTexture)
Expand Down Expand Up @@ -862,6 +873,7 @@ void OnPreRender()
}
else
{
//GI is still flickering a bit when the scene view and the game view are opened at the same time
origin = transform.position + transform.forward * voxelSpaceSize / 4.0f;
}
//Lock the voxel volume origin based on the interval
Expand Down