namespacify everything
This commit is contained in:
@@ -1,182 +1,181 @@
|
||||
using FlaxEditor.Content.Settings;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace Game
|
||||
namespace Game;
|
||||
|
||||
/// <summary>
|
||||
/// CameraRender Script.
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
public class CameraRender : PostProcessEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// CameraRender Script.
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
public class CameraRender : PostProcessEffect
|
||||
public Camera camera;
|
||||
|
||||
private bool lastEnabled;
|
||||
public Material material;
|
||||
|
||||
private MaterialInstance materialInstance;
|
||||
private SceneRenderTask sceneTask;
|
||||
private SceneRenderTask sceneTask2;
|
||||
|
||||
private GPUTexture texture;
|
||||
private GPUTexture texture2;
|
||||
|
||||
//public override PostProcessEffectLocation Location => PostProcessEffectLocation.Default;
|
||||
//public override int Order => 110;
|
||||
//public override bool CanRender => camera.IsActive;
|
||||
|
||||
private bool useMainCamera = true;
|
||||
public bool rescaleModel = true;
|
||||
|
||||
private Actor viewModelHolder;
|
||||
|
||||
private void CreateTextures(int width, int height)
|
||||
{
|
||||
public Camera camera;
|
||||
GPUTextureDescription textureDesc = GPUTextureDescription.New2D(width, height, PixelFormat.R8G8B8A8_UNorm);
|
||||
|
||||
private bool lastEnabled;
|
||||
public Material material;
|
||||
// Prepare texture and SceneRenderTask for viewmodel camera
|
||||
if (texture == null)
|
||||
texture = new GPUTexture();
|
||||
if (texture.Init(ref textureDesc))
|
||||
Console.Print("Failed to create camera texture");
|
||||
|
||||
private MaterialInstance materialInstance;
|
||||
private SceneRenderTask sceneTask;
|
||||
private SceneRenderTask sceneTask2;
|
||||
// Prepare depth texture and SceneRenderTask for viewmodel camera
|
||||
textureDesc.Format = PixelFormat.R8_UNorm;
|
||||
if (texture2 == null)
|
||||
texture2 = new GPUTexture();
|
||||
if (texture2.Init(ref textureDesc))
|
||||
Console.Print("Failed to create camera depth texture");
|
||||
}
|
||||
|
||||
private GPUTexture texture;
|
||||
private GPUTexture texture2;
|
||||
|
||||
//public override PostProcessEffectLocation Location => PostProcessEffectLocation.Default;
|
||||
//public override int Order => 110;
|
||||
//public override bool CanRender => camera.IsActive;
|
||||
|
||||
private bool useMainCamera = true;
|
||||
public bool rescaleModel = true;
|
||||
|
||||
private Actor viewModelHolder;
|
||||
|
||||
private void CreateTextures(int width, int height)
|
||||
public override void OnAwake()
|
||||
{
|
||||
viewModelHolder = Parent.Parent.Parent.Parent.GetChild("ViewModelHolder");
|
||||
if (useMainCamera)
|
||||
{
|
||||
GPUTextureDescription textureDesc = GPUTextureDescription.New2D(width, height, PixelFormat.R8G8B8A8_UNorm);
|
||||
|
||||
// Prepare texture and SceneRenderTask for viewmodel camera
|
||||
if (texture == null)
|
||||
texture = new GPUTexture();
|
||||
if (texture.Init(ref textureDesc))
|
||||
Console.Print("Failed to create camera texture");
|
||||
|
||||
// Prepare depth texture and SceneRenderTask for viewmodel camera
|
||||
textureDesc.Format = PixelFormat.R8_UNorm;
|
||||
if (texture2 == null)
|
||||
texture2 = new GPUTexture();
|
||||
if (texture2.Init(ref textureDesc))
|
||||
Console.Print("Failed to create camera depth texture");
|
||||
}
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
viewModelHolder = Parent.Parent.Parent.Parent.GetChild("ViewModelHolder");
|
||||
if (useMainCamera)
|
||||
camera.IsActive = false;
|
||||
void foo(Actor actor)
|
||||
{
|
||||
camera.IsActive = false;
|
||||
void foo(Actor actor)
|
||||
{
|
||||
actor.Layer = 0;
|
||||
foreach (Actor actChild in actor.GetChildren<Actor>())
|
||||
foo(actChild);
|
||||
}
|
||||
|
||||
foo(viewModelHolder);
|
||||
actor.Layer = 0;
|
||||
foreach (Actor actChild in actor.GetChildren<Actor>())
|
||||
foo(actChild);
|
||||
}
|
||||
|
||||
if (!camera.IsActive)
|
||||
return;
|
||||
|
||||
CreateTextures((int)camera.Viewport.Width, (int)camera.Viewport.Height);
|
||||
|
||||
// Color pass
|
||||
sceneTask = new SceneRenderTask();
|
||||
sceneTask.Order = -1;
|
||||
sceneTask.Camera = camera;
|
||||
sceneTask.ViewMode = ViewMode.Default;
|
||||
sceneTask.Output = texture;
|
||||
sceneTask.ViewFlags = ViewFlags.DefaultGame;
|
||||
sceneTask.Enabled = true;
|
||||
sceneTask.RenderingPercentage = MainRenderTask.Instance.RenderingPercentage;
|
||||
|
||||
// Depth pass
|
||||
sceneTask2 = new SceneRenderTask();
|
||||
sceneTask2.Order = -2;
|
||||
sceneTask2.Camera = camera;
|
||||
sceneTask2.ViewMode = ViewMode.Depth;
|
||||
sceneTask2.Output = texture2;
|
||||
sceneTask2.ViewFlags = ViewFlags.None;
|
||||
sceneTask2.Enabled = true;
|
||||
sceneTask2.RenderingPercentage = MainRenderTask.Instance.RenderingPercentage;
|
||||
|
||||
// Setup material instance and parameters
|
||||
if (materialInstance == null)
|
||||
materialInstance = material.CreateVirtualInstance();
|
||||
materialInstance.SetParameterValue("Input", texture);
|
||||
materialInstance.SetParameterValue("Depth", texture2);
|
||||
|
||||
materialInstance.SetParameterValue("New parameter", true);
|
||||
materialInstance.SetParameterValue("New parameter 0", ChannelMask.Blue);
|
||||
materialInstance.SetParameterValue("New parameter 1", new Color(0.67f));
|
||||
|
||||
materialInstance.SetParameterValue("New parameter 3", 123f);
|
||||
materialInstance.SetParameterValue("New parameter 4", new Float2(1,2));
|
||||
materialInstance.SetParameterValue("New parameter 5", new Float3(1,2,3));
|
||||
materialInstance.SetParameterValue("New parameter 6", new Float4(1,2,3,4));
|
||||
|
||||
materialInstance.SetParameterValue("New parameter 8", 123);
|
||||
materialInstance.SetParameterValue("New parameter 9", new Matrix(0.666f));
|
||||
|
||||
materialInstance.SetParameterValue("New parameter 11", new Quaternion(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
|
||||
materialInstance.SetParameterValue("New parameter 13", new Vector2(1,2));
|
||||
materialInstance.SetParameterValue("New parameter 14", new Vector3(1,2,3));
|
||||
materialInstance.SetParameterValue("New parameter 15", new Vector4(1,2,3,4));
|
||||
//materialInstance.SetParameterValue("New parameter 16", new Transform(new Vector3(1,2,3), new Quaternion(0.5f, 0.5f, 0.5f, 0.5f)));
|
||||
|
||||
lastEnabled = true;
|
||||
foo(viewModelHolder);
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
Destroy(ref sceneTask);
|
||||
Destroy(ref sceneTask2);
|
||||
Destroy(ref texture);
|
||||
Destroy(ref texture2);
|
||||
}
|
||||
if (!camera.IsActive)
|
||||
return;
|
||||
|
||||
public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input,
|
||||
GPUTexture output)
|
||||
{
|
||||
if (texture == null || texture2 == null)
|
||||
return;
|
||||
CreateTextures((int)camera.Viewport.Width, (int)camera.Viewport.Height);
|
||||
|
||||
Renderer.DrawPostFxMaterial(context, ref renderContext, materialInstance, output, input.View());
|
||||
}
|
||||
// Color pass
|
||||
sceneTask = new SceneRenderTask();
|
||||
sceneTask.Order = -1;
|
||||
sceneTask.Camera = camera;
|
||||
sceneTask.ViewMode = ViewMode.Default;
|
||||
sceneTask.Output = texture;
|
||||
sceneTask.ViewFlags = ViewFlags.DefaultGame;
|
||||
sceneTask.Enabled = true;
|
||||
sceneTask.RenderingPercentage = MainRenderTask.Instance.RenderingPercentage;
|
||||
|
||||
private bool lastRescale = false;
|
||||
public override void OnUpdate()
|
||||
{
|
||||
// Depth pass
|
||||
sceneTask2 = new SceneRenderTask();
|
||||
sceneTask2.Order = -2;
|
||||
sceneTask2.Camera = camera;
|
||||
sceneTask2.ViewMode = ViewMode.Depth;
|
||||
sceneTask2.Output = texture2;
|
||||
sceneTask2.ViewFlags = ViewFlags.None;
|
||||
sceneTask2.Enabled = true;
|
||||
sceneTask2.RenderingPercentage = MainRenderTask.Instance.RenderingPercentage;
|
||||
|
||||
// Setup material instance and parameters
|
||||
if (materialInstance == null)
|
||||
materialInstance = material.CreateVirtualInstance();
|
||||
materialInstance.SetParameterValue("Input", texture);
|
||||
materialInstance.SetParameterValue("Depth", texture2);
|
||||
|
||||
materialInstance.SetParameterValue("New parameter", true);
|
||||
materialInstance.SetParameterValue("New parameter 0", ChannelMask.Blue);
|
||||
materialInstance.SetParameterValue("New parameter 1", new Color(0.67f));
|
||||
|
||||
materialInstance.SetParameterValue("New parameter 3", 123f);
|
||||
materialInstance.SetParameterValue("New parameter 4", new Float2(1,2));
|
||||
materialInstance.SetParameterValue("New parameter 5", new Float3(1,2,3));
|
||||
materialInstance.SetParameterValue("New parameter 6", new Float4(1,2,3,4));
|
||||
|
||||
materialInstance.SetParameterValue("New parameter 8", 123);
|
||||
materialInstance.SetParameterValue("New parameter 9", new Matrix(0.666f));
|
||||
|
||||
materialInstance.SetParameterValue("New parameter 11", new Quaternion(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
|
||||
materialInstance.SetParameterValue("New parameter 13", new Vector2(1,2));
|
||||
materialInstance.SetParameterValue("New parameter 14", new Vector3(1,2,3));
|
||||
materialInstance.SetParameterValue("New parameter 15", new Vector4(1,2,3,4));
|
||||
//materialInstance.SetParameterValue("New parameter 16", new Transform(new Vector3(1,2,3), new Quaternion(0.5f, 0.5f, 0.5f, 0.5f)));
|
||||
|
||||
lastEnabled = true;
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
Destroy(ref sceneTask);
|
||||
Destroy(ref sceneTask2);
|
||||
Destroy(ref texture);
|
||||
Destroy(ref texture2);
|
||||
}
|
||||
|
||||
public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input,
|
||||
GPUTexture output)
|
||||
{
|
||||
if (texture == null || texture2 == null)
|
||||
return;
|
||||
|
||||
Renderer.DrawPostFxMaterial(context, ref renderContext, materialInstance, output, input.View());
|
||||
}
|
||||
|
||||
private bool lastRescale = false;
|
||||
public override void OnUpdate()
|
||||
{
|
||||
#if FLAX_EDITOR
|
||||
if (Input.GetKeyDown(KeyboardKeys.F7))
|
||||
{
|
||||
PhysicsSettings physicsSettings = GameSettings.Load<PhysicsSettings>();
|
||||
physicsSettings.EnableSubstepping = !physicsSettings.EnableSubstepping;
|
||||
GameSettings.Save(physicsSettings);
|
||||
//GameSettings.Apply();
|
||||
}
|
||||
if (Input.GetKeyDown(KeyboardKeys.F7))
|
||||
{
|
||||
PhysicsSettings physicsSettings = GameSettings.Load<PhysicsSettings>();
|
||||
physicsSettings.EnableSubstepping = !physicsSettings.EnableSubstepping;
|
||||
GameSettings.Save(physicsSettings);
|
||||
//GameSettings.Apply();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (lastEnabled != camera.IsActive)
|
||||
{
|
||||
lastEnabled = camera.IsActive;
|
||||
sceneTask.Enabled = lastEnabled;
|
||||
sceneTask2.Enabled = lastEnabled;
|
||||
sceneTask.RenderingPercentage = MainRenderTask.Instance.RenderingPercentage * 0.5f;
|
||||
sceneTask2.RenderingPercentage = MainRenderTask.Instance.RenderingPercentage * 0.5f;
|
||||
}
|
||||
|
||||
if (useMainCamera && rescaleModel != lastRescale)
|
||||
{
|
||||
lastRescale = rescaleModel;
|
||||
if (rescaleModel)
|
||||
viewModelHolder.Scale = new Float3(0.75f);
|
||||
else
|
||||
viewModelHolder.Scale = new Float3(1.0f);
|
||||
}
|
||||
|
||||
if (!camera.IsActive)
|
||||
return;
|
||||
if (texture == null)
|
||||
OnAwake();
|
||||
|
||||
if ((int)camera.Viewport.Width != texture.Width || (int)camera.Viewport.Height != texture.Height)
|
||||
CreateTextures((int)camera.Viewport.Width, (int)camera.Viewport.Height);
|
||||
}
|
||||
|
||||
public override void OnEnable()
|
||||
if (lastEnabled != camera.IsActive)
|
||||
{
|
||||
//OnAwake();
|
||||
lastEnabled = camera.IsActive;
|
||||
sceneTask.Enabled = lastEnabled;
|
||||
sceneTask2.Enabled = lastEnabled;
|
||||
sceneTask.RenderingPercentage = MainRenderTask.Instance.RenderingPercentage * 0.5f;
|
||||
sceneTask2.RenderingPercentage = MainRenderTask.Instance.RenderingPercentage * 0.5f;
|
||||
}
|
||||
|
||||
if (useMainCamera && rescaleModel != lastRescale)
|
||||
{
|
||||
lastRescale = rescaleModel;
|
||||
if (rescaleModel)
|
||||
viewModelHolder.Scale = new Float3(0.75f);
|
||||
else
|
||||
viewModelHolder.Scale = new Float3(1.0f);
|
||||
}
|
||||
|
||||
if (!camera.IsActive)
|
||||
return;
|
||||
if (texture == null)
|
||||
OnAwake();
|
||||
|
||||
if ((int)camera.Viewport.Width != texture.Width || (int)camera.Viewport.Height != texture.Height)
|
||||
CreateTextures((int)camera.Viewport.Width, (int)camera.Viewport.Height);
|
||||
}
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
//OnAwake();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user