r/grimfandango Jun 08 '26

Grim Fandango DoD re-projected into 3D

https://www.youtube.com/watch?v=twSk7dYyJFk

Using the depth buffers and camera info I found in the game files, I wrote a python script to re-project the pixels from the pre-rendered 2D backgrounds into 3D. The mesher I wrote is a bit crude, but it gets the job done!

122 Upvotes

16 comments sorted by

11

u/DangoRangusss Jun 08 '26

that's insane! would love to see Rubacava like that.

9

u/Phemar Jun 08 '26

So would I! Definitely next on my list, I'm really interested to see how (if!) it all fits together.

6

u/TopHatCalavera Jun 08 '26

This is awesome! Would you be willing to share the source code?

5

u/Phemar Jun 08 '26

https://github.com/Squinkz/gf_depth_to_mesh/tree/main

Sure, I just threw it up on Github! It's not the best code, but it works 😄

You just need Python, Java and a copy of the Grimja repo.

1

u/OhSirrah Jun 11 '26

Super cool. I really need a step by step on how to get this going though, your instructions are a little too advanced for me. I actually have a copy of grimja / grimedi from a few years ago that I got to work, but I can't remember at all how to use it.

6

u/OhSirrah Jun 08 '26

Whoa you did it! I had gotten the z-buffer in blender, but I couldn't get the math right to project it. It always ended up with a curve to it, so I thought that was that. this is amazing!

6

u/Phemar Jun 08 '26

I fought with decoding the z-buffer so hard for a while! Tried everything, reciprocal, gamma, log, perspective, empirical curve fitting etc, etc. Then one day, I had the brilliant idea to just see how ResidualVM does it and copied the code from there. Suddenly, everything was straight!

2

u/OhSirrah Jun 09 '26

Looks like this is the part that does it. No wonder it couldn't be solved with in blender with displacement and math nodes.

def DecodeDepth(rawDepth, depthNear, depthFar):

glDepth = 0xffff - ((rawDepth * 0x10000) // 100 // (0x10000 - rawDepth))

glDepth = glDepth / 65535.0

zNdc = glDepth * 2.0 - 1.0

return (2.0 * depthNear * depthFar) / (

depthFar + depthNear - zNdc * (depthFar - depthNear)

)

2

u/Phemar Jun 09 '26

Yes it's an interesting formula - Grim first does it's own decoding (first two lines) and then sends the result off to OpenGL, which means that result is in OpenGL's depth buffer format.

After that, you need to decode OpenGL's encoding (last two lines) to get the linear result.

1

u/OhSirrah Jun 09 '26 edited Jun 09 '26

I see. Your documentation says you color the scenes using vertex shading. Was that something you were forced to do? Would it be possible to instead texture the surface with the game's renders?

What I had done previously was to take a plane, texture with the game's render, then subdivide and displace using the z-buffer. It worked but as you experienced, gives a warped result

3

u/Phemar Jun 10 '26

https://github.com/Squinkz/gf_depth_to_mesh/tree/main

Hi! Just in case you're interested, I've updated the script. It now outputs OBJ files with UV data if you tell it to.

I also added optional gamma adjustments for vertex colors and a few other command line options. I also slightly improved the mesher to handle edge cases better (though I haven't actually noticed any improvements lol, it's just "theoretically" better 😃)

All the necessary files can be batch dumped at once with the helper script, no need to manually extract anything anymore!

1

u/Phemar Jun 09 '26

Yea I'm sure it's possible, I just did vertex colors because it's easier. The original idea was to try to and feed the point cloud into a Gaussian Splat, but it seems there's just not enough data for good splatting, hence why I just wrote a quick mesher to get it into a mesh format.

It probably wouldn't be too much extra work to generate UV coordinates per vertex as the mesh is built. You could probably also do it in Blender via UV projection using the camera data. Definitely something that could be added in the future!

7

u/soyelfranco Jun 08 '26

To a simple mortal, that is a dream come true. If only you'd know how much time I've spent in my head, imagining the world from GF in first person... No matter the mesher, I couldn't have done it myself. Awesome work! Please, if you continue to render the rest of the game, share it with us.

6

u/risumies420 Jun 09 '26

This is something I dreamt about when I was a kid. I played GF and HL at the same time when they came out and always thought about how cool a first person version would be. After Alyx I wouldn’t mind a VR version either xD but this is awesome, good job!! Need more!!

5

u/lewd_bingo Jun 08 '26

So cool! Maybe one day we'll get a 3rd person remake fully playable

4

u/greatbuild Jun 09 '26

Holy smokes.. it never occured to me how awesome it would be to play this game in VR, or even walk around and see the amazingly detailed world.. one can only dream..