• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
zacaj

Simulating PS1 "shaky vertices" with shaders

11 posts in this topic

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?

0

Share this post


Link to post
Share on other sites

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

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

(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.

 

0

Share this post


Link to post
Share on other sites

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.  

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites
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.

2

Share this post


Link to post
Share on other sites
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.
http://www.youtube.com/watch?v=MXCZ--6uJmc

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!
1

Share this post


Link to post
Share on other sites

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.

Edited by Sik_the_hedgehog
0

Share this post


Link to post
Share on other sites
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.
2

Share this post


Link to post
Share on other sites
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 :)

0

Share this post


Link to post
Share on other sites
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 smile.png

Fixed it by multiplying by w inside the floor and dividing outside.  

 

gl_Position.xy = floor(gl_Position.xy*gl_Position.w*.25)*4/gl_Position.w;

 

Gives a wobbling effect.  Doesn't quite feel like PS1 shaking yet, but there's probably a lot of other stuff combining too.  Thanks

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0