Oxygen Basic

Information => Open Forum => Topic started by: JRS on November 03, 2014, 12:21:42 AM

Title: The Outer Limits
Post by: JRS on November 03, 2014, 12:21:42 AM
I was reading a thread about the smallest .exe that Windows can run. (97 bytes) It seems to run without error under Wine but got a way too funny result under XP. (in a VirtualBox - see attached)

Creating the smallest possible PE executable (http://www.phreedom.org/research/tinype/)

.
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on November 03, 2014, 05:44:14 AM
Such hocus-pocuses were doable way back at the times of Win2K but aren't possible any more under genuine XP and up. The smallest exe that I was able to machine code and get going under XP was somewhere around 1,300 bytes in size. Smaller exes are rejected by the PE loader. They say that's part of MS AV policy.
Title: Re: The Outer Limits
Post by: Charles Pegge on November 03, 2014, 07:24:38 AM
It is perfectly feasible to create a customised binary loader, if so desired. OxygenBasic's code is relocatable, so address remapping is not required.
Title: The Outer Limits - File System Redirector
Post by: JRS on December 14, 2014, 11:27:48 PM
I ran into this and thought I would pass it along.

Quote
File System Redirector

The %windir%\System32 directory is reserved for 64-bit applications. Most DLL file names were not changed when 64-bit versions of the DLLs were created, so 32-bit versions of the DLLs are stored in a different directory. WOW64 hides this difference by using a file system redirector.

In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64. Access to %windir%\lastgood\system32 is redirected to %windir%\lastgood\SysWOW64. Access to %windir%\regedit.exe is redirected to %windir%\SysWOW64\regedit.exe.

If the access causes the system to display the UAC prompt, redirection does not occur. Instead, the 64-bit version of the requested file is launched. To prevent this problem, either specify the SysWOW64 directory to avoid redirection and ensure access to the 32-bit version of the file, or run the 32-bit application with administrator privileges so the UAC prompt is not displayed.

Windows Server 2003 and Windows XP: UAC is not supported.

Certain subdirectories are exempt from redirection. Access to these subdirectories is not redirected to %windir%\SysWOW64:
%windir%\system32\catroot%windir%\system32\catroot2%windir%\system32\driverstore %windir%\system32\drivers\etc%windir%\system32\logfiles%windir%\system32\spool
Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: %windir%\system32\driverstore is redirected.

To retrieve the name of the 32-bit system directory, 64-bit applications should use the GetSystemWow64Directory function.

Applications should use the SHGetSpecialFolderPath function to determine the %ProgramFiles% directory name.

Applications can control the WOW64 file system redirector using the Wow64DisableWow64FsRedirection, Wow64EnableWow64FsRedirection, and Wow64RevertWow64FsRedirection functions. Disabling file system redirection affects all file operations performed by the calling thread, so it should be disabled only when necessary for a single CreateFile call and re-enabled again immediately after the function returns. Disabling file system redirection for longer periods can prevent 32-bit applications from loading system DLLs, causing the applications to fail.

32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. This mechanism is flexible and easy to use, therefore, it is the recommended mechanism to bypass file system redirection. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one.

Windows Server 2003 and Windows XP: The Sysnative alias was added starting with Windows Vista.
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on December 15, 2014, 12:00:39 AM
Thanks for sharing, John.
Title: Re: The Outer Limits - Smallest Windows Executable
Post by: Mike Lobanovsky on December 15, 2014, 12:34:04 AM
Here's the smallest Windows GUI executable that I was able to compile with MS VC6. It's only 496 bytes large and it doesn't produce any visible output. Nonetheless it does load in memory and it does fulfill its only purpose, which is to return a zero exit code to the system.

Not sure though if it's compilable with any later version of MS Visual C.

Code: [Select]
#include <windows.h>
 
// Make section alignment really small
#pragma comment(linker, "/FILEALIGN:16")
#pragma comment(linker, "/ALIGN:16")
// Merge sections
#pragma comment(linker, "/MERGE:.rdata=.data")
#pragma comment(linker, "/MERGE:.text=.data")
#pragma comment(linker, "/MERGE:.reloc=.data")
// Favour small code
#pragma optimize("gsy", on)
 
// Single entrypoint
int WinMainCRTStartup()
{
return 0;
}

.
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on January 04, 2015, 08:21:25 PM
Interestingly, similar results are feasible under Linux as well. Here's a tutorial (http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html) on how you can generate a 45-byte-only Linux executable that would be only as large as a fraction of its circumcized ELF header. That's effectively less than one fiftieth the size of the smallest executable that you would be able to create using your favorite GNU C compiler. :)
Title: Re: The Outer Limits
Post by: JRS on January 20, 2015, 12:09:13 AM
Here is a recap of the activity for the OxygenBasic site for 2014. Thanks to those that contributed and made the site interesting. As always, Charles keeps me amazed and humbled.



