Topic: Advanced GI with UFE

Hey guys, I have a question in regards to baking down lighting in UFE for stages... now I'm trying to test out the lighting for my Immortal Valley stage and unfortunately in builds, I'm losing ALL of my baked lighting and real-time global illumination. Honestly it's extremely frustrating and I don't want to lose all of my hard work getting this to work.

Same thing with skyboxes and ambient lighting. It's redoing work I already did and it's not productive. I did find out that I can set a skybox material via script but it forces to make sure the script is set the same as the level. I do hope you consider either using the actual scene file as a level. (.unity format. It will save EVERYTHING about your scene including lighting information), or have UFE create a lighting asset file which will bake everything lighting wise, including render settings for the current scene and apply this to the global config for stages.

Sorry for the long post but a lot of the games I'm seeing so fat have had flat lighting

Re: Advanced GI with UFE

Hey, guys. So I'm bumping this topic (again) because I'm trying to light my levels using the progressive lightmapper, and because of the prefab nature of the levels, you can't save the lighting data. And I can prove this by building my GI, and playing a standalone build and I lose all of my lighting.

There is a script that saves light maps to prefabs but it doesn't save light probes, which levels in .unity extension DOES, per level. So how will you rectify this? I'm using GI extensively in my game and without my lighting data, the game will not look correct. I'm also using PBR, so having GI helps.

Having levels in .unity format would alleviate this as is saves all of the lighting info. Please keep this in mind.

Re: Advanced GI with UFE

Save the stage in it's own scene with the lighting baked in that scene. Load the scene in addition to the main scene and it'll work the way you want.

Share

Thumbs up Thumbs down

Re: Advanced GI with UFE

soonk wrote:

Save the stage in it's own scene with the lighting baked in that scene. Load the scene in addition to the main scene and it'll work the way you want.

How is this possible with UFE? The levels are all prefabs, remember?

Re: Advanced GI with UFE

Do you have source? Comment out the call for the stage prefab and replace it with a switch that grabs the stage name and loads the appropriate scene using LoadSceneAsync and LoadSceneMode.Additive

Share

Thumbs up +2 Thumbs down

Re: Advanced GI with UFE

KRGraphics wrote:
soonk wrote:

Save the stage in it's own scene with the lighting baked in that scene. Load the scene in addition to the main scene and it'll work the way you want.

How is this possible with UFE? The levels are all prefabs, remember?

He's saying modify the ufe boot stage code to boot a scene instead that on awake will start the match. It's a little complicated for newbie programmers though fyi.

Share

Thumbs up Thumbs down

7 (edited by soonk 2017-12-21 17:01:24)

Re: Advanced GI with UFE

That's not what I'm saying.
LoadSceneAdditive loads a second scene into your current scene, along with the lighting data and so forth. Instead of loading the prefab it loads the scene instead. It's a couple lines of code inserted into the preload area of UFE.cs, and if he has source we can go further with this.

Share

Thumbs up +1 Thumbs down

Re: Advanced GI with UFE

This is pretty interesting... smile

Me encontraste en un negro camino como un peregrino sin rumbo ni fe, pero la luz de tus ojos divinos cambio mi suerte por dicha y placer.

Re: Advanced GI with UFE

Well, if this could be shown to me, then my lighting issues are pretty much solved... I basically want to use the Unity scene on level load instead of the prefab.

What about existing cameras in these scenes?

Re: Advanced GI with UFE

You only need a normal camera in your stage scene for testing purposes while working in that scene. Disable it before you save the scene to be loaded in game.

This is the basic code you'll need, find the first line in UFE.cs and go from there:

