Implementing "Detect Life" Spell Effect

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

Implementing "Detect Life" Spell Effect

Post by Magicono43 »

I'm currently working on a new mod that aims to add dozens of new spell effects to Daggerfall, as well as probably update/improve some of the vanilla effects as well while I'm at it.

So probably a bit stupidly, I've decided to make the first effect I work on potentially be moderately difficult. That being I want to essentially overhaul the entire current list of vanilla "Detect" spell effects and variants, as well as add some more where appropriate to that list.

Here is the current (basically empty) Github Repo for anyone interested: https://github.com/magicono43/DFU-Mod_G ... -of-Spells

However, the difference here being instead of adding a mostly useless and uninteresting marker to the compass, the spell will instead (if all works out at least) work similar to how the "Detect Life" effect does in ES: Oblivion. That being in real-time while the effect is active you actually see a wall ignoring effect centered on the detected object that shows some distinct visual effect around the object, that hopefully also gives some shape to it to give a better idea what the object is even through walls.

Here are some examples from modded Oblivion for those that don't know what I'm referring to:
2291-1-1205123830.jpg
2291-1-1205123830.jpg (55.52 KiB) Viewed 998 times
25204-3-1245489609.jpg
25204-3-1245489609.jpg (45.49 KiB) Viewed 998 times
32725-2-1278227552.jpg
32725-2-1278227552.jpg (438.98 KiB) Viewed 998 times
So yeah, it's probably not the most mind-blowing or complex effect. But in terms of implementing into Unity there are a few road-blocks of "challenge" for me currently. First one being what method would make the most sense for this sort of thing, initially I was thinking something Unity calls a "Particle System" which is a surprisingly robust feature that the Unity Editor has built in basically that allows for some pretty complex behaviors to be done in terms of emitting particles.

But after playing around with it for a few hours (had a surprising amount of fun just screwing around with it.) I found that for many of the sprites, especially the mobile ones that I had no clue how I would get these particles to make any sort of outline, or even stay within a defined border inside the current state of the sprite basically.

So I started reading more stuff about "Shaders" which are a pretty universal, vague, and confusing (to me at least) thing that I have not screwed around with yet, that apparently are used for alot of things, including making outlines around sprites or something, but I have not played around with this idea enough yet to say or not if it's the most logical approach to take.

Now besides all of that with how to make the effect look some way. The other issue I'm not sure about also is how to actually tell the game/effect that the player should be able to see these particular "effects" through collidable objects/walls. This one I'm sure I can find a tutorial online about it, but I figure I may as well bring it up here as well.

But yeah, just wanted to post this to see if anyone has experience with this sort of thing, I'm still very new to actually using the Unity Editor and it's various tools, I've basically exclusively been a script monkey when it comes to my DFU modding "career" so far, lol. It's clearly a very powerful thing, but also equally as confusing when dove into head-first (maybe not as bad as Blender at least.) So thanks for any help that somebody may or may not be able to provide, it will be much appreciated if it comes!

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Implementing "Detect Life" Spell Effect

Post by BadLuckBurt »

The effect in Oblivion is probably built-in to the shader they use on those models and activated by a global shader variable, at least I think that would be the 'elegant' way to do it.

We don't have that luxury but I'm quite sure you can accomplish this by making a modified version of the DaggerfallBillboard.shader. By playing around with the code in there you can change the appearance of the sprite. If you create a new material that uses this shader, you can then replace the material on the billboards you want to affect at runtime.

Unity has a built-in render queue that determines the draw order of things: https://docs.unity3d.com/2020.2/Documen ... order.html. You'd have to experiment to find the right queue number but I know it's higher than the geometry one.

So it won't be that hard to draw things through walls but getting them to look good might take some doing.

I can recommend reading these blog posts: https://halisavakis.com/category/shaderquest/. Start at the bottom and then work your way up. Don't worry too much about understanding everything at once, as long as you understand parts of it, the rest will click gradually when you start messing with a shader.

There are some more in-depth posts on that site too: https://halisavakis.com/category/blog-p ... ader-bits/. The World and Screen position / distance from camera stuff might come in handy if this effect has a finite or variable distance since you can use that to control the opacity of the pixel being rendered.

- edit

And I dug up another series that explains Unity shaders step by step: https://www.alanzucconi.com/2015/06/10/ ... n-unity3d/
Last edited by BadLuckBurt on Fri Aug 12, 2022 3:30 pm, edited 1 time in total.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

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

