Simulating PS1 "shaky vertices" with shaders

Started by
10 comments, last by Daaark 11 years, 3 months ago

I'd like to get the game I'm working on to look like it uses an old software renderer, and one of the artifacts I'd like to reproduce is how in many old games (specifically on the PS1, but also many computer games) the vertices would shake slightly. From what I can find this was because the coordinates were passed from the math hardware to the rasterization hardware in integers. I tried to produce a similar effect by flooring the calculated positions in my vertex shader:


gl_Position.xy=floor(gl_Position.xy*256)/256;

but it doesn't seem to produce any noticable effect unless I lower the 256 down to less than 10, and then it is EXTREMELY wobbly to the point of being unusable. (I chose 256 because my window is 1024 pixels wide, and the position ranges from -1 to 1 (unless I'm remembering this incorrectly?))

Any ideas?

Advertisement

in what space is gl_Position.xy? if it's after you've applied the view projection matrix, then you'd need to divide it by w to get the screenspace positions.

then you could do your magic and then multiply by w again.

kind of like

gl_Position.xy = fractgl_Position.xy/gl_Position..w*(1./4.))*4.*gl_Position.w;

(untested ;) )

btw. you shall also be able to simulate that texture interpolation bugs by multiplying the texturecoordinates in the vertexshader by gl_Position.w and dividing it per pixel again (you'd obviously also need to pass .w to the pixelshader.

you'll still miss the lovely gabs between triangles that those oldschool rasterizer had, that would be some more effort.

glPosition was post all transformations. that line was the last line in the vertex shader. I'm not sure quite what you're going for wit that code.. I assume that you meant to type this:

gl_Position.xy = fract(gl_Position.xy/gl_Position.w*(1./4.))*4.*gl_Position.w;

Using fract doesn't make sense to me in this case. floor makes more sense, but I get similar problems anyway. Everything shows up strangely stretched in one quarter of the screen.

You are applying the quantisation to verts in 4D HCLIP space so you'll need to so as Krypt0n says and transform to screenspace and then reproject back after the fract(or floor). Note that this will break for any triangles with verts in front of the projection near plane which is problematic. in these cases you are best not doing anything to them.

Make sure you transform into screen pixels and not normalised device coordinates. i.e for a 1024x600 window Multiply by 512,300 then add 512,300. Make you do the inverse when going back to HCLIP space.

"you'll still miss the lovely gabs between triangles that those oldschool rasterizer had, that would be some more effort."

By manually inserting some T-junctions into your models you will get this oldschool effect.

The vertex positions in world space need to be rounded to integer coordinates. I don't think the system had any kind of floating point support.

Besides that you need to enable point sampling for textures, disable perspective correction (divide by depth in the VS) and you'll have to manage to render without the use of a z-buffer.

The vertex positions in world space need to be rounded to integer coordinates. I don't think the system had any kind of floating point support.

It didn't even have any 3D support, the GPU only saw 2D coordinates. All projection was done in the CPU using fixed point. Also clipping - this one is important because a lot of issues arised from inaccurate clipping, but in modern hardware clipping is done with the GPU which of course will try to apply as much accuracy as it can. You'll have to deal with this as well.

Also: at what resolution are you rendering? The PS1 had 256×240 and 320×240 as the available resolutions. At lot of the problems (like the shakiness) became exaggerated because pixels were so big. Make sure you're rendering to a low-resolution buffer and then scale it to fill the screen, otherwise all your effort will be moot.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Fixed point 3D and lack of perspective correction on the textures caused this. Had nothing to do with the resolution. The same shaky texture artifacts will show up in 1920x1080 just like they did on the PS1 resolution.

Watch the street texture in this video. The white lines swim all over the place. Then when the playing starts, watch the yellow lines near the curb.
">


Look at the brick wall in this image:
http://img1.mlstatic.com/ps1-syphon-filter-1ra-edicion_MLM-O-75534286_2935.jpg

And the wall here:
http://farm9.staticflickr.com/8185/8119988218_fb4ef9b281.jpg

And here, the floor is completely messed up, and the wall pattern distorts just before the left edge of the frame:
http://psoneclassics.com/wp-content/uploads/2010/08/moh1psx_004-large.jpg

Hello wavy wall!
http://images.psxextreme.com/screenshots/medal_of_honor_2/medal_of_honor_2_24_med.jpg

This one takes the cake:
http://199.101.98.242/media/shots/37147-Medal_of_Honor_-_Underground-2.jpg

Textures would go crazy from frame to frame. Especially fun that the whole texture area wouldn't warp consistently!

You're talking about texture artifacts (which is caused exclusively by lack of perspective correction in the texture, nothing else), he's talking about vertices moving out of place (it was common for vertices to get off by 1 pixel as the camera moved, resulting in seemingly shaking polygons and such), which was indeed caused by inaccuracies in the computations, and also were quite noticeable because of the low resolution (at a high resolution they aren't as noticeable).

EDIT: typo.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
There was a 512 x 256 mode which most games used on the PS1 (in fact Sony would likely not consder games at lower res later on in the PS1 life cycle). There was also an interlaced mode which doubled the frame buffer height but looked awful if you didn't run at 60fps and used too much VRAM anyway. Stuff like the wobbly lines down the middle of the road in the first video could be alleviated a bit by putting the lines near the edge of polygons (because the non-perspective correction caused most warping along the diagonal of quads). Looks like they textured the line down the middle of a quad, the worst case. You could also render things like the lines as separate polygons (I think Gran Turismo did this?) as long as you made sure the lines were drawn after the road.

Clipping was done on the rasteriser as long as the polygon wasn't too large, but you had to manually subdivide polygons to make the non-perspective rendering look halfway decent anyway.

There was a geometry coprocessor which could do fixed point matrix maths so it wasn't all done on the CPU.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
glPosition was post all transformations. that line was the last line in the vertex shader. I'm not sure quite what you're going for wit that code.. I assume that you meant to type this:

gl_Position.xy = fract(gl_Position.xy/gl_Position.w*(1./4.))*4.*gl_Position.w;

Using fract doesn't make sense to me in this case. floor makes more sense, but I get similar problems anyway. Everything shows up strangely stretched in one quarter of the screen.

sorry, that was a typo, was a bit in a hurry. floor instead of fract is correct.

but my point was, that you need the division by .w to be in screenspace.

maybe your issue is a different bug, post a screenshot maybe :)

This topic is closed to new replies.

Advertisement