Beispiel #1
0
        public void Awake()
        {
            print("ksp-graphics-overhaul: initialized");

            configReader = new XMLConfigReader();
            configReader.FromFile("GameData/ksp-graphics-overhaul/ksp-graphics-overhaul.xml");

            Shaders.LoadShaders(configReader.ShaderPaths, configReader.ShaderReplacements);

            dummyCamera       = this.gameObject.AddComponent <Camera>();
            dummyCamera.depth = 10;

            foreach (string hookName in configReader.CameraHooks)
            {
                foreach (Camera camera in GameObject.FindObjectsOfType <Camera>())
                {
                    if (hookName == camera.gameObject.name)
                    {
                        if (camera.gameObject.GetComponent <CameraHook>() == null)
                        {
                            var hook = camera.gameObject.AddComponent <CameraHook>();
                            cameraHooks.Add(camera.gameObject.name, hook);
                            print("ksp-graphics-overhaul: Hooking " + camera.gameObject.name);
                        }
                    }
                }
            }
        }
        void OnPreRender()
        {
            foreach (Renderer renderer in GameObject.FindObjectsOfType <Renderer>())
            {
                var shaderName = renderer.material.shader.name;
                if (Shaders.Replacements.ContainsKey(shaderName))
                {
                    renderer.material.shader = Shaders.GetShader(Shaders.Replacements[shaderName]);
                }
            }

            RenderTexture.active = targetTexture;
            GL.Clear(true, true, new Color(1, 0, 1, 0));
        }
Beispiel #3
0
        void OnPostRender()
        {
            RenderTexture.active = null;

            GL.Clear(true, true, new Color(0, 0, 0, 1.0f));

            print("start frame");

            foreach (var hook in cameraHooks)
            {
                print("blitting " + hook.Value.gameObject.name);
                if (renderDepth)
                {
                    Graphics.Blit(hook.Value.targetTexture, (RenderTexture)null, Shaders.GetMaterial("RenderDepth"));
                }
                else
                {
                    Graphics.Blit(hook.Value.targetTexture, (RenderTexture)null);
                }
            }
        }
Beispiel #4
0
 public void OnDestroy()
 {
     Shaders.ClearAll();
     print("ksp-graphics-overhaul: destroyed");
 }