Disable / Hide Exterior Building

Discuss modding questions and implementation details.
User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Disable / Hide Exterior Building

Post by Macadaynu »

Does anyone know how to disable or hide an Exterior Building?

Disabling an entire DaggerfallBlock is easy enough, but I need to disable a specific building within that block at runtime. Just being able to resize it to 0 will do, I just need to make it not visible to the player.

I am working on this mod: viewtopic.php?t=4533

And one problem I have found when testing is that not all buildings actually have the same size outside as inside, here is an example:

daggerfall-unity-0.12.3-beta - DaggerfallUnityGame - PC, Mac & Linux Standalone - Unity 2019.4.28f1 Personal [PREVIEW PACKAGES IN USE] _DX11_ 30-Dec-21 7_23_29 PM.png
daggerfall-unity-0.12.3-beta - DaggerfallUnityGame - PC, Mac & Linux Standalone - Unity 2019.4.28f1 Personal [PREVIEW PACKAGES IN USE] _DX11_ 30-Dec-21 7_23_29 PM.png (1.34 MiB) Viewed 1263 times

So the easiest solution I can think of is just disable the current Exterior Building you are inside of at the moment, as you won't be able to see the building you are looking out from anyway.

I think this would be much cleaner than going through and correcting each building that has mismatched sizing somehow.

Is this possible?

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

Re: Disable / Hide Exterior Building

Post by BadLuckBurt »

For performance reasons, Daggerfall Unity combines all exterior buildings into one because of this setting:

Image

While you can turn that off in the editor to debug stuff, the released builds all have that switched on.

I wonder if you could manually 'clip' the RMB mesh against a cube volume.

If you were to calculate the bounding box of the interior and then use a cube of that size to cull / hide that part of the RMB mesh while in the interior, that should give you the result you're after.
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
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: Disable / Hide Exterior Building

Post by Macadaynu »

BadLuckBurt wrote: Sat Jan 01, 2022 9:18 am For performance reasons, Daggerfall Unity combines all exterior buildings into one because of this setting:

While you can turn that off in the editor to debug stuff, the released builds all have that switched on.

I wonder if you could manually 'clip' the RMB mesh against a cube volume.

If you were to calculate the bounding box of the interior and then use a cube of that size to cull / hide that part of the RMB mesh while in the interior, that should give you the result you're after.
Thanks for this suggestion, I have tried many methods to do this but the closest I have got is an example I found here:

https://answers.unity.com/questions/176 ... a-box.html
daggerfall-unity-0.12.3-beta - DaggerfallUnityGame - PC, Mac & Linux Standalone - Unity 2019.4.28f1 Personal [PREVIEW PACKAGES IN USE] _DX11_ 03-Jan-22 1_37_57 PM.png
daggerfall-unity-0.12.3-beta - DaggerfallUnityGame - PC, Mac & Linux Standalone - Unity 2019.4.28f1 Personal [PREVIEW PACKAGES IN USE] _DX11_ 03-Jan-22 1_37_57 PM.png (1.29 MiB) Viewed 1165 times

What this is doing is only rendering textures within the cube's volume, what I need is the opposite (so that textures are only rendered outside of the cube).

I wonder if anyone knows how to achieve this by modifying the below shader script? I think it's just the clip methods that need modifying, but everything I've tried up to now has not worked how I would want it to.

Code: Select all

Shader "Custom/ClipBox" {
    Properties{
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
    }

        SubShader{
            Tags { "RenderType" = "Opaque" }
            LOD 200

            CGPROGRAM
            #pragma surface surf Standard fullforwardshadows addshadow
            #pragma target 3.0

            sampler2D _MainTex;
            half _Glossiness;
            half _Metallic;
            float4x4 _WorldToBox;

            struct Input {
                float2 uv_MainTex;
                float3 worldPos;
            };

            void surf(Input IN, inout SurfaceOutputStandard o) {
                float3 boxPosition = mul(_WorldToBox, float4(IN.worldPos, 1));
                clip(boxPosition + 0.5);
                clip(0.5 - boxPosition);

                fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
                o.Albedo = c.rgb;
                o.Metallic = _Metallic;
                o.Smoothness = _Glossiness;
                o.Alpha = c.a;
            }
            ENDCG
        }
            FallBack "Diffuse"
}

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

