[MOD] Realtime Reflections
- Nystul
- Posts: 1501
- Joined: Mon Mar 23, 2015 8:31 am
Re: Investigations on Realtime Reflections in Unity
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
will allow texture injection not only for specular map also optional injection of albedo and normal map
- Nystul
- Posts: 1501
- Joined: Mon Mar 23, 2015 8:31 am
Re: Investigations on Realtime Reflections in Unity
ReflectionsMod version 0.3:
shadows are working again correctly now
0.23 changes:
lots of bugfixes, improvements
outdoors:
installation:
- 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
- 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
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
- 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
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;"
- LypyL
- Posts: 512
- Joined: Sun Mar 22, 2015 3:48 am
Re: Investigations on Realtime Reflections in Unity
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!
- Nystul
- Posts: 1501
- Joined: Mon Mar 23, 2015 8:31 am
Re: Investigations on Realtime Reflections in Unity
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
https://drive.google.com/file/d/0B1QjwG ... sp=sharing
- Interkarma
- Posts: 7247
- Joined: Sun Mar 22, 2015 1:51 am
Re: Investigations on Realtime Reflections in Unity
Working on integrating this now. Could you please fix up the following bit of code for me?
There are two key problems with this:
Code: Select all
Camera cameraToUse = GameObject.Find("stackedCamera").GetComponent<Camera>();
- 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.
- 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.
- Nystul
- Posts: 1501
- Joined: Mon Mar 23, 2015 8:31 am
Re: Investigations on Realtime Reflections in Unity
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
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
- Interkarma
- Posts: 7247
- Joined: Sun Mar 22, 2015 1:51 am
Re: Investigations on Realtime Reflections in Unity
Cheers mate. If there's anything I can do to help just let me know.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
- Nystul
- Posts: 1501
- Joined: Mon Mar 23, 2015 8:31 am
Re: Investigations on Realtime Reflections in Unity
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...
- Interkarma
- Posts: 7247
- Joined: Sun Mar 22, 2015 1:51 am
Re: Investigations on Realtime Reflections in Unity
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.
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.
- Nystul
- Posts: 1501
- Joined: Mon Mar 23, 2015 8:31 am
Re: Investigations on Realtime Reflections in Unity
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
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