Surface glitches on a scaled model

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
User avatar
Enjay
 
 
Posts: 26877
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Surface glitches on a scaled model

Post by Enjay »

Noticed in 4.14.0 plus git build from 21 Feb 2025.

Short version: Glitches on the surface of a scaled model can happen with Vanilla sector lighting mode.
dpJudas has provided both an explanation and a possible solution:
dpJudas wrote: Sat Feb 22, 2025 3:32 am Doom originally used different light calculations for sides and flats. The vanilla light mode doesn't know if something is a side or a flat, so what it does instead is to look at the normal of the surface and see if its mostly horizontal or mostly vertical. If its horizontal it uses the side math for the light, and if its vertical it uses the flat math.

The spots on the satellite dish must be exactly at the point where it changes mode. My guess is that scaling the model also scales the normal vectors on the model, but the vanilla light mode seemingly doesn't normalize the vector before using it. Perhaps adding a "normal = normalize(normal)" line in the vertex shader would fix the issue for that model.
More info in this thread: viewtopic.php?t=80200

Example file: https://aspectsweb.co.uk/enjay/doom/Tes ... ellite.pk3
Just load in Doom2 and play map01.

Screenshots:


User avatar
phantombeta
Posts: 2149
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Surface glitches on a scaled model

Post by phantombeta »

Renormalizing the normals does seem to fix it.
Changing

Code: Select all

		vWorldNormal = NormalModelMatrix * vec4(normalize(bones.Normal), 1.0);
		vEyeNormal = NormalViewMatrix * vec4(normalize(vWorldNormal.xyz), 1.0);
to

Code: Select all

		vWorldNormal = vec4(normalize((NormalModelMatrix * vec4(normalize(bones.Normal), 1.0)).xyz), 1.0);
		vEyeNormal = vec4(normalize((NormalViewMatrix * vec4(normalize(vWorldNormal.xyz), 1.0)).xyz), 1.0);
in shaders/glsl/main.vp works.
(Removing the w component is necessary or it'll be normalized wrong and break the ones that aren't scaled)
User avatar
Enjay
 
 
Posts: 26877
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Surface glitches on a scaled model

Post by Enjay »

Yep.

I had a go myself before. I found the right file, but couldn't figure out the syntax.

phantombeta's change does it.


User avatar
Rachael
Posts: 13885
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Surface glitches on a scaled model

Post by Rachael »

phantombeta wrote: Sat Feb 22, 2025 5:56 am

Code: Select all

		vWorldNormal = vec4(normalize((NormalModelMatrix * vec4(normalize(bones.Normal), 1.0)).xyz), 1.0);
		vEyeNormal = vec4(normalize((NormalViewMatrix * vec4(normalize(vWorldNormal.xyz), 1.0)).xyz), 1.0);
Did this as proposed.

Return to “Closed Bugs [GZDoom]”