if (UFE.config.preloadStage) {
            switch (UFE.config.selectedStage.stageName) {
            case "Your Stage Name":
                stageScene = "YourSceneName";
                break;
            default:
                break;
            }
            UnityEngine.SceneManagement.SceneManager.LoadSceneAsync (stageScene, UnityEngine.SceneManagement.LoadSceneMode.Additive);
            #if UNITY_EDITOR
            //SearchAndCastGameObject(UFE.config.selectedStage, warmTimer);
            #endif
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Stage Loaded");

I'm using a weather controller for skyboxes and such, but if you want to transfer the skybox and the ambient light, just add spots for those in the Stages section of the Global Editor and they can be called in this block, right before the switch using something like this:

            Material newSkybox = UFE.config.selectedStage.stageSkybox;
            RenderSettings.skybox = newSkybox;
            Color newAmbientColor = UFE.config.selectedStage.stageColor;
            RenderSettings.ambientSkyColor = newAmbientColor;

Share

Thumbs up +4 Thumbs down

11 (edited by KRGraphics 2017-12-21 18:31:27)

Re: Advanced GI with UFE

For some of my outdoor levels, I'm using Enviro for outdoor lighting (which is awesome btw) and with this code, it should load. I already have a script that applies my skybox. And to complicate things, I have post effects profiles for each level too, so I will have to figure out how to apply this to each stage.

Maybe we can add this to the global stage options... would make this A HELL of a lot easier.

Re: Advanced GI with UFE

Don't overthink it. Just create a new Enviro prefab for each stage and give it the settings you want. Keep that prefab in the stage scene and it'll load with the rest of it. Make sure you set Enviro to grab the camera on runtime using the MainCamera tag.

Share

Thumbs up Thumbs down

Re: Advanced GI with UFE

soonk wrote:

Don't overthink it. Just create a new Enviro prefab for each stage and give it the settings you want. Keep that prefab in the stage scene and it'll load with the rest of it. Make sure you set Enviro to grab the camera on runtime using the MainCamera tag.

I already have and it works. This is for more or less interior levels that I can't save GI with... have you played with the Post Processing Behaviours in Unity 2017? I want to swap out profiles for each stage...

Re: Advanced GI with UFE

I haven't touched that, no; I just got our project updated to 2017.3 after being stuck on 5.6 for a long time.

Share

Thumbs up Thumbs down

Re: Advanced GI with UFE

soonk wrote:

I haven't touched that, no; I just got our project updated to 2017.3 after being stuck on 5.6 for a long time.


Dude, it's FREAKING AWESOME big_smile

Re: Advanced GI with UFE

if (UFE.config.preloadStage) {
            switch (UFE.config.selectedStage.stageName) {
            case "Your Stage Name":
                stageScene = "YourSceneName";
                break;
            default:
                break;
            }
            UnityEngine.SceneManagement.SceneManager.LoadSceneAsync (stageScene, UnityEngine.SceneManagement.LoadSceneMode.Additive);
            #if UNITY_EDITOR
            //SearchAndCastGameObject(UFE.config.selectedStage, warmTimer);
            #endif
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Stage Loaded");

I can't seem to get this working. No errors on the code, but it won't load the new scene for me, it just stays in whatever scene Im in.

Share

Thumbs up Thumbs down

Re: Advanced GI with UFE

Steviebops wrote:
if (UFE.config.preloadStage) {
            switch (UFE.config.selectedStage.stageName) {
            case "Your Stage Name":
                stageScene = "YourSceneName";
                break;
            default:
                break;
            }
            UnityEngine.SceneManagement.SceneManager.LoadSceneAsync (stageScene, UnityEngine.SceneManagement.LoadSceneMode.Additive);
            #if UNITY_EDITOR
            //SearchAndCastGameObject(UFE.config.selectedStage, warmTimer);
            #endif
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Stage Loaded");

I can't seem to get this working. No errors on the code, but it won't load the new scene for me, it just stays in whatever scene Im in.


That sucks. I'm glad I haven't tried it yet...

Re: Advanced GI with UFE

Steviebops wrote:
if (UFE.config.preloadStage) {
            switch (UFE.config.selectedStage.stageName) {
            case "Your Stage Name":
                stageScene = "YourSceneName";
                break;
            default:
                break;
            }
            UnityEngine.SceneManagement.SceneManager.LoadSceneAsync (stageScene, UnityEngine.SceneManagement.LoadSceneMode.Additive);
            #if UNITY_EDITOR
            //SearchAndCastGameObject(UFE.config.selectedStage, warmTimer);
            #endif
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Stage Loaded");

I can't seem to get this working. No errors on the code, but it won't load the new scene for me, it just stays in whatever scene Im in.

Wrapping up another project right now but I'll take a look and see what I can do for you. Any chance you can pm me your preloading section of code so I can take a look?

Share

Thumbs up Thumbs down

Re: Advanced GI with UFE

The UFE class is unchanged from the vanilla version. The code above is the only addition.

Share

Thumbs up Thumbs down

Re: Advanced GI with UFE

Steviebops wrote:

The UFE class is unchanged from the vanilla version. The code above is the only addition.

OK I'll try to take a look today and get you sorted.

Share

Thumbs up +1 Thumbs down

Re: Advanced GI with UFE

thank you very much smile

Share

Thumbs up Thumbs down

Re: Advanced GI with UFE

And once you guy get this sorted, I can try it. I am surprised this has been an omission for SO LONG

Re: Advanced GI with UFE

I never know how much code is ok to post, but here's my whole PreloadBattle block

public static void PreloadBattle(float warmTimer) {
        if (UFE.config.preloadHitEffects) {
            SearchAndCastGameObject(UFE.config.hitOptions, warmTimer);
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Hit Effects Loaded");
        }
        if (UFE.config.preloadStage) {
            //#if !UNITY_EDITOR
            print(UFE.config.selectedStage.stageName + " STAGE");
            Material newSkybox = UFE.config.selectedStage.stageSkybox;
            RenderSettings.skybox = newSkybox;
            Color newAmbientColor = UFE.config.selectedStage.stageColor;
            RenderSettings.ambientSkyColor = newAmbientColor;

            switch (UFE.config.selectedStage.stageName) {
                case "Titan's Alley Clear Day":
                    print ("switch for Titan's Alley Clear Day");
                    stageScene = "TitanClearDay";
                    break;
                default:
                    break;
            }
            UnityEngine.SceneManagement.SceneManager.LoadSceneAsync (stageScene, UnityEngine.SceneManagement.LoadSceneMode.Additive);
            //#endif
            //#if UNITY_EDITOR
            //SearchAndCastGameObject(UFE.config.selectedStage, warmTimer);
            //#endif
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Stage Loaded");
        }
            string p1Char = UFE.config.player1Character.name;
            string p2Char = UFE.config.player2Character.name;

        instance.StartCoroutine (instance._PreloadCharactersAsync (warmTimer));

        if (UFE.config.warmAllShaders) Shader.WarmupAllShaders();

        memoryDump.Clear();
    }

You can ignore the end, where I butcher the character loading. We have to handle characters differently so that's all changed. I also don't remember what the original code looks like, which is part of why I asked you to send me yours, but that's ok we'll work with what we have.

The important stuff is everything in the preload stage block. You can also ignore the skybox and color settings -unless- you want to set those through the editor per stage, but we can deal with that later. I used to, but don't anymore and haven't taken it out.

Abuse print statements. It will at least help me figure out where the code is getting to before doing nothing. You should probably put one in the default section of the switch, too, so you know if that's getting called ie nothing is getting called. Since I don't know where your code is not working, I'll run through the obvious fixes and we'll go from there.

Make sure your switch case is named properly in the code, or nothing will happen
http://i.imgs.fyi/img/2azc.png

Make sure your stageScene is named properly in the code, also.
http://i.imgs.fyi/img/2azd.png

Last, make sure the scene is included in your build list. Order doesn't matter, and you don't have to build, just has to be in the list
http://i.imgs.fyi/img/2azg.png

If it's still not working, try to give me a detailed post like this with some screenshots of your stage settings and the print results of your console so we can see where it's stopping, otherwise I'm just guessing.

Share

Thumbs up +2 Thumbs down

24 (edited by Steviebops 2018-01-10 16:06:16)

Re: Advanced GI with UFE

thanks! I'll give it a try now smile

One question though, where do you declare the string stageScene ?

Share

Thumbs up Thumbs down

Re: Advanced GI with UFE

At the beginning of the file where everything else is declared is what I have

public static string stageScene;

Also, in EndGame() I have this

       if (gameEngine != null) {
            GameObject.Destroy(gameEngine);
            UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync (stageScene);
            gameEngine = null;
        }

Share

Thumbs up +2 Thumbs down