Re: Implementing "Detect Life" Spell Effect

Post by Magicono43 »

Thanks for the detailed answer, Burt. This will definitely be very helpful!

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: Implementing "Detect Life" Spell Effect

Post by DunnyOfPenwick »

You could use a second camera with cullingMask set to only render the 'Enemies' layer.

Then use your own custom shader to manipulate the colors. Black pixels could be changed to bright blue, other colors could be changed to a darker blue, or something like that.

see the following:
Camera.RenderWithShader(shader, tag)
material.SetOverrideTag(tag, val)

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

Re: Implementing "Detect Life" Spell Effect

Post by Magicono43 »

Thanks for the interesting suggestion as well, Denny. I'll have to start practically working on trying to implement this later this evening and see ultimately which approach makes the most sense. If I can figure it out I may consider yours over what Burt and I were thinking, thanks.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Implementing "Detect Life" Spell Effect

Post by BadLuckBurt »

DunnyOfPenwick wrote: Thu Aug 11, 2022 2:02 pm You could use a second camera with cullingMask set to only render the 'Enemies' layer.

Then use your own custom shader to manipulate the colors. Black pixels could be changed to bright blue, other colors could be changed to a darker blue, or something like that.

see the following:
Camera.RenderWithShader(shader, tag)
material.SetOverrideTag(tag, val)
That's a good point. If he can get away with only rendering certain layers and creating the effect that way, that should perform better than having to attach stuff to GameObjects or swapping out their materials.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

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

Re: Implementing "Detect Life" Spell Effect

Post by Magicono43 »

I like the idea with the camera, but it could possibly disallow for more "fine" adjustment of properties that attaching components to gameobjects in the scene might be better for, potentially at least.

Since I would like to reuse this effect in a similar way (probably with different colors) for other objects as well, such as loot-piles for "detect treasure" and something else for "detect magic" or something of those sorts, not just living entities. Little misleading thread title in that sense, but mostly just wanted to use the effect from other games as a clear example :P

I'll have to obviously play around and see what I can do though, it's almost definitely going to be using shaders instead of the particle system like I originally was thinking.

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

Re: Implementing "Detect Life" Spell Effect

Post by Magicono43 »

So was screwing around again for a few hours in the Unity Editor and realized something that is slightly strange. That being the "layer" that the skeleton prefab is on is the "enemies" layer, but the actual billboard object that is attached to this prefab (the thing that actually renders the sprite and has the sprite sheet and such) is actually on the "Default" layer as most other things are.

Probably not really a big issue since you can change the layer of objects anyway it seems through scripting of the specific gameobject in question, at least I think. Still have not been able to get some objects to be viewable through opaque objects like walls, etc. But I'm guessing it's mostly me just being dumb, I'm still going to keep bumbling around and hopefully figure something out.

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

Re: Implementing "Detect Life" Spell Effect

Post by Magicono43 »

Alright so some progress in the bumbling about, I've finally gotten a method to work for seeing other objects through walls, in this case it involved a second camera. I found this video that was super helpful for this particular thing.



Basically the most important setting appeared to be changing the second camera's "Clear Flags" property to "Depth Only", don't know what it really did compared to the others, but in this case it made the effect work at least. There are still other issues I'd need to resolve with using a second camera, such as the position and possibly performance? I noticed when I tried this for a bit the framerate started to get bad here and there it was kind of strange but I don't know why or how to prevent that atm.

Here are some examples of what it looked like in the editor in play-mode for testing it in this case:
2022_08_11_20_33_21.jpg
2022_08_11_20_33_21.jpg (106.43 KiB) Viewed 867 times
2022_08_11_20_36_51.jpg
2022_08_11_20_36_51.jpg (92.11 KiB) Viewed 867 times
Still not sure how I'd implement this exactly atm, stuff gets kind of funky when you have multiple cameras active at once, like I think the second camera was not staying with the same transform as the "main" first one, so viewing the skeleton at certain angles and when not behind the wall would have like a duplicate version rendered slightly above the first one, it's strange but hopefully I can figure it out at some point. At least I got something to "work" at least as I'd sort of expected, so progress never the less.

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: Implementing "Detect Life" Spell Effect

Post by DunnyOfPenwick »

Those crabs look terrifying.

Post Reply