.
Title: Re: The Outer Limits
Post by: JRS on March 12, 2015, 09:28:43 AM
I came across this ad on craiglist.  I guess we still haven't reached the bottom yet but this is close.  :'(

Quote
I gave you a ride from the courthouse Sept. 22 2014 You had just gotten out of jail, and you stole my pink plaid laptop. If you return it unharmed I'll pay you for it!!! It has all my daughters pictures on it for the last 6 year's! It's super special to me!! Please!! If any one reading this knows who stole it, please tell her ill pay her for it!
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on March 12, 2015, 10:35:37 AM
Are you willing to pay for DDOS? I guess skyrocketing the visits counter won't be too hard to fix up. ;)

(http://sminews.info/uploads/posts/2013-12/1386204087_anonymous.jpg)



P.S. I was simply trying to relate your two latest posts in this thread to each other. I'm just not sure if it was obvious enough. :)
Title: Re: The Outer Limits
Post by: JRS on April 09, 2015, 02:16:00 PM
PC shipments mark lowest recorded volume since Q1 2009: IDC (http://www.zdnet.com/article/idc-offers-less-glowing-q1-recap-for-pc-industry-but-it-beat-expectations/#ftag=RSSbaffb68)

Quote
It should be noted IDC defines the PC category a bit more broadly than Gartner, specificing data spans desktops, laptops, Chromebooks, Workstations and Ultraslim notebooks but not handhelds, x86 servers and tablets.

Title: Re: The Outer Limits
Post by: Mike Lobanovsky on April 10, 2015, 05:22:23 AM
The last year's springtime saw the deprecation of installed XP base worldwide, which naturally led to a boost in volume sales of newer machines in that period onward. Now that the transition period is evidently over, a certain decline in net sales would be an expected phenomenon. It is yet too early to regard this figure as an onset of the trend IMO.

Note also that the US figures are not that bad at all.
Title: Re: The Outer Limits
Post by: JRS on April 10, 2015, 07:08:07 PM
I hope some of those ancient PC's (unable to run current Windows OS) will find a new home with Linux rather than a scrap yard. (remember A.I.)

(http://i.kinja-img.com/gawker-media/image/upload/s--cLbYNNRg--/c_fit,fl_progressive,q_80,w_636/17rdo6q6j846fjpg.jpg)
Title: Re: The Outer Limits
Post by: JRS on April 23, 2015, 01:52:59 PM
(http://ecx.images-amazon.com/images/I/51iTjRQZddL.jpg) (http://www.amazon.com/DIAOTEC-antennas-Cortex-A9-processor-Mali-400MP4/dp/B00ECBY5VS/ref=pd_sim_e_13?ie=UTF8&refRID=0C692NPXVXQGFPA07EVW)
Title: Re: The Outer Limits
Post by: Charles Pegge on April 24, 2015, 02:36:18 PM

(http://vignette2.wikia.nocookie.net/jamescameronsavatar/images/f/f7/The_making_of_avatar_front_cover.jpg/revision/latest?cb=20100819155716)

https://www.youtube.com/watch?v=KcBuqUDLg7w


the gigital resources used in the production of Avatar (2009)

Quote
The lead visual effects company was Weta Digital in Wellington, New Zealand, at one point employing 900 people to work on the film.[103] Because of the huge amount of data which needed to be stored, cataloged and available for everybody involved, even on the other side of the world, a new cloud computing and Digital Asset Management (DAM) system named Gaia was created by Microsoft especially for Avatar, which allowed the crews to keep track of and coordinate all stages in the digital processing.[104] To render Avatar, Weta used a 10,000 sq ft (930 m2) server farm making use of 4,000 Hewlett-Packard servers with 35,000 processor cores with 104 terabytes of RAM and three petabytes of network area storage running Ubuntu Linux, Grid Engine cluster manager, and 2 of the animation software and managers, Pixar's RenderMan and Pixar's Alfred queue management system.[105][106][107][108] The render farm occupies the 193rd to 197th spots in the TOP500 list of the world's most powerful supercomputers. A new texturing and paint software system, called Mari, was developed by The Foundry in cooperation with Weta.[109][110] Creating the Na'vi characters and the virtual world of Pandora required over a petabyte of digital storage,[111] and each minute of the final footage for Avatar occupies 17.28 gigabytes of storage.[112] Often, it would take each frame of the movie several hours to render.[113] To help finish preparing the special effects sequences on time, a number of other companies were brought on board, including Industrial Light & Magic, which worked alongside Weta Digital to create the battle sequences. ILM was responsible for the visual effects for many of the film's specialized vehicles and devised a new way to make CGI explosions.[114] Joe Letteri was the film's visual effects general supervisor.[115]
http://en.wikipedia.org/wiki/Avatar_%282009_film%29
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on April 24, 2015, 11:13:41 PM
www.amazon.com DIAOTEC-antennas-Cortex-A9-processor-Mali-400MP4

This is NOT a PC, this is only a multimedia TV dongle.  >:(
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on April 24, 2015, 11:20:32 PM
the gigital resources used in the production of Avatar (2009)

This is very, very impressive but is becoming part of history. The preproduction phase of three sequels to be released starting December 2017 began in November last year.

I wish to live long enough to watch all the three of them, and also to see the first manned landing on Mars. :)
Title: Re: The Outer Limits
Post by: JRS on April 25, 2015, 12:39:55 AM
Quote
This is NOT a PC, this is only a multimedia TV dongle.

It has twice as many processors as my Samsung Galaxy Tab 2 10.1 tablet and has USB ports the GT2 doesn't have. It's a tablet class device in a memory stick form factor.  8)
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on April 25, 2015, 01:39:07 AM
It has twice as many processors as my Samsung Galaxy Tab 2 10.1 tablet and has USB ports the GT2 doesn't have.

Exactly half of its processors total are on the GPU. :D
Title: Re: The Outer Limits
Post by: JRS on April 28, 2015, 07:44:47 PM
MSDN - Project Detroit: OBD-II Manager (http://channel9.msdn.com/coding4fun/projects/Project-Detroit-OBD-II-Manager)

A Microsoft Channel 9 Coding4Fun project.

(http://files.channel9.msdn.com/thumbnail/b964d3a7-3494-4f60-9ffd-98e10f57cfdc.png)

Maybe Patrice can figure out how to incorporate this into his models and plug the USB cable into his car making the (model) cars none of us can afford come alive.  8)
Title: Re: The Outer Limits
Post by: JRS on May 05, 2015, 07:56:45 PM
PowerBASIC Update

Quote from: Donald Montaine - José Roca forum - May 04, 2015
After doing a small amount of research and asking around, it seems the company is not really operational at this point.  I don't believe either Jim Bailey or Tom Hanlin are involved any more.
Title: Re: The Outer Limits
Post by: JRS on May 07, 2015, 11:10:38 PM
I really like this logo and can see a variation for Script Ledger.

(https://pbs.twimg.com/profile_images/530474068894445568/MYBNbfQd_400x400.jpeg)
Title: Re: The Outer Limits
Post by: JRS on May 08, 2015, 04:19:56 AM
PC sales continue to take a beating (http://www.zdnet.com/article/pc-sales-continue-to-take-a-beating/#ftag=RSSbaffb68)

Quote
PC OEMs are hoping that Terry Myerson, the head of Microsoft's Operating Systems Group, wasn't making an idle boast when he said Windows 10 would be on a billion devices in two to three years. That's because by research house Canalys's reckoning, "The global PC market, including tablets, experienced an annual decline of 7 percent in Q1 2015."

(http://zdnet4.cbsistatic.com/hub/i/2015/05/07/9394f4c6-eea8-4b8a-b067-cfe1762fc618/4f80b9ffba4e4e268337575fb45402a5/pc-sales-1st2015.jpg)
Title: Re: The Outer Limits
Post by: JRS on May 10, 2015, 09:01:51 AM
Scarface mansion price slashed in half. (was $35 million)

(http://upload.wikimedia.org/wikipedia/en/5/5c/Scarface.jpg)

Virtual Tour (https://homes.yahoo.com/blogs/spaces/-scarface--mansion-price-gets-slashed-in-half-191536563.html)
Title: Re: The Outer Limits
Post by: JRS on May 23, 2015, 12:41:16 PM
It has been interesting and a great leaning experience lurking the Mike & Patrice show. Patrice's latest mesh editor example sparked an idea for how to buy clothes on-line.  Have a 3D model created of your body and vendors can match inventory they have that would be a good fit. They could also demo it for you on-line. Just a thought.

 Fits like a glove.  :)

(http://www.oxygenbasic.org/forum/index.php?action=dlattach;topic=1274.0;attach=4626;image)
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on May 23, 2015, 03:35:03 PM
... and you could also earn a coupla $$ in the process by hiring yourself out to them to create the 3D models of their current stock. No wait, this can even turn into a never-ending inflow of cash because the inventory's going to be updated every season. :)
Title: Re: The Outer Limits
Post by: JRS on May 23, 2015, 03:59:12 PM
Actually I'm looking for a job scanning real models and selling their ass to designers.  :P
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on May 23, 2015, 04:26:13 PM
Have you filed an application with Milla yet? ;)
Title: Re: The Outer Limits
Post by: JRS on November 30, 2015, 07:03:09 PM
Climate change protester.  8)

.
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on November 30, 2015, 07:44:42 PM
I'm calling this "the land of untamable idiots". There are so many more urgent challenges in the world today! For example, look at that crazy putinist Russia: this weekend's prime time on their main nationwide TV channels has been devoted to  some heated debates on whether they should drop an H-bomb on Istanbul or not!! HORRIBLE!!!
Title: Re: The Outer Limits
Post by: JRS on November 30, 2015, 08:19:14 PM
Quote
There are so many more urgent challenges in the world today!

Like building new planes that can't fly in combat and aircraft carriers they can't land on while spending billions sending shit into space. Better than going to the circus.
Title: Re: The Outer Limits
Post by: JRS on February 27, 2016, 07:47:00 AM
(https://pbs.twimg.com/media/CcJ80Y8UcAArUKd.jpg)
Title: Re: The Outer Limits
Post by: JRS on March 17, 2016, 01:36:52 AM
This years pi Day was kind of special.

3-14-16

100,000 Digits of Pi (http://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html)
Title: Re: The Outer Limits
Post by: JRS on April 09, 2016, 12:36:28 AM
Yesterday's date (4/8/2016):  2²/2³/2⁴ (for all those using the mm/dd/yy date format)

Code: Script BASIC
  1. PRINT FORMAT("%i/%i/%i\n",2^2,2^3,2^4)
  2.  


jrs@laptop:~/sb/sb22/test$ scriba 2day.sb
4/8/16
jrs@laptop:~/sb/sb22/test$

Title: Re: The Outer Limits
Post by: Charles Pegge on April 09, 2016, 12:46:21 AM
Is this a better day than 1st April for posting an update? :)
Title: Re: The Outer Limits
Post by: JRS on April 03, 2018, 01:09:04 PM
What is the smallest number that can be exactly divided by all the numbers 1 to 10?

Title: Re: The Outer Limits
Post by: jack on April 03, 2018, 01:21:58 PM
interesting question.
Title: Re: The Outer Limits
Post by: Charles Pegge on April 03, 2018, 02:42:11 PM
Solving by brute force.

The challenge escalates rapidly for higher n. I would advise not going above 20.

Code: [Select]
'2018-04-03 T 23:39:49
'FIND LOWEST NUMBER EXACTLY DIVISIBLE BY 1..N
double i,m,n,mx
mx=1e11 : n=10
for m=n to mx
 for i=2 to n-1
  if mod(m,i) then exit for
 next
 if i>=n then print m : exit for
next

Any more efficient algorithms?

Perhaps something to do with primes..
Title: Re: The Outer Limits
Post by: JRS on April 03, 2018, 08:58:42 PM
The Cord

Code: C
  1. //#define ANOTHER_LEVEL
  2.  
  3.  
  4. /* SHADERTOY FROM HERE */
  5.  
  6. float guiLead = 0.6;
  7. float guiInnerRatio = 0.4407892623709694;
  8. float guiFocal = 3.;
  9. float guiRotateModel = 0.4560833039600971;
  10. float guiDebug = 0.6749066960348409;
  11. float guiZipOffset = 30.;
  12. float guiZipSize = 60.;
  13. float guiZipSpeed = 3.3;
  14. float guiZoom = 0.1;
  15. float guiModelScale = 7.749066960348409;
  16.  
  17. mat4 cameraMatrix = mat4(
  18.     -0.7063226699829102,
  19.     0.7052236199378967,
  20.     0.06198469549417496,
  21.     0,
  22.     -0.30620118975639343,
  23.     -0.3832840919494629,
  24.     0.8714323043823242,
  25.     0,
  26.     0.6382971405982971,
  27.     0.5965006947517395,
  28.     0.48660656809806824,
  29.     0,
  30.     0.14653973281383514,
  31.     0.6211488246917725,
  32.     0.13233166933059692,
  33.     1
  34. );
  35.  
  36. vec3 camPosition = vec3(0.14653973281383514, 0.6211488246917725, 0.13233166933059692);
  37.  
  38. float time;
  39.  
  40. #define PI 3.14159265359
  41. #define HALF_PI 1.5707963267948966
  42. #define TAU 6.28318530718
  43. #define PHI 1.618033988749895
  44.  
  45.  
  46. // --------------------------------------------------------
  47. // Utils
  48. // --------------------------------------------------------
  49.  
  50. #define saturate(x) clamp(x, 0., 1.)
  51.  
  52. // Rotate around a coordinate axis (i.e. in a plane perpendicular to that axis) by angle <a>.
  53. // Read like this: R(p.xz, a) rotates "x towards z".
  54. // This is fast if <a> is a compile-time constant and slower (but still practical) if not.
  55. void pR(inout vec2 p, float a) {
  56.     p = cos(a)*p + sin(a)*vec2(p.y, -p.x);
  57. }
  58.  
  59. // http://www.neilmendoza.com/glsl-rotation-about-an-arbitrary-axis/
  60. mat3 rotationMatrix(vec3 axis, float angle)
  61. {
  62.     axis = normalize(axis);
  63.     float s = sin(angle);
  64.     float c = cos(angle);
  65.     float oc = 1.0 - c;
  66.    
  67.     return mat3(
  68.         oc * axis.x * axis.x + c,           oc * axis.x * axis.y - axis.z * s,  oc * axis.z * axis.x + axis.y * s,
  69.         oc * axis.x * axis.y + axis.z * s,  oc * axis.y * axis.y + c,           oc * axis.y * axis.z - axis.x * s,
  70.         oc * axis.z * axis.x - axis.y * s,  oc * axis.y * axis.z + axis.x * s,  oc * axis.z * axis.z + c
  71.     );
  72. }
  73.  
  74. float range(float vmin, float vmax, float value) {
  75.   return (value - vmin) / (vmax - vmin);
  76. }
  77.  
  78. float rangec(float a, float b, float t) {
  79.     return clamp(range(a, b, t), 0., 1.);
  80. }
  81.  
  82. float vmax(vec2 v) {
  83.     return max(v.x, v.y);
  84. }
  85.  
  86. float fBox2(vec2 p, vec2 b) {
  87.     vec2 d = abs(p) - b;
  88.     return length(max(d, vec2(0))) + vmax(min(d, vec2(0)));
  89. }
  90.  
  91. // Repeat space along one axis. Use like this to repeat along the x axis:
  92. // <float cell = pMod1(p.x,5);> - using the return value is optional.
  93. float pMod1(inout float p, float size) {
  94.     float halfsize = size*0.5;
  95.     float c = floor((p + halfsize)/size);
  96.     p = mod(p + halfsize, size) - halfsize;
  97.     return c;
  98. }
  99.  
  100. vec3 cartToPolar(vec3 p) {
  101.     float x = p.x; // distance from the plane it lies on
  102.     float a = atan(p.y, p.z); // angle around center
  103.     float r = length(p.zy); // distance from center
  104.     return vec3(x, a, r);
  105. }
  106.  
  107. vec3 polarToCart(vec3 p) {
  108.     return vec3(
  109.         p.x,
  110.         sin(p.y) * p.z,
  111.         cos(p.y) * p.z
  112.     );
  113. }
  114.  
  115. vec2 closestPointOnLine(vec2 line, vec2 point){
  116.     line = normalize(line);
  117.     float d = dot(point, line);
  118.     return line * d;
  119. }
  120.  
  121. // Closest of two points
  122. vec3 closestPoint(vec3 pos, vec3 p1, vec3 p2) {
  123.     if (length(pos - p1) < length(pos - p2)) {
  124.         return p1;
  125.     } else {
  126.         return p2;
  127.     }
  128. }
  129.  
  130. // --------------------------------------------------------
  131. // Helix
  132. // --------------------------------------------------------
  133.  
  134. // Closest point on a helix for one revolution
  135. vec3 closestHelixSection(vec3 p, float lead, float radius) {
  136.  
  137.     p = cartToPolar(p);
  138.     p.y *= radius;
  139.  
  140.     vec2 line = vec2(lead, radius * PI * 2.);
  141.     vec2 closest = closestPointOnLine(line, p.xy);
  142.  
  143.     closest.y /= radius;
  144.     vec3 closestCart = polarToCart(vec3(closest, radius));
  145.  
  146.     return closestCart;
  147. }
  148.  
  149. // Closest point on a helix for infinite revolutions
  150. vec3 closestHelix(vec3 p, float lead, float radius) {
  151.     float c = pMod1(p.x, lead);
  152.     vec3 offset = vec3(lead, 0, 0);
  153.     vec3 A = closestHelixSection(p, lead, radius);
  154.     vec3 B = closestHelixSection(p + offset, lead, radius) - offset;
  155.     vec3 C = closestHelixSection(p - offset, lead, radius) + offset;
  156.     vec3 closest = closestPoint(p, A, closestPoint(p, B, C));
  157.     closest += offset * c;
  158.     return closest;
  159. }
  160.  
  161. // Cartesian to helix coordinates
  162. void pModHelix(inout vec3 p, float lead, float radius) {
  163.     vec3 closest = closestHelix(p, lead, radius);
  164.     float helixAngle = atan((2. * PI * radius) / lead);
  165.     vec3 normal = normalize(closest - vec3(closest.x,0,0));
  166.     vec3 tangent = vec3(1,0,0) * rotationMatrix(normal, helixAngle);
  167.     float x = (closest.x / lead) * radius * PI * 2.;
  168.     float y = dot(p - closest, cross(tangent, normal));
  169.     float z = dot(p - closest, normal);
  170.     p = vec3(x, y, z);
  171. }
  172.  
  173. float pModHelixScale(inout vec3 p, float lead, float innerRatio) {
  174.     float radius = mix(.25, .5, innerRatio);
  175.     pModHelix(p, lead, radius);
  176.     float scale = mix(.5, 0., innerRatio);
  177.     p /= scale;
  178.     return 1. / scale;
  179. }
  180.  
  181. float pModHelixUnwrap(inout vec3 p, float lead, float innerRatio, float t) {
  182.     float radius = mix(.25, .5, innerRatio);
  183.     float width = cos(asin(t));
  184.     float adjust = (1. / width);
  185.     float offset = ((.5 * adjust) - .5) * 7.;
  186.  
  187.     vec3 pp = p;
  188.     pp.z -= radius;
  189.     pR(pp.xy, PI * -.5);
  190.     pp.x *= -1.;
  191.  
  192.     p.z += offset;
  193.     radius += offset;
  194.     pModHelix(p, lead, radius);
  195.  
  196.     p = mix(p, pp, rangec(.8, 1., t));
  197.  
  198.     float scale = mix(.5, 0., innerRatio);
  199.     p /= scale;
  200.     return 1. / scale;
  201. }
  202.  
  203.  
  204. // --------------------------------------------------------
  205. // Modelling
  206. // --------------------------------------------------------
  207.  
  208. struct Model {
  209.     float dist;
  210.     vec3 albedo;
  211.     int id;
  212. };
  213.  
  214. float anim(float t, float index) {
  215.     float overlap = .5;
  216.     float steps = 2.;
  217.     float all = mix(steps, 1., overlap);
  218.     float width = 1. / (all - 1.);
  219.     float each = width * (1.- overlap);
  220.     float start = index * each - width * .5;
  221.     float end = start + width;
  222.     return range(start, end, t);
  223. }
  224.  
  225. float unzip(vec3 p, float t) {
  226.     float size = guiZipSize;
  227.     float speed = guiZipSpeed;
  228.  
  229.     t *= size * speed;
  230.  
  231.     if (sign(p.y) != sign(p.x)) {
  232.         float radius = mix(.25, .5, guiInnerRatio);
  233.         float scale = mix(.5, 0., guiInnerRatio);
  234.         float factor = radius / scale * PI * 2.;
  235.         t -= (factor - .5);
  236.     }
  237.  
  238.     return range(size, 0., abs(p.x) + size - t);
  239. }
  240.  
  241. void addPipe(inout float d, vec3 p, float scale, float tt) {
  242.  
  243.     float t = clamp(tt, 0., 1.);
  244.  
  245.     float boundry = 1.;
  246.     float part;
  247.     float separate = (
  248.         rangec(0., boundry * .01, t) * .3 +
  249.         rangec(boundry * .01, boundry, t) * .7
  250.     );
  251.  
  252.     float round = rangec(.0, 1., t);
  253.  
  254.     part = fBox2(p.yz, vec2(mix(guiLead * 2., .5, separate), .5));
  255.     part = mix(part, length(p.yz) - .5, round);
  256.     part /= scale;
  257.  
  258.     d = mix(d, part, smoothstep(.0, .01, t));
  259. }
  260.  
  261. void unzipHelixModel(inout float d, inout float scale, inout vec3 p, float lead, float innerRatio, float step, float invert) {
  262.     float offset = guiZipOffset / lead;
  263.     scale *= pModHelixScale(p, lead, innerRatio);
  264.     p.x *= -1.;
  265.     float t1 = unzip(p + vec3(offset,0,0) * invert, anim(time, step));
  266.     addPipe(d, p, scale, t1);
  267. }
  268.  
  269. Model map(vec3 p) {
  270.  
  271.     float part, d, t1, t2, t3, t4;
  272.     float lead = guiLead;
  273.     float innerRatio = guiInnerRatio;
  274.     vec2 uv1, uv2, uv3;
  275.  
  276.     p /= guiModelScale;
  277.  
  278.     vec3 pp = p;
  279.  
  280.     d = 1e12;
  281.  
  282.     float s = mix(.5, 0., innerRatio);
  283.  
  284.     float scale = 1./pow(1./s, time);
  285.  
  286.     pR(p.xy, PI * -.5 * time + guiRotateModel * PI * 2.);
  287.    
  288.     p *= scale;
  289.     p.z += .5;
  290.  
  291.     scale *= pModHelixUnwrap(p, lead, innerRatio, time);
  292.     p.x *= -1.;
  293.     scale *= pModHelixScale(p, lead, innerRatio);
  294.     p.x *= -1.;
  295.  
  296.     #ifdef ANOTHER_LEVEL
  297.         scale *= pModHelixScale(p, lead, innerRatio);
  298.         p.x *= -1.;
  299.     #endif
  300.  
  301.     d = min(d, length(p.yz) - .5);
  302.     d /= scale;
  303.  
  304.     unzipHelixModel(d, scale, p, lead, innerRatio, -1., 1.);
  305.     unzipHelixModel(d, scale, p, lead, innerRatio, 0., -1.);
  306.     unzipHelixModel(d, scale, p, lead, innerRatio, 1., 1.);
  307.  
  308.     d *= guiModelScale;
  309.  
  310.     return Model(d, vec3(0), 1);
  311. }
  312.  
  313.  
  314. // --------------------------------------------------------
  315. // Ray Marching
  316. // Adapted from: https://www.shadertoy.com/view/Xl2XWt
  317. // --------------------------------------------------------
  318.  
  319. const float MAX_TRACE_DISTANCE = 1.5; // max trace distance
  320. const float INTERSECTION_PRECISION = .001; // precision of the intersection
  321. const int NUM_OF_TRACE_STEPS = 100;
  322. const float FUDGE_FACTOR = 1.; // Default is 1, reduce to fix overshoots
  323.  
  324. struct CastRay {
  325.     vec3 origin;
  326.     vec3 direction;
  327. };
  328.  
  329. struct Ray {
  330.     vec3 origin;
  331.     vec3 direction;
  332.     float len;
  333. };
  334.  
  335. struct Hit {
  336.     Ray ray;
  337.     Model model;
  338.     vec3 pos;
  339.     bool isBackground;
  340.     vec3 normal;
  341.     bool isOutline;
  342. };
  343.  
  344. // Faster runtime
  345. vec3 _calcNormal(vec3 pos){
  346.     vec3 eps = vec3(.0001,0,0);
  347.     vec3 nor = vec3(
  348.         map(pos+eps.xyy).dist - map(pos-eps.xyy).dist,
  349.         map(pos+eps.yxy).dist - map(pos-eps.yxy).dist,
  350.         map(pos+eps.yyx).dist - map(pos-eps.yyx).dist );
  351.     return normalize(nor);
  352. }
  353.  
  354. // Faster compilation
  355. const int NORMAL_STEPS = 6;
  356. vec3 calcNormal(vec3 pos){
  357.     vec3 eps = vec3(.001,0,0);
  358.     vec3 nor = vec3(0);
  359.     float invert = 1.;
  360.     for (int i = 0; i < NORMAL_STEPS; i++){
  361.         nor += map(pos + eps * invert).dist * eps * invert;
  362.         eps = eps.zxy;
  363.         invert *= -1.;
  364.     }
  365.     return normalize(nor);
  366. }
  367.  
  368.  
  369. Hit raymarch(CastRay castRay){
  370.  
  371.     float currentDist = INTERSECTION_PRECISION * 2.0;
  372.     float outlineDist = INTERSECTION_PRECISION * 2.0;
  373.     Model model;
  374.  
  375.     float outline = .0023;
  376.     bool isOutline = false;
  377.     bool miss = false;
  378.  
  379.     float lastDist = currentDist;
  380.  
  381.     Ray ray = Ray(castRay.origin, castRay.direction, 0.);
  382.  
  383.     for( int i=0; i< NUM_OF_TRACE_STEPS ; i++ ){
  384.         if (currentDist < INTERSECTION_PRECISION || ray.len > MAX_TRACE_DISTANCE) {
  385.             break;
  386.         }
  387.         model = map(ray.origin + ray.direction * ray.len);
  388.         lastDist = currentDist;
  389.         currentDist = model.dist;
  390.         miss = currentDist > lastDist;
  391.         outlineDist = currentDist * -1. + outline;
  392.         isOutline = outlineDist > .0 && outlineDist < currentDist && miss;
  393.         if (isOutline) {
  394.             currentDist = outlineDist;
  395.         }
  396.         ray.len += currentDist * FUDGE_FACTOR;
  397.     }
  398.  
  399.     bool isBackground = false;
  400.     vec3 pos = vec3(0);
  401.     vec3 normal = vec3(0);
  402.  
  403.     if (ray.len > MAX_TRACE_DISTANCE) {
  404.         isBackground = true;
  405.     } else {
  406.         pos = ray.origin + ray.direction * ray.len;
  407.         normal = calcNormal(pos);
  408.     }
  409.  
  410.     return Hit(ray, model, pos, isBackground, normal, isOutline);
  411. }
  412.  
  413.  
  414. // --------------------------------------------------------
  415. // Rendering
  416. // --------------------------------------------------------
  417.  
  418. float softshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
  419. {
  420.     float res = 1.0;
  421.     float t = mint;
  422.     float ph = 1e10;
  423.    
  424.     for( int i=0; i<32; i++ )
  425.     {
  426.         float h = map( ro + rd*t ).dist;
  427.         res = min( res, 10.0*h/t );
  428.         t += h;
  429.         if( res<0.0001 || t>tmax ) break;
  430.        
  431.     }
  432.     return clamp( res, 0.0, 1.0 );
  433. }
  434.  
  435.  
  436. float calcAO( in vec3 pos, in vec3 nor )
  437. {
  438.     float occ = 0.0;
  439.     float sca = 1.0;
  440.     for( int i=0; i<5; i++ )
  441.     {
  442.         float hr = 0.01 + 0.12*float(i)/4.0;
  443.         vec3 aopos =  nor * hr + pos;
  444.         float dd = map( aopos ).dist;
  445.         occ += -(dd-hr)*sca;
  446.         sca *= 0.95;
  447.     }
  448.     return clamp( 1.0 - 3.0*occ, 0.0, 1.0 );    
  449. }
  450.  
  451.  
  452. vec3 doLighting(vec3 pos, vec3 nor, vec3 ref, vec3 rd) {
  453.  
  454.     vec3 col;
  455.     vec3 up = normalize(vec3(1));
  456.  
  457.     // lighitng        
  458.     float occ = mix(calcAO( pos, nor ), 1., .8);
  459.     vec3  lig = normalize(vec3(0,.2,1));
  460.     float amb = clamp(dot(nor, up) * .5 + .5, 0., 1.);
  461.     float dif = clamp( dot( nor, lig ), 0.0, 1.0 );
  462.     float fre = pow( clamp(1.0+dot(nor,rd),0.0,1.0), 2.0 );
  463.     vec3  hal = normalize( lig-rd );
  464.     float spe = pow(clamp( dot( nor, hal ), 0.0, 1.0 ),16.0);
  465.  
  466.     vec3 cA = vec3(.7,.3,.9);
  467.     vec3 cB = vec3(.4,.9,.8);
  468.     vec3 cC = vec3(.7,0,.7);
  469.  
  470.     col = mix(cA, cB, rangec(.0, 1., dot(-rd, nor))); // need better ramp
  471.     col = mix(col, vec3(.8,.5,1), rangec(.5, 1., dif) * .5);
  472.     col += cC * rangec(.5, 1., dif) * .1;
  473.  
  474.     dif *= softshadow( pos, lig, 0.02, 2.5 ) * .9;
  475.  
  476.     vec3 lin = vec3(0);
  477.     lin += .5 * dif;
  478.     lin += .1 * spe * dif;
  479.     lin += .2 * fre * occ;
  480.     lin += .5 * amb * occ;
  481.     lin += .4 * occ;
  482.     col = col*lin;
  483.  
  484.     return col;
  485. }
  486.  
  487. void render(inout vec3 color, Hit hit){
  488.  
  489.     vec3 background = vec3(.1)* vec3(.5,0,1);
  490.     background = color;
  491.  
  492.     if (hit.isBackground) {
  493.         color = background;
  494.         return;
  495.     }
  496.  
  497.     if (hit.isOutline) {
  498.         color = vec3(background * .33);
  499.     } else {
  500.         vec3 ref = reflect(hit.ray.direction, hit.normal);
  501.         color = doLighting(
  502.             hit.pos,
  503.             hit.normal,
  504.             ref,
  505.             hit.ray.direction
  506.         );
  507.     }
  508.  
  509.     float fog = length(camPosition - hit.pos);
  510.     fog = smoothstep(float(MAX_TRACE_DISTANCE) * .36, float(MAX_TRACE_DISTANCE), fog);
  511.     color = mix(color, background, fog);
  512. }
  513.  
  514. void mainImage( out vec4 fragColor, in vec2 fragCoord )
  515. {
  516.     vec2 p = (-iResolution.xy + 2.0*fragCoord.xy)/iResolution.y;
  517.  
  518.     vec3 color = mix(vec3(.4,.3,.5) * .9, vec3(.6), -.2);
  519.  
  520.     vec3 bgA = vec3(.6,.5,.8) * .55;
  521.     vec3 bgB = vec3(.7,.9,1.) * .5;
  522.     color = mix(bgA, bgB, dot(p, normalize(vec2(.2,-.6))) * .5);
  523.  
  524.     time = iTime;
  525.     time *= .6;
  526.     time = mod(time, 1.);
  527.  
  528.     float camDist = length(camPosition);
  529.  
  530.     mat4 camMat = cameraMatrix;
  531.     float focalLength = guiFocal;
  532.     vec3 rd = normalize(
  533.         (vec4(p, -focalLength, 1) * camMat).xyz
  534.     );
  535.  
  536.     Hit hit = raymarch(CastRay(camPosition, rd));
  537.  
  538.     render(color, hit);
  539.  
  540.     vec2 uv = fragCoord/iResolution.xy;
  541.     float vig = pow(
  542.         16. * uv.x * uv.y * (1. - uv.x) * (1. - uv.y),
  543.         0.075
  544.     );
  545.     color *= vec3(.9, .95, 1.) * vig * 1.1;
  546.  
  547.     color = mix(color, vec3(pow(length(color * .6), 2.)), .1);
  548.     color *= 1.05;
  549.     color = pow(color, vec3(1.2,1.3,1.2));
  550.  
  551.     fragColor = vec4(color,1.0);
  552. }
  553.  
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on April 04, 2018, 01:29:51 AM
John,

This is part of OpenGL GLSL shader source code. Not sufficient to run OOTB though. Where can I find the rest of it, please?

This raymarching stuff will be pretty hard to run in a medium sized OpenGL window even on a decent hardware accelerated GPU like mine. And it will be absolutely impossible to mimic it in real time in an ordinary C or assembly program run on a conventional CPU. ;)
Title: Re: The Outer Limits
Post by: jack on April 04, 2018, 02:15:40 AM
@John
D.J.Peters posted FreeBasic code to run shadertoy code https://www.freebasic.net/forum/viewtopic.php?p=217073
using his FB code and replacing iTime with iGlobalTime everything works on my Mac, I get 60 fps
Title: Re: The Outer Limits
Post by: jack on April 04, 2018, 03:29:24 AM
I am impressed with what is possible with so few lines of code https://www.shadertoy.com/view/Ms2SD1
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on April 04, 2018, 03:35:12 AM
Thanks Jack,

The FB code you pointed to helps to determine which uniforms in fact the shader uses. I'm not going to use the code proper though because I have a renderer written in FBSL that can run ShaderToy GLSL shaders directly without modification.
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on April 04, 2018, 07:40:58 AM
Like I said, the shader is rather heavy on the GPU as is always the case with such complex raymarching techniques. The original FB code isn't very reliable in its FPS measurements, so what I get in a 640x360 px OpenGL window that would be the ShaderToy's default is in fact stable 30 FPS (verified by 3rd party Fraps app; yellow figures at bottom right) @ some 75% GPU load. The attached renderer is VSYNC'ed at 60FPS so that's the upper limit it would allow the scene to be rendered at. I'm getting 5FPS full screen on my 1980x1050 monitors.

The zip below contains the precompiled renderer and may cause false AV alarms.
Title: Re: The Outer Limits
Post by: JRS on April 04, 2018, 08:03:16 AM
Outstanding Mike!

Title: Re: The Outer Limits
Post by: jack on April 04, 2018, 08:16:03 AM
hi Mike
when I run your cord.exe I get the following warning
Code: [Select]
---------------------------
OGLApp Class Warning
---------------------------
MSAA is not supported on this computer.
Please upgrade your OpenGL video driver.
---------------------------
OK   
---------------------------
also, all I get is a black screen.
tested on a VM with Windows 10 x64
(https://i.imgur.com/P4msoXM.png)
Title: Re: The Outer Limits
Post by: jack on April 04, 2018, 08:35:23 AM
compiled with FB x86 the 640 x 360 view gives about 70 to 80 fps
(https://i.imgur.com/n4RtryR.png)
Title: Re: The Outer Limits
Post by: Mike Lobanovsky on April 04, 2018, 08:58:47 AM
Hi Jack,

The COGLApp class that's the core of FBSL OpenGL renderer applications uses Windows specific routines to initialize window pixel formats and 3D canvases that rely on the native drivers' extended feature sets. They can't always be (and in this particular case aren't) emulated in a virtual machine that would use macOS' (?) own OpenGL driver directly via hardware virtualization.

MSAA stands for multisample anti aliasing, a HW-assisted technique to eliminate edge jaggies and excessive distant texture blur. Evidently your VM somehow fails at emulating this Windows native option.

Once a similar warning is issued by COGLApp, further behavior of the program is undefined.

compiled with FB x86 the 640 x 360 view gives about 70 to 80 fps

That looks nice. The FB thread you gave the links to doesn't seem to show the OpenGL initialization code so I can't tell how platform specific it may be. At any rate, if you can compile it directly on macOS then it should run faster than it would in the VM. Next, your particular GPU may be somewhat stronger than mine, and that could also add a couple dozen FPS to the render speed. Then, my renderer is set (sync'ed with the monitor retrace frequency) to yield 60FPS max to protect the GPU from possible overload. And finally, my FBSL code is executed in interpretative BASIC rather than direct machine code like FB. :)

Can you attach a screenshot of your 640x360 px OpenGL window?
Title: Re: The Outer Limits
Post by: jack on April 04, 2018, 09:28:00 AM
thanks Mike for the explanation, I attached image on previous post. :)
Title: Re: The Outer Limits
Post by: JRS on April 04, 2018, 02:33:02 PM
Quote from: Charles
Any more efficient algorithms?

Perhaps something to do with primes..

Thanks Charles for the opening resolution to the challenge.

I'm thinking there is hidden power in being able to divide equally to the smallest form without brute force or a complex algorithm. Filling shipping containers with odd size boxes would seem to be an application.

The primes direction is an interesting thought.