CodeWalrus

Development => PC, Mac & Vintage Computers => Topic started by: Snektron on May 05, 2015, 10:46:20 AM

Title: [pico-8] Raymarcher
Post by: Snektron on May 05, 2015, 10:46:20 AM
So i downloaded pico-8 a few days ago, and i made a shader-like thingy (basically it loops through every pixel and runs a function to get the color).
Ofcourse, i had to make a raymarcher with it:
(http://img.codewalr.us/pico8sphere.png)
It contains some vector functions, a few raymarch primitives (only 2 atm), atan, acos, sqrt (which i didnt make), and rgb-to-16-color converter, and some functions for the raymarcher lie getting normals and calculating a diffuse value.
The function "f" in the code makes the scene, the image just shows "return sdSphere(p, 2)" which makes a sphere with a radius of 2.
The variable "ro" is the camera position, and dir is the look direction. "sun" is the light direction. "STEPS" is the max # of steps, MAX_DST the maximum distance and EPS/EPS2 a small edge value. It takes a few sec to render an image, but it turned out pretty nice i think :D
(also press action to end the program when its done, or esc to stop it anytime)

EDIT: so i added the "opRep" function which repeates space and increased the max distance:
(http://img.codewalr.us/pic8rm0.png)
Title: Re: Raymarcher
Post by: CKH4 on May 05, 2015, 11:16:07 AM
Can you make it move? How long does it take to draw the second imgae screen? This is very cool and I'll see what I can make with it.
Title: Re: [pico-8] Raymarcher
Post by: Snektron on May 05, 2015, 11:22:49 AM
Well, theoretically you can, and on real shaders its easy, but it takes a relatively long time to render one frame that it would take too long for movement. Also the second one takes like 30 sec or something, quite long :P (a plane takes longer though). You can decrease the render time by lowering the steps and max_dst, though the result would not be as good
Title: Re: Raymarcher
Post by: CKH4 on May 05, 2015, 11:31:04 AM
I'll see what I can do with it. I'm going to try anyway on the movement so maybe I'll do a time lapse.
Title: Re: [pico-8] Raymarcher
Post by: Snektron on May 05, 2015, 11:33:12 AM
Cool :) also keep in mind the ray dir still has a few bugs. It doesnt work right when you have any other value than vec3(1,0,0), vec3(0,1,0) or vec3(0,0,1) (i think itssomething with the mormalize function)

EDIT: i've updated the cartridge: The ray dir is now fixed :D. also i've added the sdBox primitive, but i've not really tested it.
Title: Re: Raymarcher
Post by: matrefeytontias on May 05, 2015, 02:33:44 PM
Nice :D I like the pixelated look it gives to a raymarcher.
Title: Re: [pico-8] Raymarcher
Post by: Snektron on May 05, 2015, 02:42:49 PM
Thanks! and i like that too :)
Title: Re: Raymarcher
Post by: Dream of Omnimaga on May 06, 2015, 09:53:32 PM
Woah that looks very cool! That texture above could pretty much be used as pixel art in a sprite sheet O.O