Re: Disable / Hide Exterior Building

Post by BadLuckBurt »

Sadly I've never worked with shaders, they're odd creatures.

I'm thinking it may need some more math to reverse that clipping process, maybe related to the distance of the cube compared to the RMB edges. I really should've paid more attention in math class back then.

I'll report back if I find something useful.
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
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Disable / Hide Exterior Building

Post by pango »

Code: Select all

                clip(boxPosition + 0.5);
                clip(0.5 - boxPosition);
clipping is based on the sign of the parameter, if a negative value is computed the pixel is not rendered.
So to reverse the conditions, you have compute opposite values:

Code: Select all

                clip(- boxPosition - 0.5);
                clip(boxPosition - 0.5);
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: Disable / Hide Exterior Building

Post by Macadaynu »

pango wrote: Mon Jan 03, 2022 10:18 pm

Code: Select all

                clip(boxPosition + 0.5);
                clip(0.5 - boxPosition);
clipping is based on the sign of the parameter, if a negative value is computed the pixel is not rendered.
So to reverse the conditions, you have compute opposite values:

Code: Select all

                clip(- boxPosition - 0.5);
                clip(boxPosition - 0.5);
Thanks Pango, I gave that a go but unfortunately the textures don't render inside or outside of the cube (no matter where the cube is)

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Disable / Hide Exterior Building

Post by pango »

Macadaynu wrote: Mon Jan 03, 2022 11:16 pm

Code: Select all

                clip(- boxPosition - 0.5);
                clip(boxPosition - 0.5);
Thanks Pango, I gave that a go but unfortunately the textures don't render inside or outside of the cube (no matter where the cube is)
Thinking a bit more about it, the fact there's 2 clip() in sequence does the same as an OR condition: if either one of the values is negative, the pixel is skipped.
So, to reverse the overall skipping condition, not only each condition has to be negated, but the resulting conditions ANDed together instead or ORed together (De Morgan's law).
That cannot be expressed with two clip()s in sequence, and I can't think of a simple function of two parameters that's negative if and only if its two parameters are negative, so all I could think of is:

Code: Select all

                clip(abs(boxPosition) - 0.5);
P.S. In fact clip() on a float3 checks if any of the coordinates is negative (cf clip()); So applying De Morgan's law again, this any() should become an all() when the condition is negated. clip() can't be used to achieve this; Instead you have to use something like

Code: Select all

                                if (all(boxPosition > -0.5 && boxPosition < 0.5))
                                  discard;
I haven't tested, so I don't even guarantee it compiles ;)
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: Disable / Hide Exterior Building

Post by Macadaynu »

pango wrote: Tue Jan 04, 2022 12:26 am
P.S. In fact clip() on a float3 checks if any of the coordinates is negative (cf clip()); So applying De Morgan's law again, this any() should become an all() when the condition is negated. clip() can't be used to achieve this; Instead you have to use something like

Code: Select all

                                if (all(boxPosition > -0.5 && boxPosition < 0.5))
                                  discard;
I haven't tested, so I don't even guarantee it compiles ;)
Amazing! That did it, thank you so much Pango and Burt :D

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

Re: Disable / Hide Exterior Building

Post by Magicono43 »

Show a screenshot of what it looks like in action now, pretty curious :P

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

Re: Disable / Hide Exterior Building

Post by BadLuckBurt »

Macadaynu wrote: Tue Jan 04, 2022 12:21 pm Amazing! That did it, thank you so much Pango and Burt :D
All credit to Pango, I just threw the idea out there without any idea how to implement it. My brain melted a bit reading Pango's posts but happy to hear that it works. If it all works out, this will be the first TES game that has this feature. Lord knows people ask for this in every TES game :D
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

.

Post Reply