jk2mv icon indicating copy to clipboard operation
jk2mv copied to clipboard

Glass shatter effect does not work correctly

Open aufau opened this issue 4 years ago • 2 comments

Example: shot0008

While glass shatter effect is implemented in the cgame code, the error steams from CG_R_GET_BMODEL_VERTS syscall implementation. The syscall is supposed to find and return a quadrilateral surface in 3d space, which will be replaced and covered by glass shards in the cgame code, for given glass brush model. The reasonable assumption here is that:

Assumption 1: The glass brush model is a "thin" cuboid with quadrilateral base.

Current code looks for largest surface in the brush model. Error is that these brush models are partitioned by BSP algorithm so such surface is not what the author expected (largest wall of the model). On the screenshot above surface happens to be a triangle, hence the catastrophic failure. 4th corner coordinates are uninitialized, (0, 0, 0).

Solution: Replace RE_GetBModelVerts() algorithm with one that finds a quadrilateral surface covering the glass model under the Assumption 1.

I believe the syscall was intended and used only for this effect so there is no harm in changing it.

Some other examples (less catastrophic due to partitioned surfaces being rectangles) shot0015 shot0010 shot0013

aufau avatar Jan 27 '20 11:01 aufau

It turns out there are glass models with more complicated shapes eg on ctf_ns_streets. There is nothing we can do with them with current cgame algorithm, but at least engine should not error and fallback to something vaguely reasonable.

aufau avatar Feb 04 '20 01:02 aufau

There are also these small, "polygonal" windows in bases on ctf_imperial. I think old algorithm is ok for this (find largest player-facing surface or something along these lines). It only requires combining surfaces on the same plane, split by bsp algorithm and treating them as a single, large surface.

aufau avatar Feb 11 '20 23:02 aufau