Live data from Hacker News

A Shader Trick

the-witness.net

41–50 of 56 posts

Re: A Shader Trick

#41

I've been playing The Witness recently. I've enjoyed it a lot, and had a lot of "aha moments", but I wouldn't say I altogether understand the game. It has a very elusive nature. I'm working through (what I believe to be) the "ending" at the moment, but there is still a lot of the pre-ending stuff that I haven't figured out yet. At first glance The Witness is a puzzle game, made annoying by the fact that you have to w…

I think one of the key flourishes of the game has to do with intrinsic vs extrinsic motivation. The game never presents a locked door where there is some key elsewhere, and the key goes into your inventory, and now you can open the door. At all times, all doors are openable. But you may not know the rules to the puzzle on the door yet. Once you learn them, the 'key' is knowledge and the 'inventory' is your mind.

If you're keen to this then you will find it surprising how few games work this way.

Re: A Shader Trick

#42

Could you use a non-float integer instead? Do GPUs have cheap int % float -> float operations?

I think everyone who responded to you makes a point that just doesn't matter, because it's in a shadow of a much more significant problem:

If your formula involves Π, multiplying it by an integer will produce a float, with its precision problems.

Though you could define pi as 31415 integer... Though if Hwillis is right and originally an integer would overflow after ~50 days, now, being 10000 larger, it would overflow after ~7 minutes.

And finally, if you use sine or cosine, which take radians as input, any whole number passed to them (which probably are at that point converted to floats, but let's assume they aren't) will be a multiple of 57.2957795° expressed in degrees. Almost a sixth of full rotation is way too big of a step for any smooth transition.

Out of curiosity I decided to check if multiplying 1 radian could result with a very big, but visually (due to wrapping around 360°) only a little step:

  print(min((180/pi*i % 360, i) for i in range(1,100000)))
Apparently 19 radians is ~1088.62° (mod 360° =~ 8.62°)

44 radians is ~2521.01° (mod 360° =~ 1.01°)

377 radians is ~21600.509° (mod 360° =~ 0.509°)

710 radians is ~40680.00345° (mod 360° =~ 0.00345°)

The last result is surprisingly good, but isn't it a spoonful of honey in a barrel of tar? :)

BTW, changing min to max in the Python script will also give useful results (close to 360 rather than close to 0). Worse results for low multipliers but better results near the end of the range.

Re: A Shader Trick

#43

I've been playing The Witness recently. I've enjoyed it a lot, and had a lot of "aha moments", but I wouldn't say I altogether understand the game. It has a very elusive nature. I'm working through (what I believe to be) the "ending" at the moment, but there is still a lot of the pre-ending stuff that I haven't figured out yet. At first glance The Witness is a puzzle game, made annoying by the fact that you have to w…

I think one of the key flourishes of the game has to do with intrinsic vs extrinsic motivation. The game never presents a locked door where there is some key elsewhere, and the key goes into your inventory, and now you can open the door. At all times, all doors are openable. But you may not know the rules to the puzzle on the door yet. Once you learn them, the 'key' is knowledge and the 'inventory' is your mind. If y…

Outer Wilds does this as well.

Re: A Shader Trick

#44
This is a brand-new post. I'm surprised he's still blogging on the site for The Witness, given that it came out six years ago and I don't think it's seen any activity in terms of ports or content updates since the iOS port in 2017. Is it even still getting patches?

Re: A Shader Trick

#45

I've used a similar trick for decades: for example I put it in the code for my Hypnocube (www.hypnocube.com) product in 2005 (Hypnocube). I used it in games and digital art projects before (and after) that. For embedded or low resource computing, sin/cos may be expensive, so I use a table based fixed point version. I pick the table to have size power of 2, making lots of things easier. Then to make time wrap, I use a…

I remember seeing Hypnocube references and your site probably around 2005 or 2006, but it was so far beyond me at the time I just wrote it off as "cool OK". YouTube wasn't quite what it is today so I never did get to see what it looks like in motion. Today I assume similar things can be done extraordinarily cheap and easily but I still have no idea how. I'm not motivated enough right now to ask, but I just wanted to thank you for giving younger-me's friends something exciting to talk about for a short while.

Re: A Shader Trick

#46

I've been playing The Witness recently. I've enjoyed it a lot, and had a lot of "aha moments", but I wouldn't say I altogether understand the game. It has a very elusive nature. I'm working through (what I believe to be) the "ending" at the moment, but there is still a lot of the pre-ending stuff that I haven't figured out yet. At first glance The Witness is a puzzle game, made annoying by the fact that you have to w…

When you're done playing, I recommend watching this video: https://www.youtube.com/watch?v=KZokQov_aH0

Games are part art, what's more to understand?

There's some fun image out there I can't exactly recall, but it's basically of an interview with some game devs, and one of them saying something like "We wanted to have a pot with flowers on the table here, and when you come back to this room later, the color of the flowers changes. No gameplay consequences. But we cut it for time. Why did we want it? Because we thought it'd be cool."

But in a lot of games there's tons of stuff like that which doesn't get cut. Gamedev is full of those "because it'd be cool" or other vague artistic reasons (as opposed to business reasons or researched game testing reasons) for something to be there, or something to be polished well beyond reason.

Re: A Shader Trick

#47
post #14

i have been doing this for a while playing around with shadertoy. i don't think i learned it from anywhere, i just wanted some things to match up and repeat over hours and it was obvious that sin/cos are periodic, and cycling the time value would improve the imprecision at the seam. seeing it delivered as a clever trick in a blog post makes me wonder if i'm more competent than i thought, or if everyone else is genera…

Every now and then I have to remind myself that things that are obvious to me aren't obvious to everyone else. And thus, sometimes its worth explaining "obvious" things.

This is probably true for everyone.

Re: A Shader Trick

#48
Would it be useful to have a 'fraction' type that represents values in [0,1] with uniform precision?

Then instead of time deltas, we could work with fractions of the animation period.

When switching from float to fraction, we can remove code that handles float's edge cases: +inf, -inf, NaN, -0.0, non-canonical encodings, and loss of precision.

Re: A Shader Trick

#49

Would it be useful to have a 'fraction' type that represents values in [0,1] with uniform precision? Then instead of time deltas, we could work with fractions of the animation period. When switching from float to fraction, we can remove code that handles float's edge cases: +inf, -inf, NaN, -0.0, non-canonical encodings, and loss of precision.

We have various integer types, and e.g. a 0.32 or 0.16 fixed point representation is trivial on top of integer types; and is also the only efficient uniform representation on [0, 1) (which is probably more valuable than [0, 1]).

Re: A Shader Trick

#50

Earlier quoted context omitted.

Yes, the Minecraft Farlands are caused by precision issues of floating point numbers. The game becomes jittery as it tries snapping to fewer and fewer precise digits. This is most obvious at first in the selection box around blocks, but the terrain also becomes unstable after a certain point. Note that one Youtuber KurtJMac has been walking to the Farlands since 2011. He's been raising money for charity as part of th…

Huh, I remember seeing some of his videos about five years ago and wondering if he'd ever make it. Glad to see he's still going!

Another YouTuber beat him to the punch about 2 years ago actually! Here's the moment from his stream where he finally reached the Farlands [volume warning]: https://youtu.be/VAvQ_kT73W4?t=25696 (at the 7:08:17 mark)
Post reply on HN