Skip to content

Commit

Permalink
UDecal::AttachDecal(): Prevent decal creation on invisible surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
LupertEverett authored and dpjudas committed Aug 31, 2024
1 parent a731986 commit 784a270
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions SurrealEngine/UObject/UActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2490,10 +2490,16 @@ UObject* UDecal::AttachDecal(float traceDistance, const vec3& decalDir)
CollisionHitList hits = XLevel()->Model->TraceRay(to_dvec3(Location()), 0.1f, to_dvec3(dirNormalized), traceDistance, false);
if (hits.empty()) return nullptr;

vec3 N = hits.front().Normal;
// Do not attempt to create a decal if we hit a surface that's invisible or a fake backdrop
auto& hit = hits.front();
if (hit.Node && (XLevel()->Model->Surfaces[hit.Node->Surf].PolyFlags & PF_FakeBackdrop
|| XLevel()->Model->Surfaces[hit.Node->Surf].PolyFlags & PF_Invisible))
return nullptr;

vec3 N = hit.Normal;
vec3 xdir = normalize(cross(N, std::abs(N.x) > std::abs(N.y) ? vec3(0.0f, 1.0f, 0.0f) : vec3(1.0f, 0.0f, 0.0f)));
vec3 ydir = cross(N, xdir);
vec3 pos = Location() + dirNormalized * hits.front().Fraction + N;
vec3 pos = Location() + dirNormalized * hit.Fraction + N;

float usize = (float)Texture()->USize();
float vsize = (float)Texture()->VSize();
Expand Down

0 comments on commit 784a270

Please sign in to comment.