ryzorm [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=50512 Textured Bezier Curves <p> <table><tr><td> <a href="/bbs/?pid=104413#p"> <img src="/bbs/thumbs/pico8_tcurve-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=104413#p"> tcurve 2.0</a><br><br> by <a href="/bbs/?uid=50512"> ryzorm</a> <br><br><br> <a href="/bbs/?pid=104413#p"> [Click to Play]</a> </td></tr></table> </p> <p>I&rsquo;ve been curious why smooth, textured curves were never a thing in graphics. Usually just polygons, or curves made out of polygons. After I saw this video on bezier curves, <a href="https://www.youtube.com/watch?v=aVwxzDHniEw">https://www.youtube.com/watch?v=aVwxzDHniEw</a> thought I had enough tools to figure out why for myself. The video mentions two major difficulties when working with them: It&rsquo;s hard to solve cubic polynomials, and estimating distance along a bezier curve isn&rsquo;t precise.<br /> If your goal is texturing them, it turns out you don&rsquo;t even need to estimate distance. For any 2 bezier curves, they all share a start t value of 0 and an end t value of 1. You just have to scale up whatever t value you&rsquo;re on to the height of your texture and draw your tline(), and it looks great!</p> <p>The inability to solve cubic polynomials was tricky. Stack overflow has methods for drawing curves. I can&rsquo;t quite figure them out, but they appear too slow for pico 8 and take a bit of space. Originally, I would just guess a T value and see if it was one pixel away, and go to the next one. Then I saw this video on newton's method <a href="https://www.youtube.com/watch?v=hHeq-SB8uVg">https://www.youtube.com/watch?v=hHeq-SB8uVg</a><br /> Which still uses guessing, but no checking and guessing again. And, if your first guess is close enough, you don&rsquo;t even need to have a guess loop! I tried to put something together for that. Wowzers, you have to be really careful on how you approach +/- infinity. I had to precompute all the noteworthy points (the 2 local extrema, and the point in between) Newton's method acts up in areas of low velocity, so, I always approach the local extrema from t0, t1, or the time in between the extrema. (unless the point in between is starting to become a point of low velocity) When this cubic bezier function works, it&rsquo;s such a nice smooth curve. I have it up on demo slide 2.</p> <p>Picture generated in google using this equation: x-(393<em> x^3 +-552</em>x^2+252<em>x-39)/(3</em>393<em>x^2 + 2</em>-552*x+252) </p> <img style="margin-bottom:16px" border=0 src="/media/50512/a86bd5729d49d3db1c9caf78b955df01.png" alt="" /> <p>You can see when guesses start to go haywire. Newton's method is very delicate but very powerful for this sort of application</p> <p>I also put together a quadratic(t^2) bezier function to compare with the cubic(t^3) one :</p> <ul> <li>A cubic function forming an &ldquo;S&rdquo; shaped curve is faster than 2 &ldquo;C&rdquo; shaped quadratics glued together making an S shape, but&hellip;</li> <li>There is now a whole lot of setup code for the cubic function, making it as long or longer than the solutions on stack overflow.</li> <li>The cubic bezier still uses a bit more of the cpu when zoomed out, but the quadratic scales down nicely. I think I would like to play games with several cool looping structures in the distance</li> <li>Glitches remain in the cubic one. Possibly solved by using quadratic bezier functions inside of it.</li> </ul> <p>I think I will shelve the Cubic bezier for now. The Quadratic using Newton's method is nice, compact and fast, and is mostly functional.</p> <p>The next step is to figure out how to rasterize it quickly. Which will be challenging with these angled tlines. Right now this demo runs at 30fps because I draw a tline at every pixel change. I hope it could be efficient enough to have a super fast racing game at 60 fps. But, I&rsquo;m getting burnt out working on this. I think I&rsquo;ll take a step away for a while.</p> <p>The step after that is projection. From what I understand about 3d graphics, all one would have to do is project the 2 3d quadratic beziers (their 4 start and end points, and 2 control points), and one should, in theory, have a splendid textured curve in 3d space!</p> <p>The demo on slide 1 uses some mode 7 type tricks to make it look like the texture is moving and going into the distance. If anyone wants to use a texture in a more standard way, I put in the function draw_textured_quad_bez() at the end (and quad_bezier_newton() above it) that accepts 6 screen control points and map tiles x,y + width/height in tiles. It mostly works pretty well! A sample is on demo slide 3.</p> <p>TL;DR curved polygons?</p> <img style="margin-bottom:16px" border=0 src="/media/50512/bezierfun p8_0.gif" alt="" /> https://www.lexaloffle.com/bbs/?tid=46037 https://www.lexaloffle.com/bbs/?tid=46037 Thu, 06 Jan 2022 17:40:10 UTC mode 7 gravel and grit <p> <table><tr><td> <a href="/bbs/?pid=86557#p"> <img src="/bbs/thumbs/pico8_ftest947284957820183847501c-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=86557#p"> ftest947284957820183847501c</a><br><br> by <a href="/bbs/?uid=50512"> ryzorm</a> <br><br><br> <a href="/bbs/?pid=86557#p"> [Click to Play]</a> </td></tr></table> </p> <p>More mode 7 posts I say! </p> <p>I was wondering if pico 8 could be used for making a fast mode 7 multiplayer racing game with the new tline function.<br /> Unfortunately pixels near to the camera look huge if you want to have a racetrack of a decent size.</p> <p>This solution uses another tline to render a gravel and grit texture to break up the huge pixels. Is there a name for that? I guess it's close to mipmaping.</p> <p>I think It looks pretty good at slow and medium speeds. At fast speeds it looks a bit repetitive. Perhaps a different effect could be used at high speeds.</p> <p>This video helped me figure out the mode 7 equations: <a href="https://www.youtube.com/watch?v=ybLZyY655iY">https://www.youtube.com/watch?v=ybLZyY655iY</a></p> <p>I've been chaotically jumping between projects. I do not know if I will make this into a game or not.</p> https://www.lexaloffle.com/bbs/?tid=41197 https://www.lexaloffle.com/bbs/?tid=41197 Mon, 18 Jan 2021 16:59:49 UTC