Implementing "Detect Life" Spell Effect

Discuss modding questions and implementation details.
User avatar
Magicono43
Posts: 1139
Joined: Tue Nov 06, 2018 7:06 am

Re: Implementing "Detect Life" Spell Effect

Post by Magicono43 »

DunnyOfPenwick wrote: Fri Aug 12, 2022 12:18 pm Those crabs look terrifying.
Indeed they do, Mr. Crabs is pretty scary when he's choking :lol:

User avatar
Sluggy
Posts: 20
Joined: Tue Aug 23, 2022 9:28 pm

Re: Implementing "Detect Life" Spell Effect

Post by Sluggy »

Just wanted to chime in on a few things that might help you out.

For starters, while I think using shaders would generally be the best approach to this problem I can also say that is a very deep rabbit hole. One that is worth learning but probably not going to get the results very quickly. As well, I'm not sure what, if any, limitations there are in DFU for importing your own shaders and materials into the system via mods.

For the sake of simplicity I'd say stick with the idea of using additional cameras and render layers. The cameras themselves carry relatively little overhead and the only real cost comes from the rendering itself, which in this case should be just about nothing.

For ensuring the effect camera is in sync with the default camera, you can make it a child of the default camera and then zero out its local position and rotation so that they are always in the same spot at all times. As well, you'll want to copy the default camera's near plane and FoV and maybe a few other settings as well. It might be easiest to create a gameobject in a scene, add the camera component to it and then go to the default camera and select 'Copy Component Values' from the inspector and then paste those values to the new camera. Then you can save this as a prefab and instantiate that prefab at runtime.

As for the depth clearing: all cameras rendering to the same target can be thought of as rendering a few different types of data that gets composited to a final image. The two most important in this case are the pixel color buffer and the depth buffer. The pixel color data is pretty obvious since that is what you see on the screen. However, during the process of rendering, many shaders will also write to the complimentary depth buffer for that pixel as well. This will store data about how far away the object was from the camera that the pixel represents. In this way, rendering systems can be sure that if they draw one object and then later draw another that is further away from the camera, the second object doesn't overwrite the previous color data. In your case you obviously WANT that effect and since your second spell effect camera is rendered after the default one, you want to tell it to specifically clear that depth info so that everything will be rendered even if it would technically be behind something already visible. On the other hand, you are leaving the color buffer untouched so that the previous rendered pixel colors remain on screen and only the new colo data for the second camera will be updated.

I'd say one simple approach you could do if you want to emulate the effect in Oblivion is this: Create a new GameObject and attach a particle effect system to it. Adjust the particle system until you like it and then make a prefab out of this GameObject. Be sure to set the GameObject to a layer that is different from anything else in the scene and also be sure that your effect camera only renders objects on this layer. You could possibly do different prefabs for each different type of detectable object with different layers and particle effects.

At runtime, when your spell detects a lifeform (or lootable, or whatever), instantiate a new copy of this particle effect prefab and make it a child of the lifeform. When the spell ends be sure to remove this effect from all lifeforms by destroying the prefabs that were spawned. The spell itself can probably cache this data.

A few things to keep in mind: I saw some specific notes in one of the tutorials about spawning prefabs so I'm not sure what troubles that might give you. Also, there are a very limited number of layers in Unity, many are likely already in use by DFU and they are shared between the rendering system and the physics system. You might be able to get away with different detectable items on different layers or you might have to lump them all together depending on how many free layers are left or able to be repurposed.

User avatar
Magicono43
Posts: 1139
Joined: Tue Nov 06, 2018 7:06 am

Re: Implementing "Detect Life" Spell Effect

Post by Magicono43 »

Thanks very much for the reply, Sluggy.

DFU does have some allocated layers for modding purposes it seems, atleast 4 of them I think, so I'd probably consider using one of those, or making one that is not in use if necessary, there are a few left at least.

As for the rest of the info, thanks for the write up, I'm sure I will find it very useful when I inevitably get to working on this spell-effect in full force. At the moment for my own sanity I've been trying to slowly chip away at the "easier" ones to get a better hang of it, so it might be some weeks before I get back to this relatively complex one.

But I appreciate the added info, I definitely will find it useful when I get back on this!

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Implementing "Detect Life" Spell Effect

Post by l3lessed »

For my minimap mod, I ended up having to program custom shaders and use custom layer masks to render only what I wanted and how I wanted.

I ended up setting up a second camera, setting up a custom layermask for that camera, and then assigning my shaders and things to that custom layermask. I then used a camera texture to apply the custom 2nd camera to the minimap. This provided a normal camera and a custom layered camera for the minimap.

As stated above, You should look at the layermasks and how they work for rendering what you want on the 2nd camera and when. You can change them when you want. You could use them to turn on and off the effect by changing the rendering layermask and the shaders and things assigned to it.

https://docs.unity3d.com/Manual/Layers.html
https://docs.unity3d.com/Manual/layermask-set.html

I setup the custom shader largerly to allow me to combine all the individual textures into a single larger texture, which still allowed proper rotation effects.

Also, as stated above, I personally would look at custom particle effects to get some really nice looking detect life effects. I setup custom particles for my weapon sparks, and its not to bad to do. You just set it up as a prefab you import through the mod system and then assign to the enemy object and render through a specific layer mask.

https://learn.unity.com/tutorial/introd ... 20effects.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Magicono43
Posts: 1139
Joined: Tue Nov 06, 2018 7:06 am

Re: Implementing "Detect Life" Spell Effect

Post by Magicono43 »

I haven't touched this in a while and put down the spell-effects for a bit to work on some other stuff, but thanks for the added info, Blessed. I'll certainly use it when I eventually get back into this, thanks.

Post Reply