141 points by nkanaev
16 days ago
Linked in the README is the article this is probably based on, which explains the rendering for a PS1 and why it has certain behaviors, it's a great article: https://www.david-colson.com/2021/11/30/ps1-style-renderer.h...
This should be required reading for anyone that trying to emulate the PS1 rendering aesthetic. Too many developers seem to think that PS1 games probably looked worse than how they remember them and try to compensate for their nostalgia (or just want to heighten the aesthetic) by introducing far, far more wobbling and warping than there actually was!
Love the project and the spirit of it. Brings be back to playing FFT.
Question to all C/C++ programmers out there. Why are your variables so terse? I have no idea what td and dt mean and why they are both in the same function. I'm genuinely trying to read your code and have no idea what is happening because there is seemingly a desire by the author to keep variables as short as possible. Why?
Don’t go to ShaderToy. You will find a really cool shader and then be disappointed when the code is incomprehensible because whoever wrote it want used one letter variables (starting alphabetically! So x, y, and x coordinates might not even be “x, y, z” but “o, p, q”).
That's so legit.. I just spent 3 hr reading code of shader toy last night at 1 am, all I could do was changing color... And it was in a variable named c1
Amazing. On the other hand it makes use of a graphics library that is way bigger than 500 lines. Regardless thank you for sharing but I get the feeling it was good fun.
It's true that https://github.com/nkanaev/tipsy/blob/master/src/tigr.c is 5500 lines of C but, as far as I can tell, it's just being used to load texture images, draw lines, get double-buffered pixel buffers onto the screen, and get keyboard and mouse events. It wouldn't be difficult to port it to something like https://gitlab.com/kragen/bubbleos/blob/master/yeso. yeso.h yeso-pic.c yeso-xlib.c png.c total 560 lines of C, and all you're missing then is a line-drawing function.
heh, I wrote an N64 one not too long ago with the exact same style:
You might notice that your project is already included in the Readme under credits.
I did not notice. Neat. I appreciate the PS1 more. Remembering way back, N64 carts were 10 dollars or so more than PS1 discs, and as a result I had a stockpile of PS1 games. The texture popping of the PS1 I could never make sense of but it became an aesthetic of the era. Nice work OP, and thankyou for the credit
I know there’s another reply with videos here. I’m gonna put an explanation in text.
The N64 had two things which made things smoother. It had sub-pixel precision for geometry after projection, and it had perspective-correct interpolation. This meant that moving objects looked smooth and didn’t “pop”. Games on the PS1 addressed the interpolation problem by subdividing, but you could sometimes see geometry suddenly move when you got closer and saw more subdivisions.
The N64 also had texture interpolation (kind of like bilinear) and antialiasing, but those don’t make as big an impact.
The N64 got all these things right, more or less, but had problems with memory bandwidth and small texture memory.
I was also under the impression the PS1 only had integer precision? Would that contribute to the wobbling and popping?
That’s the “subpixel” precision I’m talking about.
> The texture popping of the PS1 I could never make sense of but it became an aesthetic of the era.
The Truth About PS1 Graphics
Why PlayStation 1 Graphics Warped and Wobbled so much
Very nicely written. Glad you shared this here, and that it was mentioned in the README.md.
Edit: It looks like all of your C is actually very well written. What a pleasure to read!
Why thank you. They've all been passion projects and they were all published only after numerous rewrites. Roman2 ended up being the pinnacle of my work. I sadly don't know to work on next. Never thought I'd run out of ideas, but I guess turning 30 does that
Dig for that crazy pile of N64 game ideas Kid You drew out and start hacking on one, now that you have the renderer!
i came across this a few days ago searching n64 style rendering, its awesome! i plan on trying to make a spiritual successor of sorts for blast corps using those techniques in another renderer
This looks nice! Great work.
If anyone is interested in learning how graphics rendering works under the hood without too much scaffolding, there's a great course at https://pikuma.com/courses/learn-3d-computer-graphics-progra... (I'm no way associated with that website, just loved the course). That course starts from absolute basics: creating a colour buffer as in memory array and gradually covers lot of ground on 3D rendering: drawing pixels, lines, triangle fill rasterisation, texturing. The course uses minimal help: SDL is used for rendering on window and dynamic arrays are provided as a small C library. But everything else is coded from scratch in C by the instructor in the lecture, word by word.
So cool. Took me back to my childhood instantly. You nailed it
My first reaction was "damn that looks good!". I guess it was the nostalgia taking over.
Glad to see PS1 style rendering that simulates the affine texture warping side effects of the console. The original Playstation was very much not designed with 3D in mind, lack of perspective correction on textures lead to the aforementioned warping.
Vertex coordinates were rounded to whole integers, giving that hallmark polygon jiggle effect from the rounding that 'snapped' them in place. The complete lack of a z-buffer also lead to lots of z fighting, as the system rendered polygons strictly in the order they were calculated.
I couldn't help noticing that it tests every pixel on the "screen" to see whether it's inside a face. Back in the software renderer days we'd run the inner loop just for the pixels that fell inside a triangle. But then you'd need to explicitly handle polygon clipping and it would greatly complicate the code. I guess 320*240 tests is nothing these days.
Anyway, great job!
I thought this was referring to Prompt Shell 1 :')
would love to see this run inside a browser. how do you create ps1 texture and lo-poly models like this? I so badly want to create a PS1 style game in the browser.
For lot of us, our childhood was defined by this console. N64 as well but just something about the PS1 graphic that really speaks to me. Anybody else feel the same?
No clue what people use today, but when I worked on a psx game 3D Studio Max was the the main choice, with Lightwave 3D having a lot of fans as well. Doing low poly modeling you basically just live between the edge split, rotate, merge, and vertex move tools, so it's incredibly important they have a low friction UI.
omg what game
It was a never published port of Unreal to Playstation 1.
Interestingly enough the renderer was up and running. It was a lot more limited in triangle count than the PC version, hence a lot of fiddling with models.
In any case, the project fell apart for the usual disorganized management reasons.
From a quick glance at the graphics library being used here, it doesn't seem like a terrible amount of work to add support for WebGL and then get this entire project compiled into wasm (at least for someone more comfortable working in C than myself!)
Funny that my first thought was that the polygons better wobble and it's right there in the features list.
Very cool and nostalgic! Had no idea the PS1 look was trending.
Also, due to Stack Overflow conditioning: fgetc() does not return 'char', it returns 'int' else EOF won't fit.
> fgetc() does not return 'char', it returns 'int' else EOF won't fit.
Or more precisely: don't store the return value in a 'char' and check if it is EOF. On some platforms (e.g. gcc ARM eabi), regular 'char' is unsigned and the check fails.
WOW! Looks great! Definitely hit my nostalgia nerve!
Have PS1 triangular graphics made a retro resurgence yet? Because I'm so down for that.
Yes, very much so. Mostly for horror games, for some reason.
It's a Lovecraftian thing. Abstraction of the horror itself (through primitive illustration) lets your own imagination fill in the blanks.
Silent Hill inspired, I guess
And Resident Evil, surely?
They need to be coupled with the same bespoke, precise controls and input handling though. There's a tightness to a lot of PS1 and N64 games that takes care to replicate. And Unity and friends don't exactly help you in that department.
r/ps1graphics is a small but active community.
There's also some people on YouTube doing PS1 and N64 style graphics.
that was pretty prompt!
I was wondering how this was done in 500 lines...then I saw the 5000+ line library file borrowed from another project. I do enjoy the look of your results though.
How long before somebody includes your library and says they created PSX graphics in 25 lines?
depends on how you look at things. The library is a rendering library (presumably for calling GL).
And what about any of the operating system calls that might get used? It's also a library (despite the source code not being in the project).
The actual code to compute the logic of the graphics PS1 style, is indeed around 500 lines.