[MOD] Realtime Reflections

A curated forum for compatible and maintained mods. Users are unable to create new topics in this forum but can reply to existing topics. Please message a moderator to have your mod moved into this forum area.
Post Reply
User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Investigations on Realtime Reflections in Unity

Post by Nystul »

plugged in wooden texture from free asset from the unity store - worked out of the box with my shader...
will allow texture injection not only for specular map also optional injection of albedo and normal map

Image

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Investigations on Realtime Reflections in Unity

Post by Nystul »

ReflectionsMod version 0.3:
  • outdoor ground and sea reflections
  • indoor reflections in some buildings (check out daggerfall castle)
  • support for metallic gloss maps for indoor and dungeon floors
  • floor material configuration via ini-file
0.3 changes:
  • metallic gloss maps are now supported
  • indoor and dungeon floor materials can be configured via configInjectionTextures.ini file in the Resources folder
  • optional albedoMap and normalMap injection is possible for floor materials as well
0.24 changes:
shadows are working again correctly now

0.23 changes:
lots of bugfixes, improvements
outdoors:
  • no more pink shaders on terrain tiles when loading new terrains
  • working with FloatingOrigin and PositionUpdate script now, still working without also ;)
  • location reflections can be seen from other map pixels as long as it is the largest neighbor location and no location is at the current player location's map pixel
indoors:
  • reflection plane determination for lower level is now more robust
    • much less cases where lower level reflection plane computation is wrong
    • holes in walls, floors in daggerfall's indoor geometry are handled correctly much more often
    • mages guild with 4 floors also works now
    • reflections "around the corner" work now in most cases
https://drive.google.com/file/d/0B1QjwG ... sp=sharing

installation:
  • make sure you have iniFileParser installed and loaded as asset - you can get it here: https://github.com/rickyah/ini-parser
  • import the ReflectionsMod package
  • drag&drop prefab ReflectionsMod into the hierarchy at root level
  • add this function to MaterialReader.cs:

    Code: Select all

                public bool SetCachedMaterial(int archive, int record, int frame, CachedMaterial cachedMaterialIn)
                {
                    int key = MakeTextureKey((short)archive, (byte)record, (byte)frame);
                    if (materialDict.ContainsKey(key))
                    {
                        materialDict[key] = cachedMaterialIn;
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
    
  • if you are using the game branch of DFTFU change lines "using DaggerfallWorkshop.Demo;" into "using DaggerfallWorkshop.Game;"

User avatar
LypyL
Posts: 512
Joined: Sun Mar 22, 2015 3:48 am

Re: Investigations on Realtime Reflections in Unity

Post by LypyL »

I love where this is going! The texture injection is an exciting feature. Once I get some free time I'm going to have to see what I can do with that!

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Investigations on Realtime Reflections in Unity

Post by Nystul »

ReflectionsMod 0.31 (this should be working with the work-in-progress branch - when adding the function for MaterialReader.cs as described above):
https://drive.google.com/file/d/0B1QjwG ... sp=sharing

User avatar
Interkarma
Posts: 7242
Joined: Sun Mar 22, 2015 1:51 am

Re: Investigations on Realtime Reflections in Unity

Post by Interkarma »

Working on integrating this now. Could you please fix up the following bit of code for me? :)

Code: Select all

Camera cameraToUse = GameObject.Find("stackedCamera").GetComponent<Camera>();
There are two key problems with this:
  1. The "stackedCamera" object may not be present at startup (disabled, script startup order different, etc.), which means GameObject.Find("stackedCamera") will return null. This subsequently throws an exception on .GetComponent<Camera>(). The best way to fix this is to first get the game object, check if it's null, then get the component.
  2. OnWillRenderObject() is called once per frame after culling. Expensive operations like GameObject.Find("stackedCamera") should only be called once at scene startup. It is quite costly to be calling this once per frame.
I'm not sure of the best way to fix second issue. It's not like we can set camera in editor as it doesn't get created until runtime. Maybe setup a coroutine that does the "cameraToUse" check once per second rather than once per frame? Or possibly open this up as a property and the increased terrain can push this camera to MirrorReflection class at the same time "stackedCamera" is created. Could also use events and a couple other methods as well. The important thing is just to avoid expensive stuff every frame where you can. :)

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Investigations on Realtime Reflections in Unity

Post by Nystul »

regarding issue2: what about just do the gameobject find on startup and save the reference to the camera object?
edit: I see what the problem is - camera is not present at start... ok will find a solution for this

to make the IncreasedTerrainDistance use the reflection texture for sea reflections the line
// #define REFLECTIONSMOD_AVAILABLE
in IncreasedTerrainDistance.cs has to be changed to
#define REFLECTIONSMOD_AVAILABLE

if it is ok I will change this in the next pull request ;)

User avatar
Interkarma
Posts: 7242
Joined: Sun Mar 22, 2015 1:51 am

Re: Investigations on Realtime Reflections in Unity

Post by Interkarma »

Nystul wrote:regarding issue2: what about just do the gameobject find on startup and save the reference to the camera object?
edit: I see what the problem is - camera is not present at start... ok will find a solution for this

to make the IncreasedTerrainDistance use the reflection texture for sea reflections the line
// #define REFLECTIONSMOD_AVAILABLE
in IncreasedTerrainDistance.cs has to be changed to
#define REFLECTIONSMOD_AVAILABLE

if it is ok I will change this in the next pull request ;)
Cheers mate. :) If there's anything I can do to help just let me know.

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Investigations on Realtime Reflections in Unity

Post by Nystul »

my suggested solution is this (if you agree that this is reasonable):
  • change to IncreasedTerrainDistance script: currently the function SetupGameObjects() is called inside of Start() - I would call it also before on OnAwake() - maybe we can then eliminate the call inside Start() but we will have to check if it can be eliminated there without introducing other problems (anyway calling it for a second time is not critical since all objects are null-checked anyway)
  • change to ReflectionMod's MirrorReflection script: Camera object cameraToUse as private class member, which is assigned in Start() function - since this function is invoked after OnAwake functions of all other gameobjects, the camera should be present here - that's why invocation of SetupGameObjects() in IncreasedTerrainDistance script is not early enough in its own Start() function - since order of start() function seem to be unpredictable...
hope my argument is valid

User avatar
Interkarma
Posts: 7242
Joined: Sun Mar 22, 2015 1:51 am

Re: Investigations on Realtime Reflections in Unity

Post by Interkarma »

Seems reasonable. Give it a shot and show me how it works out. :)

Fortunately we're only talking about a few lines of startup code here and there, and we can just keep iterating over those bits until the startup process is locked down. The other 99% of code is pretty much good as-is.

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: Investigations on Realtime Reflections in Unity

Post by Nystul »

seems to work - wrapping up everything for my next pull request - just want to test everything works before I initiate it

there are some TODO comments where I didn't find an easy fix for slow operations in OnWillRenderObject()

is there for example a fast and easy way to check if player is outside or inside (building or dungeon)
is there further a way to differ if player is inside a building or inside a dungeon?
of course I could try to derive it from the Transition Events but maybe there is already an easy helper function or attribute one can use

Post Reply